#led #embedded-hal #gpio-pin #send #morse-code

no-std on-off-sequence-output

Sends a sequence of on/off states to a GPIO Pin

3 unstable releases

0.2.0 Jun 3, 2021
0.1.1 May 30, 2021
0.1.0 May 30, 2021

#1478 in Embedded development

22 downloads per month

MIT license

33KB
639 lines

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

Dependencies

~71KB