embassy-stm32

Crates

git

Versions

stm32h7b3li

Flavors

Struct SimplePwm

Source
pub struct SimplePwm<'d, T: GeneralInstance4Channel> { /* private fields */ }
Expand description

Simple PWM driver.

Implementations§

Source§

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

Source

pub fn new( tim: Peri<'d, T>, _ch1: Option<PwmPin<'d, T, Ch1>>, _ch2: Option<PwmPin<'d, T, Ch2>>, _ch3: Option<PwmPin<'d, T, Ch3>>, _ch4: Option<PwmPin<'d, T, Ch4>>, freq: Hertz, counting_mode: CountingMode, ) -> Self

Create a new simple PWM driver.

Source

pub fn channel(&mut self, channel: Channel) -> SimplePwmChannel<'_, T>

Get a single channel

If you need to use multiple channels, use Self::split.

Source

pub fn ch1(&mut self) -> SimplePwmChannel<'_, T>

Channel 1

This is just a convenience wrapper around Self::channel.

If you need to use multiple channels, use Self::split.

Source

pub fn ch2(&mut self) -> SimplePwmChannel<'_, T>

Channel 2

This is just a convenience wrapper around Self::channel.

If you need to use multiple channels, use Self::split.

Source

pub fn ch3(&mut self) -> SimplePwmChannel<'_, T>

Channel 3

This is just a convenience wrapper around Self::channel.

If you need to use multiple channels, use Self::split.

Source

pub fn ch4(&mut self) -> SimplePwmChannel<'_, T>

Channel 4

This is just a convenience wrapper around Self::channel.

If you need to use multiple channels, use Self::split.

Source

pub fn split(self) -> SimplePwmChannels<'static, T>
where 'd: 'static,

Splits a SimplePwm into four pwm channels.

This returns all four channels, including channels that aren’t configured with a PwmPin.

Source

pub fn set_frequency(&mut self, freq: Hertz)

Set PWM frequency.

Note: when you call this, the max duty value changes, so you will have to call set_duty on all channels with the duty calculated based on the new max duty.

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 async fn waveform_up( &mut self, dma: Peri<'_, impl UpDma<T>>, channel: Channel, duty: &[u16], )

Generate a sequence of PWM waveform

Note: you will need to provide corresponding TIMx_UP DMA channel to use this method.

Source

pub async fn waveform_up_multi_channel( &mut self, dma: Peri<'_, impl UpDma<T>>, starting_channel: Channel, ending_channel: Channel, duty: &[u16], )

Generate a multichannel sequence of PWM waveforms using DMA triggered by timer update events.

This method utilizes the timer’s DMA burst transfer capability to update multiple CCRx registers in sequence on each update event (UEV). The data is written via the DMAR register using the DMA base address (DBA) and burst length (DBL) configured in the DCR register.

The duty buffer must be structured as a flattened 2D array in row-major order, where each row represents a single update event and each column corresponds to a specific timer channel (starting from starting_channel up to and including ending_channel).

For example, if using channels 1 through 4, a buffer of 4 update steps might look like:

let dma_buf: [u16; 16] = [ ch1_duty_1, ch2_duty_1, ch3_duty_1, ch4_duty_1, // update 1 ch1_duty_2, ch2_duty_2, ch3_duty_2, ch4_duty_2, // update 2 ch1_duty_3, ch2_duty_3, ch3_duty_3, ch4_duty_3, // update 3 ch1_duty_4, ch2_duty_4, ch3_duty_4, ch4_duty_4, // update 4 ];

Each group of N values (where N = number of channels) is transferred on one update event, updating the duty cycles of all selected channels simultaneously.

Note: you will need to provide corresponding TIMx_UP DMA channel to use this method.

Source§

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

Source

pub async fn waveform_ch1( &mut self, dma: Peri<'_, impl Ch1Dma<T>>, duty: &[u16], )

Generate a sequence of PWM waveform

Source§

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

Source

pub async fn waveform_ch2( &mut self, dma: Peri<'_, impl Ch2Dma<T>>, duty: &[u16], )

Generate a sequence of PWM waveform

Source§

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

Source

pub async fn waveform_ch3( &mut self, dma: Peri<'_, impl Ch3Dma<T>>, duty: &[u16], )

Generate a sequence of PWM waveform

Source§

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

Source

pub async fn waveform_ch4( &mut self, dma: Peri<'_, impl Ch4Dma<T>>, duty: &[u16], )

Generate a sequence of PWM waveform

Trait Implementations§

Source§

impl<'d, T: GeneralInstance4Channel> Pwm for SimplePwm<'d, T>

Source§

type Channel = Channel

Enumeration of channels that can be used with this Pwm interface Read more
Source§

type Time = Hertz

A time unit that can be converted into a human time unit (e.g. seconds)
Source§

type Duty = u32

Type for the duty methods Read more
Source§

fn disable(&mut self, channel: Self::Channel)

Disables a PWM channel
Source§

fn enable(&mut self, channel: Self::Channel)

Enables a PWM channel
Source§

fn get_period(&self) -> Self::Time

Returns the current PWM period
Source§

fn get_duty(&self, channel: Self::Channel) -> Self::Duty

Returns the current duty cycle
Source§

fn get_max_duty(&self) -> Self::Duty

Returns the maximum duty cycle value
Source§

fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty)

Sets a new duty cycle
Source§

fn set_period<P>(&mut self, period: P)
where P: Into<Self::Time>,

Sets a new PWM period

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'d, T> !UnwindSafe for SimplePwm<'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.