diff options
Diffstat (limited to 'embassy-stm32/src/timer/input_capture.rs')
| -rw-r--r-- | embassy-stm32/src/timer/input_capture.rs | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index ec8b1ddf1..dda33e7f1 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -6,14 +6,12 @@ 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. |
| @@ -23,27 +21,17 @@ pub struct CapturePin<'d, T, C> { | |||
| 23 | _pin: Peri<'d, AnyPin>, | 21 | _pin: Peri<'d, AnyPin>, |
| 24 | phantom: PhantomData<(T, C)>, | 22 | phantom: PhantomData<(T, C)>, |
| 25 | } | 23 | } |
| 26 | 24 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel> CapturePin<'d, T, C> { | |
| 27 | macro_rules! channel_impl { | 25 | /// Create a new capture pin instance. |
| 28 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 26 | pub fn new(pin: Peri<'d, impl TimerPin<T, C>>, pull: Pull) -> Self { |
| 29 | impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { | 27 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 30 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] | 28 | CapturePin { |
| 31 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, pull: Pull) -> Self { | 29 | _pin: pin.into(), |
| 32 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 30 | phantom: PhantomData, |
| 33 | CapturePin { | ||
| 34 | _pin: pin.into(), | ||
| 35 | phantom: PhantomData, | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | 31 | } |
| 39 | }; | 32 | } |
| 40 | } | 33 | } |
| 41 | 34 | ||
| 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. | 35 | /// Input capture driver. |
| 48 | pub struct InputCapture<'d, T: GeneralInstance4Channel> { | 36 | pub struct InputCapture<'d, T: GeneralInstance4Channel> { |
| 49 | inner: Timer<'d, T>, | 37 | inner: Timer<'d, T>, |
