Skip to content

Commit 813ca7a

Browse files
committed
Introduce embedded-hal, and refactor to use the OuputPin trait as before
The microbit crate apparently don't reexport the hal's OutputPin trail, there for add embedded-hal as a dependency.
1 parent c0889bf commit 813ca7a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

microbit/src/05-led-roulette/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ optional = true
1515
[dependencies]
1616
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
1717
cortex-m-rt = "0.7.3"
18+
embedded-hal = "1.0.0"
1819
panic-halt = "0.2.0"
1920
# rtt-target = "0.5.0"
2021
# panic-rtt-target = "0.1.3"

microbit/src/05-led-roulette/light-it-up.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ In this chapter we are going to make one of the many LEDs on the back of the mic
55
basically the "Hello World" of embedded programming. In order to get this task done we will use one of the traits
66
provided by `embedded-hal`, specifically the [`OutputPin`] trait which allows us to turn a pin on or off.
77

8-
[`OutputPin`]: https://docs.rs/embedded-hal/0.2.6/embedded_hal/digital/v2/trait.OutputPin.html
8+
[`OutputPin`]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/digital/trait.OutputPin.html
99

1010
## The micro:bit LEDs
1111

@@ -37,18 +37,16 @@ a look at it and then we can go through it step by step:
3737
#![no_std]
3838

3939
use cortex_m_rt::entry;
40+
use embedded_hal::digital::OutputPin;
4041
use panic_halt as _;
41-
use microbit::{
42-
board::Board,
43-
hal::gpio::Level,
44-
};
42+
use microbit::board::Board,
4543

4644
#[entry]
4745
fn main() -> ! {
48-
let board = Board::take().unwrap();
46+
let mut board = Board::take().unwrap();
4947

50-
board.display_pins.col1.into_push_pull_output(Level::Low);
51-
board.display_pins.row1.into_push_pull_output(Level::High);
48+
board.display_pins.col1.set_low().unwrap();
49+
board.display_pins.row1.set_high().unwrap();
5250

5351
loop {}
5452
}
@@ -59,7 +57,7 @@ However, the main function looks pretty different to what we have seen up to now
5957

6058
The first line is related to how most HALs written in Rust work internally.
6159
As discussed before they are built on top of PAC crates which own (in the Rust sense)
62-
all the peripherals of a chip. `let board = Board::take().unwrap();` basically takes all
60+
all the peripherals of a chip. `let mut board = Board::take().unwrap();` basically takes all
6361
these peripherals from the PAC and binds them to a variable. In this specific case we are
6462
not only working with a HAL but with an entire BSP, so this also takes ownership
6563
of the Rust representation of the other chips on the board.

0 commit comments

Comments
 (0)