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 <b.j.rady@gmail.com>
This commit is contained in:
		| @@ -437,6 +437,37 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||||||
|     pub fn is_low(&self) -> bool { |     pub fn is_low(&self) -> bool { | ||||||
|         self.pin.is_low() |         self.pin.is_low() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Returns current pin level | ||||||
|  |     #[inline] | ||||||
|  |     pub fn get_level(&self) -> Level { | ||||||
|  |         self.is_high().into() | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[inline] | ||||||
|  |     pub async fn wait_for_high(&mut self) { | ||||||
|  |         self.pin.wait_for_high().await; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[inline] | ||||||
|  |     pub async fn wait_for_low(&mut self) { | ||||||
|  |         self.pin.wait_for_low().await; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[inline] | ||||||
|  |     pub async fn wait_for_rising_edge(&mut self) { | ||||||
|  |         self.pin.wait_for_rising_edge().await; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[inline] | ||||||
|  |     pub async fn wait_for_falling_edge(&mut self) { | ||||||
|  |         self.pin.wait_for_falling_edge().await; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[inline] | ||||||
|  |     pub async fn wait_for_any_edge(&mut self) { | ||||||
|  |         self.pin.wait_for_any_edge().await; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /// GPIO flexible pin. | /// GPIO flexible pin. | ||||||
| @@ -1117,4 +1148,32 @@ mod eh1 { | |||||||
|             Ok(()) |             Ok(()) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     #[cfg(feature = "nightly")] | ||||||
|  |     impl<'d, T: Pin> embedded_hal_async::digital::Wait for OutputOpenDrain<'d, T> { | ||||||
|  |         async fn wait_for_high(&mut self) -> Result<(), Self::Error> { | ||||||
|  |             self.wait_for_high().await; | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         async fn wait_for_low(&mut self) -> Result<(), Self::Error> { | ||||||
|  |             self.wait_for_low().await; | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { | ||||||
|  |             self.wait_for_rising_edge().await; | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { | ||||||
|  |             self.wait_for_falling_edge().await; | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { | ||||||
|  |             self.wait_for_any_edge().await; | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user