Skip to content

Commit

Permalink
Re-added v1 feature flag in Cargo.toml and updated src/main.rs for co…
Browse files Browse the repository at this point in the history
…mpatibility
  • Loading branch information
A-Young-Git committed Oct 27, 2024
1 parent 9a53970 commit 7ae76a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
13 changes: 12 additions & 1 deletion microbit/src/07-uart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ version = "0.1.0"
authors = ["Henrik Böving <hargonix@gmail.com>"]
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"
Expand All @@ -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"]
1 change: 1 addition & 0 deletions microbit/src/07-uart/Embed.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 25 additions & 3 deletions microbit/src/07-uart/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
#![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]
fn main() -> ! {
rtt_init_print!();
let board = microbit::Board::take().unwrap();

#[cfg(feature = "v1")]
let mut serial = {
let serial = uarte::Uarte::new(
board.UARTE0,
Expand All @@ -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 {}
Expand Down

0 comments on commit 7ae76a0

Please sign in to comment.