From 71e46d7efdcf903a1493f02ef03d1376fc6bc6df Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 3 May 2022 00:44:27 +0200 Subject: [PATCH] stm32/gpio: add EH1.0 trait impls. --- embassy-stm32/src/gpio.rs | 101 +++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 1ac6f395..30f90031 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -3,7 +3,6 @@ use core::convert::Infallible; use core::marker::PhantomData; use embassy::util::Unborrow; use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; -use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; use crate::pac; use crate::pac::gpio::{self, vals}; @@ -605,6 +604,9 @@ pub(crate) unsafe fn init() { mod eh02 { use super::*; + use embedded_hal_02::digital::v2::{ + InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, + }; impl<'d, T: Pin> InputPin for Input<'d, T> { type Error = Infallible; @@ -691,6 +693,103 @@ mod eh02 { } } +#[cfg(feature = "unstable-traits")] +mod eh1 { + use super::*; + use embedded_hal_1::digital::blocking::{ + InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, + }; + use embedded_hal_1::digital::ErrorType; + + impl<'d, T: Pin> ErrorType for Input<'d, T> { + type Error = Infallible; + } + + impl<'d, T: Pin> InputPin for Input<'d, T> { + #[inline] + fn is_high(&self) -> Result { + Ok(self.is_high()) + } + + #[inline] + fn is_low(&self) -> Result { + Ok(self.is_low()) + } + } + + impl<'d, T: Pin> ErrorType for Output<'d, T> { + type Error = Infallible; + } + + impl<'d, T: Pin> OutputPin for Output<'d, T> { + #[inline] + fn set_high(&mut self) -> Result<(), Self::Error> { + Ok(self.set_high()) + } + + #[inline] + fn set_low(&mut self) -> Result<(), Self::Error> { + Ok(self.set_low()) + } + } + + impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> { + #[inline] + fn is_set_high(&self) -> Result { + Ok(self.is_set_high()) + } + + /// Is the output pin set as low? + #[inline] + fn is_set_low(&self) -> Result { + Ok(self.is_set_low()) + } + } + + impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> { + #[inline] + fn toggle(&mut self) -> Result<(), Self::Error> { + Ok(self.toggle()) + } + } + + impl<'d, T: Pin> ErrorType for OutputOpenDrain<'d, T> { + type Error = Infallible; + } + + impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> { + #[inline] + fn set_high(&mut self) -> Result<(), Self::Error> { + Ok(self.set_high()) + } + + #[inline] + fn set_low(&mut self) -> Result<(), Self::Error> { + Ok(self.set_low()) + } + } + + impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> { + #[inline] + fn is_set_high(&self) -> Result { + Ok(self.is_set_high()) + } + + /// Is the output pin set as low? + #[inline] + fn is_set_low(&self) -> Result { + Ok(self.is_set_low()) + } + } + + impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> { + #[inline] + fn toggle(&mut self) -> Result<(), Self::Error> { + Ok(self.toggle()) + } + } +} + #[cfg(feature = "unstable-pac")] pub mod low_level { pub use super::sealed::*;