stm32/exti: add wait_for_high, wait_for_low.
This commit is contained in:
parent
b526addf7b
commit
ade44e91c4
@ -3,7 +3,9 @@ use core::future::Future;
|
|||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use core::task::{Context, Poll};
|
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::util::Unborrow;
|
||||||
use embassy::waitqueue::AtomicWaker;
|
use embassy::waitqueue::AtomicWaker;
|
||||||
use embassy_hal_common::unsafe_impl_unborrow;
|
use embassy_hal_common::unsafe_impl_unborrow;
|
||||||
@ -103,6 +105,22 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
|
|||||||
self.pin.is_low()
|
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) {
|
pub async fn wait_for_rising_edge<'a>(&'a mut self) {
|
||||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false).await
|
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> {
|
impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> {
|
||||||
type Future<'a>
|
type Future<'a>
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user