aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer
diff options
context:
space:
mode:
authorxoviat <[email protected]>2025-11-15 11:13:02 -0600
committerGitHub <[email protected]>2025-11-15 11:13:02 -0600
commit548fe48bd89bc619845ddde6495be7a16285a38c (patch)
tree8ca532803a36b554ede69e0ea5c8535481051009 /embassy-stm32/src/timer
parent3fb16229c7a237c29731aa05d5f29e8ea2eb015f (diff)
parent435267941c5e585c0de714e3251f3d28426bcdca (diff)
Merge branch 'main' into stm32_sai_frame_length
Diffstat (limited to 'embassy-stm32/src/timer')
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs48
1 files changed, 37 insertions, 11 deletions
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index 06315d7f3..c338b0fd4 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -309,7 +309,9 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
309 /// Generate a sequence of PWM waveform 309 /// Generate a sequence of PWM waveform
310 /// 310 ///
311 /// Note: 311 /// Note:
312 /// you will need to provide corresponding TIMx_UP DMA channel to use this method. 312 /// You will need to provide corresponding `TIMx_UP` DMA channel to use this method.
313 /// Also be aware that embassy timers use one of timers internally. It is possible to
314 /// switch this timer by using `time-driver-timX` feature.
313 pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[u16]) { 315 pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[u16]) {
314 #[allow(clippy::let_unit_value)] // eg. stm32f334 316 #[allow(clippy::let_unit_value)] // eg. stm32f334
315 let req = dma.request(); 317 let req = dma.request();
@@ -339,14 +341,33 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
339 ..Default::default() 341 ..Default::default()
340 }; 342 };
341 343
342 Transfer::new_write( 344 match self.inner.bits() {
343 dma, 345 TimerBits::Bits16 => {
344 req, 346 Transfer::new_write(
345 duty, 347 dma,
346 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16, 348 req,
347 dma_transfer_option, 349 duty,
348 ) 350 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16,
349 .await 351 dma_transfer_option,
352 )
353 .await
354 }
355 #[cfg(not(any(stm32l0)))]
356 TimerBits::Bits32 => {
357 #[cfg(not(any(bdma, gpdma)))]
358 panic!("unsupported timer bits");
359
360 #[cfg(any(bdma, gpdma))]
361 Transfer::new_write(
362 dma,
363 req,
364 duty,
365 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u32,
366 dma_transfer_option,
367 )
368 .await
369 }
370 };
350 }; 371 };
351 372
352 // restore output compare state 373 // restore output compare state
@@ -378,18 +399,23 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
378 /// 399 ///
379 /// For example, if using channels 1 through 4, a buffer of 4 update steps might look like: 400 /// For example, if using channels 1 through 4, a buffer of 4 update steps might look like:
380 /// 401 ///
402 /// ```rust,ignore
381 /// let dma_buf: [u16; 16] = [ 403 /// let dma_buf: [u16; 16] = [
382 /// ch1_duty_1, ch2_duty_1, ch3_duty_1, ch4_duty_1, // update 1 404 /// ch1_duty_1, ch2_duty_1, ch3_duty_1, ch4_duty_1, // update 1
383 /// ch1_duty_2, ch2_duty_2, ch3_duty_2, ch4_duty_2, // update 2 405 /// ch1_duty_2, ch2_duty_2, ch3_duty_2, ch4_duty_2, // update 2
384 /// ch1_duty_3, ch2_duty_3, ch3_duty_3, ch4_duty_3, // update 3 406 /// ch1_duty_3, ch2_duty_3, ch3_duty_3, ch4_duty_3, // update 3
385 /// ch1_duty_4, ch2_duty_4, ch3_duty_4, ch4_duty_4, // update 4 407 /// ch1_duty_4, ch2_duty_4, ch3_duty_4, ch4_duty_4, // update 4
386 /// ]; 408 /// ];
409 /// ```
387 /// 410 ///
388 /// Each group of N values (where N = number of channels) is transferred on one update event, 411 /// Each group of `N` values (where `N` is number of channels) is transferred on one update event,
389 /// updating the duty cycles of all selected channels simultaneously. 412 /// updating the duty cycles of all selected channels simultaneously.
390 /// 413 ///
391 /// Note: 414 /// Note:
392 /// you will need to provide corresponding TIMx_UP DMA channel to use this method. 415 /// You will need to provide corresponding `TIMx_UP` DMA channel to use this method.
416 /// Also be aware that embassy timers use one of timers internally. It is possible to
417 /// switch this timer by using `time-driver-timX` feature.
418 ///
393 pub async fn waveform_up_multi_channel( 419 pub async fn waveform_up_multi_channel(
394 &mut self, 420 &mut self,
395 dma: Peri<'_, impl super::UpDma<T>>, 421 dma: Peri<'_, impl super::UpDma<T>>,