|
1 | 1 | //! # Quadrature Encoder Interface
|
2 |
| -use crate::{ |
3 |
| - hal::{self, Direction}, |
4 |
| - pac::RCC, |
5 |
| - rcc, |
6 |
| -}; |
| 2 | +
|
| 3 | +use crate::{pac::RCC, rcc}; |
7 | 4 |
|
8 | 5 | pub trait Pins<TIM> {}
|
9 | 6 | use crate::timer::{CPin, C1, C2};
|
@@ -47,22 +44,39 @@ impl<TIM: Instance, PINS> Qei<TIM, PINS> {
|
47 | 44 | }
|
48 | 45 | }
|
49 | 46 |
|
50 |
| -impl<TIM: Instance, PINS> hal::Qei for Qei<TIM, PINS> { |
| 47 | +impl<TIM: Instance, PINS> embedded_hal::Qei for Qei<TIM, PINS> { |
51 | 48 | type Count = TIM::Count;
|
52 | 49 |
|
53 | 50 | fn count(&self) -> Self::Count {
|
54 | 51 | self.tim.read_count() as Self::Count
|
55 | 52 | }
|
56 | 53 |
|
57 |
| - fn direction(&self) -> Direction { |
| 54 | + fn direction(&self) -> embedded_hal::Direction { |
58 | 55 | if self.tim.read_direction() {
|
59 |
| - hal::Direction::Upcounting |
| 56 | + embedded_hal::Direction::Upcounting |
60 | 57 | } else {
|
61 |
| - hal::Direction::Downcounting |
| 58 | + embedded_hal::Direction::Downcounting |
62 | 59 | }
|
63 | 60 | }
|
64 | 61 | }
|
65 | 62 |
|
| 63 | +impl<TIM: Instance, PINS> embedded_hal_one::qei::blocking::Qei for Qei<TIM, PINS> { |
| 64 | + type Error = core::convert::Infallible; |
| 65 | + type Count = TIM::Count; |
| 66 | + |
| 67 | + fn count(&self) -> Result<Self::Count, Self::Error> { |
| 68 | + Ok(self.tim.read_count() as Self::Count) |
| 69 | + } |
| 70 | + |
| 71 | + fn direction(&self) -> Result<embedded_hal_one::qei::Direction, Self::Error> { |
| 72 | + Ok(if self.tim.read_direction() { |
| 73 | + embedded_hal_one::qei::Direction::Upcounting |
| 74 | + } else { |
| 75 | + embedded_hal_one::qei::Direction::Downcounting |
| 76 | + }) |
| 77 | + } |
| 78 | +} |
| 79 | + |
66 | 80 | pub trait Instance: crate::Sealed + rcc::Enable + rcc::Reset {
|
67 | 81 | type Count;
|
68 | 82 |
|
|
0 commit comments