Trait cortex_m::prelude::_embedded_hal_Pwm

source ·
pub trait _embedded_hal_Pwm {
    type Channel;
    type Time;
    type Duty;

    // Required methods
    fn disable(&mut self, channel: Self::Channel);
    fn enable(&mut self, channel: Self::Channel);
    fn get_period(&self) -> Self::Time;
    fn get_duty(&self, channel: Self::Channel) -> Self::Duty;
    fn get_max_duty(&self) -> Self::Duty;
    fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty);
    fn set_period<P>(&mut self, period: P)
       where P: Into<Self::Time>;
}
Expand description

Pulse Width Modulation

This trait is available if embedded-hal is built with the "unproven" feature.

§Examples

Use this interface to control the power output of some actuator

extern crate embedded_hal as hal;

use hal::prelude::*;

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

    pwm.set_period(1.khz());

    let max_duty = pwm.get_max_duty();

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

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

Required Associated Types§

source

type Channel

Enumeration of channels that can be used with this Pwm interface

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

source

type Time

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

source

type Duty

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§

source

fn disable(&mut self, channel: Self::Channel)

Disables a PWM channel

source

fn enable(&mut self, channel: Self::Channel)

Enables a PWM channel

source

fn get_period(&self) -> Self::Time

Returns the current PWM period

source

fn get_duty(&self, channel: Self::Channel) -> Self::Duty

Returns the current duty cycle

source

fn get_max_duty(&self) -> Self::Duty

Returns the maximum duty cycle value

source

fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty)

Sets a new duty cycle

source

fn set_period<P>(&mut self, period: P)
where P: Into<Self::Time>,

Sets a new PWM period

Object Safety§

This trait is not object safe.

Implementors§