diff --git a/microbit/src/07-uart/Cargo.toml b/microbit/src/07-uart/Cargo.toml index adb153b6..03ea9c6f 100644 --- a/microbit/src/07-uart/Cargo.toml +++ b/microbit/src/07-uart/Cargo.toml @@ -4,8 +4,15 @@ version = "0.1.0" authors = ["Henrik Böving "] edition = "2018" +[dependencies.microbit-v2] +version = "0.15.1" +optional = true + +[dependencies.microbit] +version = "0.15.1" +optional = true + [dependencies] -microbit-v2 = "0.15.1" cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" rtt-target = "0.5.0" @@ -15,3 +22,7 @@ heapless = "0.8.0" embedded-hal = "1.0.0" embedded-hal-nb = "1.0.0" embedded-io = "0.6.1" + +[features] +v2 = ["microbit-v2"] +v1 = ["microbit"] \ No newline at end of file diff --git a/microbit/src/07-uart/Embed.toml b/microbit/src/07-uart/Embed.toml index 25598358..b2535bd9 100644 --- a/microbit/src/07-uart/Embed.toml +++ b/microbit/src/07-uart/Embed.toml @@ -1,5 +1,6 @@ [default.general] chip = "nrf52833_xxAA" # uncomment this line for micro:bit V2 +# chip = "nrf51822_xxAA" # uncomment this line for micro:bit V1 [default.reset] halt_afterwards = false diff --git a/microbit/src/07-uart/src/main.rs b/microbit/src/07-uart/src/main.rs index 9c02e760..8be62be5 100644 --- a/microbit/src/07-uart/src/main.rs +++ b/microbit/src/07-uart/src/main.rs @@ -1,18 +1,29 @@ #![no_main] #![no_std] -use core::fmt::Write; use cortex_m_rt::entry; use panic_rtt_target as _; use rtt_target::rtt_init_print; +#[cfg(feature = "v1")] use microbit::{ + hal::prelude::*, + hal::uart, + hal::uart::{Baudrate, Parity}, +}; + +#[cfg(feature = "v2")] +use microbit::{ + hal::prelude::*, hal::uarte, hal::uarte::{Baudrate, Parity}, }; -use embedded_hal_nb::serial::Write as _; +#[cfg(feature = "v2")] +use embedded_hal_nb::serial::Write; +#[cfg(feature = "v2")] mod serial_setup; +#[cfg(feature = "v2")] use serial_setup::UartePort; #[entry] @@ -20,6 +31,7 @@ fn main() -> ! { rtt_init_print!(); let board = microbit::Board::take().unwrap(); + #[cfg(feature = "v1")] let mut serial = { let serial = uarte::Uarte::new( board.UARTE0, @@ -30,8 +42,18 @@ fn main() -> ! { UartePort::new(serial) }; - write!(serial, "The quick brown fox jumps over the lazy dog.\r\n").unwrap(); + #[cfg(feature = "v2")] + let mut serial = { + let serial = uarte::Uarte::new( + board.UARTE0, + board.uart.into(), + Parity::EXCLUDED, + Baudrate::BAUD115200, + ); + UartePort::new(serial) + }; + nb::block!(serial.write(b'X')).unwrap(); nb::block!(serial.flush()).unwrap(); loop {}