From 5d6354ccbd62527452968074c4a92a4fc6c6a635 Mon Sep 17 00:00:00 2001 From: BMCG0011 <161685058+BMCG0011@users.noreply.github.com> Date: Wed, 24 Jul 2024 05:47:59 +1000 Subject: [PATCH] =?UTF-8?q?Expose=20InputPin.is=5Finterrupt=5Fset=20in=20i?= =?UTF-8?q?mplementation=20of=20esp-hal::gpio::=E2=80=A6=20(#1839)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Expose InputPin.is_interrupt_set in implementation of esp-hal::gpio::Input * Move entry in changelog from changed to added --- esp-hal/CHANGELOG.md | 1 + esp-hal/src/gpio/mod.rs | 6 ++++++ examples/src/bin/gpio_interrupt.rs | 12 ++++++++++++ 3 files changed, 19 insertions(+) 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)