Skip to content

Commit c21287a

Browse files
bugadaniMabezDev
andauthored
Provide ehal impls for DummyPin (#2019)
Co-authored-by: Scott Mabin <[email protected]>
1 parent 671003a commit c21287a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

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

1415
### Changed

esp-hal/src/gpio/dummy_pin.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,55 @@ impl InputPin for DummyPin {
132132

133133
fn disconnect_input_from_peripheral(&mut self, _signal: InputSignal, _: private::Internal) {}
134134
}
135+
136+
#[cfg(feature = "embedded-hal-02")]
137+
impl embedded_hal_02::digital::v2::OutputPin for DummyPin {
138+
type Error = core::convert::Infallible;
139+
140+
fn set_high(&mut self) -> Result<(), Self::Error> {
141+
self.set_output_high(true, private::Internal);
142+
Ok(())
143+
}
144+
fn set_low(&mut self) -> Result<(), Self::Error> {
145+
self.set_output_high(false, private::Internal);
146+
Ok(())
147+
}
148+
}
149+
#[cfg(feature = "embedded-hal-02")]
150+
impl embedded_hal_02::digital::v2::StatefulOutputPin for DummyPin {
151+
fn is_set_high(&self) -> Result<bool, Self::Error> {
152+
Ok(OutputPin::is_set_high(self, private::Internal))
153+
}
154+
fn is_set_low(&self) -> Result<bool, Self::Error> {
155+
Ok(!OutputPin::is_set_high(self, private::Internal))
156+
}
157+
}
158+
159+
#[cfg(feature = "embedded-hal")]
160+
impl embedded_hal::digital::ErrorType for DummyPin {
161+
type Error = core::convert::Infallible;
162+
}
163+
164+
#[cfg(feature = "embedded-hal")]
165+
impl embedded_hal::digital::OutputPin for DummyPin {
166+
fn set_low(&mut self) -> Result<(), Self::Error> {
167+
self.set_output_high(true, private::Internal);
168+
Ok(())
169+
}
170+
171+
fn set_high(&mut self) -> Result<(), Self::Error> {
172+
self.set_output_high(false, private::Internal);
173+
Ok(())
174+
}
175+
}
176+
177+
#[cfg(feature = "embedded-hal")]
178+
impl embedded_hal::digital::StatefulOutputPin for DummyPin {
179+
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
180+
Ok(OutputPin::is_set_high(self, private::Internal))
181+
}
182+
183+
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
184+
Ok(!OutputPin::is_set_high(self, private::Internal))
185+
}
186+
}

0 commit comments

Comments
 (0)