From 693177ec27600f71c70f6089ff19d3f6a2a13755 Mon Sep 17 00:00:00 2001 From: Michael Beaumont Date: Sun, 14 Mar 2021 23:28:29 +0100 Subject: [PATCH] Add embedded_hal::digital::v2::* for ExtiPin --- embassy-stm32f4/src/exti.rs | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/embassy-stm32f4/src/exti.rs b/embassy-stm32f4/src/exti.rs index 52cf5a294..d9a68daf7 100644 --- a/embassy-stm32f4/src/exti.rs +++ b/embassy-stm32f4/src/exti.rs @@ -10,6 +10,7 @@ use crate::hal::gpio; use crate::hal::gpio::{Edge, ExtiPin as HalExtiPin}; use crate::hal::syscfg::SysCfg; use crate::pac::EXTI; +use embedded_hal::digital::v2 as digital; use crate::interrupt; @@ -42,6 +43,52 @@ pub struct ExtiPin { _mgr: &'static ExtiManager, } +impl digital::OutputPin for ExtiPin { + type Error = T::Error; + + fn set_low(&mut self) -> Result<(), Self::Error> { + self.pin.set_low() + } + + fn set_high(&mut self) -> Result<(), Self::Error> { + self.pin.set_high() + } +} + +impl digital::StatefulOutputPin + for ExtiPin +{ + fn is_set_low(&self) -> Result { + self.pin.is_set_low() + } + + fn is_set_high(&self) -> Result { + self.pin.is_set_high() + } +} + +impl digital::ToggleableOutputPin + for ExtiPin +{ + type Error = T::Error; + + fn toggle(&mut self) -> Result<(), Self::Error> { + self.pin.toggle() + } +} + +impl digital::InputPin for ExtiPin { + type Error = T::Error; + + fn is_high(&self) -> Result { + self.pin.is_high() + } + + fn is_low(&self) -> Result { + self.pin.is_low() + } +} + /* Irq Handler Description EXTI0_IRQn EXTI0_IRQHandler Handler for pins connected to line 0