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..c8b9d2081 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -911,6 +911,18 @@ 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 +1476,10 @@ 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 +1491,15 @@ 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 +1516,28 @@ mod eh1 { } } + impl OutputPin for Pin + where + I: PinId, + P: PullType, + { + fn set_low(&mut self) -> Result<(), DynPinError> { + match self.function() { + DynFunction::Sio(func::DynSioConfig::Output) => self._set_low(), + _ => return Err(DynPinError::IncompatibleFunction), + } + Ok(()) + } + + fn set_high(&mut self) -> Result<(), DynPinError> { + match self.function() { + DynFunction::Sio(func::DynSioConfig::Output) => self._set_high(), + _ => return Err(DynPinError::IncompatibleFunction), + } + Ok(()) + } + } + impl StatefulOutputPin for Pin, P> where I: PinId,