Skip to content

Commit

Permalink
Provide ehal impls for DummyPin
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 28, 2024
1 parent 99c238d commit e1133b2
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 @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow DMA to/from psram for esp32s3 (#1827)
- Added missing methods to `SpiDmaBus` (#2016).
- PARL_IO use ReadBuffer and WriteBuffer for Async DMA (#1996)
- Implement `embedded-hal` output pin traits for `DummyPin` (#2019)

### 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 e1133b2

Please sign in to comment.