stm32/exti: add wait_for_high, wait_for_low.
This commit is contained in:
parent
b526addf7b
commit
ade44e91c4
1 changed files with 41 additions and 1 deletions
|
@ -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<Output = ()> + '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<Output = ()> + '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
|
||||
|
|
Loading…
Reference in a new issue