diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-09 20:50:08 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-09 20:50:08 +0000 |
| commit | df17a88448752ba73b25f0d09667888b863190ca (patch) | |
| tree | 6ce2b396d166aea8167a17e3becd6b28e55e5d0d | |
| parent | dee8c71a2d57f3015fde55da28758a35fcbf7ca6 (diff) | |
| parent | 1fbb8f0b321a15fd6b473c466d41fac40302ec3c (diff) | |
Merge #1342
1342: feat(rp): add `Wait` impl to `OutputOpenDrain` r=Dirbaio a=TheLostLambda
A while ago `OutputOpenDrain` was made to implement `InputPin`, something that allowed drivers for various one-wire protocols to be written, but it's been lacking a `Wait` implementation — something that's needed to write async versions of these drivers.
This commit also adds `get_level()` to `OutputOpenDrain`, since `is_high()` and `is_low()` were already implemented, but `get_level()` itself was missing.
Co-authored-by: Brooks J Rady <[email protected]>
| -rw-r--r-- | embassy-rp/src/gpio.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index fb45ef7cf..98e182868 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -437,6 +437,37 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 437 | pub fn is_low(&self) -> bool { | 437 | pub fn is_low(&self) -> bool { |
| 438 | self.pin.is_low() | 438 | self.pin.is_low() |
| 439 | } | 439 | } |
| 440 | |||
| 441 | /// Returns current pin level | ||
| 442 | #[inline] | ||
| 443 | pub fn get_level(&self) -> Level { | ||
| 444 | self.is_high().into() | ||
| 445 | } | ||
| 446 | |||
| 447 | #[inline] | ||
| 448 | pub async fn wait_for_high(&mut self) { | ||
| 449 | self.pin.wait_for_high().await; | ||
| 450 | } | ||
| 451 | |||
| 452 | #[inline] | ||
| 453 | pub async fn wait_for_low(&mut self) { | ||
| 454 | self.pin.wait_for_low().await; | ||
| 455 | } | ||
| 456 | |||
| 457 | #[inline] | ||
| 458 | pub async fn wait_for_rising_edge(&mut self) { | ||
| 459 | self.pin.wait_for_rising_edge().await; | ||
| 460 | } | ||
| 461 | |||
| 462 | #[inline] | ||
| 463 | pub async fn wait_for_falling_edge(&mut self) { | ||
| 464 | self.pin.wait_for_falling_edge().await; | ||
| 465 | } | ||
| 466 | |||
| 467 | #[inline] | ||
| 468 | pub async fn wait_for_any_edge(&mut self) { | ||
| 469 | self.pin.wait_for_any_edge().await; | ||
| 470 | } | ||
| 440 | } | 471 | } |
| 441 | 472 | ||
| 442 | /// GPIO flexible pin. | 473 | /// GPIO flexible pin. |
| @@ -1117,4 +1148,32 @@ mod eh1 { | |||
| 1117 | Ok(()) | 1148 | Ok(()) |
| 1118 | } | 1149 | } |
| 1119 | } | 1150 | } |
| 1151 | |||
| 1152 | #[cfg(feature = "nightly")] | ||
| 1153 | impl<'d, T: Pin> embedded_hal_async::digital::Wait for OutputOpenDrain<'d, T> { | ||
| 1154 | async fn wait_for_high(&mut self) -> Result<(), Self::Error> { | ||
| 1155 | self.wait_for_high().await; | ||
| 1156 | Ok(()) | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | async fn wait_for_low(&mut self) -> Result<(), Self::Error> { | ||
| 1160 | self.wait_for_low().await; | ||
| 1161 | Ok(()) | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { | ||
| 1165 | self.wait_for_rising_edge().await; | ||
| 1166 | Ok(()) | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { | ||
| 1170 | self.wait_for_falling_edge().await; | ||
| 1171 | Ok(()) | ||
| 1172 | } | ||
| 1173 | |||
| 1174 | async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { | ||
| 1175 | self.wait_for_any_edge().await; | ||
| 1176 | Ok(()) | ||
| 1177 | } | ||
| 1178 | } | ||
| 1120 | } | 1179 | } |
