pub struct RingBufferedPwmChannel<'d, T: GeneralInstance4Channel> { /* private fields */ }Expand description
A PWM channel that uses a DMA ring buffer for continuous waveform generation.
This allows you to continuously update PWM duty cycles via DMA without blocking the CPU. The ring buffer enables smooth, uninterrupted waveform generation by automatically cycling through duty cycle values stored in memory.
You can write new duty cycle values to the ring buffer while it’s running, enabling dynamic waveform generation for applications like motor control, LED dimming, or audio output.
§Example
let mut channel = pwm.ch1().into_ring_buffered_channel(dma_ch, &mut buffer);
channel.start(); // Start DMA transfer
channel.write(&[100, 200, 300]).ok(); // Update duty cyclesImplementations§
Source§impl<'d, T: GeneralInstance4Channel> RingBufferedPwmChannel<'d, T>
impl<'d, T: GeneralInstance4Channel> RingBufferedPwmChannel<'d, T>
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Start the ring buffer operation.
You must call this after creating it for it to work.
Sourcepub fn write_immediate(&mut self, buf: &[u16]) -> Result<(usize, usize), Error>
pub fn write_immediate(&mut self, buf: &[u16]) -> Result<(usize, usize), Error>
Write elements directly to the raw buffer. This can be used to fill the buffer before starting the DMA transfer.
Sourcepub fn write(&mut self, buf: &[u16]) -> Result<(usize, usize), Error>
pub fn write(&mut self, buf: &[u16]) -> Result<(usize, usize), Error>
Write elements from the ring buffer Return a tuple of the length written and the length remaining in the buffer
Sourcepub async fn write_exact(&mut self, buffer: &[u16]) -> Result<usize, Error>
pub async fn write_exact(&mut self, buffer: &[u16]) -> Result<usize, Error>
Write an exact number of elements to the ringbuffer.
Sourcepub async fn wait_write_error(&mut self) -> Result<usize, Error>
pub async fn wait_write_error(&mut self) -> Result<usize, Error>
Wait for any ring buffer write error.
Sourcepub fn set_waker(&mut self, waker: &Waker)
pub fn set_waker(&mut self, waker: &Waker)
Set a waker to be woken when at least one byte is send.
Sourcepub fn request_reset(&mut self)
pub fn request_reset(&mut self)
Request the DMA to reset. The configuration for this channel will not be preserved.
This doesn’t immediately stop the transfer, you have to wait until is_running returns false.
Sourcepub fn request_pause(&mut self)
pub fn request_pause(&mut self)
Request the transfer to pause, keeping the existing configuration for this channel.
To restart the transfer, call start again.
This doesn’t immediately stop the transfer, you have to wait until is_running returns false.
Sourcepub fn is_running(&mut self) -> bool
pub fn is_running(&mut self) -> bool
Return whether DMA is still running.
If this returns false, it can be because either the transfer finished, or it was requested to stop early with request_stop.
Sourcepub async fn stop(&mut self)
pub async fn stop(&mut self)
Stop the DMA transfer and await until the buffer is empty.
This disables the DMA transfer’s circular mode so that the transfer stops when all available data has been written.
This is designed to be used with streaming output data such as the I2S/SAI or DAC.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check whether given channel is enabled
Sourcepub fn max_duty_cycle(&self) -> u16
pub fn max_duty_cycle(&self) -> u16
Get max duty value.
This value depends on the configured frequency and the timer’s clock rate from RCC.
Sourcepub fn set_polarity(&mut self, polarity: OutputPolarity)
pub fn set_polarity(&mut self, polarity: OutputPolarity)
Set the output polarity for a given channel.
Sourcepub fn set_output_compare_mode(&mut self, mode: OutputCompareMode)
pub fn set_output_compare_mode(&mut self, mode: OutputCompareMode)
Set the output compare mode for a given channel.