Merge pull request #143 from lulf/nrf-port-any-edge

Add detection of edge transitions for ports
This commit is contained in:
Dario Nieuwenhuis 2021-04-20 16:05:50 +02:00 committed by GitHub
commit 0d02e64f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ use core::future::Future;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::task::{Context, Poll}; use core::task::{Context, Poll};
use embassy::interrupt::InterruptExt; use embassy::interrupt::InterruptExt;
use embassy::traits::gpio::{WaitForHigh, WaitForLow}; use embassy::traits::gpio::{WaitForAnyEdge, WaitForHigh, WaitForLow};
use embassy::util::AtomicWaker; use embassy::util::AtomicWaker;
use embassy_extras::impl_unborrow; use embassy_extras::impl_unborrow;
use embedded_hal::digital::v2::{InputPin, StatefulOutputPin}; use embedded_hal::digital::v2::{InputPin, StatefulOutputPin};
@ -340,6 +340,21 @@ impl<'d, T: GpioPin> WaitForLow for PortInput<'d, T> {
} }
} }
impl<'d, T: GpioPin> WaitForAnyEdge for PortInput<'d, T> {
type Future<'a> = PortInputFuture<'a>;
fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> {
if self.is_high().ok().unwrap() {
self.pin.pin.conf().modify(|_, w| w.sense().low());
} else {
self.pin.pin.conf().modify(|_, w| w.sense().high());
}
PortInputFuture {
pin_port: self.pin.pin.pin_port(),
phantom: PhantomData,
}
}
}
pub struct PortInputFuture<'a> { pub struct PortInputFuture<'a> {
pin_port: u8, pin_port: u8,
phantom: PhantomData<&'a mut AnyPin>, phantom: PhantomData<&'a mut AnyPin>,