Trait embedded_hal::pwm::blocking::Pwm[][src]

pub trait Pwm {
    type Error: Debug;
    type Channel;
    type Time;
    type Duty;
    fn disable(&mut self, channel: &Self::Channel) -> Result<(), Self::Error>;
fn enable(&mut self, channel: &Self::Channel) -> Result<(), Self::Error>;
fn get_period(&self) -> Result<Self::Time, Self::Error>;
fn get_duty(
        &self,
        channel: &Self::Channel
    ) -> Result<Self::Duty, Self::Error>;
fn get_max_duty(&self) -> Result<Self::Duty, Self::Error>;
fn set_duty(
        &mut self,
        channel: &Self::Channel,
        duty: Self::Duty
    ) -> Result<(), Self::Error>;
fn set_period<P>(&mut self, period: P) -> Result<(), Self::Error>
    where
        P: Into<Self::Time>
; }
Expand description

Pulse Width Modulation

Examples

Use this interface to control the power output of some actuator

extern crate embedded_hal as hal;

use hal::pwm::blocking::Pwm;

fn main() {
    let mut pwm: Pwm1 = {
        // ..
    };

    pwm.set_period(1.khz()).unwrap();

    let max_duty = pwm.get_max_duty().unwrap();

    // brightest LED
    pwm.set_duty(&Channel::_1, max_duty).unwrap();

    // dimmer LED
    pwm.set_duty(&Channel::_2, max_duty / 4).unwrap();
}

Associated Types

Enumeration of Pwm errors

Enumeration of channels that can be used with this Pwm interface

If your Pwm interface has no channels you can use the type () here

A time unit that can be converted into a human time unit (e.g. seconds)

Type for the duty methods

The implementer is free to choose a float / percentage representation (e.g. 0.0 .. 1.0) or an integer representation (e.g. 0 .. 65535)

Required methods

Disables a PWM channel

Enables a PWM channel

Returns the current PWM period

Returns the current duty cycle

While the pin is transitioning to the new duty cycle after a set_duty call, this may return the old or the new duty cycle depending on the implementation.

Returns the maximum duty cycle value

Sets a new duty cycle

Sets a new PWM period

Implementors