diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-01-06 01:10:48 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-01-06 01:10:48 +0100 |
| commit | f6be0b8d122ee78565bd03436cba7060f0737747 (patch) | |
| tree | 94530fc2fc8c6e8ce08f2ffa0eef90d688e85fb5 | |
| parent | 9bb4c97dc2167331df97288b014085f6c22c23c8 (diff) | |
Add gpio WaitForFoo traits
| -rw-r--r-- | embassy/src/gpio.rs | 48 | ||||
| -rw-r--r-- | embassy/src/lib.rs | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/embassy/src/gpio.rs b/embassy/src/gpio.rs new file mode 100644 index 000000000..4c3feac21 --- /dev/null +++ b/embassy/src/gpio.rs | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | use core::future::Future; | ||
| 2 | use core::pin::Pin; | ||
| 3 | |||
| 4 | /// Wait for a pin to become high. | ||
| 5 | pub trait WaitForHigh { | ||
| 6 | type Future<'a>: Future<Output = ()> + 'a; | ||
| 7 | |||
| 8 | /// Wait for a pin to become high. | ||
| 9 | /// | ||
| 10 | /// If the pin is already high, the future completes immediately. | ||
| 11 | /// Otherwise, it completes when it becomes high. | ||
| 12 | fn wait_for_high<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>; | ||
| 13 | } | ||
| 14 | |||
| 15 | /// Wait for a pin to become low. | ||
| 16 | pub trait WaitForLow { | ||
| 17 | type Future<'a>: Future<Output = ()> + 'a; | ||
| 18 | |||
| 19 | /// Wait for a pin to become low. | ||
| 20 | /// | ||
| 21 | /// If the pin is already low, the future completes immediately. | ||
| 22 | /// Otherwise, it completes when it becomes low. | ||
| 23 | fn wait_for_low<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>; | ||
| 24 | } | ||
| 25 | |||
| 26 | /// Wait for a rising edge (transition from low to high) | ||
| 27 | pub trait WaitForRisingEdge { | ||
| 28 | type Future<'a>: Future<Output = ()> + 'a; | ||
| 29 | |||
| 30 | /// Wait for a rising edge (transition from low to high) | ||
| 31 | fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>; | ||
| 32 | } | ||
| 33 | |||
| 34 | /// Wait for a falling edge (transition from high to low) | ||
| 35 | pub trait WaitForFallingEdge { | ||
| 36 | type Future<'a>: Future<Output = ()> + 'a; | ||
| 37 | |||
| 38 | /// Wait for a falling edge (transition from high to low) | ||
| 39 | fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>; | ||
| 40 | } | ||
| 41 | |||
| 42 | /// Wait for any edge (any transition, high to low or low to high) | ||
| 43 | pub trait WaitForAnyEdge { | ||
| 44 | type Future<'a>: Future<Output = ()> + 'a; | ||
| 45 | |||
| 46 | /// Wait for any edge (any transition, high to low or low to high) | ||
| 47 | fn wait_for_any_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>; | ||
| 48 | } | ||
diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 02d72a84f..4fa37a55c 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs | |||
| @@ -8,6 +8,7 @@ pub(crate) mod fmt; | |||
| 8 | 8 | ||
| 9 | pub mod executor; | 9 | pub mod executor; |
| 10 | pub mod flash; | 10 | pub mod flash; |
| 11 | pub mod gpio; | ||
| 11 | pub mod interrupt; | 12 | pub mod interrupt; |
| 12 | pub mod io; | 13 | pub mod io; |
| 13 | pub mod rand; | 14 | pub mod rand; |
