Struct Pwm

Source
pub struct Pwm<'a> { /* private fields */ }
Expand description

Main struct for controlling PWM peripheral

Implementations§

Source§

impl<'a> Pwm<'a>

Source

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.
Source

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)

Source§

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 stop(&self, pin: &Self::Pin) -> Result<(), ErrorCode>

Stop the given pin

§Errors

This method may never fail.

§Safety

It is safe to call this method multiple times on the same pin. If the pin is already stopped, then it does nothing.

Source§

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

Return an opaque value representing 100% duty cycle

Source§

type Pin = RPGpio

The chip-dependent type of a PWM pin.

Auto Trait Implementations§

§

impl<'a> !Freeze for Pwm<'a>

§

impl<'a> !RefUnwindSafe for Pwm<'a>

§

impl<'a> !Send for Pwm<'a>

§

impl<'a> !Sync for Pwm<'a>

§

impl<'a> Unpin for Pwm<'a>

§

impl<'a> !UnwindSafe for Pwm<'a>

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.