diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-09-05 23:44:25 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-09-05 23:44:25 +0200 |
| commit | 35f4ae378cbc9a1263e46baaeac536cae2337896 (patch) | |
| tree | 7f142a458cf10b0ffa444b9963d0e2b30349ef0b /embassy-stm32/src/timer | |
| parent | 7419b398bf7cc5c1ff164c504f4a4027cd6bcd3b (diff) | |
stm32/afio: make the A generic param only appear in chips with AFIO.
Diffstat (limited to 'embassy-stm32/src/timer')
| -rw-r--r-- | embassy-stm32/src/timer/complementary_pwm.rs | 26 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/input_capture.rs | 18 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/one_pulse.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/pwm_input.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/qei.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/simple_pwm.rs | 22 |
6 files changed, 56 insertions, 42 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index d3b84ed16..693eb3456 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -16,15 +16,15 @@ use crate::Peri; | |||
| 16 | /// Complementary PWM pin wrapper. | 16 | /// Complementary PWM pin wrapper. |
| 17 | /// | 17 | /// |
| 18 | /// This wraps a pin to make it usable with PWM. | 18 | /// This wraps a pin to make it usable with PWM. |
| 19 | pub struct ComplementaryPwmPin<'d, T, C, A> { | 19 | pub struct ComplementaryPwmPin<'d, T, C, #[cfg(afio)] A> { |
| 20 | #[allow(unused)] | 20 | #[allow(unused)] |
| 21 | pin: Peri<'d, AnyPin>, | 21 | pin: Peri<'d, AnyPin>, |
| 22 | phantom: PhantomData<(T, C, A)>, | 22 | phantom: PhantomData<if_afio!((T, C, A))>, |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | impl<'d, T: AdvancedInstance4Channel, C: TimerChannel, A> ComplementaryPwmPin<'d, T, C, A> { | 25 | impl<'d, T: AdvancedInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(ComplementaryPwmPin<'d, T, C, A>) { |
| 26 | /// Create a new complementary PWM pin instance. | 26 | /// Create a new complementary PWM pin instance. |
| 27 | pub fn new(pin: Peri<'d, impl TimerComplementaryPin<T, C, A>>, output_type: OutputType) -> Self { | 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerComplementaryPin<T, C, A>)>, output_type: OutputType) -> Self { |
| 28 | critical_section::with(|_| { | 28 | critical_section::with(|_| { |
| 29 | pin.set_low(); | 29 | pin.set_low(); |
| 30 | pin.set_as_af( | 30 | pin.set_as_af( |
| @@ -58,16 +58,16 @@ pub enum IdlePolarity { | |||
| 58 | impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | 58 | impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { |
| 59 | /// Create a new complementary PWM driver. | 59 | /// Create a new complementary PWM driver. |
| 60 | #[allow(clippy::too_many_arguments, unused)] | 60 | #[allow(clippy::too_many_arguments, unused)] |
| 61 | pub fn new<A>( | 61 | pub fn new<#[cfg(afio)] A>( |
| 62 | tim: Peri<'d, T>, | 62 | tim: Peri<'d, T>, |
| 63 | ch1: Option<PwmPin<'d, T, Ch1, A>>, | 63 | ch1: Option<if_afio!(PwmPin<'d, T, Ch1, A>)>, |
| 64 | ch1n: Option<ComplementaryPwmPin<'d, T, Ch1, A>>, | 64 | ch1n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch1, A>)>, |
| 65 | ch2: Option<PwmPin<'d, T, Ch2, A>>, | 65 | ch2: Option<if_afio!(PwmPin<'d, T, Ch2, A>)>, |
| 66 | ch2n: Option<ComplementaryPwmPin<'d, T, Ch2, A>>, | 66 | ch2n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch2, A>)>, |
| 67 | ch3: Option<PwmPin<'d, T, Ch3, A>>, | 67 | ch3: Option<if_afio!(PwmPin<'d, T, Ch3, A>)>, |
| 68 | ch3n: Option<ComplementaryPwmPin<'d, T, Ch3, A>>, | 68 | ch3n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch3, A>)>, |
| 69 | ch4: Option<PwmPin<'d, T, Ch4, A>>, | 69 | ch4: Option<if_afio!(PwmPin<'d, T, Ch4, A>)>, |
| 70 | ch4n: Option<ComplementaryPwmPin<'d, T, Ch4, A>>, | 70 | ch4n: Option<if_afio!(ComplementaryPwmPin<'d, T, Ch4, A>)>, |
| 71 | freq: Hertz, | 71 | freq: Hertz, |
| 72 | counting_mode: CountingMode, | 72 | counting_mode: CountingMode, |
| 73 | ) -> Self { | 73 | ) -> Self { |
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index 262f9d067..41391bd6d 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -17,14 +17,14 @@ use crate::Peri; | |||
| 17 | /// Capture pin wrapper. | 17 | /// Capture pin wrapper. |
| 18 | /// | 18 | /// |
| 19 | /// This wraps a pin to make it usable with capture. | 19 | /// This wraps a pin to make it usable with capture. |
| 20 | pub struct CapturePin<'d, T, C, A> { | 20 | pub struct CapturePin<'d, T, C, #[cfg(afio)] A> { |
| 21 | #[allow(unused)] | 21 | #[allow(unused)] |
| 22 | pin: Peri<'d, AnyPin>, | 22 | pin: Peri<'d, AnyPin>, |
| 23 | phantom: PhantomData<(T, C, A)>, | 23 | phantom: PhantomData<if_afio!((T, C, A))>, |
| 24 | } | 24 | } |
| 25 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> CapturePin<'d, T, C, A> { | 25 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(CapturePin<'d, T, C, A>) { |
| 26 | /// Create a new capture pin instance. | 26 | /// Create a new capture pin instance. |
| 27 | pub fn new(pin: Peri<'d, impl TimerPin<T, C, A>>, pull: Pull) -> Self { | 27 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { |
| 28 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 28 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 29 | CapturePin { | 29 | CapturePin { |
| 30 | pin: pin.into(), | 30 | pin: pin.into(), |
| @@ -41,12 +41,12 @@ pub struct InputCapture<'d, T: GeneralInstance4Channel> { | |||
| 41 | impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { | 41 | impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { |
| 42 | /// Create a new input capture driver. | 42 | /// Create a new input capture driver. |
| 43 | #[allow(unused)] | 43 | #[allow(unused)] |
| 44 | pub fn new<A>( | 44 | pub fn new<#[cfg(afio)] A>( |
| 45 | tim: Peri<'d, T>, | 45 | tim: Peri<'d, T>, |
| 46 | ch1: Option<CapturePin<'d, T, Ch1, A>>, | 46 | ch1: Option<if_afio!(CapturePin<'d, T, Ch1, A>)>, |
| 47 | ch2: Option<CapturePin<'d, T, Ch2, A>>, | 47 | ch2: Option<if_afio!(CapturePin<'d, T, Ch2, A>)>, |
| 48 | ch3: Option<CapturePin<'d, T, Ch3, A>>, | 48 | ch3: Option<if_afio!(CapturePin<'d, T, Ch3, A>)>, |
| 49 | ch4: Option<CapturePin<'d, T, Ch4, A>>, | 49 | ch4: Option<if_afio!(CapturePin<'d, T, Ch4, A>)>, |
| 50 | _irq: impl Binding<T::CaptureCompareInterrupt, CaptureCompareInterruptHandler<T>> + 'd, | 50 | _irq: impl Binding<T::CaptureCompareInterrupt, CaptureCompareInterruptHandler<T>> + 'd, |
| 51 | freq: Hertz, | 51 | freq: Hertz, |
| 52 | counting_mode: CountingMode, | 52 | counting_mode: CountingMode, |
diff --git a/embassy-stm32/src/timer/one_pulse.rs b/embassy-stm32/src/timer/one_pulse.rs index b15cea679..edab38022 100644 --- a/embassy-stm32/src/timer/one_pulse.rs +++ b/embassy-stm32/src/timer/one_pulse.rs | |||
| @@ -64,7 +64,7 @@ impl SealedTriggerSource for Ext {} | |||
| 64 | 64 | ||
| 65 | impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> { | 65 | impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> { |
| 66 | /// Create a new Channel trigger pin instance. | 66 | /// Create a new Channel trigger pin instance. |
| 67 | pub fn new<A>(pin: Peri<'d, impl TimerPin<T, C, A>>, pull: Pull) -> Self { | 67 | pub fn new<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self { |
| 68 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 68 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 69 | #[cfg(afio)] | 69 | #[cfg(afio)] |
| 70 | pin.afio_remap(); | 70 | pin.afio_remap(); |
| @@ -77,7 +77,7 @@ impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin | |||
| 77 | 77 | ||
| 78 | impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> { | 78 | impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> { |
| 79 | /// Create a new external trigger pin instance. | 79 | /// Create a new external trigger pin instance. |
| 80 | pub fn new_external<A>(pin: Peri<'d, impl ExternalTriggerPin<T, A>>, pull: Pull) -> Self { | 80 | pub fn new_external<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl ExternalTriggerPin<T, A>)>, pull: Pull) -> Self { |
| 81 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 81 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 82 | #[cfg(afio)] | 82 | #[cfg(afio)] |
| 83 | pin.afio_remap(); | 83 | pin.afio_remap(); |
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index 62d7a8550..4c1df0316 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -18,7 +18,12 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> { | |||
| 18 | 18 | ||
| 19 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | 19 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { |
| 20 | /// Create a new PWM input driver. | 20 | /// Create a new PWM input driver. |
| 21 | pub fn new_ch1<A>(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1, A>>, pull: Pull, freq: Hertz) -> Self { | 21 | pub fn new_ch1<#[cfg(afio)] A>( |
| 22 | tim: Peri<'d, T>, | ||
| 23 | pin: Peri<'d, if_afio!(impl TimerPin<T, Ch1, A>)>, | ||
| 24 | pull: Pull, | ||
| 25 | freq: Hertz, | ||
| 26 | ) -> Self { | ||
| 22 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 27 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 23 | #[cfg(afio)] | 28 | #[cfg(afio)] |
| 24 | pin.afio_remap(); | 29 | pin.afio_remap(); |
| @@ -27,7 +32,12 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 27 | } | 32 | } |
| 28 | 33 | ||
| 29 | /// Create a new PWM input driver. | 34 | /// Create a new PWM input driver. |
| 30 | pub fn new_ch2<A>(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2, A>>, pull: Pull, freq: Hertz) -> Self { | 35 | pub fn new_ch2<#[cfg(afio)] A>( |
| 36 | tim: Peri<'d, T>, | ||
| 37 | pin: Peri<'d, if_afio!(impl TimerPin<T, Ch2, A>)>, | ||
| 38 | pull: Pull, | ||
| 39 | freq: Hertz, | ||
| 40 | ) -> Self { | ||
| 31 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 41 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 32 | #[cfg(afio)] | 42 | #[cfg(afio)] |
| 33 | pin.afio_remap(); | 43 | pin.afio_remap(); |
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index 39d051294..528c4a904 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs | |||
| @@ -20,15 +20,15 @@ pub enum Direction { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | /// Wrapper for using a pin with QEI. | 22 | /// Wrapper for using a pin with QEI. |
| 23 | pub struct QeiPin<'d, T, Channel, A> { | 23 | pub struct QeiPin<'d, T, Channel, #[cfg(afio)] A> { |
| 24 | #[allow(unused)] | 24 | #[allow(unused)] |
| 25 | pin: Peri<'d, AnyPin>, | 25 | pin: Peri<'d, AnyPin>, |
| 26 | phantom: PhantomData<(T, Channel, A)>, | 26 | phantom: PhantomData<if_afio!((T, Channel, A))>, |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | impl<'d, T: GeneralInstance4Channel, C: QeiChannel, A> QeiPin<'d, T, C, A> { | 29 | impl<'d, T: GeneralInstance4Channel, C: QeiChannel, #[cfg(afio)] A> if_afio!(QeiPin<'d, T, C, A>) { |
| 30 | /// Create a new QEI pin instance. | 30 | /// Create a new QEI pin instance. |
| 31 | pub fn new(pin: Peri<'d, impl TimerPin<T, C, A>>) -> Self { | 31 | pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>) -> Self { |
| 32 | critical_section::with(|_| { | 32 | critical_section::with(|_| { |
| 33 | pin.set_low(); | 33 | pin.set_low(); |
| 34 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); | 34 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); |
| @@ -62,7 +62,11 @@ pub struct Qei<'d, T: GeneralInstance4Channel> { | |||
| 62 | impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { | 62 | impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { |
| 63 | /// Create a new quadrature decoder driver. | 63 | /// Create a new quadrature decoder driver. |
| 64 | #[allow(unused)] | 64 | #[allow(unused)] |
| 65 | pub fn new<A>(tim: Peri<'d, T>, ch1: QeiPin<'d, T, Ch1, A>, ch2: QeiPin<'d, T, Ch2, A>) -> Self { | 65 | pub fn new<#[cfg(afio)] A>( |
| 66 | tim: Peri<'d, T>, | ||
| 67 | ch1: if_afio!(QeiPin<'d, T, Ch1, A>), | ||
| 68 | ch2: if_afio!(QeiPin<'d, T, Ch2, A>), | ||
| 69 | ) -> Self { | ||
| 66 | Self::new_inner(tim) | 70 | Self::new_inner(tim) |
| 67 | } | 71 | } |
| 68 | 72 | ||
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index 53f7cdd22..c08a3939f 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. |
| 17 | pub struct PwmPin<'d, T, C, A> { | 17 | pub struct PwmPin<'d, T, C, #[cfg(afio)] 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, A)>, | 20 | phantom: PhantomData<if_afio!((T, C, A))>, |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /// PWM pin config | 23 | /// PWM pin config |
| @@ -35,9 +35,9 @@ pub struct PwmPinConfig { | |||
| 35 | pub pull: Pull, | 35 | pub pull: Pull, |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> PwmPin<'d, T, C, A> { | 38 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(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, A>>, output_type: OutputType) -> Self { | 40 | pub fn new(pin: Peri<'d, if_afio!(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)); |
| @@ -50,8 +50,8 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel, A> PwmPin<'d, T, C, A> { | |||
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | /// Create a new PWM pin instance with config. | 53 | /// Create a new PWM pin instance with a specific configuration. |
| 54 | pub fn new_with_config(pin: Peri<'d, impl TimerPin<T, C, A>>, pin_config: PwmPinConfig) -> Self { | 54 | pub fn new_with_config(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pin_config: PwmPinConfig) -> Self { |
| 55 | critical_section::with(|_| { | 55 | critical_section::with(|_| { |
| 56 | pin.set_low(); | 56 | pin.set_low(); |
| 57 | pin.set_as_af( | 57 | pin.set_as_af( |
| @@ -184,12 +184,12 @@ pub struct SimplePwm<'d, T: GeneralInstance4Channel> { | |||
| 184 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | 184 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { |
| 185 | /// Create a new simple PWM driver. | 185 | /// Create a new simple PWM driver. |
| 186 | #[allow(unused)] | 186 | #[allow(unused)] |
| 187 | pub fn new<A>( | 187 | pub fn new<#[cfg(afio)] A>( |
| 188 | tim: Peri<'d, T>, | 188 | tim: Peri<'d, T>, |
| 189 | ch1: Option<PwmPin<'d, T, Ch1, A>>, | 189 | ch1: Option<if_afio!(PwmPin<'d, T, Ch1, A>)>, |
| 190 | ch2: Option<PwmPin<'d, T, Ch2, A>>, | 190 | ch2: Option<if_afio!(PwmPin<'d, T, Ch2, A>)>, |
| 191 | ch3: Option<PwmPin<'d, T, Ch3, A>>, | 191 | ch3: Option<if_afio!(PwmPin<'d, T, Ch3, A>)>, |
| 192 | ch4: Option<PwmPin<'d, T, Ch4, A>>, | 192 | ch4: Option<if_afio!(PwmPin<'d, T, Ch4, A>)>, |
| 193 | freq: Hertz, | 193 | freq: Hertz, |
| 194 | counting_mode: CountingMode, | 194 | counting_mode: CountingMode, |
| 195 | ) -> Self { | 195 | ) -> Self { |
