Skip to content
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

Provide ehal impls for DummyPin #2019

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Implement `embedded-hal` output pin traits for `DummyPin` (#2019)

### Changed

### Fixed
Expand Down
52 changes: 52 additions & 0 deletions esp-hal/src/gpio/dummy_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,55 @@ impl InputPin for DummyPin {

fn disconnect_input_from_peripheral(&mut self, _signal: InputSignal, _: private::Internal) {}
}

#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::digital::v2::OutputPin for DummyPin {
type Error = core::convert::Infallible;

fn set_high(&mut self) -> Result<(), Self::Error> {
self.set_output_high(true, private::Internal);
Ok(())
}
fn set_low(&mut self) -> Result<(), Self::Error> {
self.set_output_high(false, private::Internal);
Ok(())
}
}
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::digital::v2::StatefulOutputPin for DummyPin {
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(OutputPin::is_set_high(self, private::Internal))
}
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(!OutputPin::is_set_high(self, private::Internal))
}
}

#[cfg(feature = "embedded-hal")]
impl embedded_hal::digital::ErrorType for DummyPin {
type Error = core::convert::Infallible;
}

#[cfg(feature = "embedded-hal")]
impl embedded_hal::digital::OutputPin for DummyPin {
fn set_low(&mut self) -> Result<(), Self::Error> {
self.set_output_high(true, private::Internal);
Ok(())
}

fn set_high(&mut self) -> Result<(), Self::Error> {
self.set_output_high(false, private::Internal);
Ok(())
}
}

#[cfg(feature = "embedded-hal")]
impl embedded_hal::digital::StatefulOutputPin for DummyPin {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(OutputPin::is_set_high(self, private::Internal))
}

fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(!OutputPin::is_set_high(self, private::Internal))
}
}