diff options
Diffstat (limited to 'embassy-stm32/src/timer/input_capture.rs')
| -rw-r--r-- | embassy-stm32/src/timer/input_capture.rs | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index ec8b1ddf1..7a25e6c21 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -6,44 +6,33 @@ use core::pin::Pin; | |||
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | 7 | ||
| 8 | use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; | 8 | use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; |
| 9 | use super::{ | 9 | use super::{CaptureCompareInterruptHandler, Channel, GeneralInstance4Channel, TimerPin}; |
| 10 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, | ||
| 11 | GeneralInstance4Channel, | ||
| 12 | }; | ||
| 13 | pub use super::{Ch1, Ch2, Ch3, Ch4}; | 10 | pub use super::{Ch1, Ch2, Ch3, Ch4}; |
| 14 | use crate::gpio::{AfType, AnyPin, Pull}; | 11 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 15 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 12 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 16 | use crate::time::Hertz; | 13 | use crate::time::Hertz; |
| 14 | use crate::timer::TimerChannel; | ||
| 17 | use crate::Peri; | 15 | use crate::Peri; |
| 18 | 16 | ||
| 19 | /// Capture pin wrapper. | 17 | /// Capture pin wrapper. |
| 20 | /// | 18 | /// |
| 21 | /// This wraps a pin to make it usable with capture. | 19 | /// This wraps a pin to make it usable with capture. |
| 22 | pub struct CapturePin<'d, T, C> { | 20 | pub struct CapturePin<'d, T, C, #[cfg(afio)] A> { |
| 23 | _pin: Peri<'d, AnyPin>, | 21 | #[allow(unused)] |
| 24 | phantom: PhantomData<(T, C)>, | 22 | pin: Peri<'d, AnyPin>, |
| 23 | phantom: PhantomData<if_afio!((T, C, A))>, | ||
| 25 | } | 24 | } |
| 26 | 25 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(CapturePin<'d, T, C, A>) { | |
| 27 | macro_rules! channel_impl { | 26 | /// Create a new capture pin instance. |
| 28 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { |
| 29 | impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { | 28 | set_as_af!(pin, AfType::input(pull)); |
| 30 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] | 29 | CapturePin { |
| 31 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, pull: Pull) -> Self { | 30 | pin: pin.into(), |
| 32 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 31 | phantom: PhantomData, |
| 33 | CapturePin { | ||
| 34 | _pin: pin.into(), | ||
| 35 | phantom: PhantomData, | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | 32 | } |
| 39 | }; | 33 | } |
| 40 | } | 34 | } |
| 41 | 35 | ||
| 42 | channel_impl!(new_ch1, Ch1, Channel1Pin); | ||
| 43 | channel_impl!(new_ch2, Ch2, Channel2Pin); | ||
| 44 | channel_impl!(new_ch3, Ch3, Channel3Pin); | ||
| 45 | channel_impl!(new_ch4, Ch4, Channel4Pin); | ||
| 46 | |||
| 47 | /// Input capture driver. | 36 | /// Input capture driver. |
| 48 | pub struct InputCapture<'d, T: GeneralInstance4Channel> { | 37 | pub struct InputCapture<'d, T: GeneralInstance4Channel> { |
| 49 | inner: Timer<'d, T>, | 38 | inner: Timer<'d, T>, |
| @@ -51,12 +40,13 @@ pub struct InputCapture<'d, T: GeneralInstance4Channel> { | |||
| 51 | 40 | ||
| 52 | impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { | 41 | impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { |
| 53 | /// Create a new input capture driver. | 42 | /// Create a new input capture driver. |
| 54 | pub fn new( | 43 | #[allow(unused)] |
| 44 | pub fn new<#[cfg(afio)] A>( | ||
| 55 | tim: Peri<'d, T>, | 45 | tim: Peri<'d, T>, |
| 56 | _ch1: Option<CapturePin<'d, T, Ch1>>, | 46 | ch1: Option<if_afio!(CapturePin<'d, T, Ch1, A>)>, |
| 57 | _ch2: Option<CapturePin<'d, T, Ch2>>, | 47 | ch2: Option<if_afio!(CapturePin<'d, T, Ch2, A>)>, |
| 58 | _ch3: Option<CapturePin<'d, T, Ch3>>, | 48 | ch3: Option<if_afio!(CapturePin<'d, T, Ch3, A>)>, |
| 59 | _ch4: Option<CapturePin<'d, T, Ch4>>, | 49 | ch4: Option<if_afio!(CapturePin<'d, T, Ch4, A>)>, |
| 60 | _irq: impl Binding<T::CaptureCompareInterrupt, CaptureCompareInterruptHandler<T>> + 'd, | 50 | _irq: impl Binding<T::CaptureCompareInterrupt, CaptureCompareInterruptHandler<T>> + 'd, |
| 61 | freq: Hertz, | 51 | freq: Hertz, |
| 62 | counting_mode: CountingMode, | 52 | counting_mode: CountingMode, |
