Embassy
embassy-stm32

Crates

git

Versions

stm32l041g6

Flavors

Struct embassy_stm32::timer::simple_pwm::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: impl Peripheral<P = T> + 'd, _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 enable(&mut self, channel: Channel)

Enable the given channel.

source

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

Disable the given channel.

source

pub fn is_enabled(&self, channel: Channel) -> bool

Check whether given channel is enabled

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 get_max_duty(&self) -> u32

Get max duty value.

This value depends on the configured frequency and the timer’s clock rate from RCC.

source

pub fn set_duty(&mut self, channel: Channel, duty: u32)

Set the duty for a given channel.

The value ranges from 0 for 0% duty, to get_max_duty for 100% duty, both included.

source

pub fn get_duty(&self, channel: Channel) -> u32

Get the duty for a given channel.

The value ranges from 0 for 0% duty, to get_max_duty for 100% duty, both included.

source

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

Set the output polarity for a given channel.

source

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

Set the output compare mode for a given channel.

source

pub async fn waveform_up( &mut self, dma: impl Peripheral<P = 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§

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

source

pub async fn waveform_ch1( &mut self, dma: impl Peripheral<P = impl Ch1Dma<T>>, duty: &[u16] )

Generate a sequence of PWM waveform

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

source§

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

source

pub async fn waveform_ch2( &mut self, dma: impl Peripheral<P = impl Ch2Dma<T>>, duty: &[u16] )

Generate a sequence of PWM waveform

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

source§

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

source

pub async fn waveform_ch3( &mut self, dma: impl Peripheral<P = impl Ch3Dma<T>>, duty: &[u16] )

Generate a sequence of PWM waveform

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

source§

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

source

pub async fn waveform_ch4( &mut self, dma: impl Peripheral<P = impl Ch4Dma<T>>, duty: &[u16] )

Generate a sequence of PWM waveform

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

Trait Implementations§

source§

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

§

type Channel = Channel

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

type Time = Hertz

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

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>,

§

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>,

§

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.