diff options
| author | 1-rafael-1 <[email protected]> | 2025-09-15 20:07:18 +0200 |
|---|---|---|
| committer | 1-rafael-1 <[email protected]> | 2025-09-15 20:07:18 +0200 |
| commit | 6bb3d2c0720fa082f27d3cdb70f516058497ec87 (patch) | |
| tree | 5a1e255cff999b00800f203b91a759c720c973e5 /embassy-stm32/src/timer/mod.rs | |
| parent | eb685574601d98c44faed9a3534d056199b46e20 (diff) | |
| parent | 92a6fd2946f2cbb15359290f68aa360953da2ff7 (diff) | |
Merge branch 'main' into rp2040-rtc-alarm
Diffstat (limited to 'embassy-stm32/src/timer/mod.rs')
| -rw-r--r-- | embassy-stm32/src/timer/mod.rs | 101 |
1 files changed, 81 insertions, 20 deletions
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index b29382fc8..b09bc7166 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, @A); |
| 153 | pin_trait!(Channel2Pin, GeneralInstance4Channel); | 227 | pin_trait!(ExternalTriggerPin, GeneralInstance4Channel, @A); |
| 154 | pin_trait!(Channel3Pin, GeneralInstance4Channel); | ||
| 155 | pin_trait!(Channel4Pin, GeneralInstance4Channel); | ||
| 156 | pin_trait!(ExternalTriggerPin, GeneralInstance4Channel); | ||
| 157 | |||
| 158 | pin_trait!(Channel1ComplementaryPin, AdvancedInstance4Channel); | ||
| 159 | pin_trait!(Channel2ComplementaryPin, AdvancedInstance4Channel); | ||
| 160 | pin_trait!(Channel3ComplementaryPin, AdvancedInstance4Channel); | ||
| 161 | pin_trait!(Channel4ComplementaryPin, AdvancedInstance4Channel); | ||
| 162 | 228 | ||
| 163 | pin_trait!(BreakInputPin, AdvancedInstance4Channel); | 229 | pin_trait!(TimerComplementaryPin, AdvancedInstance4Channel, TimerChannel, @A); |
| 164 | pin_trait!(BreakInput2Pin, AdvancedInstance4Channel); | ||
| 165 | 230 | ||
| 166 | pin_trait!(BreakInputComparator1Pin, AdvancedInstance4Channel); | 231 | pin_trait!(BreakInputPin, AdvancedInstance4Channel, BreakInput, @A); |
| 167 | pin_trait!(BreakInputComparator2Pin, AdvancedInstance4Channel); | ||
| 168 | 232 | ||
| 169 | pin_trait!(BreakInput2Comparator1Pin, AdvancedInstance4Channel); | 233 | pin_trait!(BreakInputComparator1Pin, AdvancedInstance4Channel, BreakInput, @A); |
| 170 | pin_trait!(BreakInput2Comparator2Pin, AdvancedInstance4Channel); | 234 | pin_trait!(BreakInputComparator2Pin, AdvancedInstance4Channel, BreakInput, @A); |
| 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 { |
