diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index df465d84cf3..9a2d23ea431 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - uart: Make `rx_timeout` optional in Config struct (#1759) - Add interrupt related functions to `PeriodicTimer`/`OneShotTimer`, added `ErasedTimer` (#1753) - Added blocking `read_bytes` method to `Uart` and `UartRx` (#1784) +- Add method to expose `InputPin::is_interrupt_set` in `Input` for use in interrupt handlers (#1829) ### Fixed diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 4f1deff0c73..a605027753c 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -1727,6 +1727,12 @@ where self.pin.clear_interrupt(private::Internal); } + /// Checks if the interrupt status bit for this Pin is set + #[inline] + pub fn is_interrupt_set(&self) -> bool { + self.pin.is_interrupt_set(private::Internal) + } + /// Enable as a wake-up source. /// /// This will unlisten for interrupts diff --git a/examples/src/bin/gpio_interrupt.rs b/examples/src/bin/gpio_interrupt.rs index aa51b43d30f..a4f0cfad313 100644 --- a/examples/src/bin/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -73,6 +73,18 @@ fn handler() { #[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] esp_println::println!("GPIO Interrupt"); + if critical_section::with(|cs| { + BUTTON + .borrow_ref_mut(cs) + .as_mut() + .unwrap() + .is_interrupt_set() + }) { + esp_println::println!("Button was the source of the interrupt"); + } else { + esp_println::println!("Button was not the source of the interrupt"); + } + critical_section::with(|cs| { BUTTON .borrow_ref_mut(cs)