Initial Setup for the microbit v1

This commit is contained in:
2024-10-11 20:01:36 +02:00
commit e70e2b2104
37 changed files with 22320 additions and 0 deletions

13
examples/bitfield.rs Normal file
View File

@@ -0,0 +1,13 @@
#![no_main]
#![no_std]
use template_microbit as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
// value of the FREQUENCY register (nRF52840 device; RADIO peripheral)
let frequency: u32 = 276;
defmt::info!("FREQUENCY: {0=0..7}, MAP: {0=8..9}", frequency);
template_microbit::exit()
}

29
examples/format.rs Normal file
View File

@@ -0,0 +1,29 @@
#![no_main]
#![no_std]
use template_microbit as _; // global logger + panicking-behavior + memory layout
use defmt::Format; // <- derive attribute
#[derive(Format)]
struct S1<T> {
x: u8,
y: T,
}
#[derive(Format)]
struct S2 {
z: u8,
}
#[cortex_m_rt::entry]
fn main() -> ! {
let s = S1 {
x: 42,
y: S2 { z: 43 },
};
defmt::println!("s={:?}", s);
let x = 42;
defmt::println!("x={=u8}", x);
template_microbit::exit()
}

18
examples/hello.rs Normal file
View File

@@ -0,0 +1,18 @@
#![no_main]
#![no_std]
// global logger + panicking-behavior + memory layout
use microbit::board::Board;
use microbit::hal::gpio::Level::High;
#[cortex_m_rt::entry]
fn main() -> ! {
let board = Board::take().unwrap();
board.display_pins.col1.into_pulldown_input();
board.display_pins.row1.into_push_pull_output(High);
defmt::println!("Hello, world! freq ", );
template_microbit::exit()
}

20
examples/levels.rs Normal file
View File

@@ -0,0 +1,20 @@
#![no_main]
#![no_std]
use template_microbit as _;
use template_microbit::exit;
// global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
// try setting the DEFMT_LOG environment variable
// e.g. `export DEFMT_LOG=info` or `DEFMT_LOG=trace cargo rb levels`
defmt::info!("info");
defmt::trace!("trace");
defmt::warn!("warn");
defmt::debug!("debug");
defmt::error!("error");
exit();
template_microbit::exit()
}

28
examples/overflow.rs Normal file
View File

@@ -0,0 +1,28 @@
#![no_main]
#![no_std]
use template_microbit as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
ack(10, 10);
template_microbit::exit()
}
fn ack(m: u32, n: u32) -> u32 {
// waste stack space to trigger a stack overflow
let mut buffer = [0u8; 16 * 1024];
// estimate of the Stack Pointer register
let sp = buffer.as_mut_ptr();
defmt::println!("ack(m={=u32}, n={=u32}, SP={:x})", m, n, sp);
if m == 0 {
n + 1
} else {
if n == 0 {
ack(m - 1, 1)
} else {
ack(m - 1, ack(m, n - 1))
}
}
}

11
examples/panic.rs Normal file
View File

@@ -0,0 +1,11 @@
#![no_main]
#![no_std]
use template_microbit as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
defmt::println!("main");
defmt::panic!()
}