diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 8a3e8a1b..abda909f 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -350,17 +350,13 @@ pub(crate) mod sealed { /// Set the output as high. #[inline] fn set_high(&self) { - unsafe { - self.block().outset.write(|w| w.bits(1u32 << self._pin())); - } + unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) } } /// Set the output as low. #[inline] fn set_low(&self) { - unsafe { - self.block().outclr.write(|w| w.bits(1u32 << self._pin())); - } + unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) } } } diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 8e7af266..f1104904 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -342,78 +342,60 @@ impl<'a> Future for PortInputFuture<'a> { } } -impl<'d, T: GpioPin> embassy::traits::gpio::WaitForHigh for Input<'d, T> { - type Future<'a> - where - Self: 'a, - = impl Future + Unpin + 'a; +impl<'d, T: GpioPin> Input<'d, T> { + pub async fn wait_for_high(&mut self) { + self.pin.wait_for_high().await + } - fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { - self.pin.wait_for_high() + pub async fn wait_for_low(&mut self) { + self.pin.wait_for_low().await + } + + pub async fn wait_for_rising_edge(&mut self) { + self.pin.wait_for_rising_edge().await + } + + pub async fn wait_for_falling_edge(&mut self) { + self.pin.wait_for_falling_edge().await + } + + pub async fn wait_for_any_edge(&mut self) { + self.pin.wait_for_any_edge().await } } -impl<'d, T: GpioPin> embassy::traits::gpio::WaitForLow for Input<'d, T> { - type Future<'a> - where - Self: 'a, - = impl Future + Unpin + 'a; - - fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { - self.pin.wait_for_low() - } -} - -impl<'d, T: GpioPin> embassy::traits::gpio::WaitForAnyEdge for Input<'d, T> { - type Future<'a> - where - Self: 'a, - = impl Future + Unpin + 'a; - - fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { - self.pin.wait_for_any_edge() - } -} - -impl<'d, T: GpioPin> embassy::traits::gpio::WaitForHigh for Flex<'d, T> { - type Future<'a> - where - Self: 'a, - = impl Future + Unpin + 'a; - - fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { +impl<'d, T: GpioPin> Flex<'d, T> { + pub async fn wait_for_high(&mut self) { self.pin.conf().modify(|_, w| w.sense().high()); PortInputFuture { pin_port: self.pin.pin_port(), phantom: PhantomData, } + .await } -} -impl<'d, T: GpioPin> embassy::traits::gpio::WaitForLow for Flex<'d, T> { - type Future<'a> - where - Self: 'a, - = impl Future + Unpin + 'a; - - fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { + pub async fn wait_for_low(&mut self) { self.pin.conf().modify(|_, w| w.sense().low()); PortInputFuture { pin_port: self.pin.pin_port(), phantom: PhantomData, } + .await } -} -impl<'d, T: GpioPin> embassy::traits::gpio::WaitForAnyEdge for Flex<'d, T> { - type Future<'a> - where - Self: 'a, - = impl Future + Unpin + 'a; + pub async fn wait_for_rising_edge(&mut self) { + self.wait_for_low().await; + self.wait_for_high().await; + } - fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { + pub async fn wait_for_falling_edge(&mut self) { + self.wait_for_high().await; + self.wait_for_low().await; + } + + pub async fn wait_for_any_edge(&mut self) { if self.is_high() { self.pin.conf().modify(|_, w| w.sense().low()); } else { @@ -423,6 +405,7 @@ impl<'d, T: GpioPin> embassy::traits::gpio::WaitForAnyEdge for Flex<'d, T> { pin_port: self.pin.pin_port(), phantom: PhantomData, } + .await } } diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs index 76c861d9..3ea9a6e6 100644 --- a/examples/nrf/src/bin/gpiote_port.rs +++ b/examples/nrf/src/bin/gpiote_port.rs @@ -6,7 +6,6 @@ mod example_common; use embassy::executor::Spawner; -use embassy::traits::gpio::{WaitForHigh, WaitForLow}; use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; use embassy_nrf::Peripherals; use example_common::*; diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs index 78c2205d..cc199be9 100644 --- a/examples/nrf/src/bin/wdt.rs +++ b/examples/nrf/src/bin/wdt.rs @@ -10,7 +10,6 @@ use embassy::executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::wdt::{Config, Watchdog}; use embassy_nrf::Peripherals; -use embassy_traits::gpio::{WaitForHigh, WaitForLow}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) {