pub struct SimplePwm<'d> { /* private fields */ }Expand description
SimplePwm is the traditional pwm interface you’re probably used to, allowing to simply set a duty cycle across up to four channels.
Per-channel handles implementing embedded_hal_1::pwm::SetDutyCycle can be obtained with
ch0..ch3 (borrowed) or split (owned).
Implementations§
Source§impl<'d> SimplePwm<'d>
impl<'d> SimplePwm<'d>
Sourcepub fn new_1ch<T: Instance>(
pwm: Peri<'d, T>,
ch0: Peri<'d, impl GpioPin>,
config: SimpleConfig,
) -> Self
pub fn new_1ch<T: Instance>( pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>, config: SimpleConfig, ) -> Self
Create a new 1-channel PWM
Sourcepub fn new_2ch<T: Instance>(
pwm: Peri<'d, T>,
ch0: Peri<'d, impl GpioPin>,
ch1: Peri<'d, impl GpioPin>,
config: SimpleConfig,
) -> Self
pub fn new_2ch<T: Instance>( pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>, ch1: Peri<'d, impl GpioPin>, config: SimpleConfig, ) -> Self
Create a new 2-channel PWM
Sourcepub fn new_3ch<T: Instance>(
pwm: Peri<'d, T>,
ch0: Peri<'d, impl GpioPin>,
ch1: Peri<'d, impl GpioPin>,
ch2: Peri<'d, impl GpioPin>,
config: SimpleConfig,
) -> Self
pub fn new_3ch<T: Instance>( pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>, ch1: Peri<'d, impl GpioPin>, ch2: Peri<'d, impl GpioPin>, config: SimpleConfig, ) -> Self
Create a new 3-channel PWM
Sourcepub fn new_4ch<T: Instance>(
pwm: Peri<'d, T>,
ch0: Peri<'d, impl GpioPin>,
ch1: Peri<'d, impl GpioPin>,
ch2: Peri<'d, impl GpioPin>,
ch3: Peri<'d, impl GpioPin>,
config: SimpleConfig,
) -> Self
pub fn new_4ch<T: Instance>( pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>, ch1: Peri<'d, impl GpioPin>, ch2: Peri<'d, impl GpioPin>, ch3: Peri<'d, impl GpioPin>, config: SimpleConfig, ) -> Self
Create a new 4-channel PWM
Sourcepub fn ch0(&mut self) -> SimplePwmChannel<'_>
pub fn ch0(&mut self) -> SimplePwmChannel<'_>
Borrow channel 0.
Sourcepub fn ch1(&mut self) -> SimplePwmChannel<'_>
pub fn ch1(&mut self) -> SimplePwmChannel<'_>
Borrow channel 1.
Sourcepub fn ch2(&mut self) -> SimplePwmChannel<'_>
pub fn ch2(&mut self) -> SimplePwmChannel<'_>
Borrow channel 2.
Sourcepub fn ch3(&mut self) -> SimplePwmChannel<'_>
pub fn ch3(&mut self) -> SimplePwmChannel<'_>
Borrow channel 3.
Sourcepub fn split(
self,
) -> (Option<SimplePwmChannel<'d>>, Option<SimplePwmChannel<'d>>, Option<SimplePwmChannel<'d>>, Option<SimplePwmChannel<'d>>)
pub fn split( self, ) -> (Option<SimplePwmChannel<'d>>, Option<SimplePwmChannel<'d>>, Option<SimplePwmChannel<'d>>, Option<SimplePwmChannel<'d>>)
Split the PWM into its channels, consuming the driver.
A channel is returned for every pin the PWM was created with. The PWM is disabled once all the returned channels have been dropped.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns the enable state of the pwm counter
Sourcepub fn disable(&mut self)
pub fn disable(&mut self)
Disables the PWM generator. Does NOT clear the last duty cycle from the pin.
Sourcepub fn set_all_duties(&mut self, duty: [DutyCycle; 4])
pub fn set_all_duties(&mut self, duty: [DutyCycle; 4])
Sets the duty cycle (15 bit) and polarity for all PWM channels.
You can safely set the duty cycle of disabled PWM channels.
When using this function, a single DMA transfer sets all the duty cycles.
If you call SimplePwmChannel::set_duty() multiple times,
each duty cycle will be set by a separate DMA transfer.
Sourcepub fn set_prescaler(&mut self, div: Prescaler)
pub fn set_prescaler(&mut self, div: Prescaler)
Sets the PWM clock prescaler.
Sourcepub fn set_max_duty(&mut self, duty: u16)
pub fn set_max_duty(&mut self, duty: u16)
Sets the maximum duty cycle value.
Sourcepub fn set_frequency(&mut self, freq: Hertz)
pub fn set_frequency(&mut self, freq: Hertz)
Sets the PWM output frequency, by adjusting the maximum duty cycle value.
The current prescaler limits the range of reachable frequencies: with Div1
the lowest is about 489 Hz, with Div128 about 3.8 Hz. Set the prescaler first
for low frequencies.
Sourcepub fn set_ch0_drive(&mut self, drive: OutputDrive)
pub fn set_ch0_drive(&mut self, drive: OutputDrive)
Sets the PWM-Channel0 output drive strength
Sourcepub fn set_ch1_drive(&mut self, drive: OutputDrive)
pub fn set_ch1_drive(&mut self, drive: OutputDrive)
Sets the PWM-Channel1 output drive strength
Sourcepub fn set_ch2_drive(&mut self, drive: OutputDrive)
pub fn set_ch2_drive(&mut self, drive: OutputDrive)
Sets the PWM-Channel2 output drive strength
Sourcepub fn set_ch3_drive(&mut self, drive: OutputDrive)
pub fn set_ch3_drive(&mut self, drive: OutputDrive)
Sets the PWM-Channel3 output drive strength