From e1133b2937ac4de64e798c851e37d5c5c2fe2228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 28 Aug 2024 15:05:10 +0200 Subject: [PATCH] Provide ehal impls for DummyPin --- esp-hal/CHANGELOG.md | 1 + esp-hal/src/gpio/dummy_pin.rs | 52 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 6addb344224..99013b29369 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -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 diff --git a/esp-hal/src/gpio/dummy_pin.rs b/esp-hal/src/gpio/dummy_pin.rs index 6d919a5d666..c26511af370 100644 --- a/esp-hal/src/gpio/dummy_pin.rs +++ b/esp-hal/src/gpio/dummy_pin.rs @@ -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 { + Ok(OutputPin::is_set_high(self, private::Internal)) + } + fn is_set_low(&self) -> Result { + 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 { + Ok(OutputPin::is_set_high(self, private::Internal)) + } + + fn is_set_low(&mut self) -> Result { + Ok(!OutputPin::is_set_high(self, private::Internal)) + } +}