Skip to content

Commit

Permalink
initial port of microbit to embassy
Browse files Browse the repository at this point in the history
* Update v2 microbit
* Update display blocking/nonblocking examples
  • Loading branch information
lulf committed Feb 15, 2024
1 parent c7fbd9a commit 7d42f4a
Show file tree
Hide file tree
Showing 19 changed files with 408 additions and 543 deletions.
25 changes: 6 additions & 19 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@ xtask = "run --package xtask --"
# For micro:bit v1.x

[target.thumbv6m-none-eabi]
runner = 'probe-run --chip nRF51822_xxAA'
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
]
runner = 'probe-rs run --chip nRF51822_xxAA'

# For micro:bit v2

[target.thumbv7em-none-eabi]
runner = "probe-run --chip nRF52833_xxAA"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
]
runner = "probe-rs run --chip nRF52833_xxAA"

[target.thumbv7em-none-eabihf]
runner = "probe-run --chip nRF52833_xxAA"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
]
runner = "probe-rs run --chip nRF52833_xxAA"

[env]
DEFMT_LOG = "trace"
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ members = [
"examples/*",
"xtask",
]
resolver = "2"

[profile.release]
debug = 2

[patch.crates-io]
embassy-nrf = { path = "../embassy/embassy-nrf" }
embassy-time = { path = "../embassy/embassy-time" }
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ fn main() {
// Only re-run the build script when memory.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}
16 changes: 2 additions & 14 deletions examples/analog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ edition = "2018"
cortex-m = { version = "0.7.3", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
defmt-rtt = "0.3.2"
defmt = "0.3.1"
defmt-rtt = "0.4"
defmt = "0.3"

[dependencies.microbit]
path = "../../microbit"
Expand All @@ -23,15 +23,3 @@ optional = true
[features]
v1 = ["microbit"]
v2 = ["microbit-v2"]

default = [
"defmt-default",
]

# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
18 changes: 4 additions & 14 deletions examples/display-blocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ edition = "2018"
[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
panic-probe = { version = "0.3.1", features = ["print-defmt"] }
defmt-rtt = "0.4"
defmt = "0.3.1"
defmt = "0.3"

embedded-hal = "1.0"

[dependencies.microbit]
path = "../../microbit"
Expand All @@ -21,15 +23,3 @@ optional = true
[features]
v1 = ["microbit"]
v2 = ["microbit-v2"]

default = [
"defmt-default",
]

# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
130 changes: 62 additions & 68 deletions examples/display-blocking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,79 @@
#![no_main]

use defmt_rtt as _;
use panic_halt as _;
use panic_probe as _;

use cortex_m_rt::entry;

use microbit::{
board::Board,
display::blocking::Display,
hal::{prelude::*, Timer},
};
use embedded_hal::delay::DelayNs;
use microbit::{board::Board, display::blocking::Display, time::Delay};

#[entry]
fn main() -> ! {
if let Some(board) = Board::take() {
let mut timer = Timer::new(board.TIMER0);
let mut display = Display::new(board.display_pins);
let board = Board::default();
let mut display = Display::new(board.display_pins);

#[allow(non_snake_case)]
let letter_I = [
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
];
#[allow(non_snake_case)]
let letter_I = [
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
];

let heart = [
[0, 1, 0, 1, 0],
[1, 0, 1, 0, 1],
[1, 0, 0, 0, 1],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
];
let heart = [
[0, 1, 0, 1, 0],
[1, 0, 1, 0, 1],
[1, 0, 0, 0, 1],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
];

#[allow(non_snake_case)]
let letter_R = [
[0, 1, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 1, 0, 1, 0],
];
#[allow(non_snake_case)]
let letter_R = [
[0, 1, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 1, 0, 1, 0],
];

#[allow(non_snake_case)]
let letter_u = [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 1, 0, 1, 0],
[0, 1, 0, 1, 0],
[0, 1, 1, 1, 0],
];
#[allow(non_snake_case)]
let letter_u = [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 1, 0, 1, 0],
[0, 1, 0, 1, 0],
[0, 1, 1, 1, 0],
];

#[allow(non_snake_case)]
let letter_s = [
[0, 0, 0, 0, 0],
[0, 0, 1, 1, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
];
#[allow(non_snake_case)]
let letter_s = [
[0, 0, 0, 0, 0],
[0, 0, 1, 1, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
];

#[allow(non_snake_case)]
let letter_t = [
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
];
loop {
display.show(&mut timer, letter_I, 1000);
display.show(&mut timer, heart, 1000);
display.show(&mut timer, letter_R, 1000);
display.show(&mut timer, letter_u, 1000);
display.show(&mut timer, letter_s, 1000);
display.show(&mut timer, letter_t, 1000);
display.clear();
timer.delay_ms(250_u32);
}
#[allow(non_snake_case)]
let letter_t = [
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
];
let mut timer = Delay;
loop {
display.show(&mut timer, letter_I, 1000);
display.show(&mut timer, heart, 1000);
display.show(&mut timer, letter_R, 1000);
display.show(&mut timer, letter_u, 1000);
display.show(&mut timer, letter_s, 1000);
display.show(&mut timer, letter_t, 1000);
display.clear();
timer.delay_ms(250_u32);
}

panic!("End");
}
14 changes: 1 addition & 13 deletions examples/display-nonblocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cortex-m = { version = "0.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
defmt-rtt = "0.4"
defmt = "0.3.1"
defmt = "0.3"

[dependencies.microbit]
path = "../../microbit"
Expand All @@ -21,15 +21,3 @@ optional = true
[features]
v1 = ["microbit"]
v2 = ["microbit-v2"]

default = [
"defmt-default",
]

# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
Loading

0 comments on commit 7d42f4a

Please sign in to comment.