Skip to content

Commit 2b1be69

Browse files
Merge #177
177: Add check_interrupt method for GPIO pins r=therealprof a=mvirkkunen This is needed to properly use pins where the interrupt vector is shared between multiple pins. Copied and pasted from stm32f1xx-hal, except that I changed the method to `&self` as opposed to `&mut self` because that makes more sense for a getter. Personally I'd prefer a single method that both checks and clears the interrupt bit in one operation and returns if it was set, but I'm not sure if that has issues in some use cases. This way the user gets to decide. Co-authored-by: Matti Virkkunen <[email protected]>
2 parents a327cb9 + 9a488ec commit 2b1be69

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515

1616
- Reexport PAC as `pac` for consistency with other crates, consider `stm32` virtually deprecated
1717
- Added external interrupt (EXTI) support for output pins
18+
- Added `check_interrupt` method for GPIO pins
1819

1920
## [v0.8.3] - 2020-06-12
2021

src/gpio.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub trait ExtiPin {
9090
fn enable_interrupt(&mut self, exti: &mut EXTI);
9191
fn disable_interrupt(&mut self, exti: &mut EXTI);
9292
fn clear_interrupt_pending_bit(&mut self);
93+
fn check_interrupt(&self) -> bool;
9394
}
9495

9596
macro_rules! exti_erased {
@@ -163,6 +164,11 @@ macro_rules! exti_erased {
163164
fn clear_interrupt_pending_bit(&mut self) {
164165
unsafe { (*EXTI::ptr()).pr.write(|w| w.bits(1 << self.i)) };
165166
}
167+
168+
/// Reads the interrupt pending bit for this pin
169+
fn check_interrupt(&self) -> bool {
170+
unsafe { ((*EXTI::ptr()).pr.read().bits() & (1 << self.i)) != 0 }
171+
}
166172
}
167173
};
168174
}
@@ -220,6 +226,11 @@ macro_rules! exti {
220226
fn clear_interrupt_pending_bit(&mut self) {
221227
unsafe { (*EXTI::ptr()).pr.write(|w| w.bits(1 << $i)) };
222228
}
229+
230+
/// Reads the interrupt pending bit for this pin
231+
fn check_interrupt(&self) -> bool {
232+
unsafe { ((*EXTI::ptr()).pr.read().bits() & (1 << $i)) != 0 }
233+
}
223234
}
224235
};
225236
}

0 commit comments

Comments
 (0)