Skip to content
This repository was archived by the owner on Jun 6, 2018. It is now read-only.

Commit 7ac7d88

Browse files
committed
Implemented a InputPin for open-drain outputs
This is behind a flag for now, since it's incredibly hacky. Hopefully, rust-embedded/embedded-hal#29 will eventually have a nicer fix.
1 parent 37bbf23 commit 7ac7d88

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords = ["arm", "cortex-m", "stm32", "hal"]
66
license = "MIT OR Apache-2.0"
77
name = "stm32f0x0-hal"
88
repository = "https://github.com/PicoNodes/stm32f0x0-hal"
9-
version = "0.1.2"
9+
version = "0.1.3"
1010

1111
[dependencies]
1212
cortex-m = "0.4.0"
@@ -21,3 +21,4 @@ version = "0.2.2"
2121
[features]
2222
rt = ["stm32f0x0/rt"]
2323
unproven = ["embedded-hal/unproven"]
24+
unproven_opendrain_input = []

src/gpio.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,18 @@ macro_rules! gpio {
497497
}
498498
}
499499

500+
#[cfg(feature = "unproven_opendrain_input")]
501+
impl InputPin for $PXi<Output<OpenDrain>> {
502+
fn is_high(&self) -> bool {
503+
!InputPin::is_low(self)
504+
}
505+
506+
fn is_low(&self) -> bool {
507+
// NOTE(unsafe) atomic read with no side effects
508+
unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 }
509+
}
510+
}
511+
500512
#[cfg(feature = "unproven")]
501513
impl<MODE> InputPin for $PXi<Input<MODE>> {
502514
fn is_high(&self) -> bool {

0 commit comments

Comments
 (0)