Skip to content

Commit afd5498

Browse files
committed
samples: blinky: Use the newly unsafe gpio calls
Signed-off-by: David Brown <[email protected]>
1 parent 595dfc8 commit afd5498

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

samples/blinky/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ extern "C" fn rust_main() {
3737

3838
// fn blink() {
3939
unsafe extern "C" fn blink(_p1: *mut c_void, _p2: *mut c_void, _p3: *mut c_void) {
40+
// Just call a "safe" rust function.
41+
do_blink();
42+
}
43+
44+
fn do_blink() {
4045
warn!("Inside of blinky");
4146

4247
let mut led0 = zephyr::devicetree::aliases::led0::get_instance().unwrap();
48+
let mut gpio_token = unsafe { zephyr::device::gpio::GpioToken::get_instance().unwrap() };
4349

4450
if !led0.is_ready() {
4551
warn!("LED is not ready");
@@ -48,10 +54,10 @@ unsafe extern "C" fn blink(_p1: *mut c_void, _p2: *mut c_void, _p3: *mut c_void)
4854
// return;
4955
}
5056

51-
led0.configure(GPIO_OUTPUT_ACTIVE);
57+
unsafe { led0.configure(&mut gpio_token, GPIO_OUTPUT_ACTIVE); }
5258
let duration = Duration::millis_at_least(500);
5359
loop {
54-
led0.toggle_pin();
60+
unsafe { led0.toggle_pin(&mut gpio_token); }
5561
sleep(duration);
5662
}
5763
}

0 commit comments

Comments
 (0)