diff --git a/rp2040-hal/src/gpio/func.rs b/rp2040-hal/src/gpio/func.rs index f988bbb85..40d408b5e 100644 --- a/rp2040-hal/src/gpio/func.rs +++ b/rp2040-hal/src/gpio/func.rs @@ -145,6 +145,7 @@ impl SioConfig for SioOutput { //============================================================================== /// Error type for invalid function conversion. +#[derive(Debug)] pub struct InvalidFunction; /// Marker of valid pin -> function combination. diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index 71a346682..b8e83080b 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -911,6 +911,19 @@ pub struct AsInputPin<'a, I: PinId, F: func::Function, P: PullType>(&'a Pin embedded_hal::digital::ErrorKind { + embedded_hal::digital::ErrorKind::Other + } +} + impl embedded_hal_0_2::digital::v2::OutputPin for Pin, P> where I: PinId, @@ -1464,9 +1477,11 @@ impl embedded_hal_0_2::digital::v2::OutputPin for InOutPin { mod eh1 { use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin}; + use crate::gpio::DynPinError; + use super::{ - func, AnyPin, AsInputPin, Error, FunctionSio, InOutPin, OutputEnableOverride, Pin, PinId, - PullType, SioConfig, SioInput, SioOutput, + func, AnyPin, AsInputPin, DynFunction, Error, FunctionSio, InOutPin, OutputEnableOverride, + Pin, PinId, PullType, SioConfig, SioInput, SioOutput, }; impl ErrorType for Pin, P> @@ -1478,6 +1493,14 @@ mod eh1 { type Error = Error; } + impl ErrorType for Pin + where + I: PinId, + P: PullType, + { + type Error = DynPinError; + } + impl OutputPin for Pin, P> where I: PinId, @@ -1494,6 +1517,48 @@ mod eh1 { } } + impl OutputPin for Pin + where + I: PinId, + P: PullType, + { + fn set_low(&mut self) -> Result<(), Self::Error> { + match self.function() { + DynFunction::Sio(func::DynSioConfig::Output) => self._set_low(), + _ => return Err(DynPinError::IncompatibleFunction), + } + Ok(()) + } + + fn set_high(&mut self) -> Result<(), Self::Error> { + match self.function() { + DynFunction::Sio(func::DynSioConfig::Output) => self._set_high(), + _ => return Err(DynPinError::IncompatibleFunction), + } + Ok(()) + } + } + + impl InputPin for Pin + where + I: PinId, + P: PullType, + { + fn is_high(&mut self) -> Result { + match self.function() { + DynFunction::Sio(func::DynSioConfig::Input) => Ok(self._is_high()), + _ => Err(DynPinError::IncompatibleFunction), + } + } + + fn is_low(&mut self) -> Result { + match self.function() { + DynFunction::Sio(func::DynSioConfig::Input) => Ok(self._is_low()), + _ => Err(DynPinError::IncompatibleFunction), + } + } + } + impl StatefulOutputPin for Pin, P> where I: PinId,