aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer
diff options
context:
space:
mode:
authorLiu Hancheng <[email protected]>2025-01-04 20:16:34 +0800
committerLiu Hancheng <[email protected]>2025-01-04 20:16:34 +0800
commitff526e1604f4e9edc682f4bc270ddc815a860e48 (patch)
treecc6c4e901d9c187d72dee59167a7189fed56ed65 /embassy-stm32/src/timer
parent90b41644261440a535c35c1c75c22ce2606c5037 (diff)
refactor: update DMA transfer functions to use separate memory and peripheral sizes
Diffstat (limited to 'embassy-stm32/src/timer')
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs26
1 files changed, 9 insertions, 17 deletions
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index f36fa026c..8d3c9a131 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -334,7 +334,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
334 &mut dma, 334 &mut dma,
335 req, 335 req,
336 duty, 336 duty,
337 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut _, 337 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16,
338 dma_transfer_option, 338 dma_transfer_option,
339 ) 339 )
340 .await 340 .await
@@ -362,13 +362,7 @@ macro_rules! impl_waveform_chx {
362 ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => { 362 ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => {
363 impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { 363 impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
364 /// Generate a sequence of PWM waveform 364 /// Generate a sequence of PWM waveform
365 /// 365 pub async fn $fn_name(&mut self, dma: impl Peripheral<P = impl super::$dma_ch<T>>, duty: &[u16]) {
366 /// Note:
367 /// 1. you will need to provide corresponding TIMx_CHy DMA channel to use this method.
368 /// 2. Please make sure the duty data length is aligned to the timer data width(16-bit or 32-bit).
369 /// 3. Please notice the endianess of the duty data. STM32 use little endian,
370 /// for example, 0x12345678 as u32 will be stored as [0x78, 0x56, 0x34, 0x12] in memory.
371 pub async fn $fn_name(&mut self, dma: impl Peripheral<P = impl super::$dma_ch<T>>, duty: &[u8]) {
372 use crate::pac::timer::vals::Ccds; 366 use crate::pac::timer::vals::Ccds;
373 367
374 into_ref!(dma); 368 into_ref!(dma);
@@ -411,32 +405,30 @@ macro_rules! impl_waveform_chx {
411 405
412 match self.inner.bits() { 406 match self.inner.bits() {
413 TimerBits::Bits16 => { 407 TimerBits::Bits16 => {
414 // the data must be aligned to double words
415 assert!(duty.len() % 2 == 0);
416 let duty = core::slice::from_raw_parts(duty.as_ptr() as *const u16, duty.len() / 2);
417 Transfer::new_write( 408 Transfer::new_write(
418 &mut dma, 409 &mut dma,
419 req, 410 req,
420 duty, 411 duty,
421 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut _, 412 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16,
422 dma_transfer_option, 413 dma_transfer_option,
423 ) 414 )
424 .await 415 .await
425 } 416 }
426 #[cfg(not(stm32l0))] 417 #[cfg(not(any(stm32l0, bdma, gpdma)))]
427 TimerBits::Bits32 => { 418 TimerBits::Bits32 => {
428 // the data must be aligned to quad words
429 assert!(duty.len() % 4 == 0);
430 let duty = core::slice::from_raw_parts(duty.as_ptr() as *const u32, duty.len() / 4);
431 Transfer::new_write( 419 Transfer::new_write(
432 &mut dma, 420 &mut dma,
433 req, 421 req,
434 duty, 422 duty,
435 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut _, 423 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32,
436 dma_transfer_option, 424 dma_transfer_option,
437 ) 425 )
438 .await 426 .await
439 } 427 }
428 #[cfg(any(stm32l0, bdma, gpdma))]
429 _ => {
430 panic!("unsupported timer bits")
431 }
440 }; 432 };
441 }; 433 };
442 434