aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/timer/mod.rs')
-rw-r--r--embassy-stm32/src/timer/mod.rs64
1 files changed, 32 insertions, 32 deletions
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 9480d6972..9397da2a1 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -65,17 +65,17 @@ pub(crate) mod sealed {
65 fn regs_core() -> crate::pac::timer::TimCore; 65 fn regs_core() -> crate::pac::timer::TimCore;
66 66
67 /// Start the timer. 67 /// Start the timer.
68 fn start(&mut self) { 68 fn start(&self) {
69 Self::regs_core().cr1().modify(|r| r.set_cen(true)); 69 Self::regs_core().cr1().modify(|r| r.set_cen(true));
70 } 70 }
71 71
72 /// Stop the timer. 72 /// Stop the timer.
73 fn stop(&mut self) { 73 fn stop(&self) {
74 Self::regs_core().cr1().modify(|r| r.set_cen(false)); 74 Self::regs_core().cr1().modify(|r| r.set_cen(false));
75 } 75 }
76 76
77 /// Reset the counter value to 0 77 /// Reset the counter value to 0
78 fn reset(&mut self) { 78 fn reset(&self) {
79 Self::regs_core().cnt().write(|r| r.set_cnt(0)); 79 Self::regs_core().cnt().write(|r| r.set_cnt(0));
80 } 80 }
81 81
@@ -85,7 +85,7 @@ pub(crate) mod sealed {
85 /// the timer counter will wrap around at the same frequency as is being set. 85 /// the timer counter will wrap around at the same frequency as is being set.
86 /// In center-aligned mode (which not all timers support), the wrap-around frequency is effectively halved 86 /// In center-aligned mode (which not all timers support), the wrap-around frequency is effectively halved
87 /// because it needs to count up and down. 87 /// because it needs to count up and down.
88 fn set_frequency(&mut self, frequency: Hertz) { 88 fn set_frequency(&self, frequency: Hertz) {
89 let f = frequency.0; 89 let f = frequency.0;
90 let timer_f = Self::frequency().0; 90 let timer_f = Self::frequency().0;
91 assert!(f > 0); 91 assert!(f > 0);
@@ -108,7 +108,7 @@ pub(crate) mod sealed {
108 /// Clear update interrupt. 108 /// Clear update interrupt.
109 /// 109 ///
110 /// Returns whether the update interrupt flag was set. 110 /// Returns whether the update interrupt flag was set.
111 fn clear_update_interrupt(&mut self) -> bool { 111 fn clear_update_interrupt(&self) -> bool {
112 let regs = Self::regs_core(); 112 let regs = Self::regs_core();
113 let sr = regs.sr().read(); 113 let sr = regs.sr().read();
114 if sr.uif() { 114 if sr.uif() {
@@ -122,12 +122,12 @@ pub(crate) mod sealed {
122 } 122 }
123 123
124 /// Enable/disable the update interrupt. 124 /// Enable/disable the update interrupt.
125 fn enable_update_interrupt(&mut self, enable: bool) { 125 fn enable_update_interrupt(&self, enable: bool) {
126 Self::regs_core().dier().modify(|r| r.set_uie(enable)); 126 Self::regs_core().dier().modify(|r| r.set_uie(enable));
127 } 127 }
128 128
129 /// Enable/disable autoreload preload. 129 /// Enable/disable autoreload preload.
130 fn set_autoreload_preload(&mut self, enable: bool) { 130 fn set_autoreload_preload(&self, enable: bool) {
131 Self::regs_core().cr1().modify(|r| r.set_arpe(enable)); 131 Self::regs_core().cr1().modify(|r| r.set_arpe(enable));
132 } 132 }
133 133
@@ -154,7 +154,7 @@ pub(crate) mod sealed {
154 fn regs_basic_no_cr2() -> crate::pac::timer::TimBasicNoCr2; 154 fn regs_basic_no_cr2() -> crate::pac::timer::TimBasicNoCr2;
155 155
156 /// Enable/disable the update dma. 156 /// Enable/disable the update dma.
157 fn enable_update_dma(&mut self, enable: bool) { 157 fn enable_update_dma(&self, enable: bool) {
158 Self::regs_basic_no_cr2().dier().modify(|r| r.set_ude(enable)); 158 Self::regs_basic_no_cr2().dier().modify(|r| r.set_ude(enable));
159 } 159 }
160 160
@@ -186,7 +186,7 @@ pub(crate) mod sealed {
186 fn regs_1ch() -> crate::pac::timer::Tim1ch; 186 fn regs_1ch() -> crate::pac::timer::Tim1ch;
187 187
188 /// Set clock divider. 188 /// Set clock divider.
189 fn set_clock_division(&mut self, ckd: vals::Ckd) { 189 fn set_clock_division(&self, ckd: vals::Ckd) {
190 Self::regs_1ch().cr1().modify(|r| r.set_ckd(ckd)); 190 Self::regs_1ch().cr1().modify(|r| r.set_ckd(ckd));
191 } 191 }
192 192
@@ -218,7 +218,7 @@ pub(crate) mod sealed {
218 fn regs_gp16() -> crate::pac::timer::TimGp16; 218 fn regs_gp16() -> crate::pac::timer::TimGp16;
219 219
220 /// Set counting mode. 220 /// Set counting mode.
221 fn set_counting_mode(&mut self, mode: CountingMode) { 221 fn set_counting_mode(&self, mode: CountingMode) {
222 let (cms, dir) = mode.into(); 222 let (cms, dir) = mode.into();
223 223
224 let timer_enabled = Self::regs_core().cr1().read().cen(); 224 let timer_enabled = Self::regs_core().cr1().read().cen();
@@ -237,7 +237,7 @@ pub(crate) mod sealed {
237 } 237 }
238 238
239 /// Set input capture filter. 239 /// Set input capture filter.
240 fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::FilterValue) { 240 fn set_input_capture_filter(&self, channel: Channel, icf: vals::FilterValue) {
241 let raw_channel = channel.index(); 241 let raw_channel = channel.index();
242 Self::regs_gp16() 242 Self::regs_gp16()
243 .ccmr_input(raw_channel / 2) 243 .ccmr_input(raw_channel / 2)
@@ -245,17 +245,17 @@ pub(crate) mod sealed {
245 } 245 }
246 246
247 /// Clear input interrupt. 247 /// Clear input interrupt.
248 fn clear_input_interrupt(&mut self, channel: Channel) { 248 fn clear_input_interrupt(&self, channel: Channel) {
249 Self::regs_gp16().sr().modify(|r| r.set_ccif(channel.index(), false)); 249 Self::regs_gp16().sr().modify(|r| r.set_ccif(channel.index(), false));
250 } 250 }
251 251
252 /// Enable input interrupt. 252 /// Enable input interrupt.
253 fn enable_input_interrupt(&mut self, channel: Channel, enable: bool) { 253 fn enable_input_interrupt(&self, channel: Channel, enable: bool) {
254 Self::regs_gp16().dier().modify(|r| r.set_ccie(channel.index(), enable)); 254 Self::regs_gp16().dier().modify(|r| r.set_ccie(channel.index(), enable));
255 } 255 }
256 256
257 /// Set input capture prescaler. 257 /// Set input capture prescaler.
258 fn set_input_capture_prescaler(&mut self, channel: Channel, factor: u8) { 258 fn set_input_capture_prescaler(&self, channel: Channel, factor: u8) {
259 let raw_channel = channel.index(); 259 let raw_channel = channel.index();
260 Self::regs_gp16() 260 Self::regs_gp16()
261 .ccmr_input(raw_channel / 2) 261 .ccmr_input(raw_channel / 2)
@@ -263,7 +263,7 @@ pub(crate) mod sealed {
263 } 263 }
264 264
265 /// Set input TI selection. 265 /// Set input TI selection.
266 fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection) { 266 fn set_input_ti_selection(&self, channel: Channel, tisel: InputTISelection) {
267 let raw_channel = channel.index(); 267 let raw_channel = channel.index();
268 Self::regs_gp16() 268 Self::regs_gp16()
269 .ccmr_input(raw_channel / 2) 269 .ccmr_input(raw_channel / 2)
@@ -271,7 +271,7 @@ pub(crate) mod sealed {
271 } 271 }
272 272
273 /// Set input capture mode. 273 /// Set input capture mode.
274 fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode) { 274 fn set_input_capture_mode(&self, channel: Channel, mode: InputCaptureMode) {
275 Self::regs_gp16().ccer().modify(|r| match mode { 275 Self::regs_gp16().ccer().modify(|r| match mode {
276 InputCaptureMode::Rising => { 276 InputCaptureMode::Rising => {
277 r.set_ccnp(channel.index(), false); 277 r.set_ccnp(channel.index(), false);
@@ -289,7 +289,7 @@ pub(crate) mod sealed {
289 } 289 }
290 290
291 /// Set output compare mode. 291 /// Set output compare mode.
292 fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) { 292 fn set_output_compare_mode(&self, channel: Channel, mode: OutputCompareMode) {
293 let raw_channel: usize = channel.index(); 293 let raw_channel: usize = channel.index();
294 Self::regs_gp16() 294 Self::regs_gp16()
295 .ccmr_output(raw_channel / 2) 295 .ccmr_output(raw_channel / 2)
@@ -297,14 +297,14 @@ pub(crate) mod sealed {
297 } 297 }
298 298
299 /// Set output polarity. 299 /// Set output polarity.
300 fn set_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { 300 fn set_output_polarity(&self, channel: Channel, polarity: OutputPolarity) {
301 Self::regs_gp16() 301 Self::regs_gp16()
302 .ccer() 302 .ccer()
303 .modify(|w| w.set_ccp(channel.index(), polarity.into())); 303 .modify(|w| w.set_ccp(channel.index(), polarity.into()));
304 } 304 }
305 305
306 /// Enable/disable a channel. 306 /// Enable/disable a channel.
307 fn enable_channel(&mut self, channel: Channel, enable: bool) { 307 fn enable_channel(&self, channel: Channel, enable: bool) {
308 Self::regs_gp16().ccer().modify(|w| w.set_cce(channel.index(), enable)); 308 Self::regs_gp16().ccer().modify(|w| w.set_cce(channel.index(), enable));
309 } 309 }
310 310
@@ -314,12 +314,12 @@ pub(crate) mod sealed {
314 } 314 }
315 315
316 /// Set compare value for a channel. 316 /// Set compare value for a channel.
317 fn set_compare_value(&mut self, channel: Channel, value: u16) { 317 fn set_compare_value(&self, channel: Channel, value: u16) {
318 Self::regs_gp16().ccr(channel.index()).modify(|w| w.set_ccr(value)); 318 Self::regs_gp16().ccr(channel.index()).modify(|w| w.set_ccr(value));
319 } 319 }
320 320
321 /// Get capture value for a channel. 321 /// Get capture value for a channel.
322 fn get_capture_value(&mut self, channel: Channel) -> u16 { 322 fn get_capture_value(&self, channel: Channel) -> u16 {
323 Self::regs_gp16().ccr(channel.index()).read().ccr() 323 Self::regs_gp16().ccr(channel.index()).read().ccr()
324 } 324 }
325 325
@@ -329,7 +329,7 @@ pub(crate) mod sealed {
329 } 329 }
330 330
331 /// Set output compare preload. 331 /// Set output compare preload.
332 fn set_output_compare_preload(&mut self, channel: Channel, preload: bool) { 332 fn set_output_compare_preload(&self, channel: Channel, preload: bool) {
333 let channel_index = channel.index(); 333 let channel_index = channel.index();
334 Self::regs_gp16() 334 Self::regs_gp16()
335 .ccmr_output(channel_index / 2) 335 .ccmr_output(channel_index / 2)
@@ -342,7 +342,7 @@ pub(crate) mod sealed {
342 } 342 }
343 343
344 /// Set capture compare DMA selection 344 /// Set capture compare DMA selection
345 fn set_cc_dma_selection(&mut self, ccds: super::vals::Ccds) { 345 fn set_cc_dma_selection(&self, ccds: super::vals::Ccds) {
346 Self::regs_gp16().cr2().modify(|w| w.set_ccds(ccds)) 346 Self::regs_gp16().cr2().modify(|w| w.set_ccds(ccds))
347 } 347 }
348 348
@@ -352,7 +352,7 @@ pub(crate) mod sealed {
352 } 352 }
353 353
354 /// Set capture compare DMA enable state 354 /// Set capture compare DMA enable state
355 fn set_cc_dma_enable_state(&mut self, channel: Channel, ccde: bool) { 355 fn set_cc_dma_enable_state(&self, channel: Channel, ccde: bool) {
356 Self::regs_gp16().dier().modify(|w| w.set_ccde(channel.index(), ccde)) 356 Self::regs_gp16().dier().modify(|w| w.set_ccde(channel.index(), ccde))
357 } 357 }
358 } 358 }
@@ -369,7 +369,7 @@ pub(crate) mod sealed {
369 fn regs_gp32() -> crate::pac::timer::TimGp32; 369 fn regs_gp32() -> crate::pac::timer::TimGp32;
370 370
371 /// Set timer frequency. 371 /// Set timer frequency.
372 fn set_frequency(&mut self, frequency: Hertz) { 372 fn set_frequency(&self, frequency: Hertz) {
373 let f = frequency.0; 373 let f = frequency.0;
374 assert!(f > 0); 374 assert!(f > 0);
375 let timer_f = Self::frequency().0; 375 let timer_f = Self::frequency().0;
@@ -398,12 +398,12 @@ pub(crate) mod sealed {
398 } 398 }
399 399
400 /// Set comapre value for a channel. 400 /// Set comapre value for a channel.
401 fn set_compare_value(&mut self, channel: Channel, value: u32) { 401 fn set_compare_value(&self, channel: Channel, value: u32) {
402 Self::regs_gp32().ccr(channel.index()).modify(|w| w.set_ccr(value)); 402 Self::regs_gp32().ccr(channel.index()).modify(|w| w.set_ccr(value));
403 } 403 }
404 404
405 /// Get capture value for a channel. 405 /// Get capture value for a channel.
406 fn get_capture_value(&mut self, channel: Channel) -> u32 { 406 fn get_capture_value(&self, channel: Channel) -> u32 {
407 Self::regs_gp32().ccr(channel.index()).read().ccr() 407 Self::regs_gp32().ccr(channel.index()).read().ccr()
408 } 408 }
409 409
@@ -430,17 +430,17 @@ pub(crate) mod sealed {
430 fn regs_1ch_cmp() -> crate::pac::timer::Tim1chCmp; 430 fn regs_1ch_cmp() -> crate::pac::timer::Tim1chCmp;
431 431
432 /// Set clock divider for the dead time. 432 /// Set clock divider for the dead time.
433 fn set_dead_time_clock_division(&mut self, value: vals::Ckd) { 433 fn set_dead_time_clock_division(&self, value: vals::Ckd) {
434 Self::regs_1ch_cmp().cr1().modify(|w| w.set_ckd(value)); 434 Self::regs_1ch_cmp().cr1().modify(|w| w.set_ckd(value));
435 } 435 }
436 436
437 /// Set dead time, as a fraction of the max duty value. 437 /// Set dead time, as a fraction of the max duty value.
438 fn set_dead_time_value(&mut self, value: u8) { 438 fn set_dead_time_value(&self, value: u8) {
439 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_dtg(value)); 439 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_dtg(value));
440 } 440 }
441 441
442 /// Enable timer outputs. 442 /// Enable timer outputs.
443 fn enable_outputs(&mut self) { 443 fn enable_outputs(&self) {
444 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_moe(true)); 444 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_moe(true));
445 } 445 }
446 } 446 }
@@ -468,14 +468,14 @@ pub(crate) mod sealed {
468 fn regs_advanced() -> crate::pac::timer::TimAdv; 468 fn regs_advanced() -> crate::pac::timer::TimAdv;
469 469
470 /// Set complementary output polarity. 470 /// Set complementary output polarity.
471 fn set_complementary_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { 471 fn set_complementary_output_polarity(&self, channel: Channel, polarity: OutputPolarity) {
472 Self::regs_advanced() 472 Self::regs_advanced()
473 .ccer() 473 .ccer()
474 .modify(|w| w.set_ccnp(channel.index(), polarity.into())); 474 .modify(|w| w.set_ccnp(channel.index(), polarity.into()));
475 } 475 }
476 476
477 /// Enable/disable a complementary channel. 477 /// Enable/disable a complementary channel.
478 fn enable_complementary_channel(&mut self, channel: Channel, enable: bool) { 478 fn enable_complementary_channel(&self, channel: Channel, enable: bool) {
479 Self::regs_advanced() 479 Self::regs_advanced()
480 .ccer() 480 .ccer()
481 .modify(|w| w.set_ccne(channel.index(), enable)); 481 .modify(|w| w.set_ccne(channel.index(), enable));