aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-01-14 22:22:38 +0100
committerDario Nieuwenhuis <[email protected]>2022-01-19 17:59:55 +0100
commitade44e91c47364b40d015f2f0d438866d8af0fd4 (patch)
treef792f01320fec2baf09d18643dcfb891ab61ad67
parentb526addf7b98a9c3612f2299184592dad3cd74f7 (diff)
stm32/exti: add wait_for_high, wait_for_low.
-rw-r--r--embassy-stm32/src/exti.rs42
1 files changed, 41 insertions, 1 deletions
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index b2f168882..af401796c 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -3,7 +3,9 @@ use core::future::Future;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::pin::Pin; 4use core::pin::Pin;
5use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
6use embassy::traits::gpio::{WaitForAnyEdge, WaitForFallingEdge, WaitForRisingEdge}; 6use embassy::traits::gpio::{
7 WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge,
8};
7use embassy::util::Unborrow; 9use embassy::util::Unborrow;
8use embassy::waitqueue::AtomicWaker; 10use embassy::waitqueue::AtomicWaker;
9use embassy_hal_common::unsafe_impl_unborrow; 11use embassy_hal_common::unsafe_impl_unborrow;
@@ -103,6 +105,22 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
103 self.pin.is_low() 105 self.pin.is_low()
104 } 106 }
105 107
108 pub async fn wait_for_high<'a>(&'a mut self) {
109 let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false);
110 if self.is_high() {
111 return;
112 }
113 fut.await
114 }
115
116 pub async fn wait_for_low<'a>(&'a mut self) {
117 let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true);
118 if self.is_low() {
119 return;
120 }
121 fut.await
122 }
123
106 pub async fn wait_for_rising_edge<'a>(&'a mut self) { 124 pub async fn wait_for_rising_edge<'a>(&'a mut self) {
107 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false).await 125 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false).await
108 } 126 }
@@ -128,6 +146,28 @@ impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> {
128 } 146 }
129} 147}
130 148
149impl<'d, T: GpioPin> WaitForHigh for ExtiInput<'d, T> {
150 type Future<'a>
151 where
152 Self: 'a,
153 = impl Future<Output = ()> + 'a;
154
155 fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> {
156 self.wait_for_high()
157 }
158}
159
160impl<'d, T: GpioPin> WaitForLow for ExtiInput<'d, T> {
161 type Future<'a>
162 where
163 Self: 'a,
164 = impl Future<Output = ()> + 'a;
165
166 fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> {
167 self.wait_for_low()
168 }
169}
170
131impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> { 171impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> {
132 type Future<'a> 172 type Future<'a>
133 where 173 where