From f6be0b8d122ee78565bd03436cba7060f0737747 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 6 Jan 2021 01:10:48 +0100 Subject: [PATCH] Add gpio WaitForFoo traits --- embassy/src/gpio.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++ embassy/src/lib.rs | 1 + 2 files changed, 49 insertions(+) create mode 100644 embassy/src/gpio.rs diff --git a/embassy/src/gpio.rs b/embassy/src/gpio.rs new file mode 100644 index 00000000..4c3feac2 --- /dev/null +++ b/embassy/src/gpio.rs @@ -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 + '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 + '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 + '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 + '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 + '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>; +} diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 02d72a84..4fa37a55 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -8,6 +8,7 @@ pub(crate) mod fmt; pub mod executor; pub mod flash; +pub mod gpio; pub mod interrupt; pub mod io; pub mod rand;