diff options
Diffstat (limited to 'embassy-stm32/src/timer/qei.rs')
| -rw-r--r-- | embassy-stm32/src/timer/qei.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index fc5835414..bac290f28 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs | |||
| @@ -2,13 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 6 | use stm32_metapac::timer::vals; | 5 | use stm32_metapac::timer::vals; |
| 7 | 6 | ||
| 8 | use super::low_level::Timer; | 7 | use super::low_level::Timer; |
| 9 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 8 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; |
| 10 | use crate::gpio::{AfType, AnyPin, Pull}; | 9 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 11 | use crate::Peripheral; | 10 | use crate::Peri; |
| 12 | 11 | ||
| 13 | /// Counting direction | 12 | /// Counting direction |
| 14 | pub enum Direction { | 13 | pub enum Direction { |
| @@ -25,7 +24,7 @@ pub enum Ch2 {} | |||
| 25 | 24 | ||
| 26 | /// Wrapper for using a pin with QEI. | 25 | /// Wrapper for using a pin with QEI. |
| 27 | pub struct QeiPin<'d, T, Channel> { | 26 | pub struct QeiPin<'d, T, Channel> { |
| 28 | _pin: PeripheralRef<'d, AnyPin>, | 27 | _pin: Peri<'d, AnyPin>, |
| 29 | phantom: PhantomData<(T, Channel)>, | 28 | phantom: PhantomData<(T, Channel)>, |
| 30 | } | 29 | } |
| 31 | 30 | ||
| @@ -33,14 +32,13 @@ macro_rules! channel_impl { | |||
| 33 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 32 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 34 | impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> { | 33 | impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> { |
| 35 | #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] | 34 | #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] |
| 36 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { | 35 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 37 | into_ref!(pin); | ||
| 38 | critical_section::with(|_| { | 36 | critical_section::with(|_| { |
| 39 | pin.set_low(); | 37 | pin.set_low(); |
| 40 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); | 38 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); |
| 41 | }); | 39 | }); |
| 42 | QeiPin { | 40 | QeiPin { |
| 43 | _pin: pin.map_into(), | 41 | _pin: pin.into(), |
| 44 | phantom: PhantomData, | 42 | phantom: PhantomData, |
| 45 | } | 43 | } |
| 46 | } | 44 | } |
| @@ -58,11 +56,11 @@ pub struct Qei<'d, T: GeneralInstance4Channel> { | |||
| 58 | 56 | ||
| 59 | impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { | 57 | impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { |
| 60 | /// Create a new quadrature decoder driver. | 58 | /// Create a new quadrature decoder driver. |
| 61 | pub fn new(tim: impl Peripheral<P = T> + 'd, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { | 59 | pub fn new(tim: Peri<'d, T>, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { |
| 62 | Self::new_inner(tim) | 60 | Self::new_inner(tim) |
| 63 | } | 61 | } |
| 64 | 62 | ||
| 65 | fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self { | 63 | fn new_inner(tim: Peri<'d, T>) -> Self { |
| 66 | let inner = Timer::new(tim); | 64 | let inner = Timer::new(tim); |
| 67 | let r = inner.regs_gp16(); | 65 | let r = inner.regs_gp16(); |
| 68 | 66 | ||
