diff options
| author | eZio Pan <[email protected]> | 2024-03-25 19:25:38 +0800 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:51:20 +0200 |
| commit | 348a46b110b63e7ba1ca8ca558331c00963d0800 (patch) | |
| tree | cd5599235428f28255913d9d280bc3ce353193be /embassy-stm32/src/timer/mod.rs | |
| parent | d597815c9aed3c2d6b8729db1b78fd0e843181f6 (diff) | |
move `enable_outputs` to private trait ...
... to avoid API leaking.
Diffstat (limited to 'embassy-stm32/src/timer/mod.rs')
| -rw-r--r-- | embassy-stm32/src/timer/mod.rs | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 2ba6b3f11..5c03aa1cb 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -69,17 +69,26 @@ pub trait GeneralInstance1Channel: CoreInstance {} | |||
| 69 | /// General-purpose 16-bit timer with 2 channels instance. | 69 | /// General-purpose 16-bit timer with 2 channels instance. |
| 70 | pub trait GeneralInstance2Channel: GeneralInstance1Channel {} | 70 | pub trait GeneralInstance2Channel: GeneralInstance1Channel {} |
| 71 | 71 | ||
| 72 | /// General-purpose 16-bit timer with 4 channels instance. | 72 | // This trait add *extra* methods to GeneralInstance4Channel, |
| 73 | pub trait GeneralInstance4Channel: BasicInstance + GeneralInstance2Channel { | 73 | // that GeneralInstance4Channel doesn't use, but the "AdvancedInstance"s need. |
| 74 | // And it's a private trait, so it's content won't leak to outer namespace. | ||
| 75 | // | ||
| 76 | // If you want to add a new method to it, please leave a detail comment to explain it. | ||
| 77 | trait General4ChBlankSealed { | ||
| 74 | // SimplePwm<'d, T> is implemented for T: GeneralInstance4Channel | 78 | // SimplePwm<'d, T> is implemented for T: GeneralInstance4Channel |
| 75 | // Advanced timers implement this trait, but the output needs to be | 79 | // Advanced timers implement this trait, but the output needs to be |
| 76 | // enabled explicitly. | 80 | // enabled explicitly. |
| 77 | // To support general-purpose and advanced timers, this function is added | 81 | // To support general-purpose and advanced timers, this function is added |
| 78 | // here defaulting to noop and overwritten for advanced timers. | 82 | // here defaulting to noop and overwritten for advanced timers. |
| 79 | /// Enable timer outputs. | 83 | // |
| 84 | // Enable timer outputs. | ||
| 80 | fn enable_outputs(&self) {} | 85 | fn enable_outputs(&self) {} |
| 81 | } | 86 | } |
| 82 | 87 | ||
| 88 | /// General-purpose 16-bit timer with 4 channels instance. | ||
| 89 | #[allow(private_bounds)] | ||
| 90 | pub trait GeneralInstance4Channel: BasicInstance + GeneralInstance2Channel + General4ChBlankSealed {} | ||
| 91 | |||
| 83 | /// General-purpose 32-bit timer with 4 channels instance. | 92 | /// General-purpose 32-bit timer with 4 channels instance. |
| 84 | pub trait GeneralInstance32bit4Channel: GeneralInstance4Channel {} | 93 | pub trait GeneralInstance32bit4Channel: GeneralInstance4Channel {} |
| 85 | 94 | ||
| @@ -138,6 +147,21 @@ macro_rules! impl_core_timer { | |||
| 138 | }; | 147 | }; |
| 139 | } | 148 | } |
| 140 | 149 | ||
| 150 | // This macro only apply to "AdvancedInstance(s)", | ||
| 151 | // not "GeneralInstance4Channel" itself. | ||
| 152 | #[allow(unused)] | ||
| 153 | macro_rules! impl_general_4ch_blank_sealed { | ||
| 154 | ($inst:ident) => { | ||
| 155 | impl General4ChBlankSealed for crate::peripherals::$inst { | ||
| 156 | fn enable_outputs(&self) { | ||
| 157 | unsafe { crate::pac::timer::Tim1chCmp::from_ptr(Self::regs()) } | ||
| 158 | .bdtr() | ||
| 159 | .modify(|w| w.set_moe(true)); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | }; | ||
| 163 | } | ||
| 164 | |||
| 141 | foreach_interrupt! { | 165 | foreach_interrupt! { |
| 142 | ($inst:ident, timer, TIM_BASIC, UP, $irq:ident) => { | 166 | ($inst:ident, timer, TIM_BASIC, UP, $irq:ident) => { |
| 143 | impl_core_timer!($inst, TimerBits::Bits16); | 167 | impl_core_timer!($inst, TimerBits::Bits16); |
| @@ -152,6 +176,7 @@ foreach_interrupt! { | |||
| 152 | impl GeneralInstance1Channel for crate::peripherals::$inst {} | 176 | impl GeneralInstance1Channel for crate::peripherals::$inst {} |
| 153 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 177 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 154 | impl GeneralInstance4Channel for crate::peripherals::$inst {} | 178 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 179 | impl General4ChBlankSealed for crate::peripherals::$inst {} | ||
| 155 | }; | 180 | }; |
| 156 | 181 | ||
| 157 | ($inst:ident, timer, TIM_2CH, UP, $irq:ident) => { | 182 | ($inst:ident, timer, TIM_2CH, UP, $irq:ident) => { |
| @@ -161,6 +186,7 @@ foreach_interrupt! { | |||
| 161 | impl GeneralInstance1Channel for crate::peripherals::$inst {} | 186 | impl GeneralInstance1Channel for crate::peripherals::$inst {} |
| 162 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 187 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 163 | impl GeneralInstance4Channel for crate::peripherals::$inst {} | 188 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 189 | impl General4ChBlankSealed for crate::peripherals::$inst {} | ||
| 164 | }; | 190 | }; |
| 165 | 191 | ||
| 166 | ($inst:ident, timer, TIM_GP16, UP, $irq:ident) => { | 192 | ($inst:ident, timer, TIM_GP16, UP, $irq:ident) => { |
| @@ -170,6 +196,7 @@ foreach_interrupt! { | |||
| 170 | impl GeneralInstance1Channel for crate::peripherals::$inst {} | 196 | impl GeneralInstance1Channel for crate::peripherals::$inst {} |
| 171 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 197 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 172 | impl GeneralInstance4Channel for crate::peripherals::$inst {} | 198 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 199 | impl General4ChBlankSealed for crate::peripherals::$inst {} | ||
| 173 | }; | 200 | }; |
| 174 | 201 | ||
| 175 | ($inst:ident, timer, TIM_GP32, UP, $irq:ident) => { | 202 | ($inst:ident, timer, TIM_GP32, UP, $irq:ident) => { |
| @@ -180,6 +207,7 @@ foreach_interrupt! { | |||
| 180 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 207 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 181 | impl GeneralInstance4Channel for crate::peripherals::$inst {} | 208 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 182 | impl GeneralInstance32bit4Channel for crate::peripherals::$inst {} | 209 | impl GeneralInstance32bit4Channel for crate::peripherals::$inst {} |
| 210 | impl General4ChBlankSealed for crate::peripherals::$inst {} | ||
| 183 | }; | 211 | }; |
| 184 | 212 | ||
| 185 | ($inst:ident, timer, TIM_1CH_CMP, UP, $irq:ident) => { | 213 | ($inst:ident, timer, TIM_1CH_CMP, UP, $irq:ident) => { |
| @@ -188,7 +216,8 @@ foreach_interrupt! { | |||
| 188 | impl BasicInstance for crate::peripherals::$inst {} | 216 | impl BasicInstance for crate::peripherals::$inst {} |
| 189 | impl GeneralInstance1Channel for crate::peripherals::$inst {} | 217 | impl GeneralInstance1Channel for crate::peripherals::$inst {} |
| 190 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 218 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 191 | impl GeneralInstance4Channel for crate::peripherals::$inst { fn enable_outputs(&self) { set_moe::<Self>() }} | 219 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 220 | impl_general_4ch_blank_sealed!($inst); | ||
| 192 | impl AdvancedInstance1Channel for crate::peripherals::$inst { type CaptureCompareInterrupt = crate::_generated::peripheral_interrupts::$inst::CC; } | 221 | impl AdvancedInstance1Channel for crate::peripherals::$inst { type CaptureCompareInterrupt = crate::_generated::peripheral_interrupts::$inst::CC; } |
| 193 | impl AdvancedInstance2Channel for crate::peripherals::$inst {} | 222 | impl AdvancedInstance2Channel for crate::peripherals::$inst {} |
| 194 | impl AdvancedInstance4Channel for crate::peripherals::$inst {} | 223 | impl AdvancedInstance4Channel for crate::peripherals::$inst {} |
| @@ -200,7 +229,8 @@ foreach_interrupt! { | |||
| 200 | impl BasicInstance for crate::peripherals::$inst {} | 229 | impl BasicInstance for crate::peripherals::$inst {} |
| 201 | impl GeneralInstance1Channel for crate::peripherals::$inst {} | 230 | impl GeneralInstance1Channel for crate::peripherals::$inst {} |
| 202 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 231 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 203 | impl GeneralInstance4Channel for crate::peripherals::$inst { fn enable_outputs(&self) { set_moe::<Self>() }} | 232 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 233 | impl_general_4ch_blank_sealed!($inst); | ||
| 204 | impl AdvancedInstance1Channel for crate::peripherals::$inst { type CaptureCompareInterrupt = crate::_generated::peripheral_interrupts::$inst::CC; } | 234 | impl AdvancedInstance1Channel for crate::peripherals::$inst { type CaptureCompareInterrupt = crate::_generated::peripheral_interrupts::$inst::CC; } |
| 205 | impl AdvancedInstance2Channel for crate::peripherals::$inst {} | 235 | impl AdvancedInstance2Channel for crate::peripherals::$inst {} |
| 206 | impl AdvancedInstance4Channel for crate::peripherals::$inst {} | 236 | impl AdvancedInstance4Channel for crate::peripherals::$inst {} |
| @@ -212,7 +242,8 @@ foreach_interrupt! { | |||
| 212 | impl BasicInstance for crate::peripherals::$inst {} | 242 | impl BasicInstance for crate::peripherals::$inst {} |
| 213 | impl GeneralInstance1Channel for crate::peripherals::$inst {} | 243 | impl GeneralInstance1Channel for crate::peripherals::$inst {} |
| 214 | impl GeneralInstance2Channel for crate::peripherals::$inst {} | 244 | impl GeneralInstance2Channel for crate::peripherals::$inst {} |
| 215 | impl GeneralInstance4Channel for crate::peripherals::$inst { fn enable_outputs(&self) { set_moe::<Self>() }} | 245 | impl GeneralInstance4Channel for crate::peripherals::$inst {} |
| 246 | impl_general_4ch_blank_sealed!($inst); | ||
| 216 | impl AdvancedInstance1Channel for crate::peripherals::$inst { type CaptureCompareInterrupt = crate::_generated::peripheral_interrupts::$inst::CC; } | 247 | impl AdvancedInstance1Channel for crate::peripherals::$inst { type CaptureCompareInterrupt = crate::_generated::peripheral_interrupts::$inst::CC; } |
| 217 | impl AdvancedInstance2Channel for crate::peripherals::$inst {} | 248 | impl AdvancedInstance2Channel for crate::peripherals::$inst {} |
| 218 | impl AdvancedInstance4Channel for crate::peripherals::$inst {} | 249 | impl AdvancedInstance4Channel for crate::peripherals::$inst {} |
