Goal of this crate is to provide high level hardware abstraction layer for the pybade and the edgebadge. It should allow people with no/less knowledge of rust and embedded hardware, to program the boards mention before. If you try to do anything hardware-near or usinig additonal expensions, you should probably use the more hardware-near the edgebadge or atsamd_hal crate instead.
bash
rustup target install thumbv7em-none-eabihf
rust
rustup toolchain install nightly --target thumbv7em-none-eabihf
bash
cargo new my-app
.cargo/config.toml
with the following content, to define target architecture and flasher```toml [target.thumbv7em-none-eabihf] runner = "hf2 elf"
[build] target = "thumbv7em-none-eabihf" rustflags = [
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 "-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x", ] ```
bash
cargo add pybadge-high
cargo.toml
for better optimizationstoml
[profile.release]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
main.rs
You need to do some changes at your main.rs
. First you must disable the rust standart libary by adding #![no_std]
, because it is not supported by the pybadge. This does also mean you can not use the default main function any more and must disable it with #![no_main]
. But because we still need a main function to enter the code we need to define our own main with #[entry]
. This main function does never return (!
). Otherwise the pybadge would do random stuff after the program has finish. So we need a endless loop. To get access to the peripherals of the pybadge, like display, buttons, leds etc you call PyBadge::take()
. This function can only called once at runtime otherwise it will return an Error.
```rust
use pybadge_high::{prelude::*, PyBadge};
fn main() -> ! { let mut pybadge = PyBadge::take().unwrap(); loop {} } ```
When a program does panic, the red led at the back of the board starts flashing. If the bluescreen
(default) feature is enable, the display does show the postion of the error. When the beep_panic
feature is enable, the pybadge also beep for 3 seconds.
To flash you program, put your device in bootloader mode by hitting the reset button twice. After this excute
bash
cargo run --release
The display does not work until you have press the reset button of the pybadge after flashing.
This crate has spilt functionallity in multiple feature flags. See the rust book for more information about features. Enabling only the feauters, which are needed, helps to keep the binary size small and reduce the number of needed dependencies.
The following features are aviable:
beep_panic
— beep for 3 seconds, when rust pancics
bluescreen
(enabled by default) — show a bluescreen with error postion, when rust pancics
neopixel
— support for the Neopixel below the screen
usb
— support for serial communication over usb
pwm_sound
— support for single frequenc sound
time
(enabled by default) — support for time measurement