diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-03-14 23:47:56 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-14 23:47:56 +0100 |
| commit | e44079492c9b3eaaf5485e629a366f1fefa2050b (patch) | |
| tree | 609a97ecb84796eb3a2df0dedfd05da3ff2c2e39 | |
| parent | 01587458ce4e2f8c7f8d15e341d051c84911ce16 (diff) | |
| parent | 693177ec27600f71c70f6089ff19d3f6a2a13755 (diff) | |
Merge pull request #74 from michaelbeaumont/deref-stm32f4
embassy-stm32f4: Add embedded_hal::digital::v2::* for ExtiPin
| -rw-r--r-- | embassy-stm32f4/src/exti.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/embassy-stm32f4/src/exti.rs b/embassy-stm32f4/src/exti.rs index 932f29b91..90f3ade39 100644 --- a/embassy-stm32f4/src/exti.rs +++ b/embassy-stm32f4/src/exti.rs | |||
| @@ -10,6 +10,7 @@ use crate::hal::gpio; | |||
| 10 | use crate::hal::gpio::{Edge, ExtiPin as HalExtiPin}; | 10 | use crate::hal::gpio::{Edge, ExtiPin as HalExtiPin}; |
| 11 | use crate::hal::syscfg::SysCfg; | 11 | use crate::hal::syscfg::SysCfg; |
| 12 | use crate::pac::EXTI; | 12 | use crate::pac::EXTI; |
| 13 | use embedded_hal::digital::v2 as digital; | ||
| 13 | 14 | ||
| 14 | use crate::interrupt; | 15 | use crate::interrupt; |
| 15 | 16 | ||
| @@ -42,6 +43,52 @@ pub struct ExtiPin<T: HalExtiPin + WithInterrupt> { | |||
| 42 | _mgr: &'static ExtiManager, | 43 | _mgr: &'static ExtiManager, |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 46 | impl<T: HalExtiPin + WithInterrupt + digital::OutputPin> digital::OutputPin for ExtiPin<T> { | ||
| 47 | type Error = T::Error; | ||
| 48 | |||
| 49 | fn set_low(&mut self) -> Result<(), Self::Error> { | ||
| 50 | self.pin.set_low() | ||
| 51 | } | ||
| 52 | |||
| 53 | fn set_high(&mut self) -> Result<(), Self::Error> { | ||
| 54 | self.pin.set_high() | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | impl<T: HalExtiPin + WithInterrupt + digital::StatefulOutputPin> digital::StatefulOutputPin | ||
| 59 | for ExtiPin<T> | ||
| 60 | { | ||
| 61 | fn is_set_low(&self) -> Result<bool, Self::Error> { | ||
| 62 | self.pin.is_set_low() | ||
| 63 | } | ||
| 64 | |||
| 65 | fn is_set_high(&self) -> Result<bool, Self::Error> { | ||
| 66 | self.pin.is_set_high() | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | impl<T: HalExtiPin + WithInterrupt + digital::ToggleableOutputPin> digital::ToggleableOutputPin | ||
| 71 | for ExtiPin<T> | ||
| 72 | { | ||
| 73 | type Error = T::Error; | ||
| 74 | |||
| 75 | fn toggle(&mut self) -> Result<(), Self::Error> { | ||
| 76 | self.pin.toggle() | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | impl<T: HalExtiPin + WithInterrupt + digital::InputPin> digital::InputPin for ExtiPin<T> { | ||
| 81 | type Error = T::Error; | ||
| 82 | |||
| 83 | fn is_high(&self) -> Result<bool, Self::Error> { | ||
| 84 | self.pin.is_high() | ||
| 85 | } | ||
| 86 | |||
| 87 | fn is_low(&self) -> Result<bool, Self::Error> { | ||
| 88 | self.pin.is_low() | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 45 | /* | 92 | /* |
| 46 | Irq Handler Description | 93 | Irq Handler Description |
| 47 | EXTI0_IRQn EXTI0_IRQHandler Handler for pins connected to line 0 | 94 | EXTI0_IRQn EXTI0_IRQHandler Handler for pins connected to line 0 |
