diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index b2f168882..af401796c 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -3,7 +3,9 @@ use core::future::Future; use core::marker::PhantomData; use core::pin::Pin; use core::task::{Context, Poll}; -use embassy::traits::gpio::{WaitForAnyEdge, WaitForFallingEdge, WaitForRisingEdge}; +use embassy::traits::gpio::{ + WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge, +}; use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unsafe_impl_unborrow; @@ -103,6 +105,22 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { self.pin.is_low() } + pub async fn wait_for_high<'a>(&'a mut self) { + let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false); + if self.is_high() { + return; + } + fut.await + } + + pub async fn wait_for_low<'a>(&'a mut self) { + let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true); + if self.is_low() { + return; + } + fut.await + } + pub async fn wait_for_rising_edge<'a>(&'a mut self) { ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false).await } @@ -128,6 +146,28 @@ impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> { } } +impl<'d, T: GpioPin> WaitForHigh for ExtiInput<'d, T> { + type Future<'a> + where + Self: 'a, + = impl Future + 'a; + + fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { + self.wait_for_high() + } +} + +impl<'d, T: GpioPin> WaitForLow for ExtiInput<'d, T> { + type Future<'a> + where + Self: 'a, + = impl Future + 'a; + + fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { + self.wait_for_low() + } +} + impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> { type Future<'a> where