From 8b1ffb2cb7bd2e0c0f50eefb2391c15ae3050e73 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 14 Apr 2021 16:25:54 +0200 Subject: Remove Pin from GPIO traits --- embassy-stm32/src/exti.rs | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'embassy-stm32/src') diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 8d70defe6..9a12f8115 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -1,6 +1,5 @@ use core::future::Future; use core::mem; -use core::pin::Pin; use cortex_m; use crate::hal::gpio; @@ -96,13 +95,10 @@ impl digital::InputPin for ExtiPin { } impl ExtiPin { - fn wait_for_state<'a>(self: Pin<&'a mut Self>, state: bool) -> impl Future + 'a { - let s = unsafe { self.get_unchecked_mut() }; - - s.pin.clear_pending_bit(); + fn wait_for_state<'a>(&'a mut self, state: bool) -> impl Future + 'a { async move { - let fut = InterruptFuture::new(&mut s.interrupt); - let pin = &mut s.pin; + let fut = InterruptFuture::new(&mut self.interrupt); + let pin = &mut self.pin; cortex_m::interrupt::free(|_| { pin.trigger_edge(if state { EdgeOption::Rising @@ -111,37 +107,32 @@ impl ExtiPin { }); }); - if (state && s.pin.is_high().unwrap_or(false)) - || (!state && s.pin.is_low().unwrap_or(false)) + if (state && self.pin.is_high().unwrap_or(false)) + || (!state && self.pin.is_low().unwrap_or(false)) { return; } fut.await; - s.pin.clear_pending_bit(); + self.pin.clear_pending_bit(); } } } impl ExtiPin { - fn wait_for_edge<'a>( - self: Pin<&'a mut Self>, - state: EdgeOption, - ) -> impl Future + 'a { - let s = unsafe { self.get_unchecked_mut() }; - - s.pin.clear_pending_bit(); + fn wait_for_edge<'a>(&'a mut self, state: EdgeOption) -> impl Future + 'a { + self.pin.clear_pending_bit(); async move { - let fut = InterruptFuture::new(&mut s.interrupt); - let pin = &mut s.pin; + let fut = InterruptFuture::new(&mut self.interrupt); + let pin = &mut self.pin; cortex_m::interrupt::free(|_| { pin.trigger_edge(state); }); fut.await; - s.pin.clear_pending_bit(); + self.pin.clear_pending_bit(); } } } @@ -149,7 +140,7 @@ impl ExtiPin { impl WaitForHigh for ExtiPin { type Future<'a> = impl Future + 'a; - fn wait_for_high<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { + fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { self.wait_for_state(true) } } @@ -157,7 +148,7 @@ impl WaitForHigh for ExtiPin { impl WaitForLow for ExtiPin { type Future<'a> = impl Future + 'a; - fn wait_for_low<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { + fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { self.wait_for_state(false) } } @@ -176,7 +167,7 @@ impl WaitForLow for ExtiPin { impl WaitForRisingEdge for ExtiPin { type Future<'a> = impl Future + 'a; - fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { + fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a> { self.wait_for_edge(EdgeOption::Rising) } } @@ -184,7 +175,7 @@ impl WaitForRisingEdge for ExtiPin { impl WaitForFallingEdge for ExtiPin { type Future<'a> = impl Future + 'a; - fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { + fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a> { self.wait_for_edge(EdgeOption::Falling) } } @@ -192,7 +183,7 @@ impl WaitForFallingEdge for ExtiPin { impl WaitForAnyEdge for ExtiPin { type Future<'a> = impl Future + 'a; - fn wait_for_any_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { + fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { self.wait_for_edge(EdgeOption::RisingFalling) } } -- cgit