diff --git a/src/gpio.rs b/src/gpio.rs index 9268c3dc2..003a1b016 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -205,6 +205,32 @@ macro_rules! gpio { } } + + #[cfg(feature = "unproven")] + impl InputPin for PXx> { + type Error = Infallible; + + fn is_high(&self) -> Result { + Ok(!self.is_low()?) + } + + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { + match &self.gpio { + $( + #[cfg(all(any( + $(feature = $device,)+ + ), not(any( + $(feature = $device_except,)* + ))))] + Gpio::$GPIOX => (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0, + )+ + } + }) + } + } + #[cfg(feature = "unproven")] impl StatefulOutputPin for PXx> { fn is_set_high(&self) -> Result { @@ -397,6 +423,20 @@ macro_rules! gpio { } } + #[cfg(feature = "unproven")] + impl InputPin for $PXx> { + type Error = Infallible; + + fn is_high(&self) -> Result { + Ok(!self.is_low()?) + } + + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 }) + } + } + #[cfg(feature = "unproven")] impl InputPin for $PXx> { type Error = Infallible; @@ -673,6 +713,20 @@ macro_rules! gpio { } } + #[cfg(feature = "unproven")] + impl InputPin for $PXi> { + type Error = Infallible; + + fn is_high(&self) -> Result { + Ok(!self.is_low()?) + } + + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 }) + } + } + #[cfg(feature = "unproven")] impl InputPin for $PXi> { type Error = Infallible;