aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/simple_pwm.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-09-05 23:00:31 +0200
committerDario Nieuwenhuis <[email protected]>2025-09-05 23:00:31 +0200
commit7419b398bf7cc5c1ff164c504f4a4027cd6bcd3b (patch)
tree9ea26e1059b70502d0e5929a72a9f50c8c43838b /embassy-stm32/src/timer/simple_pwm.rs
parenta6562c4f033432e40970aafe82f33c5138adf84e (diff)
stm32/afio: use type inference for timer remaps as well.
Diffstat (limited to 'embassy-stm32/src/timer/simple_pwm.rs')
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index df86859fe..53f7cdd22 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -14,10 +14,10 @@ use crate::Peri;
14/// PWM pin wrapper. 14/// PWM pin wrapper.
15/// 15///
16/// This wraps a pin to make it usable with PWM. 16/// This wraps a pin to make it usable with PWM.
17pub struct PwmPin<'d, T, C> { 17pub struct PwmPin<'d, T, C, A> {
18 #[allow(unused)] 18 #[allow(unused)]
19 pub(crate) pin: Peri<'d, AnyPin>, 19 pub(crate) pin: Peri<'d, AnyPin>,
20 phantom: PhantomData<(T, C)>, 20 phantom: PhantomData<(T, C, A)>,
21} 21}
22 22
23/// PWM pin config 23/// PWM pin config
@@ -35,12 +35,14 @@ pub struct PwmPinConfig {
35 pub pull: Pull, 35 pub pull: Pull,
36} 36}
37 37
38impl<'d, T: GeneralInstance4Channel, C: TimerChannel> PwmPin<'d, T, C> { 38impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> PwmPin<'d, T, C, A> {
39 /// Create a new PWM pin instance. 39 /// Create a new PWM pin instance.
40 pub fn new(pin: Peri<'d, impl TimerPin<T, C>>, output_type: OutputType) -> Self { 40 pub fn new(pin: Peri<'d, impl TimerPin<T, C, A>>, output_type: OutputType) -> Self {
41 critical_section::with(|_| { 41 critical_section::with(|_| {
42 pin.set_low(); 42 pin.set_low();
43 pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); 43 pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh));
44 #[cfg(afio)]
45 pin.afio_remap();
44 }); 46 });
45 PwmPin { 47 PwmPin {
46 pin: pin.into(), 48 pin: pin.into(),
@@ -49,7 +51,7 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel> PwmPin<'d, T, C> {
49 } 51 }
50 52
51 /// Create a new PWM pin instance with config. 53 /// Create a new PWM pin instance with config.
52 pub fn new_with_config(pin: Peri<'d, impl TimerPin<T, C>>, pin_config: PwmPinConfig) -> Self { 54 pub fn new_with_config(pin: Peri<'d, impl TimerPin<T, C, A>>, pin_config: PwmPinConfig) -> Self {
53 critical_section::with(|_| { 55 critical_section::with(|_| {
54 pin.set_low(); 56 pin.set_low();
55 pin.set_as_af( 57 pin.set_as_af(
@@ -59,6 +61,8 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel> PwmPin<'d, T, C> {
59 #[cfg(gpio_v2)] 61 #[cfg(gpio_v2)]
60 AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), 62 AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
61 ); 63 );
64 #[cfg(afio)]
65 pin.afio_remap();
62 }); 66 });
63 PwmPin { 67 PwmPin {
64 pin: pin.into(), 68 pin: pin.into(),
@@ -180,22 +184,15 @@ pub struct SimplePwm<'d, T: GeneralInstance4Channel> {
180impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { 184impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
181 /// Create a new simple PWM driver. 185 /// Create a new simple PWM driver.
182 #[allow(unused)] 186 #[allow(unused)]
183 pub fn new( 187 pub fn new<A>(
184 tim: Peri<'d, T>, 188 tim: Peri<'d, T>,
185 ch1: Option<PwmPin<'d, T, Ch1>>, 189 ch1: Option<PwmPin<'d, T, Ch1, A>>,
186 ch2: Option<PwmPin<'d, T, Ch2>>, 190 ch2: Option<PwmPin<'d, T, Ch2, A>>,
187 ch3: Option<PwmPin<'d, T, Ch3>>, 191 ch3: Option<PwmPin<'d, T, Ch3, A>>,
188 ch4: Option<PwmPin<'d, T, Ch4>>, 192 ch4: Option<PwmPin<'d, T, Ch4, A>>,
189 freq: Hertz, 193 freq: Hertz,
190 counting_mode: CountingMode, 194 counting_mode: CountingMode,
191 ) -> Self { 195 ) -> Self {
192 #[cfg(afio)]
193 super::set_afio::<T>(&[
194 ch1.map(|p| p.pin),
195 ch2.map(|p| p.pin),
196 ch3.map(|p| p.pin),
197 ch4.map(|p| p.pin),
198 ]);
199 Self::new_inner(tim, freq, counting_mode) 196 Self::new_inner(tim, freq, counting_mode)
200 } 197 }
201 198