Skip to content

Commit

Permalink
gpio: remove ToggleableOutputPin, move toggle() to `StatefulOutpu…
Browse files Browse the repository at this point in the history
…tPin`.
  • Loading branch information
Dirbaio committed Dec 19, 2023
1 parent b327f43 commit c5c076a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 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 yet
- gpio: remove `ToggleableOutputPin`, move `toggle()` to `StatefulOutputPin`.

## [v1.0.0-rc.3] - 2023-12-14

Expand Down
14 changes: 6 additions & 8 deletions embedded-hal/src/digital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ pub trait StatefulOutputPin: OutputPin {
///
/// *NOTE* this does *not* read the electrical state of the pin.
fn is_set_low(&mut self) -> Result<bool, Self::Error>;

/// Toggle pin output.
fn toggle(&mut self) -> Result<(), Self::Error> {
let was_low: bool = self.is_set_low()?;
self.set_state(PinState::from(was_low))
}
}

impl<T: StatefulOutputPin + ?Sized> StatefulOutputPin for &mut T {
Expand All @@ -187,15 +193,7 @@ impl<T: StatefulOutputPin + ?Sized> StatefulOutputPin for &mut T {
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
T::is_set_low(self)
}
}

/// Output pin that can be toggled.
pub trait ToggleableOutputPin: ErrorType {
/// Toggle pin output.
fn toggle(&mut self) -> Result<(), Self::Error>;
}

impl<T: ToggleableOutputPin + ?Sized> ToggleableOutputPin for &mut T {
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
T::toggle(self)
Expand Down

0 comments on commit c5c076a

Please sign in to comment.