diff options
| author | xoviat <[email protected]> | 2021-04-02 13:52:31 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2021-04-02 13:52:31 -0500 |
| commit | 6f0fb6cab1eba53758a7a2282de4d7f25082fac0 (patch) | |
| tree | f1627b000042a295c5aa43821b06696571b772c4 | |
| parent | 388558263b84167a3b18003dd886c5ab49968078 (diff) | |
remove qei trait
| -rw-r--r-- | embassy-stm32/src/f4/mod.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/f4/qei.rs | 91 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-traits/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-traits/src/qei.rs | 22 |
5 files changed, 1 insertions, 116 deletions
diff --git a/embassy-stm32/src/f4/mod.rs b/embassy-stm32/src/f4/mod.rs index a80d640dc..b1fc0cf1d 100644 --- a/embassy-stm32/src/f4/mod.rs +++ b/embassy-stm32/src/f4/mod.rs | |||
| @@ -1,2 +1 @@ | |||
| 1 | pub mod qei; | ||
| 2 | pub mod serial; | pub mod serial; | |
diff --git a/embassy-stm32/src/f4/qei.rs b/embassy-stm32/src/f4/qei.rs deleted file mode 100644 index 5973e62d9..000000000 --- a/embassy-stm32/src/f4/qei.rs +++ /dev/null | |||
| @@ -1,91 +0,0 @@ | |||
| 1 | use crate::interrupt; | ||
| 2 | use core::future::Future; | ||
| 3 | use core::pin::Pin; | ||
| 4 | use embassy::traits::qei::WaitForRotate; | ||
| 5 | use embedded_hal::Direction; | ||
| 6 | use stm32f4xx_hal::pac::TIM2; | ||
| 7 | use stm32f4xx_hal::{qei, qei::Pins}; | ||
| 8 | |||
| 9 | pub struct Qei<T: Instance, PINS> { | ||
| 10 | _qei: qei::Qei<T, PINS>, | ||
| 11 | int: T::Interrupt, | ||
| 12 | } | ||
| 13 | |||
| 14 | impl<PINS: Pins<TIM2>> Qei<TIM2, PINS> { | ||
| 15 | pub fn tim2(tim: TIM2, pins: PINS, interrupt: interrupt::TIM2) -> Self { | ||
| 16 | let qei = qei::Qei::tim2(tim, pins); | ||
| 17 | |||
| 18 | let tim = unsafe { | ||
| 19 | &mut *(stm32f4xx_hal::stm32::TIM2::ptr() | ||
| 20 | as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) | ||
| 21 | }; | ||
| 22 | /* | ||
| 23 | enable qei interrupt | ||
| 24 | */ | ||
| 25 | tim.dier.write(|w| w.uie().set_bit()); | ||
| 26 | |||
| 27 | Qei { | ||
| 28 | _qei: qei, | ||
| 29 | int: interrupt, | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | impl<PINS: Pins<TIM2> + 'static> WaitForRotate for Qei<TIM2, PINS> { | ||
| 35 | type RotateFuture<'a> = impl Future<Output = Direction> + 'a; | ||
| 36 | |||
| 37 | fn wait_for_rotate<'a>( | ||
| 38 | self: Pin<&'a mut Self>, | ||
| 39 | count_down: u16, | ||
| 40 | count_up: u16, | ||
| 41 | ) -> Self::RotateFuture<'a> { | ||
| 42 | let s = unsafe { self.get_unchecked_mut() }; | ||
| 43 | |||
| 44 | let tim = unsafe { | ||
| 45 | &mut *(stm32f4xx_hal::stm32::TIM2::ptr() | ||
| 46 | as *mut stm32f4xx_hal::stm32::tim2::RegisterBlock) | ||
| 47 | }; | ||
| 48 | |||
| 49 | /* | ||
| 50 | the interrupt will be reached at zero or the max count | ||
| 51 | write the total range to the qei. | ||
| 52 | */ | ||
| 53 | tim.arr | ||
| 54 | .write(|w| unsafe { w.bits((count_down + count_up) as u32) }); | ||
| 55 | |||
| 56 | /* | ||
| 57 | set timer to the correct value in the range | ||
| 58 | */ | ||
| 59 | tim.cnt.write(|w| unsafe { w.bits(count_down as u32) }); | ||
| 60 | |||
| 61 | /* | ||
| 62 | clear interrupt flag | ||
| 63 | */ | ||
| 64 | tim.sr.write(|w| w.uif().clear_bit()); | ||
| 65 | |||
| 66 | async move { | ||
| 67 | embassy::util::InterruptFuture::new(&mut s.int).await; | ||
| 68 | |||
| 69 | if tim.cnt.read().bits() == 0 { | ||
| 70 | Direction::Downcounting | ||
| 71 | } else if tim.cnt.read() == count_down + count_up { | ||
| 72 | Direction::Upcounting | ||
| 73 | } else { | ||
| 74 | panic!("unexpected value") | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | mod sealed { | ||
| 81 | pub trait Sealed {} | ||
| 82 | } | ||
| 83 | |||
| 84 | pub trait Instance: sealed::Sealed { | ||
| 85 | type Interrupt: interrupt::Interrupt; | ||
| 86 | } | ||
| 87 | |||
| 88 | impl sealed::Sealed for TIM2 {} | ||
| 89 | impl Instance for TIM2 { | ||
| 90 | type Interrupt = interrupt::TIM2; | ||
| 91 | } | ||
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index a60c3192b..3b8b36faf 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -109,7 +109,7 @@ pub mod rtc; | |||
| 109 | feature = "stm32f469", | 109 | feature = "stm32f469", |
| 110 | feature = "stm32f479", | 110 | feature = "stm32f479", |
| 111 | ))] | 111 | ))] |
| 112 | pub use f4::{qei, serial}; | 112 | pub use f4::serial; |
| 113 | 113 | ||
| 114 | #[cfg(any( | 114 | #[cfg(any( |
| 115 | feature = "stm32f401", | 115 | feature = "stm32f401", |
diff --git a/embassy-traits/src/lib.rs b/embassy-traits/src/lib.rs index 81a847ef6..ea59444c1 100644 --- a/embassy-traits/src/lib.rs +++ b/embassy-traits/src/lib.rs | |||
| @@ -12,6 +12,5 @@ pub mod delay; | |||
| 12 | pub mod flash; | 12 | pub mod flash; |
| 13 | pub mod gpio; | 13 | pub mod gpio; |
| 14 | pub mod i2c; | 14 | pub mod i2c; |
| 15 | pub mod qei; | ||
| 16 | pub mod spi; | 15 | pub mod spi; |
| 17 | pub mod uart; | 16 | pub mod uart; |
diff --git a/embassy-traits/src/qei.rs b/embassy-traits/src/qei.rs deleted file mode 100644 index 73581256d..000000000 --- a/embassy-traits/src/qei.rs +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | use core::future::Future; | ||
| 2 | use core::pin::Pin; | ||
| 3 | use embedded_hal::Direction; | ||
| 4 | |||
| 5 | // Wait for a specified number of rotations either up or down | ||
| 6 | pub trait WaitForRotate { | ||
| 7 | type RotateFuture<'a>: Future<Output = Direction> + 'a; | ||
| 8 | |||
| 9 | /// Wait for a specified number of rotations, in ticks, either up or down. | ||
| 10 | /// | ||
| 11 | /// Return Direction::Upcounting if the high bound is reached. | ||
| 12 | /// Return Direction::Downcounting if the low bound is reached. | ||
| 13 | /// | ||
| 14 | /// Number of ticks is encoder dependent. As an example, if we connect | ||
| 15 | /// the Bourns PEC11H-4120F-S0020, we have 20 ticks per full rotation. | ||
| 16 | /// Other encoders may vary. | ||
| 17 | fn wait_for_rotate<'a>( | ||
| 18 | self: Pin<&'a mut Self>, | ||
| 19 | count_down: u16, | ||
| 20 | count_up: u16, | ||
| 21 | ) -> Self::RotateFuture<'a>; | ||
| 22 | } | ||
