From 6f0fb6cab1eba53758a7a2282de4d7f25082fac0 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 2 Apr 2021 13:52:31 -0500 Subject: [PATCH] remove qei trait --- embassy-stm32/src/f4/mod.rs | 1 - embassy-stm32/src/f4/qei.rs | 91 ------------------------------------- embassy-stm32/src/lib.rs | 2 +- embassy-traits/src/lib.rs | 1 - embassy-traits/src/qei.rs | 22 --------- 5 files changed, 1 insertion(+), 116 deletions(-) delete mode 100644 embassy-stm32/src/f4/qei.rs delete mode 100644 embassy-traits/src/qei.rs diff --git a/embassy-stm32/src/f4/mod.rs b/embassy-stm32/src/f4/mod.rs index a80d640d..b1fc0cf1 100644 --- a/embassy-stm32/src/f4/mod.rs +++ b/embassy-stm32/src/f4/mod.rs @@ -1,2 +1 @@ -pub mod qei; pub mod serial; diff --git a/embassy-stm32/src/f4/qei.rs b/embassy-stm32/src/f4/qei.rs deleted file mode 100644 index 5973e62d..00000000 --- a/embassy-stm32/src/f4/qei.rs +++ /dev/null @@ -1,91 +0,0 @@ -use crate::interrupt; -use core::future::Future; -use core::pin::Pin; -use embassy::traits::qei::WaitForRotate; -use embedded_hal::Direction; -use stm32f4xx_hal::pac::TIM2; -use stm32f4xx_hal::{qei, qei::Pins}; - -pub struct Qei { - _qei: qei::Qei, - int: T::Interrupt, -} - -impl> Qei { - pub fn tim2(tim: TIM2, pins: PINS, interrupt: interrupt::TIM2) -> Self { - let qei = qei::Qei::tim2(tim, pins); - - let tim = unsafe { - &mut *(stm32f4xx_hal::stm32::TIM2::ptr() - as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) - }; - /* - enable qei interrupt - */ - tim.dier.write(|w| w.uie().set_bit()); - - Qei { - _qei: qei, - int: interrupt, - } - } -} - -impl + 'static> WaitForRotate for Qei { - type RotateFuture<'a> = impl Future + 'a; - - fn wait_for_rotate<'a>( - self: Pin<&'a mut Self>, - count_down: u16, - count_up: u16, - ) -> Self::RotateFuture<'a> { - let s = unsafe { self.get_unchecked_mut() }; - - let tim = unsafe { - &mut *(stm32f4xx_hal::stm32::TIM2::ptr() - as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) - }; - - /* - the interrupt will be reached at zero or the max count - write the total range to the qei. - */ - tim.arr - .write(|w| unsafe { w.bits((count_down + count_up) as u32) }); - - /* - set timer to the correct value in the range - */ - tim.cnt.write(|w| unsafe { w.bits(count_down as u32) }); - - /* - clear interrupt flag - */ - tim.sr.write(|w| w.uif().clear_bit()); - - async move { - embassy::util::InterruptFuture::new(&mut s.int).await; - - if tim.cnt.read().bits() == 0 { - Direction::Downcounting - } else if tim.cnt.read() == count_down + count_up { - Direction::Upcounting - } else { - panic!("unexpected value") - } - } - } -} - -mod sealed { - pub trait Sealed {} -} - -pub trait Instance: sealed::Sealed { - type Interrupt: interrupt::Interrupt; -} - -impl sealed::Sealed for TIM2 {} -impl Instance for TIM2 { - type Interrupt = interrupt::TIM2; -} diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index a60c3192..3b8b36fa 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -109,7 +109,7 @@ pub mod rtc; feature = "stm32f469", feature = "stm32f479", ))] -pub use f4::{qei, serial}; +pub use f4::serial; #[cfg(any( feature = "stm32f401", diff --git a/embassy-traits/src/lib.rs b/embassy-traits/src/lib.rs index 81a847ef..ea59444c 100644 --- a/embassy-traits/src/lib.rs +++ b/embassy-traits/src/lib.rs @@ -12,6 +12,5 @@ pub mod delay; pub mod flash; pub mod gpio; pub mod i2c; -pub mod qei; pub mod spi; pub mod uart; diff --git a/embassy-traits/src/qei.rs b/embassy-traits/src/qei.rs deleted file mode 100644 index 73581256..00000000 --- a/embassy-traits/src/qei.rs +++ /dev/null @@ -1,22 +0,0 @@ -use core::future::Future; -use core::pin::Pin; -use embedded_hal::Direction; - -// Wait for a specified number of rotations either up or down -pub trait WaitForRotate { - type RotateFuture<'a>: Future + 'a; - - /// Wait for a specified number of rotations, in ticks, either up or down. - /// - /// Return Direction::Upcounting if the high bound is reached. - /// Return Direction::Downcounting if the low bound is reached. - /// - /// Number of ticks is encoder dependent. As an example, if we connect - /// the Bourns PEC11H-4120F-S0020, we have 20 ticks per full rotation. - /// Other encoders may vary. - fn wait_for_rotate<'a>( - self: Pin<&'a mut Self>, - count_down: u16, - count_up: u16, - ) -> Self::RotateFuture<'a>; -}