aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/one_pulse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/timer/one_pulse.rs')
-rw-r--r--embassy-stm32/src/timer/one_pulse.rs66
1 files changed, 16 insertions, 50 deletions
diff --git a/embassy-stm32/src/timer/one_pulse.rs b/embassy-stm32/src/timer/one_pulse.rs
index 0267749e1..b15cea679 100644
--- a/embassy-stm32/src/timer/one_pulse.rs
+++ b/embassy-stm32/src/timer/one_pulse.rs
@@ -15,6 +15,7 @@ use crate::gpio::{AfType, AnyPin, Pull};
15use crate::interrupt::typelevel::{Binding, Interrupt}; 15use crate::interrupt::typelevel::{Binding, Interrupt};
16use crate::pac::timer::vals::Etp; 16use crate::pac::timer::vals::Etp;
17use crate::time::Hertz; 17use crate::time::Hertz;
18use crate::timer::TimerChannel;
18use crate::Peri; 19use crate::Peri;
19 20
20/// External input marker type. 21/// External input marker type.
@@ -61,58 +62,25 @@ impl SealedTriggerSource for Ch1 {}
61impl SealedTriggerSource for Ch2 {} 62impl SealedTriggerSource for Ch2 {}
62impl SealedTriggerSource for Ext {} 63impl SealedTriggerSource for Ext {}
63 64
64trait SealedTimerTriggerPin<T, S>: crate::gpio::Pin {} 65impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> {
65 66 /// Create a new Channel trigger pin instance.
66/// Marker trait for a trigger pin. 67 pub fn new<A>(pin: Peri<'d, impl TimerPin<T, C, A>>, pull: Pull) -> Self {
67#[expect(private_bounds)] 68 pin.set_as_af(pin.af_num(), AfType::input(pull));
68// TODO: find better naming scheme than prefixing all pin traits with "Timer". 69 #[cfg(afio)]
69// The trait name cannot conflict with the corresponding type's name. 70 pin.afio_remap();
70// Applies to other timer submodules as well. 71 TriggerPin {
71pub trait TimerTriggerPin<T, S>: SealedTimerTriggerPin<T, S> { 72 pin: pin.into(),
72 /// Get the AF number needed to use this pin as a trigger source. 73 phantom: PhantomData,
73 fn af_num(&self) -> u8; 74 }
74}
75
76impl<T, P, C> TimerTriggerPin<T, C> for P
77where
78 T: GeneralInstance4Channel,
79 P: TimerPin<T, C>,
80 C: super::TimerChannel + TriggerSource,
81{
82 fn af_num(&self) -> u8 {
83 TimerPin::af_num(self)
84 }
85}
86
87impl<T, P> TimerTriggerPin<T, Ext> for P
88where
89 T: GeneralInstance4Channel,
90 P: ExternalTriggerPin<T>,
91{
92 fn af_num(&self) -> u8 {
93 ExternalTriggerPin::af_num(self)
94 } 75 }
95} 76}
96 77
97impl<T, P, C> SealedTimerTriggerPin<T, C> for P 78impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> {
98where 79 /// Create a new external trigger pin instance.
99 T: GeneralInstance4Channel, 80 pub fn new_external<A>(pin: Peri<'d, impl ExternalTriggerPin<T, A>>, pull: Pull) -> Self {
100 P: TimerPin<T, C>,
101 C: super::TimerChannel + TriggerSource,
102{
103}
104
105impl<T, P> SealedTimerTriggerPin<T, Ext> for P
106where
107 T: GeneralInstance4Channel,
108 P: ExternalTriggerPin<T>,
109{
110}
111
112impl<'d, T: GeneralInstance4Channel, C: TriggerSource> TriggerPin<'d, T, C> {
113 /// "Create a new Ch1 trigger pin instance.
114 pub fn new(pin: Peri<'d, impl TimerTriggerPin<T, C>>, pull: Pull) -> Self {
115 pin.set_as_af(pin.af_num(), AfType::input(pull)); 81 pin.set_as_af(pin.af_num(), AfType::input(pull));
82 #[cfg(afio)]
83 pin.afio_remap();
116 TriggerPin { 84 TriggerPin {
117 pin: pin.into(), 85 pin: pin.into(),
118 phantom: PhantomData, 86 phantom: PhantomData,
@@ -141,8 +109,6 @@ impl<'d, T: GeneralInstance4Channel> OnePulse<'d, T> {
141 pulse_end: u32, 109 pulse_end: u32,
142 counting_mode: CountingMode, 110 counting_mode: CountingMode,
143 ) -> Self { 111 ) -> Self {
144 #[cfg(afio)]
145 super::set_afio::<T>(&[Some(pin.pin)]);
146 let mut this = Self { inner: Timer::new(tim) }; 112 let mut this = Self { inner: Timer::new(tim) };
147 113
148 this.inner.set_trigger_source(Ts::TI1F_ED); 114 this.inner.set_trigger_source(Ts::TI1F_ED);