Skip to content

Commit

Permalink
Cleanup InputPin impls for OutputPins
Browse files Browse the repository at this point in the history
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 (stm32-rs#42)
 - Makes rustfmt happy
  • Loading branch information
teskje committed Jul 17, 2020
1 parent cad110e commit fa02c5d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ macro_rules! gpio {
}
}


#[cfg(feature = "unproven")]
impl<MODE> InputPin for PXx<Output<MODE>> {
impl InputPin for PXx<Output<OpenDrain>> {
type Error = Infallible;

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

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXx<Output<MODE>> {
impl<MODE> InputPin for $PXx<Input<MODE>> {
type Error = Infallible;

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

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXx<Input<MODE>> {
impl InputPin for $PXx<Output<OpenDrain>> {
type Error = Infallible;

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

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXi<Output<MODE>> {
impl<MODE> InputPin for $PXi<Input<MODE>> {
type Error = Infallible;

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

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

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXi<Input<MODE>> {
impl InputPin for $PXi<Output<OpenDrain>> {
type Error = Infallible;

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

0 comments on commit fa02c5d

Please sign in to comment.