nrf/gpiote: remove PortInput, move impls to Input.

This commit is contained in:
Dario Nieuwenhuis
2021-12-14 13:23:40 +01:00
parent ff82c76935
commit 153b1bbdbf
4 changed files with 107 additions and 87 deletions

View File

@ -1,6 +1,7 @@
#![macro_use]
use core::convert::Infallible;
use core::future::Future;
use core::hint::unreachable_unchecked;
use core::marker::PhantomData;
@ -72,6 +73,54 @@ impl<'d, T: Pin> InputPin for Input<'d, T> {
}
}
#[cfg(feature = "gpiote")]
impl<'d, T: Pin> embassy::traits::gpio::WaitForHigh for Input<'d, T> {
#[rustfmt::skip]
type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a;
fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> {
self.pin.conf().modify(|_, w| w.sense().high());
crate::gpiote::PortInputFuture {
pin_port: self.pin.pin_port(),
phantom: PhantomData,
}
}
}
#[cfg(feature = "gpiote")]
impl<'d, T: Pin> embassy::traits::gpio::WaitForLow for Input<'d, T> {
#[rustfmt::skip]
type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a;
fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> {
self.pin.conf().modify(|_, w| w.sense().low());
crate::gpiote::PortInputFuture {
pin_port: self.pin.pin_port(),
phantom: PhantomData,
}
}
}
#[cfg(feature = "gpiote")]
impl<'d, T: Pin> embassy::traits::gpio::WaitForAnyEdge for Input<'d, T> {
#[rustfmt::skip]
type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a;
fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> {
if self.is_high().ok().unwrap() {
self.pin.conf().modify(|_, w| w.sense().low());
} else {
self.pin.conf().modify(|_, w| w.sense().high());
}
crate::gpiote::PortInputFuture {
pin_port: self.pin.pin_port(),
phantom: PhantomData,
}
}
}
/// Digital input or output level.
#[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -277,6 +326,54 @@ impl<'d, T: Pin> StatefulOutputPin for FlexPin<'d, T> {
}
}
#[cfg(feature = "gpiote")]
impl<'d, T: Pin> embassy::traits::gpio::WaitForHigh for FlexPin<'d, T> {
#[rustfmt::skip]
type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a;
fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> {
self.pin.conf().modify(|_, w| w.sense().high());
crate::gpiote::PortInputFuture {
pin_port: self.pin.pin_port(),
phantom: PhantomData,
}
}
}
#[cfg(feature = "gpiote")]
impl<'d, T: Pin> embassy::traits::gpio::WaitForLow for FlexPin<'d, T> {
#[rustfmt::skip]
type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a;
fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> {
self.pin.conf().modify(|_, w| w.sense().low());
crate::gpiote::PortInputFuture {
pin_port: self.pin.pin_port(),
phantom: PhantomData,
}
}
}
#[cfg(feature = "gpiote")]
impl<'d, T: Pin> embassy::traits::gpio::WaitForAnyEdge for FlexPin<'d, T> {
#[rustfmt::skip]
type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a;
fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> {
if self.is_high().ok().unwrap() {
self.pin.conf().modify(|_, w| w.sense().low());
} else {
self.pin.conf().modify(|_, w| w.sense().high());
}
crate::gpiote::PortInputFuture {
pin_port: self.pin.pin_port(),
phantom: PhantomData,
}
}
}
pub(crate) mod sealed {
use super::*;