@@ -6,11 +6,11 @@ use core::mem::ManuallyDrop;
66use super :: low_level:: { CountingMode , OutputCompareMode , OutputPolarity , Timer } ;
77use super :: ringbuffered:: RingBufferedPwmChannel ;
88use super :: { Ch1 , Ch2 , Ch3 , Ch4 , Channel , GeneralInstance4Channel , TimerChannel , TimerPin } ;
9- use crate :: dma:: WritableRingBuffer ;
109use crate :: Peri ;
10+ use crate :: dma:: TransferOptions ;
11+ use crate :: dma:: WritableRingBuffer ;
1112#[ cfg( not( any( bdma, gpdma) ) ) ]
1213use crate :: dma:: { Burst , FifoThreshold } ;
13- use crate :: dma:: TransferOptions ;
1414#[ cfg( gpio_v2) ]
1515use crate :: gpio:: Pull ;
1616use crate :: gpio:: { AfType , AnyPin , OutputType , Speed } ;
@@ -379,9 +379,27 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
379379 pub async fn waveform_continuous < C : TimerChannel > ( & mut self , dma : Peri < ' _ , impl super :: Dma < T , C > > , duty : & [ u16 ] ) {
380380 self . inner . waveform_continuous ( dma, duty) . await ;
381381 }
382- pub fn into_ring_buffered_channel < C : TimerChannel > ( self , tx_dma : Peri < ' d , impl super :: Dma < T , C > > , dma_buf : & ' d mut [ u16 ] ) -> RingBufferedPwmChannel < ' d , T > {
382+
383+ /// Convert this PWM channel into a ring-buffered PWM channel.
384+ ///
385+ /// This allows continuous PWM waveform generation using a DMA ring buffer.
386+ /// The ring buffer enables dynamic updates to the PWM duty cycle without blocking.
387+ ///
388+ /// # Arguments
389+ /// * `tx_dma` - The DMA channel to use for transferring duty cycle values
390+ /// * `dma_buf` - The buffer to use as a ring buffer (must be non-empty and <= 65535 elements)
391+ ///
392+ /// # Panics
393+ /// Panics if `dma_buf` is empty or longer than 65535 elements.
394+ pub fn into_ring_buffered_channel < C : TimerChannel > (
395+ self ,
396+ tx_dma : Peri < ' d , impl super :: Dma < T , C > > ,
397+ dma_buf : & ' d mut [ u16 ] ,
398+ ) -> RingBufferedPwmChannel < ' d , T > {
383399 assert ! ( !dma_buf. is_empty( ) && dma_buf. len( ) <= 0xFFFF ) ;
384400
401+ use crate :: pac:: timer:: vals:: Ccds ;
402+
385403 let channel = C :: CHANNEL ;
386404 let request = tx_dma. request ( ) ;
387405
@@ -393,6 +411,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
393411 ..Default :: default ( )
394412 } ;
395413
414+ self . inner . set_cc_dma_selection ( Ccds :: ON_UPDATE ) ;
396415 let ring_buf = unsafe {
397416 WritableRingBuffer :: new (
398417 tx_dma,
@@ -403,11 +422,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
403422 )
404423 } ;
405424
406- RingBufferedPwmChannel :: new (
407- unsafe { self . inner . clone_unchecked ( ) } ,
408- channel,
409- ring_buf
410- )
425+ RingBufferedPwmChannel :: new ( unsafe { self . inner . clone_unchecked ( ) } , channel, ring_buf)
411426 }
412427}
413428
0 commit comments