pub struct Pwm<'a> { /* private fields */ }
Expand description
Main struct for controlling PWM peripheral
Implementations§
Source§impl<'a> Pwm<'a>
impl<'a> Pwm<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Pwm struct
Note:
- This method must be called only once when setting up the kernel peripherals.
- This peripheral depends on the chip’s clocks.
- Also, if interrupts are required, then an interrupt handler must be set. Otherwise, all the interrupts will be ignored.
Sourcepub fn gpio_to_pwm_pin(&'a self, gpio: RPGpio) -> PwmPin<'a>
pub fn gpio_to_pwm_pin(&'a self, gpio: RPGpio) -> PwmPin<'a>
Map the GPIO to a PwmPin struct
The returned structure can be used to control the PWM pin.
See PwmPin
Trait Implementations§
Source§impl Pwm for Pwm<'_>
Implementation of the Hardware Interface Layer (HIL)
impl Pwm for Pwm<'_>
Implementation of the Hardware Interface Layer (HIL)
Source§fn start(
&self,
pin: &Self::Pin,
frequency_hz: usize,
duty_cycle: usize,
) -> Result<(), ErrorCode>
fn start( &self, pin: &Self::Pin, frequency_hz: usize, duty_cycle: usize, ) -> Result<(), ErrorCode>
Start a PWM pin
Start the given PWM pin with the given frequency and the given duty cycle. The actual values may vary due to rounding errors. For high precision duty cycles, the frequency should be set less than:
let threshold_freq = pwm_struct.get_maximum_frequency_hz() / pwm_struct.get_maximum_duty_cycle()
§Errors
This method may fail in one of the following situations:
- selected frequency and duty cycle higher than the maximum possible values
- 100% duty cycle demand for low frequencies (close to or below threshold_freq)
- very low frequencies
§Safety
It is safe to call multiples times this method with different values while the pin is running.
Note: the pin must be set as a PWM pin prior to calling this method.
Source§fn get_maximum_frequency_hz(&self) -> usize
fn get_maximum_frequency_hz(&self) -> usize
Return the maximum value of the frequency in Hz
§Panics
This method will panic if the dependencies are not resolved.
Source§fn get_maximum_duty_cycle(&self) -> usize
fn get_maximum_duty_cycle(&self) -> usize
Return an opaque value representing 100% duty cycle