aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/input_capture.rs
diff options
context:
space:
mode:
author1-rafael-1 <[email protected]>2025-09-15 20:07:18 +0200
committer1-rafael-1 <[email protected]>2025-09-15 20:07:18 +0200
commit6bb3d2c0720fa082f27d3cdb70f516058497ec87 (patch)
tree5a1e255cff999b00800f203b91a759c720c973e5 /embassy-stm32/src/timer/input_capture.rs
parenteb685574601d98c44faed9a3534d056199b46e20 (diff)
parent92a6fd2946f2cbb15359290f68aa360953da2ff7 (diff)
Merge branch 'main' into rp2040-rtc-alarm
Diffstat (limited to 'embassy-stm32/src/timer/input_capture.rs')
-rw-r--r--embassy-stm32/src/timer/input_capture.rs50
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;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; 8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer};
9use super::{ 9use super::{CaptureCompareInterruptHandler, Channel, GeneralInstance4Channel, TimerPin};
10 CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin,
11 GeneralInstance4Channel,
12};
13pub use super::{Ch1, Ch2, Ch3, Ch4}; 10pub use super::{Ch1, Ch2, Ch3, Ch4};
14use crate::gpio::{AfType, AnyPin, Pull}; 11use crate::gpio::{AfType, AnyPin, Pull};
15use crate::interrupt::typelevel::{Binding, Interrupt}; 12use crate::interrupt::typelevel::{Binding, Interrupt};
16use crate::time::Hertz; 13use crate::time::Hertz;
14use crate::timer::TimerChannel;
17use crate::Peri; 15use 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.
22pub struct CapturePin<'d, T, C> { 20pub 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 25impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(CapturePin<'d, T, C, A>) {
27macro_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
42channel_impl!(new_ch1, Ch1, Channel1Pin);
43channel_impl!(new_ch2, Ch2, Channel2Pin);
44channel_impl!(new_ch3, Ch3, Channel3Pin);
45channel_impl!(new_ch4, Ch4, Channel4Pin);
46
47/// Input capture driver. 36/// Input capture driver.
48pub struct InputCapture<'d, T: GeneralInstance4Channel> { 37pub 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
52impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { 41impl<'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,