diff options
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index ead3c47d3..fbd8c093c 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -3,7 +3,7 @@ use core::future::Future; | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | use embassy::interrupt::InterruptExt; | 5 | use embassy::interrupt::InterruptExt; |
| 6 | use embassy::traits::gpio::{WaitForHigh, WaitForLow}; | 6 | use embassy::traits::gpio::{WaitForAnyEdge, WaitForHigh, WaitForLow}; |
| 7 | use embassy::util::AtomicWaker; | 7 | use embassy::util::AtomicWaker; |
| 8 | use embassy_extras::impl_unborrow; | 8 | use embassy_extras::impl_unborrow; |
| 9 | use embedded_hal::digital::v2::{InputPin, StatefulOutputPin}; | 9 | use embedded_hal::digital::v2::{InputPin, StatefulOutputPin}; |
| @@ -340,6 +340,21 @@ impl<'d, T: GpioPin> WaitForLow for PortInput<'d, T> { | |||
| 340 | } | 340 | } |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | impl<'d, T: GpioPin> WaitForAnyEdge for PortInput<'d, T> { | ||
| 344 | type Future<'a> = PortInputFuture<'a>; | ||
| 345 | fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 346 | if self.is_high().ok().unwrap() { | ||
| 347 | self.pin.pin.conf().modify(|_, w| w.sense().low()); | ||
| 348 | } else { | ||
| 349 | self.pin.pin.conf().modify(|_, w| w.sense().high()); | ||
| 350 | } | ||
| 351 | PortInputFuture { | ||
| 352 | pin_port: self.pin.pin.pin_port(), | ||
| 353 | phantom: PhantomData, | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 343 | pub struct PortInputFuture<'a> { | 358 | pub struct PortInputFuture<'a> { |
| 344 | pin_port: u8, | 359 | pin_port: u8, |
| 345 | phantom: PhantomData<&'a mut AnyPin>, | 360 | phantom: PhantomData<&'a mut AnyPin>, |
