pub struct Pwm { /* private fields */ }Expand description
A channel’s PWM setting: when in the period it turns on and when it turns off.
The PCA9685 counts from 0 to 4095 each period and lets a channel turn on at one count and off at another, so duty and phase are both programmable. The special full-on and full-off states are encoded in a dedicated bit rather than as counts.
§Examples
use pamoja_actuators::pca9685::Pwm;
// Half brightness with no phase delay: on at count 0, off at the midpoint.
let half = Pwm::duty(2048);
assert_eq!(half.bytes(), [0x00, 0x00, 0x00, 0x08]);
// Fully off is its own encoding, not a zero duty.
assert_eq!(Pwm::full_off().bytes(), [0x00, 0x00, 0x00, 0x10]);Implementations§
Source§impl Pwm
impl Pwm
Sourcepub fn from_counts(on: u16, off: u16) -> Pwm
pub fn from_counts(on: u16, off: u16) -> Pwm
Sourcepub fn servo(pulse_micros: u32, update_rate_hz: u32) -> Pwm
pub fn servo(pulse_micros: u32, update_rate_hz: u32) -> Pwm
Builds the setting that drives a hobby servo to a given pulse width.
A servo reads the high-pulse width each period; the count is that width as a
fraction of the period, pulse * 4096 / period. Typical travel is about 1000
to 2000 microseconds at a 50 Hz update rate.
§Arguments
pulse_micros- the high-pulse width in microseconds.update_rate_hz- the PWM frequency the controller is set to.
§Returns
The PWM setting for that pulse width.
Sourcepub fn full_off() -> Pwm
pub fn full_off() -> Pwm
The setting that holds the output continuously low.
§Returns
The full-off setting, the power-on state of every channel.
Sourcepub fn bytes(self) -> [u8; 4]
pub fn bytes(self) -> [u8; 4]
Returns the four register bytes for this setting.
The order is on-low, on-high, off-low, off-high, matching the channel’s four consecutive registers; the full-on and full-off flags ride in bit 4 of the high bytes.
§Returns
[on_low, on_high, off_low, off_high].
Sourcepub fn from_bytes(bytes: &[u8; 4]) -> Pwm
pub fn from_bytes(bytes: &[u8; 4]) -> Pwm
Reads a setting back from the four register bytes a channel holds.
The inverse of bytes, so a caller can read a channel back off the
bus and see what it is set to rather than decoding the registers by hand.
§Arguments
bytes- the four channel registers,[on_low, on_high, off_low, off_high].
§Returns
The PWM setting those registers hold, full-on and full-off flags included.