Skip to content

Commit

Permalink
samples: blinky: Use the newly unsafe gpio calls
Browse files Browse the repository at this point in the history
Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Oct 18, 2024
1 parent 595dfc8 commit afd5498
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions samples/blinky/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ extern "C" fn rust_main() {

// fn blink() {
unsafe extern "C" fn blink(_p1: *mut c_void, _p2: *mut c_void, _p3: *mut c_void) {
// Just call a "safe" rust function.
do_blink();
}

fn do_blink() {
warn!("Inside of blinky");

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

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

led0.configure(GPIO_OUTPUT_ACTIVE);
unsafe { led0.configure(&mut gpio_token, GPIO_OUTPUT_ACTIVE); }
let duration = Duration::millis_at_least(500);
loop {
led0.toggle_pin();
unsafe { led0.toggle_pin(&mut gpio_token); }
sleep(duration);
}
}

0 comments on commit afd5498

Please sign in to comment.