Skip to content

Commit

Permalink
Implement InputPin for Pin<I, DynFunction, P>
Browse files Browse the repository at this point in the history
  • Loading branch information
jannic committed Oct 5, 2024
1 parent 433980f commit cbb617b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions rp2040-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ pub type Error = core::convert::Infallible;
/// GPIO error type for pins with dynamic function
#[derive(Debug)]
pub enum DynPinError {
/// The DynPin is in a state incompatible with the requested function.
IncompatibleFunction,
}

Expand Down Expand Up @@ -1521,15 +1522,15 @@ mod eh1 {
I: PinId,
P: PullType,
{
fn set_low(&mut self) -> Result<(), DynPinError> {
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<(), DynPinError> {
fn set_high(&mut self) -> Result<(), Self::Error> {
match self.function() {
DynFunction::Sio(func::DynSioConfig::Output) => self._set_high(),
_ => return Err(DynPinError::IncompatibleFunction),
Expand All @@ -1538,6 +1539,26 @@ mod eh1 {
}
}

impl<I, P> InputPin for Pin<I, DynFunction, P>
where
I: PinId,
P: PullType,
{
fn is_high(&mut self) -> Result<bool, Self::Error> {
match self.function() {
DynFunction::Sio(func::DynSioConfig::Input) => Ok(self._is_high()),
_ => Err(DynPinError::IncompatibleFunction),
}
}

fn is_low(&mut self) -> Result<bool, Self::Error> {
match self.function() {
DynFunction::Sio(func::DynSioConfig::Input) => Ok(self._is_low()),
_ => Err(DynPinError::IncompatibleFunction),
}
}
}

impl<I, P> StatefulOutputPin for Pin<I, FunctionSio<SioOutput>, P>
where
I: PinId,
Expand Down

0 comments on commit cbb617b

Please sign in to comment.