-
Notifications
You must be signed in to change notification settings - Fork 13
Fixes for onewire support #25
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,21 @@ macro_rules! gpio { | |
} | ||
} | ||
|
||
impl InputPin for $PXx<Output<OpenDrain>> { | ||
type Error = Infallible; | ||
|
||
#[inline(always)] | ||
fn is_high(&self) -> Result<bool, Self::Error> { | ||
self.is_low().map(|v| !v) | ||
} | ||
|
||
#[inline(always)] | ||
fn is_low(&self) -> Result<bool, Self::Error> { | ||
// NOTE(unsafe) atomic read with no side effects | ||
Ok(unsafe { (*GPIO::ptr()).in_.read().bits() & (1 << self.i) == 0 }) | ||
} | ||
} | ||
|
||
$( | ||
/// Pin | ||
pub struct $PXi<MODE> { | ||
|
@@ -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<Output<OpenDrain>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is most definitely wrong since all the surrounding code deals with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, treating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
NB: That crate is obsolete... https://github.com/stm32-rs/stm32f1xx-hal is the new player in town. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the discussion was in the old one, but the last commit in the new one does the same: stm32-rs/stm32f1xx-hal@fa26e97 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, I happen to be one of the maintainers of that crate. However STM32F1 is "special" in a lot of regards. |
||
type Error = Infallible; | ||
|
||
#[inline(always)] | ||
fn is_high(&self) -> Result<bool, Self::Error> { | ||
self.is_low().map(|v| !v) | ||
} | ||
|
||
#[inline(always)] | ||
fn is_low(&self) -> Result<bool, Self::Error> { | ||
// NOTE(unsafe) atomic read with no side effects | ||
Ok(unsafe { (*GPIO::ptr()).in_.read().bits() & (1 << $i) == 0 }) | ||
} | ||
} | ||
)+ | ||
|
||
impl<TYPE> $PXx<TYPE> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried about changing the drive mode for existing users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was
s0d1
chosen? Did that work for anyone? Maybe it should be a separate thing, shouldOpenDrain
/etc even touch it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed for I2C operation IIRC.
Obviously.
Well, the main theme here is
Output
. Using something labelled as an output for input is already questionable. How about a separate typestate for OneWire operation, something like Bidirectional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, looking at the SDK
these things don't mention anything about "output" or "input"…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not specific to input vs. output but to the way you're using the pin. https://devzone.nordicsemi.com/f/nordic-q-a/66/gpio-drive-on-nrf51822