on-off-sequence-output

Crates.ioon-off-sequence-output
lib.rson-off-sequence-output
version0.2.0
sourcesrc
created_at2021-05-30 07:16:36.779365
updated_at2021-06-03 08:00:26.770575
descriptionSends a sequence of on/off states to a GPIO Pin
homepagehttps://github.com/almedso/on-off-sequence-output
repositoryhttps://github.com/almedso/on-off-sequence-output
max_upload_size
id403761
size46,613
Volker Kempert (volker-kempert)

documentation

https://docs.rs/on-off-sequence-output

README

on-off-sequence-output

Build Status Crate Docs

A platform-agnostic library that provides output of a sequence of on/off states e.g. on an LED.

Installation

Add this to your Cargo.toml:

[dependencies]
on-off-sequence-output = "0.1"

Usage

This is a library crate and should work with any led that implements 'embedded_hal' trait 'OutputPin' on any cortex-m MCU.

The source could look like ...

use on_off_sequence_output::prelude::*;

// This is up to the implementation details of the embedded_hal you are using.
let led_pin: OutputPin = hal_function_which_returns_output_pin();

const UPDATE_SCALE: u16 = 500;
let mut led = OnOffSequenceOutput::new(led_pin, UPDATE_SCALE);

let output_states = 0b10011101;
let number_of_output_states = 8;
led.set(output_states, number_of_output_states, Repeat::Never)
loop {
   if led.update().unwrap() { break; };
   wait(1.ms());
}

led.set(0b010, 3, Repeat::Times(2)).unwrap();
loop {
   if led.update().unwrap() { break; };
   wait(1.ms());
}

// some morse code output is possible as well
ledout.set_morse("RUST IS GOOD  ", Repeat::Forever).unwrap();
loop {
   led.update().unwrap();
   wait(1.ms());
}

The examples folder contains a working example named show-led-output. The cargo tooling (.cargo, memory.x, openocd.cfg ..) is prepared for an STM NUCLEO F401RE evaluation board.

If you have that board avaliable run

cargo build --target thumbv7em-none-eabihf --example show-led-output
openocd-flash.sh target/thumbv7em-none-eabihf/release/examples/show-led-output

alternatively you can use use cargo-flash tool.

cargo flash --chip stm32f401re --example show-rust-is-good --target thumbv7em-none-eabihf

Since this is a library, there is no toolchain configured for build in .cargo/config.

Testing

Testing is done via unit tests on host only. Run

cargo test --lib --tests

... to exclude examples because they do not compile on host

License

This project is licensed under

Commit count: 13

cargo fmt