Struct embassy_stm32::timer::simple_pwm::SimplePwm
source · pub struct SimplePwm<'d, T> { /* private fields */ }
Expand description
Simple PWM driver.
Implementations§
source§impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T>
impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T>
sourcepub 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
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.
sourcepub fn is_enabled(&self, channel: Channel) -> bool
pub fn is_enabled(&self, channel: Channel) -> bool
Check whether given channel is enabled
sourcepub fn set_frequency(&mut self, freq: Hertz)
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.
sourcepub fn get_max_duty(&self) -> u16
pub fn get_max_duty(&self) -> u16
Get max duty value.
This value depends on the configured frequency and the timer’s clock rate from RCC.
sourcepub fn set_duty(&mut self, channel: Channel, duty: u16)
pub fn set_duty(&mut self, channel: Channel, duty: u16)
Set the duty for a given channel.
The value ranges from 0 for 0% duty, to get_max_duty
for 100% duty, both included.
sourcepub fn get_duty(&self, channel: Channel) -> u16
pub fn get_duty(&self, channel: Channel) -> u16
Get the duty for a given channel.
The value ranges from 0 for 0% duty, to get_max_duty
for 100% duty, both included.
sourcepub fn set_polarity(&mut self, channel: Channel, polarity: OutputPolarity)
pub fn set_polarity(&mut self, channel: Channel, polarity: OutputPolarity)
Set the output polarity for a given channel.
sourcepub async fn gen_waveform(
&mut self,
dma: impl Peripheral<P = impl UpDma<T>>,
channel: Channel,
duty: &[u16]
)
pub async fn gen_waveform( &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.