Add gpio WaitForFoo traits

This commit is contained in:
Dario Nieuwenhuis 2021-01-06 01:10:48 +01:00
parent 9bb4c97dc2
commit f6be0b8d12
2 changed files with 49 additions and 0 deletions

48
embassy/src/gpio.rs Normal file
View File

@ -0,0 +1,48 @@
use core::future::Future;
use core::pin::Pin;
/// Wait for a pin to become high.
pub trait WaitForHigh {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a pin to become high.
///
/// If the pin is already high, the future completes immediately.
/// Otherwise, it completes when it becomes high.
fn wait_for_high<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for a pin to become low.
pub trait WaitForLow {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a pin to become low.
///
/// If the pin is already low, the future completes immediately.
/// Otherwise, it completes when it becomes low.
fn wait_for_low<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for a rising edge (transition from low to high)
pub trait WaitForRisingEdge {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a rising edge (transition from low to high)
fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for a falling edge (transition from high to low)
pub trait WaitForFallingEdge {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a falling edge (transition from high to low)
fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for any edge (any transition, high to low or low to high)
pub trait WaitForAnyEdge {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for any edge (any transition, high to low or low to high)
fn wait_for_any_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}

View File

@ -8,6 +8,7 @@ pub(crate) mod fmt;
pub mod executor; pub mod executor;
pub mod flash; pub mod flash;
pub mod gpio;
pub mod interrupt; pub mod interrupt;
pub mod io; pub mod io;
pub mod rand; pub mod rand;