Struct libbeaglebone::pwm::PWM
[−]
[src]
pub struct PWM { /* fields omitted */ }
Represents a PWM device.
Methods
impl PWM
[src]
fn new(m_pwm_chip_num: u8, m_pwm_num: u8) -> PWM
Creates a new PWM object.
Note: you will need to configure the selected pin as a PWM output prior
to use using the config-pin
utility.
For example, config-pin P9.21 pwm
.
See the examples/
directory for more help.
Examples
use libbeaglebone::pwm::PWM; // Create a new PWM device using PWM chip 0 and PWM 0. let mut pwm = PWM::new(0,0);
fn set_export(&self, state: DeviceState) -> Result<()>
Exports the PWM.
Examples
use libbeaglebone::enums::DeviceState; use libbeaglebone::pwm::PWM; // Create a new PWM device using PWM chip 0 and PWM 0. let mut pwm = PWM::new(0,0); // Export the PWM. pwm.set_export(DeviceState::Exported).unwrap();
fn set_period(&mut self, period_ns: u32) -> Result<()>
Sets the period of the PWM in nanoseconds.
Examples
use libbeaglebone::enums::DeviceState; use libbeaglebone::pwm::PWM; // Create a new PWM device using PWM chip 0 and PWM 0. let mut pwm = PWM::new(0,0); // Export the PWM. pwm.set_export(DeviceState::Exported).unwrap(); // Make the period 500,000ns. pwm.set_period(500_000).unwrap();
fn set_state(&mut self, state: PWMState) -> Result<()>
Sets the state (enabled or disabled) of the PWM.
Examples
use libbeaglebone::enums::DeviceState; use libbeaglebone::pwm::{PWM, PWMState}; // Create a new PWM device using PWM chip 0 and PWM 0. let mut pwm = PWM::new(0,0); // Export the PWM. pwm.set_export(DeviceState::Exported).unwrap(); // Make the period 500,000ns. pwm.set_period(500_000).unwrap(); // Turn the PWM on pwm.set_state(PWMState::Enabled).unwrap();
fn write(&mut self, percentage: f32) -> Result<()>
Sets the duty cycle of the PWM as a percentage of the period.
Examples
use libbeaglebone::enums::DeviceState; use libbeaglebone::pwm::{PWM, PWMState}; // Create a new PWM device using PWM chip 0 and PWM 0. let mut pwm = PWM::new(0,0); // Export the PWM. pwm.set_export(DeviceState::Exported).unwrap(); // Make the period 500,000ns. pwm.set_period(500_000).unwrap(); // Turn the PWM on. pwm.set_state(PWMState::Enabled).unwrap(); // Set the duty cycle to 50% (250,000ns). pwm.write(50.0).unwrap();
fn set_duty_cycle(&mut self, duty_cycle_ns: u32) -> Result<()>
Sets the duty cycle of the PWM in nanoseconds.
Examples
use libbeaglebone::enums::DeviceState; use libbeaglebone::pwm::{PWM, PWMState}; // Create a new PWM device using PWM chip 0 and PWM 0. let mut pwm = PWM::new(0,0); // Export the PWM. pwm.set_export(DeviceState::Exported).unwrap(); // Make the period 500,000ns. pwm.set_period(500_000).unwrap(); // Turn the PWM on. pwm.set_state(PWMState::Enabled).unwrap(); // Set the duty cycle to 250,000ns. pwm.set_duty_cycle(250_000).unwrap();