Skip to content

Commit 62f19f3

Browse files
authored
Add method to get interrupt for an ExtiPin. (#313)
1 parent ed68eab commit 62f19f3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/gpio.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, Toggleable
55
use core::convert::Infallible;
66
use core::marker::PhantomData;
77

8-
use crate::pac::{self, EXTI, SYSCFG};
8+
use crate::pac::{self, Interrupt, EXTI, SYSCFG};
99
use crate::rcc::{Enable, AHB2, APB2};
1010

1111
mod convert;
@@ -96,6 +96,7 @@ pub trait ExtiPin {
9696
fn disable_interrupt(&mut self, exti: &mut EXTI);
9797
fn clear_interrupt_pending_bit(&mut self);
9898
fn check_interrupt(&self) -> bool;
99+
fn interrupt(&self) -> Interrupt;
99100
}
100101

101102
impl<PIN> ExtiPin for PIN
@@ -188,6 +189,20 @@ where
188189
fn check_interrupt(&self) -> bool {
189190
unsafe { ((*EXTI::ptr()).pr1.read().bits() & (1 << self.pin_id())) != 0 }
190191
}
192+
193+
/// Get the `Interrupt` for this pin.
194+
fn interrupt(&self) -> Interrupt {
195+
match self.pin_id() {
196+
0 => Interrupt::EXTI0,
197+
1 => Interrupt::EXTI1,
198+
2 => Interrupt::EXTI2,
199+
3 => Interrupt::EXTI3,
200+
4 => Interrupt::EXTI4,
201+
5..=9 => Interrupt::EXTI9_5,
202+
10..=15 => Interrupt::EXTI15_10,
203+
_ => unreachable!(),
204+
}
205+
}
191206
}
192207

193208
/// Opaque MODER register

0 commit comments

Comments
 (0)