Skip to content

Commit

Permalink
Provide ehal impls for DummyPin (#2019)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Mabin <[email protected]>
  • Loading branch information
bugadani and MabezDev authored Sep 2, 2024
1 parent 671003a commit c21287a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Implement `embedded-hal` output pin traits for `DummyPin` (#2019)
- Added `esp_hal::init` to simplify HAL initialisation (#1970)

### Changed
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))
}
}

0 comments on commit c21287a

Please sign in to comment.