Crate microbit_bsp

Source
Expand description

§microbit-bsp

CI crates.io docs.rs

microbit-bsp is a board support package (BSP) library for the BBC micro:bit v2 and newer.

§Features

  • LED display driver with fonts
  • Uses embassy-nrf HAL for peripherals
  • Rust Async/Await

§Example application

#![no_std]
#![no_main]

use {defmt_rtt as _, panic_probe as _};

use microbit_bsp::*;

use {
    embassy_executor::Spawner,
    embassy_futures::select::{select, Either},
    embassy_time::Duration,
};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let board = Microbit::default();

    let mut display = board.display;
    let mut btn_a = board.btn_a;
    let mut btn_b = board.btn_b;

    display.set_brightness(display::Brightness::MAX);
    display.scroll("Hello, World!").await;
    defmt::info!("Application started, press buttons!");
    loop {
        match select(btn_a.wait_for_low(), btn_b.wait_for_low()).await {
            Either::First(_) => {
                display
                    .display(display::fonts::ARROW_LEFT, Duration::from_secs(1))
                    .await;
            }
            Either::Second(_) => {
                display
                    .display(display::fonts::ARROW_RIGHT, Duration::from_secs(1))
                    .await;
            }
        }
    }
}

§Examples

To run an example:

cd examples/display
cargo run --release

Re-exports§

pub use embassy_nrf;
pub use lsm303agr;

Modules§

accelerometer
Accelerometer for the micro:bit
display
Driver a NxM LED matrix display
mic
micrphone peripheral
speaker
Simple speaker utilities for PWM-based synth
wdt
Watchdog Timer (WDT) driver.

Structs§

Config
Configuration for peripherals. Default configuration should work on any nRF chip.
Microbit
Represents all the peripherals and pins available for the BBC micro:bit.

Enums§

Priority
The interrupt priority level.

Type Aliases§

Button
Button ‘A’
LedMatrix
LED matrix peripheral for the micro:bit