Skip to content

Commit

Permalink
Expose InputPin.is_interrupt_set in implementation of esp-hal::gpio::… (
Browse files Browse the repository at this point in the history
#1839)

* Expose InputPin.is_interrupt_set in implementation of esp-hal::gpio::Input

* Move entry in changelog from changed to added
  • Loading branch information
BMCG0011 authored Jul 23, 2024
1 parent 426c8fb commit 5d6354c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputPin>` for use in interrupt handlers (#1829)

### Fixed

Expand Down
6 changes: 6 additions & 0 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions examples/src/bin/gpio_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5d6354c

Please sign in to comment.