Skip to content

Commit 09db1f3

Browse files
author
Henrik Alsér
committed
Add check if event has been triggered
1 parent 7ef80f7 commit 09db1f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

examples/gpiote-demo/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ const APP: () = {
8888

8989
#[task(binds = GPIOTE, resources = [gpiote], schedule = [debounce])]
9090
fn on_gpiote(ctx: on_gpiote::Context) {
91+
if ctx.resources.gpiote.channel0().is_event_triggered() {
92+
rprintln!("Interrupt from channel 0 event");
93+
}
94+
if ctx.resources.gpiote.port().is_event_triggered() {
95+
rprintln!("Interrupt from port event");
96+
}
9197
// Reset all events
9298
ctx.resources.gpiote.reset_events();
9399
// Debounce

nrf-hal-common/src/gpiote.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ impl<'a> GpioteChannel<'_> {
107107
}
108108
}
109109

110+
pub fn is_event_triggered(&self) -> bool {
111+
self.gpiote.events_in[self.channel].read().bits() != 0
112+
}
113+
110114
pub fn reset_events(&self) {
111115
self.gpiote.events_in[self.channel].write(|w| w);
112116
}
@@ -164,6 +168,9 @@ impl<'a> GpiotePort<'_> {
164168
// Disable port interrupt
165169
self.gpiote.intenclr.write(|w| w.port().set_bit());
166170
}
171+
pub fn is_event_triggered(&self) -> bool {
172+
self.gpiote.events_port.read().bits() != 0
173+
}
167174
pub fn reset_events(&self) {
168175
// Mark port events as handled
169176
self.gpiote.events_port.write(|w| w);

0 commit comments

Comments
 (0)