diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:56:21 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:56:21 +0200 |
| commit | 3d7d3e028601ca05e58d82b8efc72b40855def86 (patch) | |
| tree | 277c7a59f7c811d0e2b0de9b660570f1f142d91e | |
| parent | 5dc3738bc2b4e1d8f9f77588ecab7956493b59de (diff) | |
stm32/time-driver: always use CC interrupt.
This avoids cfg's, because it works both for timers that have a a dedicated CC interrupt
line, and timers where all interrupts go to a single interrupt line.
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index a2e75020c..e592fbf7d 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -15,7 +15,7 @@ use crate::pac::timer::vals; | |||
| 15 | use crate::rcc::SealedRccPeripheral; | 15 | use crate::rcc::SealedRccPeripheral; |
| 16 | #[cfg(feature = "low-power")] | 16 | #[cfg(feature = "low-power")] |
| 17 | use crate::rtc::Rtc; | 17 | use crate::rtc::Rtc; |
| 18 | use crate::timer::CoreInstance; | 18 | use crate::timer::{CoreInstance, GeneralInstance1Channel}; |
| 19 | use crate::{interrupt, peripherals}; | 19 | use crate::{interrupt, peripherals}; |
| 20 | 20 | ||
| 21 | // NOTE regarding ALARM_COUNT: | 21 | // NOTE regarding ALARM_COUNT: |
| @@ -67,7 +67,7 @@ type T = peripherals::TIM23; | |||
| 67 | type T = peripherals::TIM24; | 67 | type T = peripherals::TIM24; |
| 68 | 68 | ||
| 69 | foreach_interrupt! { | 69 | foreach_interrupt! { |
| 70 | (TIM1, timer, $block:ident, UP, $irq:ident) => { | 70 | (TIM1, timer, $block:ident, CC, $irq:ident) => { |
| 71 | #[cfg(time_driver_tim1)] | 71 | #[cfg(time_driver_tim1)] |
| 72 | #[cfg(feature = "rt")] | 72 | #[cfg(feature = "rt")] |
| 73 | #[interrupt] | 73 | #[interrupt] |
| @@ -83,7 +83,7 @@ foreach_interrupt! { | |||
| 83 | DRIVER.on_interrupt() | 83 | DRIVER.on_interrupt() |
| 84 | } | 84 | } |
| 85 | }; | 85 | }; |
| 86 | (TIM2, timer, $block:ident, UP, $irq:ident) => { | 86 | (TIM2, timer, $block:ident, CC, $irq:ident) => { |
| 87 | #[cfg(time_driver_tim2)] | 87 | #[cfg(time_driver_tim2)] |
| 88 | #[cfg(feature = "rt")] | 88 | #[cfg(feature = "rt")] |
| 89 | #[interrupt] | 89 | #[interrupt] |
| @@ -91,7 +91,7 @@ foreach_interrupt! { | |||
| 91 | DRIVER.on_interrupt() | 91 | DRIVER.on_interrupt() |
| 92 | } | 92 | } |
| 93 | }; | 93 | }; |
| 94 | (TIM3, timer, $block:ident, UP, $irq:ident) => { | 94 | (TIM3, timer, $block:ident, CC, $irq:ident) => { |
| 95 | #[cfg(time_driver_tim3)] | 95 | #[cfg(time_driver_tim3)] |
| 96 | #[cfg(feature = "rt")] | 96 | #[cfg(feature = "rt")] |
| 97 | #[interrupt] | 97 | #[interrupt] |
| @@ -99,7 +99,7 @@ foreach_interrupt! { | |||
| 99 | DRIVER.on_interrupt() | 99 | DRIVER.on_interrupt() |
| 100 | } | 100 | } |
| 101 | }; | 101 | }; |
| 102 | (TIM4, timer, $block:ident, UP, $irq:ident) => { | 102 | (TIM4, timer, $block:ident, CC, $irq:ident) => { |
| 103 | #[cfg(time_driver_tim4)] | 103 | #[cfg(time_driver_tim4)] |
| 104 | #[cfg(feature = "rt")] | 104 | #[cfg(feature = "rt")] |
| 105 | #[interrupt] | 105 | #[interrupt] |
| @@ -107,7 +107,7 @@ foreach_interrupt! { | |||
| 107 | DRIVER.on_interrupt() | 107 | DRIVER.on_interrupt() |
| 108 | } | 108 | } |
| 109 | }; | 109 | }; |
| 110 | (TIM5, timer, $block:ident, UP, $irq:ident) => { | 110 | (TIM5, timer, $block:ident, CC, $irq:ident) => { |
| 111 | #[cfg(time_driver_tim5)] | 111 | #[cfg(time_driver_tim5)] |
| 112 | #[cfg(feature = "rt")] | 112 | #[cfg(feature = "rt")] |
| 113 | #[interrupt] | 113 | #[interrupt] |
| @@ -115,7 +115,7 @@ foreach_interrupt! { | |||
| 115 | DRIVER.on_interrupt() | 115 | DRIVER.on_interrupt() |
| 116 | } | 116 | } |
| 117 | }; | 117 | }; |
| 118 | (TIM8, timer, $block:ident, UP, $irq:ident) => { | 118 | (TIM8, timer, $block:ident, CC, $irq:ident) => { |
| 119 | #[cfg(time_driver_tim8)] | 119 | #[cfg(time_driver_tim8)] |
| 120 | #[cfg(feature = "rt")] | 120 | #[cfg(feature = "rt")] |
| 121 | #[interrupt] | 121 | #[interrupt] |
| @@ -131,7 +131,7 @@ foreach_interrupt! { | |||
| 131 | DRIVER.on_interrupt() | 131 | DRIVER.on_interrupt() |
| 132 | } | 132 | } |
| 133 | }; | 133 | }; |
| 134 | (TIM9, timer, $block:ident, UP, $irq:ident) => { | 134 | (TIM9, timer, $block:ident, CC, $irq:ident) => { |
| 135 | #[cfg(time_driver_tim9)] | 135 | #[cfg(time_driver_tim9)] |
| 136 | #[cfg(feature = "rt")] | 136 | #[cfg(feature = "rt")] |
| 137 | #[interrupt] | 137 | #[interrupt] |
| @@ -139,7 +139,7 @@ foreach_interrupt! { | |||
| 139 | DRIVER.on_interrupt() | 139 | DRIVER.on_interrupt() |
| 140 | } | 140 | } |
| 141 | }; | 141 | }; |
| 142 | (TIM12, timer, $block:ident, UP, $irq:ident) => { | 142 | (TIM12, timer, $block:ident, CC, $irq:ident) => { |
| 143 | #[cfg(time_driver_tim12)] | 143 | #[cfg(time_driver_tim12)] |
| 144 | #[cfg(feature = "rt")] | 144 | #[cfg(feature = "rt")] |
| 145 | #[interrupt] | 145 | #[interrupt] |
| @@ -147,7 +147,7 @@ foreach_interrupt! { | |||
| 147 | DRIVER.on_interrupt() | 147 | DRIVER.on_interrupt() |
| 148 | } | 148 | } |
| 149 | }; | 149 | }; |
| 150 | (TIM15, timer, $block:ident, UP, $irq:ident) => { | 150 | (TIM15, timer, $block:ident, CC, $irq:ident) => { |
| 151 | #[cfg(time_driver_tim15)] | 151 | #[cfg(time_driver_tim15)] |
| 152 | #[cfg(feature = "rt")] | 152 | #[cfg(feature = "rt")] |
| 153 | #[interrupt] | 153 | #[interrupt] |
| @@ -155,7 +155,7 @@ foreach_interrupt! { | |||
| 155 | DRIVER.on_interrupt() | 155 | DRIVER.on_interrupt() |
| 156 | } | 156 | } |
| 157 | }; | 157 | }; |
| 158 | (TIM20, timer, $block:ident, UP, $irq:ident) => { | 158 | (TIM20, timer, $block:ident, CC, $irq:ident) => { |
| 159 | #[cfg(time_driver_tim20)] | 159 | #[cfg(time_driver_tim20)] |
| 160 | #[cfg(feature = "rt")] | 160 | #[cfg(feature = "rt")] |
| 161 | #[interrupt] | 161 | #[interrupt] |
| @@ -171,7 +171,7 @@ foreach_interrupt! { | |||
| 171 | DRIVER.on_interrupt() | 171 | DRIVER.on_interrupt() |
| 172 | } | 172 | } |
| 173 | }; | 173 | }; |
| 174 | (TIM21, timer, $block:ident, UP, $irq:ident) => { | 174 | (TIM21, timer, $block:ident, CC, $irq:ident) => { |
| 175 | #[cfg(time_driver_tim21)] | 175 | #[cfg(time_driver_tim21)] |
| 176 | #[cfg(feature = "rt")] | 176 | #[cfg(feature = "rt")] |
| 177 | #[interrupt] | 177 | #[interrupt] |
| @@ -179,7 +179,7 @@ foreach_interrupt! { | |||
| 179 | DRIVER.on_interrupt() | 179 | DRIVER.on_interrupt() |
| 180 | } | 180 | } |
| 181 | }; | 181 | }; |
| 182 | (TIM22, timer, $block:ident, UP, $irq:ident) => { | 182 | (TIM22, timer, $block:ident, CC, $irq:ident) => { |
| 183 | #[cfg(time_driver_tim22)] | 183 | #[cfg(time_driver_tim22)] |
| 184 | #[cfg(feature = "rt")] | 184 | #[cfg(feature = "rt")] |
| 185 | #[interrupt] | 185 | #[interrupt] |
| @@ -187,7 +187,7 @@ foreach_interrupt! { | |||
| 187 | DRIVER.on_interrupt() | 187 | DRIVER.on_interrupt() |
| 188 | } | 188 | } |
| 189 | }; | 189 | }; |
| 190 | (TIM23, timer, $block:ident, UP, $irq:ident) => { | 190 | (TIM23, timer, $block:ident, CC, $irq:ident) => { |
| 191 | #[cfg(time_driver_tim23)] | 191 | #[cfg(time_driver_tim23)] |
| 192 | #[cfg(feature = "rt")] | 192 | #[cfg(feature = "rt")] |
| 193 | #[interrupt] | 193 | #[interrupt] |
| @@ -195,7 +195,7 @@ foreach_interrupt! { | |||
| 195 | DRIVER.on_interrupt() | 195 | DRIVER.on_interrupt() |
| 196 | } | 196 | } |
| 197 | }; | 197 | }; |
| 198 | (TIM24, timer, $block:ident, UP, $irq:ident) => { | 198 | (TIM24, timer, $block:ident, CC, $irq:ident) => { |
| 199 | #[cfg(time_driver_tim24)] | 199 | #[cfg(time_driver_tim24)] |
| 200 | #[cfg(feature = "rt")] | 200 | #[cfg(feature = "rt")] |
| 201 | #[interrupt] | 201 | #[interrupt] |
| @@ -306,17 +306,8 @@ impl RtcDriver { | |||
| 306 | w.set_ccie(0, true); | 306 | w.set_ccie(0, true); |
| 307 | }); | 307 | }); |
| 308 | 308 | ||
| 309 | <T as CoreInstance>::UpdateInterrupt::unpend(); | 309 | <T as GeneralInstance1Channel>::CaptureCompareInterrupt::unpend(); |
| 310 | unsafe { <T as CoreInstance>::UpdateInterrupt::enable() }; | 310 | unsafe { <T as GeneralInstance1Channel>::CaptureCompareInterrupt::enable() }; |
| 311 | |||
| 312 | #[cfg(any(time_driver_tim1, time_driver_tim8, time_driver_tim20))] | ||
| 313 | { | ||
| 314 | use crate::timer::GeneralInstance1Channel; | ||
| 315 | <T as GeneralInstance1Channel>::CaptureCompareInterrupt::unpend(); | ||
| 316 | unsafe { | ||
| 317 | <T as GeneralInstance1Channel>::CaptureCompareInterrupt::enable(); | ||
| 318 | } | ||
| 319 | } | ||
| 320 | 311 | ||
| 321 | r.cr1().modify(|w| w.set_cen(true)); | 312 | r.cr1().modify(|w| w.set_cen(true)); |
| 322 | } | 313 | } |
