Skip to content

gpio: remove ToggleableOutputPin, move toggle() to StatefulOutputPin. #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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