[][src]Trait kernel::hil::pwm::Pwm

pub trait Pwm {
    type Pin;
    fn start(
        &self,
        pin: &Self::Pin,
        frequency_hz: usize,
        duty_cycle: usize
    ) -> ReturnCode;
fn stop(&self, pin: &Self::Pin) -> ReturnCode;
fn get_maximum_frequency_hz(&self) -> usize;
fn get_maximum_duty_cycle(&self) -> usize; }

PWM control for a single pin.

Associated Types

type Pin

The chip-dependent type of a PWM pin.

Loading content...

Required methods

fn start(
    &self,
    pin: &Self::Pin,
    frequency_hz: usize,
    duty_cycle: usize
) -> ReturnCode

Generate a PWM single on the given pin at the given frequency and duty cycle.

  • frequency_hz is specified in Hertz.
  • duty_cycle is specified as a portion of the max duty cycle supported by the chip. Clients should call get_maximum_duty_cycle() to get the value that corresponds to 100% duty cycle, and divide that appropriately to get the desired duty cycle value. For example, a 25% duty cycle would be PWM0.get_maximum_duty_cycle() / 4.

fn stop(&self, pin: &Self::Pin) -> ReturnCode

Stop a PWM pin output.

fn get_maximum_frequency_hz(&self) -> usize

Return the maximum PWM frequency supported by the PWM implementation. The frequency will be specified in Hertz.

fn get_maximum_duty_cycle(&self) -> usize

Return an opaque number that represents a 100% duty cycle. This value will be hardware specific, and essentially represents the precision of the underlying PWM hardware.

Users of this HIL should divide this number to calculate a duty cycle value suitable for calling start(). For example, to generate a 50% duty cycle:

This example is not tested
let max = PWM0.get_maximum_duty_cycle();
let dc  = max / 2;
PWM0.start(pin, freq, dc);
Loading content...

Implementors

Loading content...