diff options
| author | xoviat <[email protected]> | 2021-03-17 20:56:48 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2021-03-17 20:56:48 -0500 |
| commit | 81d99ff1a0ccf8a8f22c93429c6ac30b8de43fe8 (patch) | |
| tree | 12ca44b8872b05c6cf23a3a8876902550a729fe0 | |
| parent | ccf2ea77f08f5ec16bb26aed821a297475b9ae3f (diff) | |
stm32: exti: update api
| -rw-r--r-- | embassy-stm32f4/src/exti.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32l0/src/exti.rs | 31 |
2 files changed, 7 insertions, 26 deletions
diff --git a/embassy-stm32f4/src/exti.rs b/embassy-stm32f4/src/exti.rs index 140b6330c..5c1a89f7b 100644 --- a/embassy-stm32f4/src/exti.rs +++ b/embassy-stm32f4/src/exti.rs | |||
| @@ -22,7 +22,7 @@ pub struct ExtiPin<T: gpio::ExtiPin + WithInterrupt> { | |||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | impl<T: gpio::ExtiPin + WithInterrupt> ExtiPin<T> { | 24 | impl<T: gpio::ExtiPin + WithInterrupt> ExtiPin<T> { |
| 25 | fn new(mut pin: T, interrupt: T::Interrupt) -> Self { | 25 | pub fn new(mut pin: T, interrupt: T::Interrupt) -> Self { |
| 26 | let mut syscfg: SysCfg = unsafe { mem::transmute(()) }; | 26 | let mut syscfg: SysCfg = unsafe { mem::transmute(()) }; |
| 27 | 27 | ||
| 28 | cortex_m::interrupt::free(|_| { | 28 | cortex_m::interrupt::free(|_| { |
diff --git a/embassy-stm32l0/src/exti.rs b/embassy-stm32l0/src/exti.rs index 831fcb2ae..32c56c490 100644 --- a/embassy-stm32l0/src/exti.rs +++ b/embassy-stm32l0/src/exti.rs | |||
| @@ -13,34 +13,16 @@ use crate::hal::{ | |||
| 13 | use crate::interrupt; | 13 | use crate::interrupt; |
| 14 | use crate::pac::EXTI; | 14 | use crate::pac::EXTI; |
| 15 | 15 | ||
| 16 | pub struct ExtiManager { | ||
| 17 | syscfg: SYSCFG, | ||
| 18 | } | ||
| 19 | |||
| 20 | impl<'a> ExtiManager { | ||
| 21 | pub fn new(_exti: Exti, syscfg: SYSCFG) -> Self { | ||
| 22 | Self { syscfg } | ||
| 23 | } | ||
| 24 | |||
| 25 | pub fn new_pin<T>(&'static self, pin: T, interrupt: T::Interrupt) -> ExtiPin<T> | ||
| 26 | where | ||
| 27 | T: PinWithInterrupt, | ||
| 28 | { | ||
| 29 | ExtiPin { | ||
| 30 | pin, | ||
| 31 | interrupt, | ||
| 32 | mgr: self, | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | pub struct ExtiPin<T: PinWithInterrupt> { | 16 | pub struct ExtiPin<T: PinWithInterrupt> { |
| 38 | pin: T, | 17 | pin: T, |
| 39 | interrupt: T::Interrupt, | 18 | interrupt: T::Interrupt, |
| 40 | mgr: &'static ExtiManager, | ||
| 41 | } | 19 | } |
| 42 | 20 | ||
| 43 | impl<T: PinWithInterrupt + 'static> ExtiPin<T> { | 21 | impl<T: PinWithInterrupt + 'static> ExtiPin<T> { |
| 22 | pub fn new(pin: T, interrupt: T::Interrupt) -> ExtiPin<T> { | ||
| 23 | ExtiPin { pin, interrupt } | ||
| 24 | } | ||
| 25 | |||
| 44 | fn wait_for_edge<'a>( | 26 | fn wait_for_edge<'a>( |
| 45 | self: Pin<&'a mut Self>, | 27 | self: Pin<&'a mut Self>, |
| 46 | edge: TriggerEdge, | 28 | edge: TriggerEdge, |
| @@ -57,10 +39,9 @@ impl<T: PinWithInterrupt + 'static> ExtiPin<T> { | |||
| 57 | let fut = InterruptFuture::new(&mut s.interrupt); | 39 | let fut = InterruptFuture::new(&mut s.interrupt); |
| 58 | 40 | ||
| 59 | let port = s.pin.port(); | 41 | let port = s.pin.port(); |
| 60 | let syscfg = &s.mgr.syscfg as *const _ as *mut SYSCFG; | ||
| 61 | cortex_m::interrupt::free(|_| { | 42 | cortex_m::interrupt::free(|_| { |
| 62 | let syscfg = unsafe { &mut *syscfg }; | 43 | let mut syscfg: SYSCFG = unsafe { mem::transmute(()) }; |
| 63 | exti.listen_gpio(syscfg, port, line, edge); | 44 | exti.listen_gpio(&mut syscfg, port, line, edge); |
| 64 | }); | 45 | }); |
| 65 | 46 | ||
| 66 | fut.await; | 47 | fut.await; |
