diff --git a/src/gpio.rs b/src/gpio.rs index 88f52c7..89b7f17 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -123,6 +123,21 @@ macro_rules! gpio { } } + impl InputPin for $PXx> { + type Error = Infallible; + + #[inline(always)] + fn is_high(&self) -> Result { + self.is_low().map(|v| !v) + } + + #[inline(always)] + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { (*GPIO::ptr()).in_.read().bits() & (1 << self.i) == 0 }) + } + } + $( /// Pin pub struct $PXi { @@ -159,7 +174,7 @@ macro_rules! gpio { w.dir() .input() .drive() - .s0d1() + .s0s1() .pull() .disabled() .sense() @@ -221,7 +236,7 @@ macro_rules! gpio { w.dir() .output() .drive() - .s0d1() + .s0s1() .pull() .disabled() .sense() @@ -380,6 +395,21 @@ macro_rules! gpio { Ok(unsafe { (*GPIO::ptr()).in_.read().bits() & (1 << $i) == 0 }) } } + + impl InputPin for $PXi> { + type Error = Infallible; + + #[inline(always)] + fn is_high(&self) -> Result { + self.is_low().map(|v| !v) + } + + #[inline(always)] + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { (*GPIO::ptr()).in_.read().bits() & (1 << $i) == 0 }) + } + } )+ impl $PXx {