Skip to content

Commit

Permalink
Merge pull request #547 from Dirbaio/gpio-mut
Browse files Browse the repository at this point in the history
gpio: require `&mut self` in `InputPin` and `StatefulOutputPin`.
  • Loading branch information
eldruin authored Dec 14, 2023
2 parents 635cf86 + fc2cc4c commit 7479ba9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion embedded-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

No unreleased changes
- gpio: require `&mut self` in `InputPin` and `StatefulOutputPin`.

## [v1.0.0-rc.2] - 2023-11-28

Expand Down
18 changes: 9 additions & 9 deletions embedded-hal/src/digital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ pub trait StatefulOutputPin: OutputPin {
/// Is the pin in drive high mode?
///
/// *NOTE* this does *not* read the electrical state of the pin.
fn is_set_high(&self) -> Result<bool, Self::Error>;
fn is_set_high(&mut self) -> Result<bool, Self::Error>;

/// Is the pin in drive low mode?
///
/// *NOTE* this does *not* read the electrical state of the pin.
fn is_set_low(&self) -> Result<bool, Self::Error>;
fn is_set_low(&mut self) -> Result<bool, Self::Error>;
}

impl<T: StatefulOutputPin + ?Sized> StatefulOutputPin for &mut T {
#[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
T::is_set_high(self)
}

#[inline]
fn is_set_low(&self) -> Result<bool, Self::Error> {
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
T::is_set_low(self)
}
}
Expand All @@ -205,20 +205,20 @@ impl<T: ToggleableOutputPin + ?Sized> ToggleableOutputPin for &mut T {
/// Single digital input pin.
pub trait InputPin: ErrorType {
/// Is the input pin high?
fn is_high(&self) -> Result<bool, Self::Error>;
fn is_high(&mut self) -> Result<bool, Self::Error>;

/// Is the input pin low?
fn is_low(&self) -> Result<bool, Self::Error>;
fn is_low(&mut self) -> Result<bool, Self::Error>;
}

impl<T: InputPin + ?Sized> InputPin for &T {
impl<T: InputPin + ?Sized> InputPin for &mut T {
#[inline]
fn is_high(&self) -> Result<bool, Self::Error> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
T::is_high(self)
}

#[inline]
fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
T::is_low(self)
}
}

0 comments on commit 7479ba9

Please sign in to comment.