Skip to content

Commit b811f29

Browse files
David-OConnorteskje
authored andcommitted
Implemented InputPin trait for output pins
1 parent 753d61c commit b811f29

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/gpio.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,20 @@ macro_rules! gpio {
398398
}
399399
}
400400

401+
#[cfg(feature = "unproven")]
402+
impl<MODE> InputPin for $PXx<Output<MODE>> {
403+
type Error = Infallible;
404+
405+
fn is_high(&self) -> Result<bool, Self::Error> {
406+
Ok(!self.is_low()?)
407+
}
408+
409+
fn is_low(&self) -> Result<bool, Self::Error> {
410+
// NOTE(unsafe) atomic read with no side effects
411+
Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 })
412+
}
413+
}
414+
401415
#[cfg(feature = "unproven")]
402416
impl<MODE> InputPin for $PXx<Input<MODE>> {
403417
type Error = Infallible;
@@ -584,6 +598,20 @@ macro_rules! gpio {
584598
}
585599
}
586600

601+
#[cfg(feature = "unproven")]
602+
impl<MODE> InputPin for $PXi<Output<MODE>> {
603+
type Error = Infallible;
604+
605+
fn is_high(&self) -> Result<bool, Self::Error> {
606+
Ok(!self.is_low()?)
607+
}
608+
609+
fn is_low(&self) -> Result<bool, Self::Error> {
610+
// NOTE(unsafe) atomic read with no side effects
611+
Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 })
612+
}
613+
}
614+
587615
#[cfg(feature = "unproven")]
588616
impl<MODE> InputPin for $PXi<Input<MODE>> {
589617
type Error = Infallible;

0 commit comments

Comments
 (0)