pub trait Pwm {
    type Pin;

    fn start(
        pin: &Self::Pin,
        frequency_hz: usize,
        duty_cycle: usize
    ) -> Result<(), ErrorCode>; fn stop(&self, pin: &Self::Pin) -> Result<(), ErrorCode>; fn get_maximum_frequency_hz(&self) -> usize; fn get_maximum_duty_cycle(&self) -> usize; }
Expand description

PWM control for a single pin.

Required Associated Types

The chip-dependent type of a PWM pin.

Required Methods

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.

Stop a PWM pin output.

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

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:

let max = PWM0.get_maximum_duty_cycle();
let dc  = max / 2;
PWM0.start(pin, freq, dc);