pybadge-high License: MIT OR Apache-2.0 pybadge-high on crates.io pybadge-high on docs.rs Source Code Repository Rust Version: none

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.

Setup

Installation

bash rustup target install thumbv7em-none-eabihf

rust rustup toolchain install nightly --target thumbv7em-none-eabihf

Create your Project

bash cargo new my-app

```toml [target.thumbv7em-none-eabihf] runner = "hf2 elf"

runner = 'probe-run --chip ATSAMD51J19A'

[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

toml [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

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

![no_std]

![no_main]

use pybadge_high::{prelude::*, PyBadge};

[entry]

fn main() -> ! { let mut pybadge = PyBadge::take().unwrap(); loop {} } ```

When a program does panic, the pybadge starts to peeping for 3 seconds and the red led at the back of the board starts flashing.

Flashing:

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.

Feature-flags

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: