embassy-stm32

Crates

git

Versions

stm32l4a6qg

Flavors

RingBufferedPwmChannel

Struct RingBufferedPwmChannel 

Source
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 cycles

Implementations§

Source§

impl<'d, T: GeneralInstance4Channel> RingBufferedPwmChannel<'d, T>

Source

pub fn start(&mut self)

Start the ring buffer operation.

You must call this after creating it for it to work.

Source

pub fn clear(&mut self)

Clear all data in the ring buffer.

Source

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.

Source

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

Source

pub async fn write_exact(&mut self, buffer: &[u16]) -> Result<usize, Error>

Write an exact number of elements to the ringbuffer.

Source

pub async fn wait_write_error(&mut self) -> Result<usize, Error>

Wait for any ring buffer write error.

Source

pub fn len(&mut self) -> Result<usize, Error>

The current length of the ringbuffer

Source

pub const fn capacity(&self) -> usize

The capacity of the ringbuffer

Source

pub fn set_waker(&mut self, waker: &Waker)

Set a waker to be woken when at least one byte is send.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn enable(&mut self)

Enable the given channel.

Source

pub fn disable(&mut self)

Disable the given channel.

Source

pub fn is_enabled(&self) -> bool

Check whether given channel is enabled

Source

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.

Source

pub fn set_polarity(&mut self, polarity: OutputPolarity)

Set the output polarity for a given channel.

Source

pub fn set_output_compare_mode(&mut self, mode: OutputCompareMode)

Set the output compare mode for a given channel.

Auto Trait Implementations§

§

impl<'d, T> Freeze for RingBufferedPwmChannel<'d, T>
where T: Freeze,

§

impl<'d, T> RefUnwindSafe for RingBufferedPwmChannel<'d, T>
where T: RefUnwindSafe,

§

impl<'d, T> Send for RingBufferedPwmChannel<'d, T>
where T: Send,

§

impl<'d, T> Sync for RingBufferedPwmChannel<'d, T>
where T: Sync,

§

impl<'d, T> Unpin for RingBufferedPwmChannel<'d, T>
where T: Unpin,

§

impl<'d, T> !UnwindSafe for RingBufferedPwmChannel<'d, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.