From 00d8c98ee945f8864b7f1e2635e7db966ab4af05 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Thu, 10 Aug 2023 21:20:44 -0400 Subject: [PATCH] gpio example: check if no gpio or no pins --- examples/gpio.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/examples/gpio.rs b/examples/gpio.rs index 8e9777a4..ee1c73bf 100644 --- a/examples/gpio.rs +++ b/examples/gpio.rs @@ -22,25 +22,22 @@ fn main() { writeln!(Console::writer(), "GPIO[{}]: {:?}", gpio_index, state).unwrap(); }); - match Gpio::count() { - Ok(gpio_count) if gpio_count > 0 => { - // Configure pin 0 as an input and enable rising interrupts - let pin = Gpio::get_pin(0).unwrap(); - let input_pin = pin.make_input::().unwrap(); - let _ = input_pin.enable_interrupts(gpio::PinInterruptEdge::Rising); - - // Wait for callbacks. - share::scope(|subscribe| { - Gpio::register_listener(&listener, subscribe).unwrap(); - - loop { - TockSyscalls::yield_wait(); - } - }); - } + if !Gpio::count().is_ok_and(|c| c > 0) { + writeln!(Console::writer(), "No GPIO pins on this board.").unwrap(); + return; + } + + // Configure pin 0 as an input and enable rising interrupts + let pin = Gpio::get_pin(0).unwrap(); + let input_pin = pin.make_input::().unwrap(); + let _ = input_pin.enable_interrupts(gpio::PinInterruptEdge::Rising); - _ => { - writeln!(Console::writer(), "No GPIO pins on this board.").unwrap(); + // Wait for callbacks. + share::scope(|subscribe| { + Gpio::register_listener(&listener, subscribe).unwrap(); + + loop { + TockSyscalls::yield_wait(); } - } + }); }