Skip to content

Commit

Permalink
samples: blink: Fix for upstream API changes
Browse files Browse the repository at this point in the history
Several things have become unsafe, so use those in unsafe blocks.
The GPIO driver now has a token that must be passed to each action, to
enforce single threadded use.

Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Dec 11, 2024
1 parent 662affd commit 96f0740
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions samples/blinky/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zephyr::time::{ Duration, sleep };

#[no_mangle]
extern "C" fn rust_main() {
zephyr::set_logger();
unsafe { zephyr::set_logger().unwrap(); }

warn!("Starting blinky");
// println!("Blinky!");
Expand Down Expand Up @@ -52,6 +52,7 @@ 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 @@ -60,10 +61,10 @@ fn do_blink() {
// 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);
}
}
Expand Down

0 comments on commit 96f0740

Please sign in to comment.