From c7acafda3c6fd4d91990f76753bf211820a82038 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:14:20 +1000 Subject: [PATCH] GPIO IRQ example: add check for interrupt source (#401) --- rp2040-hal/examples/gpio_irq_example.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/rp2040-hal/examples/gpio_irq_example.rs b/rp2040-hal/examples/gpio_irq_example.rs index e5a84fd..3365857 100644 --- a/rp2040-hal/examples/gpio_irq_example.rs +++ b/rp2040-hal/examples/gpio_irq_example.rs @@ -174,14 +174,17 @@ fn IO_IRQ_BANK0() { // these will be of type `&mut LedPin` and `&mut ButtonPin`, so we don't have // to move them back into the static after we use them let (led, button) = gpios; + // Check if the interrupt source is from the pushbutton going from high-to-low. + // Note: this will always be true in this example, as that is the only enabled GPIO interrupt source + if button.interrupt_status(EdgeLow) { + // toggle can't fail, but the embedded-hal traits always allow for it + // we can discard the return value by assigning it to an unnamed variable + let _ = led.toggle(); - // toggle can't fail, but the embedded-hal traits always allow for it - // we can discard the return value by assigning it to an unnamed variable - let _ = led.toggle(); - - // Our interrupt doesn't clear itself. - // Do that now so we don't immediately jump back to this interrupt handler. - button.clear_interrupt(EdgeLow); + // Our interrupt doesn't clear itself. + // Do that now so we don't immediately jump back to this interrupt handler. + button.clear_interrupt(EdgeLow); + } } }