Skip to content

Commit fa02c5d

Browse files
committed
Cleanup InputPin impls for OutputPins
This commit: - Makes the order of InputPin impls consistent - Impls InputPin only for Output<OpenDrain>, not the generic Output<MODE> - Adjusts the register access in accordance with the recently merged GPIO refactoring (#42) - Makes rustfmt happy
1 parent cad110e commit fa02c5d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/gpio.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,8 @@ macro_rules! gpio {
206206
}
207207
}
208208

209-
210209
#[cfg(feature = "unproven")]
211-
impl<MODE> InputPin for PXx<Output<MODE>> {
210+
impl InputPin for PXx<Output<OpenDrain>> {
212211
type Error = Infallible;
213212

214213
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -425,7 +424,7 @@ macro_rules! gpio {
425424
}
426425

427426
#[cfg(feature = "unproven")]
428-
impl<MODE> InputPin for $PXx<Output<MODE>> {
427+
impl<MODE> InputPin for $PXx<Input<MODE>> {
429428
type Error = Infallible;
430429

431430
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -439,7 +438,7 @@ macro_rules! gpio {
439438
}
440439

441440
#[cfg(feature = "unproven")]
442-
impl<MODE> InputPin for $PXx<Input<MODE>> {
441+
impl InputPin for $PXx<Output<OpenDrain>> {
443442
type Error = Infallible;
444443

445444
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -625,7 +624,7 @@ macro_rules! gpio {
625624
}
626625

627626
#[cfg(feature = "unproven")]
628-
impl<MODE> InputPin for $PXi<Output<MODE>> {
627+
impl<MODE> InputPin for $PXi<Input<MODE>> {
629628
type Error = Infallible;
630629

631630
fn is_high(&self) -> Result<bool, Self::Error> {
@@ -634,12 +633,12 @@ macro_rules! gpio {
634633

635634
fn is_low(&self) -> Result<bool, Self::Error> {
636635
// NOTE(unsafe) atomic read with no side effects
637-
Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 })
636+
Ok(unsafe { (*$GPIOX::ptr()).idr.read().$idri().is_low()})
638637
}
639638
}
640639

641640
#[cfg(feature = "unproven")]
642-
impl<MODE> InputPin for $PXi<Input<MODE>> {
641+
impl InputPin for $PXi<Output<OpenDrain>> {
643642
type Error = Infallible;
644643

645644
fn is_high(&self) -> Result<bool, Self::Error> {

0 commit comments

Comments
 (0)