diff options
21 files changed, 359 insertions, 290 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 8143c9a23..13fc23e54 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -1090,21 +1090,21 @@ fn main() { | |||
| 1090 | (("fmc", "CLK"), quote!(crate::fmc::ClkPin)), | 1090 | (("fmc", "CLK"), quote!(crate::fmc::ClkPin)), |
| 1091 | (("fmc", "BA0"), quote!(crate::fmc::BA0Pin)), | 1091 | (("fmc", "BA0"), quote!(crate::fmc::BA0Pin)), |
| 1092 | (("fmc", "BA1"), quote!(crate::fmc::BA1Pin)), | 1092 | (("fmc", "BA1"), quote!(crate::fmc::BA1Pin)), |
| 1093 | (("timer", "CH1"), quote!(crate::timer::Channel1Pin)), | 1093 | (("timer", "CH1"), quote!(crate::timer::TimerPin<Ch1>)), |
| 1094 | (("timer", "CH1N"), quote!(crate::timer::Channel1ComplementaryPin)), | 1094 | (("timer", "CH1N"), quote!(crate::timer::TimerComplementaryPin<Ch1>)), |
| 1095 | (("timer", "CH2"), quote!(crate::timer::Channel2Pin)), | 1095 | (("timer", "CH2"), quote!(crate::timer::TimerPin<Ch2>)), |
| 1096 | (("timer", "CH2N"), quote!(crate::timer::Channel2ComplementaryPin)), | 1096 | (("timer", "CH2N"), quote!(crate::timer::TimerComplementaryPin<Ch2>)), |
| 1097 | (("timer", "CH3"), quote!(crate::timer::Channel3Pin)), | 1097 | (("timer", "CH3"), quote!(crate::timer::TimerPin<Ch3>)), |
| 1098 | (("timer", "CH3N"), quote!(crate::timer::Channel3ComplementaryPin)), | 1098 | (("timer", "CH3N"), quote!(crate::timer::TimerComplementaryPin<Ch3>)), |
| 1099 | (("timer", "CH4"), quote!(crate::timer::Channel4Pin)), | 1099 | (("timer", "CH4"), quote!(crate::timer::TimerPin<Ch4>)), |
| 1100 | (("timer", "CH4N"), quote!(crate::timer::Channel4ComplementaryPin)), | 1100 | (("timer", "CH4N"), quote!(crate::timer::TimerComplementaryPin<Ch4>)), |
| 1101 | (("timer", "ETR"), quote!(crate::timer::ExternalTriggerPin)), | 1101 | (("timer", "ETR"), quote!(crate::timer::ExternalTriggerPin)), |
| 1102 | (("timer", "BKIN"), quote!(crate::timer::BreakInputPin)), | 1102 | (("timer", "BKIN"), quote!(crate::timer::BreakInputPin<BkIn1>)), |
| 1103 | (("timer", "BKIN_COMP1"), quote!(crate::timer::BreakInputComparator1Pin)), | 1103 | (("timer", "BKIN_COMP1"), quote!(crate::timer::BreakInputComparator1Pin<BkIn1>)), |
| 1104 | (("timer", "BKIN_COMP2"), quote!(crate::timer::BreakInputComparator2Pin)), | 1104 | (("timer", "BKIN_COMP2"), quote!(crate::timer::BreakInputComparator2Pin<BkIn1>)), |
| 1105 | (("timer", "BKIN2"), quote!(crate::timer::BreakInput2Pin)), | 1105 | (("timer", "BKIN2"), quote!(crate::timer::BreakInputPin<BkIn2>)), |
| 1106 | (("timer", "BKIN2_COMP1"), quote!(crate::timer::BreakInput2Comparator1Pin)), | 1106 | (("timer", "BKIN2_COMP1"), quote!(crate::timer::BreakInputComparator1Pin<BkIn2>)), |
| 1107 | (("timer", "BKIN2_COMP2"), quote!(crate::timer::BreakInput2Comparator2Pin)), | 1107 | (("timer", "BKIN2_COMP2"), quote!(crate::timer::BreakInputComparator2Pin<BkIn2>)), |
| 1108 | (("hrtim", "CHA1"), quote!(crate::hrtim::ChannelAPin)), | 1108 | (("hrtim", "CHA1"), quote!(crate::hrtim::ChannelAPin)), |
| 1109 | (("hrtim", "CHA2"), quote!(crate::hrtim::ChannelAComplementaryPin)), | 1109 | (("hrtim", "CHA2"), quote!(crate::hrtim::ChannelAComplementaryPin)), |
| 1110 | (("hrtim", "CHB1"), quote!(crate::hrtim::ChannelBPin)), | 1110 | (("hrtim", "CHB1"), quote!(crate::hrtim::ChannelBPin)), |
| @@ -1475,10 +1475,10 @@ fn main() { | |||
| 1475 | (("hash", "IN"), quote!(crate::hash::Dma)), | 1475 | (("hash", "IN"), quote!(crate::hash::Dma)), |
| 1476 | (("cryp", "IN"), quote!(crate::cryp::DmaIn)), | 1476 | (("cryp", "IN"), quote!(crate::cryp::DmaIn)), |
| 1477 | (("cryp", "OUT"), quote!(crate::cryp::DmaOut)), | 1477 | (("cryp", "OUT"), quote!(crate::cryp::DmaOut)), |
| 1478 | (("timer", "CH1"), quote!(crate::timer::Ch1Dma)), | 1478 | (("timer", "CH1"), quote!(crate::timer::Dma<Ch1>)), |
| 1479 | (("timer", "CH2"), quote!(crate::timer::Ch2Dma)), | 1479 | (("timer", "CH2"), quote!(crate::timer::Dma<Ch2>)), |
| 1480 | (("timer", "CH3"), quote!(crate::timer::Ch3Dma)), | 1480 | (("timer", "CH3"), quote!(crate::timer::Dma<Ch3>)), |
| 1481 | (("timer", "CH4"), quote!(crate::timer::Ch4Dma)), | 1481 | (("timer", "CH4"), quote!(crate::timer::Dma<Ch4>)), |
| 1482 | (("cordic", "WRITE"), quote!(crate::cordic::WriteDma)), // FIXME: stm32u5a crash on Cordic driver | 1482 | (("cordic", "WRITE"), quote!(crate::cordic::WriteDma)), // FIXME: stm32u5a crash on Cordic driver |
| 1483 | (("cordic", "READ"), quote!(crate::cordic::ReadDma)), // FIXME: stm32u5a crash on Cordic driver | 1483 | (("cordic", "READ"), quote!(crate::cordic::ReadDma)), // FIXME: stm32u5a crash on Cordic driver |
| 1484 | ] | 1484 | ] |
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 8eec6c0c7..a450705a2 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -5,14 +5,12 @@ use core::marker::PhantomData; | |||
| 5 | use stm32_metapac::timer::vals::Ckd; | 5 | use stm32_metapac::timer::vals::Ckd; |
| 6 | 6 | ||
| 7 | use super::low_level::{CountingMode, OutputPolarity, Timer}; | 7 | use super::low_level::{CountingMode, OutputPolarity, Timer}; |
| 8 | use super::simple_pwm::{Ch1, Ch2, Ch3, Ch4, PwmPin}; | 8 | use super::simple_pwm::PwmPin; |
| 9 | use super::{ | 9 | use super::{AdvancedInstance4Channel, Ch1, Ch2, Ch3, Ch4, Channel, TimerComplementaryPin}; |
| 10 | AdvancedInstance4Channel, Channel, Channel1ComplementaryPin, Channel2ComplementaryPin, Channel3ComplementaryPin, | ||
| 11 | Channel4ComplementaryPin, | ||
| 12 | }; | ||
| 13 | use crate::gpio::{AnyPin, OutputType}; | 10 | use crate::gpio::{AnyPin, OutputType}; |
| 14 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| 15 | use crate::timer::low_level::OutputCompareMode; | 12 | use crate::timer::low_level::OutputCompareMode; |
| 13 | use crate::timer::TimerChannel; | ||
| 16 | use crate::Peri; | 14 | use crate::Peri; |
| 17 | 15 | ||
| 18 | /// Complementary PWM pin wrapper. | 16 | /// Complementary PWM pin wrapper. |
| @@ -23,32 +21,23 @@ pub struct ComplementaryPwmPin<'d, T, C> { | |||
| 23 | phantom: PhantomData<(T, C)>, | 21 | phantom: PhantomData<(T, C)>, |
| 24 | } | 22 | } |
| 25 | 23 | ||
| 26 | macro_rules! complementary_channel_impl { | 24 | impl<'d, T: AdvancedInstance4Channel, C: TimerChannel> ComplementaryPwmPin<'d, T, C> { |
| 27 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 25 | /// Create a new complementary PWM pin instance. |
| 28 | impl<'d, T: AdvancedInstance4Channel> ComplementaryPwmPin<'d, T, $channel> { | 26 | pub fn new(pin: Peri<'d, impl TimerComplementaryPin<T, C>>, output_type: OutputType) -> Self { |
| 29 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] | 27 | critical_section::with(|_| { |
| 30 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, output_type: OutputType) -> Self { | 28 | pin.set_low(); |
| 31 | critical_section::with(|_| { | 29 | pin.set_as_af( |
| 32 | pin.set_low(); | 30 | pin.af_num(), |
| 33 | pin.set_as_af( | 31 | crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh), |
| 34 | pin.af_num(), | 32 | ); |
| 35 | crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh), | 33 | }); |
| 36 | ); | 34 | ComplementaryPwmPin { |
| 37 | }); | 35 | _pin: pin.into(), |
| 38 | ComplementaryPwmPin { | 36 | phantom: PhantomData, |
| 39 | _pin: pin.into(), | ||
| 40 | phantom: PhantomData, | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | 37 | } |
| 44 | }; | 38 | } |
| 45 | } | 39 | } |
| 46 | 40 | ||
| 47 | complementary_channel_impl!(new_ch1, Ch1, Channel1ComplementaryPin); | ||
| 48 | complementary_channel_impl!(new_ch2, Ch2, Channel2ComplementaryPin); | ||
| 49 | complementary_channel_impl!(new_ch3, Ch3, Channel3ComplementaryPin); | ||
| 50 | complementary_channel_impl!(new_ch4, Ch4, Channel4ComplementaryPin); | ||
| 51 | |||
| 52 | /// PWM driver with support for standard and complementary outputs. | 41 | /// PWM driver with support for standard and complementary outputs. |
| 53 | pub struct ComplementaryPwm<'d, T: AdvancedInstance4Channel> { | 42 | pub struct ComplementaryPwm<'d, T: AdvancedInstance4Channel> { |
| 54 | inner: Timer<'d, T>, | 43 | inner: Timer<'d, T>, |
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>, |
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index b29382fc8..7062f5f4c 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -51,6 +51,80 @@ pub enum Ch3 {} | |||
| 51 | /// Channel 4 marker type. | 51 | /// Channel 4 marker type. |
| 52 | pub enum Ch4 {} | 52 | pub enum Ch4 {} |
| 53 | 53 | ||
| 54 | /// Timer channel trait. | ||
| 55 | #[allow(private_bounds)] | ||
| 56 | pub trait TimerChannel: SealedTimerChannel { | ||
| 57 | /// The runtime channel. | ||
| 58 | const CHANNEL: Channel; | ||
| 59 | } | ||
| 60 | |||
| 61 | trait SealedTimerChannel {} | ||
| 62 | |||
| 63 | impl TimerChannel for Ch1 { | ||
| 64 | const CHANNEL: Channel = Channel::Ch1; | ||
| 65 | } | ||
| 66 | |||
| 67 | impl TimerChannel for Ch2 { | ||
| 68 | const CHANNEL: Channel = Channel::Ch2; | ||
| 69 | } | ||
| 70 | |||
| 71 | impl TimerChannel for Ch3 { | ||
| 72 | const CHANNEL: Channel = Channel::Ch3; | ||
| 73 | } | ||
| 74 | |||
| 75 | impl TimerChannel for Ch4 { | ||
| 76 | const CHANNEL: Channel = Channel::Ch4; | ||
| 77 | } | ||
| 78 | |||
| 79 | impl SealedTimerChannel for Ch1 {} | ||
| 80 | impl SealedTimerChannel for Ch2 {} | ||
| 81 | impl SealedTimerChannel for Ch3 {} | ||
| 82 | impl SealedTimerChannel for Ch4 {} | ||
| 83 | |||
| 84 | /// Timer break input. | ||
| 85 | #[derive(Clone, Copy)] | ||
| 86 | pub enum BkIn { | ||
| 87 | /// Break input 1. | ||
| 88 | BkIn1, | ||
| 89 | /// Break input 2. | ||
| 90 | BkIn2, | ||
| 91 | } | ||
| 92 | |||
| 93 | impl BkIn { | ||
| 94 | /// Get the channel index (0..3) | ||
| 95 | pub fn index(&self) -> usize { | ||
| 96 | match self { | ||
| 97 | BkIn::BkIn1 => 0, | ||
| 98 | BkIn::BkIn2 => 1, | ||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | /// Break input 1 marker type. | ||
| 104 | pub enum BkIn1 {} | ||
| 105 | /// Break input 2 marker type. | ||
| 106 | pub enum BkIn2 {} | ||
| 107 | |||
| 108 | /// Timer channel trait. | ||
| 109 | #[allow(private_bounds)] | ||
| 110 | pub trait BreakInput: SealedBreakInput { | ||
| 111 | /// The runtim timer channel. | ||
| 112 | const INPUT: BkIn; | ||
| 113 | } | ||
| 114 | |||
| 115 | trait SealedBreakInput {} | ||
| 116 | |||
| 117 | impl BreakInput for BkIn1 { | ||
| 118 | const INPUT: BkIn = BkIn::BkIn1; | ||
| 119 | } | ||
| 120 | |||
| 121 | impl BreakInput for BkIn2 { | ||
| 122 | const INPUT: BkIn = BkIn::BkIn2; | ||
| 123 | } | ||
| 124 | |||
| 125 | impl SealedBreakInput for BkIn1 {} | ||
| 126 | impl SealedBreakInput for BkIn2 {} | ||
| 127 | |||
| 54 | /// Amount of bits of a timer. | 128 | /// Amount of bits of a timer. |
| 55 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 129 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 56 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 130 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -149,33 +223,20 @@ pub trait AdvancedInstance2Channel: BasicInstance + GeneralInstance2Channel + Ad | |||
| 149 | /// Advanced 16-bit timer with 4 channels instance. | 223 | /// Advanced 16-bit timer with 4 channels instance. |
| 150 | pub trait AdvancedInstance4Channel: AdvancedInstance2Channel + GeneralInstance4Channel {} | 224 | pub trait AdvancedInstance4Channel: AdvancedInstance2Channel + GeneralInstance4Channel {} |
| 151 | 225 | ||
| 152 | pin_trait!(Channel1Pin, GeneralInstance4Channel); | 226 | pin_trait!(TimerPin, GeneralInstance4Channel, TimerChannel); |
| 153 | pin_trait!(Channel2Pin, GeneralInstance4Channel); | ||
| 154 | pin_trait!(Channel3Pin, GeneralInstance4Channel); | ||
| 155 | pin_trait!(Channel4Pin, GeneralInstance4Channel); | ||
| 156 | pin_trait!(ExternalTriggerPin, GeneralInstance4Channel); | 227 | pin_trait!(ExternalTriggerPin, GeneralInstance4Channel); |
| 157 | 228 | ||
| 158 | pin_trait!(Channel1ComplementaryPin, AdvancedInstance4Channel); | 229 | pin_trait!(TimerComplementaryPin, AdvancedInstance4Channel, TimerChannel); |
| 159 | pin_trait!(Channel2ComplementaryPin, AdvancedInstance4Channel); | ||
| 160 | pin_trait!(Channel3ComplementaryPin, AdvancedInstance4Channel); | ||
| 161 | pin_trait!(Channel4ComplementaryPin, AdvancedInstance4Channel); | ||
| 162 | |||
| 163 | pin_trait!(BreakInputPin, AdvancedInstance4Channel); | ||
| 164 | pin_trait!(BreakInput2Pin, AdvancedInstance4Channel); | ||
| 165 | 230 | ||
| 166 | pin_trait!(BreakInputComparator1Pin, AdvancedInstance4Channel); | 231 | pin_trait!(BreakInputPin, AdvancedInstance4Channel, BreakInput); |
| 167 | pin_trait!(BreakInputComparator2Pin, AdvancedInstance4Channel); | ||
| 168 | 232 | ||
| 169 | pin_trait!(BreakInput2Comparator1Pin, AdvancedInstance4Channel); | 233 | pin_trait!(BreakInputComparator1Pin, AdvancedInstance4Channel, BreakInput); |
| 170 | pin_trait!(BreakInput2Comparator2Pin, AdvancedInstance4Channel); | 234 | pin_trait!(BreakInputComparator2Pin, AdvancedInstance4Channel, BreakInput); |
| 171 | 235 | ||
| 172 | // Update Event trigger DMA for every timer | 236 | // Update Event trigger DMA for every timer |
| 173 | dma_trait!(UpDma, BasicInstance); | 237 | dma_trait!(UpDma, BasicInstance); |
| 174 | 238 | ||
| 175 | dma_trait!(Ch1Dma, GeneralInstance4Channel); | 239 | dma_trait!(Dma, GeneralInstance4Channel, TimerChannel); |
| 176 | dma_trait!(Ch2Dma, GeneralInstance4Channel); | ||
| 177 | dma_trait!(Ch3Dma, GeneralInstance4Channel); | ||
| 178 | dma_trait!(Ch4Dma, GeneralInstance4Channel); | ||
| 179 | 240 | ||
| 180 | #[allow(unused)] | 241 | #[allow(unused)] |
| 181 | macro_rules! impl_core_timer { | 242 | macro_rules! impl_core_timer { |
diff --git a/embassy-stm32/src/timer/one_pulse.rs b/embassy-stm32/src/timer/one_pulse.rs index 933165ef9..c8f0cafe7 100644 --- a/embassy-stm32/src/timer/one_pulse.rs +++ b/embassy-stm32/src/timer/one_pulse.rs | |||
| @@ -7,11 +7,9 @@ use core::pin::Pin; | |||
| 7 | use core::task::{Context, Poll}; | 7 | use core::task::{Context, Poll}; |
| 8 | 8 | ||
| 9 | use super::low_level::{ | 9 | use super::low_level::{ |
| 10 | CountingMode, FilterValue, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource, | 10 | CountingMode, FilterValue, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource as Ts, |
| 11 | }; | ||
| 12 | use super::{ | ||
| 13 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, ExternalTriggerPin, GeneralInstance4Channel, | ||
| 14 | }; | 11 | }; |
| 12 | use super::{CaptureCompareInterruptHandler, Channel, ExternalTriggerPin, GeneralInstance4Channel, TimerPin}; | ||
| 15 | pub use super::{Ch1, Ch2}; | 13 | pub use super::{Ch1, Ch2}; |
| 16 | use crate::gpio::{AfType, AnyPin, Pull}; | 14 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 17 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 15 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| @@ -48,24 +46,78 @@ pub struct TriggerPin<'d, T, C> { | |||
| 48 | phantom: PhantomData<(T, C)>, | 46 | phantom: PhantomData<(T, C)>, |
| 49 | } | 47 | } |
| 50 | 48 | ||
| 51 | macro_rules! channel_impl { | 49 | trait SealedTriggerSource {} |
| 52 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 50 | |
| 53 | impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, $channel> { | 51 | /// Marker trait for a trigger source. |
| 54 | #[doc = concat!("Create a new ", stringify!($channel), " trigger pin instance.")] | 52 | #[expect(private_bounds)] |
| 55 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, pull: Pull) -> Self { | 53 | pub trait TriggerSource: SealedTriggerSource {} |
| 56 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 54 | |
| 57 | TriggerPin { | 55 | impl TriggerSource for Ch1 {} |
| 58 | _pin: pin.into(), | 56 | impl TriggerSource for Ch2 {} |
| 59 | phantom: PhantomData, | 57 | impl TriggerSource for Ext {} |
| 60 | } | 58 | |
| 61 | } | 59 | impl SealedTriggerSource for Ch1 {} |
| 62 | } | 60 | impl SealedTriggerSource for Ch2 {} |
| 63 | }; | 61 | impl SealedTriggerSource for Ext {} |
| 62 | |||
| 63 | trait SealedTimerTriggerPin<T, S>: crate::gpio::Pin {} | ||
| 64 | |||
| 65 | /// Marker trait for a trigger pin. | ||
| 66 | #[expect(private_bounds)] | ||
| 67 | // TODO: find better naming scheme than prefixing all pin traits with "Timer". | ||
| 68 | // The trait name cannot conflict with the corresponding type's name. | ||
| 69 | // Applies to other timer submodules as well. | ||
| 70 | pub trait TimerTriggerPin<T, S>: SealedTimerTriggerPin<T, S> { | ||
| 71 | /// Get the AF number needed to use this pin as a trigger source. | ||
| 72 | fn af_num(&self) -> u8; | ||
| 64 | } | 73 | } |
| 65 | 74 | ||
| 66 | channel_impl!(new_ch1, Ch1, Channel1Pin); | 75 | impl<T, P, C> TimerTriggerPin<T, C> for P |
| 67 | channel_impl!(new_ch2, Ch2, Channel2Pin); | 76 | where |
| 68 | channel_impl!(new_ext, Ext, ExternalTriggerPin); | 77 | T: GeneralInstance4Channel, |
| 78 | P: TimerPin<T, C>, | ||
| 79 | C: super::TimerChannel + TriggerSource, | ||
| 80 | { | ||
| 81 | fn af_num(&self) -> u8 { | ||
| 82 | TimerPin::af_num(self) | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | impl<T, P> TimerTriggerPin<T, Ext> for P | ||
| 87 | where | ||
| 88 | T: GeneralInstance4Channel, | ||
| 89 | P: ExternalTriggerPin<T>, | ||
| 90 | { | ||
| 91 | fn af_num(&self) -> u8 { | ||
| 92 | ExternalTriggerPin::af_num(self) | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | impl<T, P, C> SealedTimerTriggerPin<T, C> for P | ||
| 97 | where | ||
| 98 | T: GeneralInstance4Channel, | ||
| 99 | P: TimerPin<T, C>, | ||
| 100 | C: super::TimerChannel + TriggerSource, | ||
| 101 | { | ||
| 102 | } | ||
| 103 | |||
| 104 | impl<T, P> SealedTimerTriggerPin<T, Ext> for P | ||
| 105 | where | ||
| 106 | T: GeneralInstance4Channel, | ||
| 107 | P: ExternalTriggerPin<T>, | ||
| 108 | { | ||
| 109 | } | ||
| 110 | |||
| 111 | impl<'d, T: GeneralInstance4Channel, C: TriggerSource> TriggerPin<'d, T, C> { | ||
| 112 | /// "Create a new Ch1 trigger pin instance. | ||
| 113 | pub fn new(pin: Peri<'d, impl TimerTriggerPin<T, C>>, pull: Pull) -> Self { | ||
| 114 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | ||
| 115 | TriggerPin { | ||
| 116 | _pin: pin.into(), | ||
| 117 | phantom: PhantomData, | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||
| 69 | 121 | ||
| 70 | /// One pulse driver. | 122 | /// One pulse driver. |
| 71 | /// | 123 | /// |
| @@ -89,7 +141,7 @@ impl<'d, T: GeneralInstance4Channel> OnePulse<'d, T> { | |||
| 89 | ) -> Self { | 141 | ) -> Self { |
| 90 | let mut this = Self { inner: Timer::new(tim) }; | 142 | let mut this = Self { inner: Timer::new(tim) }; |
| 91 | 143 | ||
| 92 | this.inner.set_trigger_source(TriggerSource::TI1F_ED); | 144 | this.inner.set_trigger_source(Ts::TI1F_ED); |
| 93 | this.inner | 145 | this.inner |
| 94 | .set_input_ti_selection(Channel::Ch1, InputTISelection::Normal); | 146 | .set_input_ti_selection(Channel::Ch1, InputTISelection::Normal); |
| 95 | this.inner | 147 | this.inner |
| @@ -114,7 +166,7 @@ impl<'d, T: GeneralInstance4Channel> OnePulse<'d, T> { | |||
| 114 | ) -> Self { | 166 | ) -> Self { |
| 115 | let mut this = Self { inner: Timer::new(tim) }; | 167 | let mut this = Self { inner: Timer::new(tim) }; |
| 116 | 168 | ||
| 117 | this.inner.set_trigger_source(TriggerSource::TI1FP1); | 169 | this.inner.set_trigger_source(Ts::TI1FP1); |
| 118 | this.inner | 170 | this.inner |
| 119 | .set_input_ti_selection(Channel::Ch1, InputTISelection::Normal); | 171 | .set_input_ti_selection(Channel::Ch1, InputTISelection::Normal); |
| 120 | this.inner | 172 | this.inner |
| @@ -140,7 +192,7 @@ impl<'d, T: GeneralInstance4Channel> OnePulse<'d, T> { | |||
| 140 | ) -> Self { | 192 | ) -> Self { |
| 141 | let mut this = Self { inner: Timer::new(tim) }; | 193 | let mut this = Self { inner: Timer::new(tim) }; |
| 142 | 194 | ||
| 143 | this.inner.set_trigger_source(TriggerSource::TI2FP2); | 195 | this.inner.set_trigger_source(Ts::TI2FP2); |
| 144 | this.inner | 196 | this.inner |
| 145 | .set_input_ti_selection(Channel::Ch2, InputTISelection::Normal); | 197 | .set_input_ti_selection(Channel::Ch2, InputTISelection::Normal); |
| 146 | this.inner | 198 | this.inner |
| @@ -172,7 +224,7 @@ impl<'d, T: GeneralInstance4Channel> OnePulse<'d, T> { | |||
| 172 | // No filtering | 224 | // No filtering |
| 173 | r.set_etf(FilterValue::NO_FILTER); | 225 | r.set_etf(FilterValue::NO_FILTER); |
| 174 | }); | 226 | }); |
| 175 | this.inner.set_trigger_source(TriggerSource::ETRF); | 227 | this.inner.set_trigger_source(Ts::ETRF); |
| 176 | this.new_inner(freq, pulse_end, counting_mode); | 228 | this.new_inner(freq, pulse_end, counting_mode); |
| 177 | 229 | ||
| 178 | this | 230 | this |
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index 98b798634..99afb5582 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | //! PWM Input driver. | 1 | //! PWM Input driver. |
| 2 | 2 | ||
| 3 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; | 3 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; |
| 4 | use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 4 | use super::{Ch1, Ch2, Channel, GeneralInstance4Channel, TimerPin}; |
| 5 | use crate::gpio::{AfType, Pull}; | 5 | use crate::gpio::{AfType, Pull}; |
| 6 | use crate::time::Hertz; | 6 | use crate::time::Hertz; |
| 7 | use crate::Peri; | 7 | use crate::Peri; |
| @@ -14,14 +14,14 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> { | |||
| 14 | 14 | ||
| 15 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | 15 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { |
| 16 | /// Create a new PWM input driver. | 16 | /// Create a new PWM input driver. |
| 17 | pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl Channel1Pin<T>>, pull: Pull, freq: Hertz) -> Self { | 17 | pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1>>, pull: Pull, freq: Hertz) -> Self { |
| 18 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 18 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 19 | 19 | ||
| 20 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) | 20 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /// Create a new PWM input driver. | 23 | /// Create a new PWM input driver. |
| 24 | pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl Channel2Pin<T>>, pull: Pull, freq: Hertz) -> Self { | 24 | pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2>>, pull: Pull, freq: Hertz) -> Self { |
| 25 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 25 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 26 | 26 | ||
| 27 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) | 27 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) |
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index f3c81667c..eabe1b22a 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs | |||
| @@ -6,8 +6,9 @@ use stm32_metapac::timer::vals; | |||
| 6 | 6 | ||
| 7 | use super::low_level::Timer; | 7 | use super::low_level::Timer; |
| 8 | pub use super::{Ch1, Ch2}; | 8 | pub use super::{Ch1, Ch2}; |
| 9 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 9 | use super::{GeneralInstance4Channel, TimerPin}; |
| 10 | use crate::gpio::{AfType, AnyPin, Pull}; | 10 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 11 | use crate::timer::TimerChannel; | ||
| 11 | use crate::Peri; | 12 | use crate::Peri; |
| 12 | 13 | ||
| 13 | /// Counting direction | 14 | /// Counting direction |
| @@ -24,26 +25,31 @@ pub struct QeiPin<'d, T, Channel> { | |||
| 24 | phantom: PhantomData<(T, Channel)>, | 25 | phantom: PhantomData<(T, Channel)>, |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | macro_rules! channel_impl { | 28 | impl<'d, T: GeneralInstance4Channel, C: QeiChannel> QeiPin<'d, T, C> { |
| 28 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 29 | /// Create a new QEI pin instance. |
| 29 | impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> { | 30 | pub fn new(pin: Peri<'d, impl TimerPin<T, C>>) -> Self { |
| 30 | #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] | 31 | critical_section::with(|_| { |
| 31 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { | 32 | pin.set_low(); |
| 32 | critical_section::with(|_| { | 33 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); |
| 33 | pin.set_low(); | 34 | }); |
| 34 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); | 35 | QeiPin { |
| 35 | }); | 36 | _pin: pin.into(), |
| 36 | QeiPin { | 37 | phantom: PhantomData, |
| 37 | _pin: pin.into(), | ||
| 38 | phantom: PhantomData, | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | 38 | } |
| 42 | }; | 39 | } |
| 43 | } | 40 | } |
| 44 | 41 | ||
| 45 | channel_impl!(new_ch1, Ch1, Channel1Pin); | 42 | trait SealedQeiChannel: TimerChannel {} |
| 46 | channel_impl!(new_ch2, Ch2, Channel2Pin); | 43 | |
| 44 | /// Marker trait for a timer channel eligible for use with QEI. | ||
| 45 | #[expect(private_bounds)] | ||
| 46 | pub trait QeiChannel: SealedQeiChannel {} | ||
| 47 | |||
| 48 | impl QeiChannel for Ch1 {} | ||
| 49 | impl QeiChannel for Ch2 {} | ||
| 50 | |||
| 51 | impl SealedQeiChannel for Ch1 {} | ||
| 52 | impl SealedQeiChannel for Ch2 {} | ||
| 47 | 53 | ||
| 48 | /// Quadrature decoder driver. | 54 | /// Quadrature decoder driver. |
| 49 | pub struct Qei<'d, T: GeneralInstance4Channel> { | 55 | pub struct Qei<'d, T: GeneralInstance4Channel> { |
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index f7f433154..c04b1ab97 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs | |||
| @@ -4,22 +4,13 @@ use core::marker::PhantomData; | |||
| 4 | use core::mem::ManuallyDrop; | 4 | use core::mem::ManuallyDrop; |
| 5 | 5 | ||
| 6 | use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; | 6 | use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; |
| 7 | use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits}; | 7 | use super::{Ch1, Ch2, Ch3, Ch4, Channel, GeneralInstance4Channel, TimerBits, TimerChannel, TimerPin}; |
| 8 | #[cfg(gpio_v2)] | 8 | #[cfg(gpio_v2)] |
| 9 | use crate::gpio::Pull; | 9 | use crate::gpio::Pull; |
| 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 11 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| 12 | use crate::Peri; | 12 | use crate::Peri; |
| 13 | 13 | ||
| 14 | /// Channel 1 marker type. | ||
| 15 | pub enum Ch1 {} | ||
| 16 | /// Channel 2 marker type. | ||
| 17 | pub enum Ch2 {} | ||
| 18 | /// Channel 3 marker type. | ||
| 19 | pub enum Ch3 {} | ||
| 20 | /// Channel 4 marker type. | ||
| 21 | pub enum Ch4 {} | ||
| 22 | |||
| 23 | /// PWM pin wrapper. | 14 | /// PWM pin wrapper. |
| 24 | /// | 15 | /// |
| 25 | /// This wraps a pin to make it usable with PWM. | 16 | /// This wraps a pin to make it usable with PWM. |
| @@ -43,46 +34,37 @@ pub struct PwmPinConfig { | |||
| 43 | pub pull: Pull, | 34 | pub pull: Pull, |
| 44 | } | 35 | } |
| 45 | 36 | ||
| 46 | macro_rules! channel_impl { | 37 | impl<'d, T: GeneralInstance4Channel, C: TimerChannel> PwmPin<'d, T, C> { |
| 47 | ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => { | 38 | /// Create a new PWM pin instance. |
| 48 | impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> { | 39 | pub fn new(pin: Peri<'d, impl TimerPin<T, C>>, output_type: OutputType) -> Self { |
| 49 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] | 40 | critical_section::with(|_| { |
| 50 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, output_type: OutputType) -> Self { | 41 | pin.set_low(); |
| 51 | critical_section::with(|_| { | 42 | pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); |
| 52 | pin.set_low(); | 43 | }); |
| 53 | pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); | 44 | PwmPin { |
| 54 | }); | 45 | _pin: pin.into(), |
| 55 | PwmPin { | 46 | phantom: PhantomData, |
| 56 | _pin: pin.into(), | ||
| 57 | phantom: PhantomData, | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")] | ||
| 62 | pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self { | ||
| 63 | critical_section::with(|_| { | ||
| 64 | pin.set_low(); | ||
| 65 | pin.set_as_af( | ||
| 66 | pin.af_num(), | ||
| 67 | #[cfg(gpio_v1)] | ||
| 68 | AfType::output(pin_config.output_type, pin_config.speed), | ||
| 69 | #[cfg(gpio_v2)] | ||
| 70 | AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), | ||
| 71 | ); | ||
| 72 | }); | ||
| 73 | PwmPin { | ||
| 74 | _pin: pin.into(), | ||
| 75 | phantom: PhantomData, | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | 47 | } |
| 79 | }; | 48 | } |
| 80 | } | ||
| 81 | 49 | ||
| 82 | channel_impl!(new_ch1, new_ch1_with_config, Ch1, Channel1Pin); | 50 | /// Create a new PWM pin instance with config. |
| 83 | channel_impl!(new_ch2, new_ch2_with_config, Ch2, Channel2Pin); | 51 | pub fn new_with_config(pin: Peri<'d, impl TimerPin<T, C>>, pin_config: PwmPinConfig) -> Self { |
| 84 | channel_impl!(new_ch3, new_ch3_with_config, Ch3, Channel3Pin); | 52 | critical_section::with(|_| { |
| 85 | channel_impl!(new_ch4, new_ch4_with_config, Ch4, Channel4Pin); | 53 | pin.set_low(); |
| 54 | pin.set_as_af( | ||
| 55 | pin.af_num(), | ||
| 56 | #[cfg(gpio_v1)] | ||
| 57 | AfType::output(pin_config.output_type, pin_config.speed), | ||
| 58 | #[cfg(gpio_v2)] | ||
| 59 | AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), | ||
| 60 | ); | ||
| 61 | }); | ||
| 62 | PwmPin { | ||
| 63 | _pin: pin.into(), | ||
| 64 | phantom: PhantomData, | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 86 | 68 | ||
| 87 | /// A single channel of a pwm, obtained from [`SimplePwm::split`], | 69 | /// A single channel of a pwm, obtained from [`SimplePwm::split`], |
| 88 | /// [`SimplePwm::channel`], [`SimplePwm::ch1`], etc. | 70 | /// [`SimplePwm::channel`], [`SimplePwm::ch1`], etc. |
| @@ -466,107 +448,98 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | |||
| 466 | } | 448 | } |
| 467 | } | 449 | } |
| 468 | 450 | ||
| 469 | macro_rules! impl_waveform_chx { | 451 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { |
| 470 | ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => { | 452 | /// Generate a sequence of PWM waveform |
| 471 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | 453 | pub async fn waveform<C: TimerChannel>(&mut self, dma: Peri<'_, impl super::Dma<T, C>>, duty: &[u16]) { |
| 472 | /// Generate a sequence of PWM waveform | 454 | use crate::pac::timer::vals::Ccds; |
| 473 | pub async fn $fn_name(&mut self, dma: Peri<'_, impl super::$dma_ch<T>>, duty: &[u16]) { | 455 | |
| 474 | use crate::pac::timer::vals::Ccds; | 456 | #[allow(clippy::let_unit_value)] // eg. stm32f334 |
| 457 | let req = dma.request(); | ||
| 475 | 458 | ||
| 476 | #[allow(clippy::let_unit_value)] // eg. stm32f334 | 459 | let cc_channel = C::CHANNEL; |
| 477 | let req = dma.request(); | ||
| 478 | 460 | ||
| 479 | let cc_channel = Channel::$cc_ch; | 461 | let original_duty_state = self.channel(cc_channel).current_duty_cycle(); |
| 462 | let original_enable_state = self.channel(cc_channel).is_enabled(); | ||
| 463 | let original_cc_dma_on_update = self.inner.get_cc_dma_selection() == Ccds::ON_UPDATE; | ||
| 464 | let original_cc_dma_enabled = self.inner.get_cc_dma_enable_state(cc_channel); | ||
| 480 | 465 | ||
| 481 | let original_duty_state = self.channel(cc_channel).current_duty_cycle(); | 466 | // redirect CC DMA request onto Update Event |
| 482 | let original_enable_state = self.channel(cc_channel).is_enabled(); | 467 | if !original_cc_dma_on_update { |
| 483 | let original_cc_dma_on_update = self.inner.get_cc_dma_selection() == Ccds::ON_UPDATE; | 468 | self.inner.set_cc_dma_selection(Ccds::ON_UPDATE) |
| 484 | let original_cc_dma_enabled = self.inner.get_cc_dma_enable_state(cc_channel); | 469 | } |
| 485 | 470 | ||
| 486 | // redirect CC DMA request onto Update Event | 471 | if !original_cc_dma_enabled { |
| 487 | if !original_cc_dma_on_update { | 472 | self.inner.set_cc_dma_enable_state(cc_channel, true); |
| 488 | self.inner.set_cc_dma_selection(Ccds::ON_UPDATE) | 473 | } |
| 489 | } | ||
| 490 | 474 | ||
| 491 | if !original_cc_dma_enabled { | 475 | if !original_enable_state { |
| 492 | self.inner.set_cc_dma_enable_state(cc_channel, true); | 476 | self.channel(cc_channel).enable(); |
| 493 | } | 477 | } |
| 494 | 478 | ||
| 495 | if !original_enable_state { | 479 | unsafe { |
| 496 | self.channel(cc_channel).enable(); | 480 | #[cfg(not(any(bdma, gpdma)))] |
| 497 | } | 481 | use crate::dma::{Burst, FifoThreshold}; |
| 482 | use crate::dma::{Transfer, TransferOptions}; | ||
| 498 | 483 | ||
| 499 | unsafe { | 484 | let dma_transfer_option = TransferOptions { |
| 485 | #[cfg(not(any(bdma, gpdma)))] | ||
| 486 | fifo_threshold: Some(FifoThreshold::Full), | ||
| 487 | #[cfg(not(any(bdma, gpdma)))] | ||
| 488 | mburst: Burst::Incr8, | ||
| 489 | ..Default::default() | ||
| 490 | }; | ||
| 491 | |||
| 492 | match self.inner.bits() { | ||
| 493 | TimerBits::Bits16 => { | ||
| 494 | Transfer::new_write( | ||
| 495 | dma, | ||
| 496 | req, | ||
| 497 | duty, | ||
| 498 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16, | ||
| 499 | dma_transfer_option, | ||
| 500 | ) | ||
| 501 | .await | ||
| 502 | } | ||
| 503 | #[cfg(not(any(stm32l0)))] | ||
| 504 | TimerBits::Bits32 => { | ||
| 500 | #[cfg(not(any(bdma, gpdma)))] | 505 | #[cfg(not(any(bdma, gpdma)))] |
| 501 | use crate::dma::{Burst, FifoThreshold}; | 506 | panic!("unsupported timer bits"); |
| 502 | use crate::dma::{Transfer, TransferOptions}; | 507 | |
| 503 | 508 | #[cfg(any(bdma, gpdma))] | |
| 504 | let dma_transfer_option = TransferOptions { | 509 | Transfer::new_write( |
| 505 | #[cfg(not(any(bdma, gpdma)))] | 510 | dma, |
| 506 | fifo_threshold: Some(FifoThreshold::Full), | 511 | req, |
| 507 | #[cfg(not(any(bdma, gpdma)))] | 512 | duty, |
| 508 | mburst: Burst::Incr8, | 513 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32, |
| 509 | ..Default::default() | 514 | dma_transfer_option, |
| 510 | }; | 515 | ) |
| 511 | 516 | .await | |
| 512 | match self.inner.bits() { | ||
| 513 | TimerBits::Bits16 => { | ||
| 514 | Transfer::new_write( | ||
| 515 | dma, | ||
| 516 | req, | ||
| 517 | duty, | ||
| 518 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16, | ||
| 519 | dma_transfer_option, | ||
| 520 | ) | ||
| 521 | .await | ||
| 522 | } | ||
| 523 | #[cfg(not(any(stm32l0)))] | ||
| 524 | TimerBits::Bits32 => { | ||
| 525 | #[cfg(not(any(bdma, gpdma)))] | ||
| 526 | panic!("unsupported timer bits"); | ||
| 527 | |||
| 528 | #[cfg(any(bdma, gpdma))] | ||
| 529 | Transfer::new_write( | ||
| 530 | dma, | ||
| 531 | req, | ||
| 532 | duty, | ||
| 533 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32, | ||
| 534 | dma_transfer_option, | ||
| 535 | ) | ||
| 536 | .await | ||
| 537 | } | ||
| 538 | }; | ||
| 539 | }; | ||
| 540 | |||
| 541 | // restore output compare state | ||
| 542 | if !original_enable_state { | ||
| 543 | self.channel(cc_channel).disable(); | ||
| 544 | } | 517 | } |
| 518 | }; | ||
| 519 | }; | ||
| 520 | |||
| 521 | // restore output compare state | ||
| 522 | if !original_enable_state { | ||
| 523 | self.channel(cc_channel).disable(); | ||
| 524 | } | ||
| 545 | 525 | ||
| 546 | self.channel(cc_channel).set_duty_cycle(original_duty_state); | 526 | self.channel(cc_channel).set_duty_cycle(original_duty_state); |
| 547 | 527 | ||
| 548 | // Since DMA is closed before timer Capture Compare Event trigger DMA is turn off, | 528 | // Since DMA is closed before timer Capture Compare Event trigger DMA is turn off, |
| 549 | // this can almost always trigger a DMA FIFO error. | 529 | // this can almost always trigger a DMA FIFO error. |
| 550 | // | 530 | // |
| 551 | // optional TODO: | 531 | // optional TODO: |
| 552 | // clean FEIF after disable UDE | 532 | // clean FEIF after disable UDE |
| 553 | if !original_cc_dma_enabled { | 533 | if !original_cc_dma_enabled { |
| 554 | self.inner.set_cc_dma_enable_state(cc_channel, false); | 534 | self.inner.set_cc_dma_enable_state(cc_channel, false); |
| 555 | } | 535 | } |
| 556 | 536 | ||
| 557 | if !original_cc_dma_on_update { | 537 | if !original_cc_dma_on_update { |
| 558 | self.inner.set_cc_dma_selection(Ccds::ON_COMPARE) | 538 | self.inner.set_cc_dma_selection(Ccds::ON_COMPARE) |
| 559 | } | ||
| 560 | } | ||
| 561 | } | 539 | } |
| 562 | }; | 540 | } |
| 563 | } | 541 | } |
| 564 | 542 | ||
| 565 | impl_waveform_chx!(waveform_ch1, Ch1Dma, Ch1); | ||
| 566 | impl_waveform_chx!(waveform_ch2, Ch2Dma, Ch2); | ||
| 567 | impl_waveform_chx!(waveform_ch3, Ch3Dma, Ch3); | ||
| 568 | impl_waveform_chx!(waveform_ch4, Ch4Dma, Ch4); | ||
| 569 | |||
| 570 | impl<'d, T: GeneralInstance4Channel> embedded_hal_1::pwm::ErrorType for SimplePwmChannel<'d, T> { | 543 | impl<'d, T: GeneralInstance4Channel> embedded_hal_1::pwm::ErrorType for SimplePwmChannel<'d, T> { |
| 571 | type Error = core::convert::Infallible; | 544 | type Error = core::convert::Infallible; |
| 572 | } | 545 | } |
diff --git a/examples/stm32f1/src/bin/input_capture.rs b/examples/stm32f1/src/bin/input_capture.rs index 6fe8e0b50..84811fb95 100644 --- a/examples/stm32f1/src/bin/input_capture.rs +++ b/examples/stm32f1/src/bin/input_capture.rs | |||
| @@ -39,7 +39,7 @@ async fn main(spawner: Spawner) { | |||
| 39 | 39 | ||
| 40 | unwrap!(spawner.spawn(blinky(p.PC13))); | 40 | unwrap!(spawner.spawn(blinky(p.PC13))); |
| 41 | 41 | ||
| 42 | let ch3 = CapturePin::new_ch3(p.PA2, Pull::None); | 42 | let ch3 = CapturePin::new(p.PA2, Pull::None); |
| 43 | let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default()); | 43 | let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default()); |
| 44 | 44 | ||
| 45 | loop { | 45 | loop { |
diff --git a/examples/stm32f4/src/bin/input_capture.rs b/examples/stm32f4/src/bin/input_capture.rs index fe5e2bdfc..e15b4d26e 100644 --- a/examples/stm32f4/src/bin/input_capture.rs +++ b/examples/stm32f4/src/bin/input_capture.rs | |||
| @@ -39,7 +39,7 @@ async fn main(spawner: Spawner) { | |||
| 39 | 39 | ||
| 40 | unwrap!(spawner.spawn(blinky(p.PB2))); | 40 | unwrap!(spawner.spawn(blinky(p.PB2))); |
| 41 | 41 | ||
| 42 | let ch3 = CapturePin::new_ch3(p.PB10, Pull::None); | 42 | let ch3 = CapturePin::new(p.PB10, Pull::None); |
| 43 | let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default()); | 43 | let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default()); |
| 44 | 44 | ||
| 45 | loop { | 45 | loop { |
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index 04811162b..e385842f0 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs | |||
| @@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) { | |||
| 14 | let p = embassy_stm32::init(Default::default()); | 14 | let p = embassy_stm32::init(Default::default()); |
| 15 | info!("Hello World!"); | 15 | info!("Hello World!"); |
| 16 | 16 | ||
| 17 | let ch1_pin = PwmPin::new_ch1(p.PE9, OutputType::PushPull); | 17 | let ch1_pin = PwmPin::new(p.PE9, OutputType::PushPull); |
| 18 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default()); | 18 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default()); |
| 19 | let mut ch1 = pwm.ch1(); | 19 | let mut ch1 = pwm.ch1(); |
| 20 | ch1.enable(); | 20 | ch1.enable(); |
diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs index 161f43c48..c981f1a76 100644 --- a/examples/stm32f4/src/bin/pwm_complementary.rs +++ b/examples/stm32f4/src/bin/pwm_complementary.rs | |||
| @@ -16,8 +16,8 @@ async fn main(_spawner: Spawner) { | |||
| 16 | let p = embassy_stm32::init(Default::default()); | 16 | let p = embassy_stm32::init(Default::default()); |
| 17 | info!("Hello World!"); | 17 | info!("Hello World!"); |
| 18 | 18 | ||
| 19 | let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull); | 19 | let ch1 = PwmPin::new(p.PE9, OutputType::PushPull); |
| 20 | let ch1n = ComplementaryPwmPin::new_ch1(p.PA7, OutputType::PushPull); | 20 | let ch1n = ComplementaryPwmPin::new(p.PA7, OutputType::PushPull); |
| 21 | let mut pwm = ComplementaryPwm::new( | 21 | let mut pwm = ComplementaryPwm::new( |
| 22 | p.TIM1, | 22 | p.TIM1, |
| 23 | Some(ch1), | 23 | Some(ch1), |
diff --git a/examples/stm32f4/src/bin/ws2812_pwm.rs b/examples/stm32f4/src/bin/ws2812_pwm.rs index ca924e181..5153e1cfd 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm.rs | |||
| @@ -50,7 +50,7 @@ async fn main(_spawner: Spawner) { | |||
| 50 | 50 | ||
| 51 | let mut ws2812_pwm = SimplePwm::new( | 51 | let mut ws2812_pwm = SimplePwm::new( |
| 52 | dp.TIM3, | 52 | dp.TIM3, |
| 53 | Some(PwmPin::new_ch1(dp.PB4, OutputType::PushPull)), | 53 | Some(PwmPin::new(dp.PB4, OutputType::PushPull)), |
| 54 | None, | 54 | None, |
| 55 | None, | 55 | None, |
| 56 | None, | 56 | None, |
diff --git a/examples/stm32g0/src/bin/hf_timer.rs b/examples/stm32g0/src/bin/hf_timer.rs index dfb6e0edc..705905f01 100644 --- a/examples/stm32g0/src/bin/hf_timer.rs +++ b/examples/stm32g0/src/bin/hf_timer.rs | |||
| @@ -37,8 +37,8 @@ async fn main(_spawner: Spawner) { | |||
| 37 | } | 37 | } |
| 38 | let p = embassy_stm32::init(config); | 38 | let p = embassy_stm32::init(config); |
| 39 | 39 | ||
| 40 | let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull); | 40 | let ch1 = PwmPin::new(p.PA8, OutputType::PushPull); |
| 41 | let ch1n = ComplementaryPwmPin::new_ch1(p.PA7, OutputType::PushPull); | 41 | let ch1n = ComplementaryPwmPin::new(p.PA7, OutputType::PushPull); |
| 42 | 42 | ||
| 43 | let mut pwm = ComplementaryPwm::new( | 43 | let mut pwm = ComplementaryPwm::new( |
| 44 | p.TIM1, | 44 | p.TIM1, |
diff --git a/examples/stm32g0/src/bin/input_capture.rs b/examples/stm32g0/src/bin/input_capture.rs index 08df4e043..df339d541 100644 --- a/examples/stm32g0/src/bin/input_capture.rs +++ b/examples/stm32g0/src/bin/input_capture.rs | |||
| @@ -47,12 +47,12 @@ async fn main(spawner: Spawner) { | |||
| 47 | unwrap!(spawner.spawn(blinky(p.PB1))); | 47 | unwrap!(spawner.spawn(blinky(p.PB1))); |
| 48 | 48 | ||
| 49 | // Connect PB1 and PA8 with a 1k Ohm resistor | 49 | // Connect PB1 and PA8 with a 1k Ohm resistor |
| 50 | let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull); | 50 | let ch1_pin = PwmPin::new(p.PA8, OutputType::PushPull); |
| 51 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default()); | 51 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default()); |
| 52 | pwm.ch1().enable(); | 52 | pwm.ch1().enable(); |
| 53 | pwm.ch1().set_duty_cycle(50); | 53 | pwm.ch1().set_duty_cycle(50); |
| 54 | 54 | ||
| 55 | let ch1 = CapturePin::new_ch1(p.PA0, Pull::None); | 55 | let ch1 = CapturePin::new(p.PA0, Pull::None); |
| 56 | let mut ic = InputCapture::new(p.TIM2, Some(ch1), None, None, None, Irqs, khz(1000), Default::default()); | 56 | let mut ic = InputCapture::new(p.TIM2, Some(ch1), None, None, None, Irqs, khz(1000), Default::default()); |
| 57 | 57 | ||
| 58 | let mut old_capture = 0; | 58 | let mut old_capture = 0; |
diff --git a/examples/stm32g0/src/bin/pwm_complementary.rs b/examples/stm32g0/src/bin/pwm_complementary.rs index 97b163c40..dbd9194c9 100644 --- a/examples/stm32g0/src/bin/pwm_complementary.rs +++ b/examples/stm32g0/src/bin/pwm_complementary.rs | |||
| @@ -26,10 +26,10 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 26 | async fn main(_spawner: Spawner) { | 26 | async fn main(_spawner: Spawner) { |
| 27 | let p = embassy_stm32::init(Default::default()); | 27 | let p = embassy_stm32::init(Default::default()); |
| 28 | 28 | ||
| 29 | let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull); | 29 | let ch1 = PwmPin::new(p.PA8, OutputType::PushPull); |
| 30 | let ch1n = ComplementaryPwmPin::new_ch1(p.PA7, OutputType::PushPull); | 30 | let ch1n = ComplementaryPwmPin::new(p.PA7, OutputType::PushPull); |
| 31 | let ch2 = PwmPin::new_ch2(p.PB3, OutputType::PushPull); | 31 | let ch2 = PwmPin::new(p.PB3, OutputType::PushPull); |
| 32 | let ch2n = ComplementaryPwmPin::new_ch2(p.PB0, OutputType::PushPull); | 32 | let ch2n = ComplementaryPwmPin::new(p.PB0, OutputType::PushPull); |
| 33 | 33 | ||
| 34 | let mut pwm = ComplementaryPwm::new( | 34 | let mut pwm = ComplementaryPwm::new( |
| 35 | p.TIM1, | 35 | p.TIM1, |
diff --git a/examples/stm32g0/src/bin/pwm_input.rs b/examples/stm32g0/src/bin/pwm_input.rs index 9d6b5fe97..dc2428607 100644 --- a/examples/stm32g0/src/bin/pwm_input.rs +++ b/examples/stm32g0/src/bin/pwm_input.rs | |||
| @@ -42,7 +42,7 @@ async fn main(spawner: Spawner) { | |||
| 42 | 42 | ||
| 43 | unwrap!(spawner.spawn(blinky(p.PB1))); | 43 | unwrap!(spawner.spawn(blinky(p.PB1))); |
| 44 | // Connect PA8 and PA6 with a 1k Ohm resistor | 44 | // Connect PA8 and PA6 with a 1k Ohm resistor |
| 45 | let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull); | 45 | let ch1_pin = PwmPin::new(p.PA8, OutputType::PushPull); |
| 46 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default()); | 46 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default()); |
| 47 | pwm.ch1().set_duty_cycle_fraction(1, 4); | 47 | pwm.ch1().set_duty_cycle_fraction(1, 4); |
| 48 | pwm.ch1().enable(); | 48 | pwm.ch1().enable(); |
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 6c965012c..5b4194927 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs | |||
| @@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) { | |||
| 14 | let p = embassy_stm32::init(Default::default()); | 14 | let p = embassy_stm32::init(Default::default()); |
| 15 | info!("Hello World!"); | 15 | info!("Hello World!"); |
| 16 | 16 | ||
| 17 | let ch1_pin = PwmPin::new_ch1(p.PC0, OutputType::PushPull); | 17 | let ch1_pin = PwmPin::new(p.PC0, OutputType::PushPull); |
| 18 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default()); | 18 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default()); |
| 19 | let mut ch1 = pwm.ch1(); | 19 | let mut ch1 = pwm.ch1(); |
| 20 | ch1.enable(); | 20 | ch1.enable(); |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 8de31ea5b..12abb8693 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -6,7 +6,7 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::gpio::{AfType, Flex, OutputType, Speed}; | 6 | use embassy_stm32::gpio::{AfType, Flex, OutputType, Speed}; |
| 7 | use embassy_stm32::time::{khz, Hertz}; | 7 | use embassy_stm32::time::{khz, Hertz}; |
| 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; | 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; |
| 9 | use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; | 9 | use embassy_stm32::timer::{Ch1, Ch2, Ch3, Ch4, Channel, GeneralInstance32bit4Channel, TimerPin}; |
| 10 | use embassy_stm32::{Config, Peri}; | 10 | use embassy_stm32::{Config, Peri}; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -67,10 +67,10 @@ pub struct SimplePwm32<'d, T: GeneralInstance32bit4Channel> { | |||
| 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { | 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { |
| 68 | pub fn new( | 68 | pub fn new( |
| 69 | tim: Peri<'d, T>, | 69 | tim: Peri<'d, T>, |
| 70 | ch1: Peri<'d, impl Channel1Pin<T>>, | 70 | ch1: Peri<'d, impl TimerPin<T, Ch1>>, |
| 71 | ch2: Peri<'d, impl Channel2Pin<T>>, | 71 | ch2: Peri<'d, impl TimerPin<T, Ch2>>, |
| 72 | ch3: Peri<'d, impl Channel3Pin<T>>, | 72 | ch3: Peri<'d, impl TimerPin<T, Ch3>>, |
| 73 | ch4: Peri<'d, impl Channel4Pin<T>>, | 73 | ch4: Peri<'d, impl TimerPin<T, Ch4>>, |
| 74 | freq: Hertz, | 74 | freq: Hertz, |
| 75 | ) -> Self { | 75 | ) -> Self { |
| 76 | let af1 = ch1.af_num(); | 76 | let af1 = ch1.af_num(); |
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index a1c53fc3f..73b43be69 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -36,7 +36,7 @@ async fn main(_spawner: Spawner) { | |||
| 36 | let p = embassy_stm32::init(config); | 36 | let p = embassy_stm32::init(config); |
| 37 | info!("Hello World!"); | 37 | info!("Hello World!"); |
| 38 | 38 | ||
| 39 | let ch1_pin = PwmPin::new_ch1(p.PA6, OutputType::PushPull); | 39 | let ch1_pin = PwmPin::new(p.PA6, OutputType::PushPull); |
| 40 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1_pin), None, None, None, khz(10), Default::default()); | 40 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1_pin), None, None, None, khz(10), Default::default()); |
| 41 | let mut ch1 = pwm.ch1(); | 41 | let mut ch1 = pwm.ch1(); |
| 42 | ch1.enable(); | 42 | ch1.enable(); |
diff --git a/examples/stm32l0/src/bin/dds.rs b/examples/stm32l0/src/bin/dds.rs index a54b28a93..eaa7a61a8 100644 --- a/examples/stm32l0/src/bin/dds.rs +++ b/examples/stm32l0/src/bin/dds.rs | |||
| @@ -11,7 +11,7 @@ use embassy_stm32::rcc::*; | |||
| 11 | use embassy_stm32::time::hz; | 11 | use embassy_stm32::time::hz; |
| 12 | use embassy_stm32::timer::low_level::{Timer as LLTimer, *}; | 12 | use embassy_stm32::timer::low_level::{Timer as LLTimer, *}; |
| 13 | use embassy_stm32::timer::simple_pwm::PwmPin; | 13 | use embassy_stm32::timer::simple_pwm::PwmPin; |
| 14 | use embassy_stm32::timer::Channel; | 14 | use embassy_stm32::timer::{Ch3, Channel}; |
| 15 | use embassy_stm32::{interrupt, pac, Config}; | 15 | use embassy_stm32::{interrupt, pac, Config}; |
| 16 | use panic_probe as _; | 16 | use panic_probe as _; |
| 17 | 17 | ||
| @@ -70,7 +70,7 @@ async fn main(_spawner: Spawner) { | |||
| 70 | let p = embassy_stm32::init(config); | 70 | let p = embassy_stm32::init(config); |
| 71 | 71 | ||
| 72 | // setup PWM pin in AF mode | 72 | // setup PWM pin in AF mode |
| 73 | let _ch3 = PwmPin::new_ch3(p.PA2, OutputType::PushPull); | 73 | let _ch3 = PwmPin::<_, Ch3>::new(p.PA2, OutputType::PushPull); |
| 74 | 74 | ||
| 75 | // initialize timer | 75 | // initialize timer |
| 76 | // we cannot use SimplePWM here because the Time is privately encapsulated | 76 | // we cannot use SimplePWM here because the Time is privately encapsulated |
