pub struct Pwm { /* private fields */ }
Implementations§
Source§impl Pwm
impl Pwm
Sourcepub fn new(chip: u32, number: u32) -> Result<Pwm>
pub fn new(chip: u32, number: u32) -> Result<Pwm>
Create a new Pwm wiht the provided chip/number
This function does not export the Pwm pin
Sourcepub fn with_exported<F>(&self, closure: F) -> Result<()>
pub fn with_exported<F>(&self, closure: F) -> Result<()>
Run a closure with the GPIO exported
Sourcepub fn get_duty_cycle_ns(&self) -> Result<u32>
pub fn get_duty_cycle_ns(&self) -> Result<u32>
Get the currently configured duty_cycle in nanoseconds
Sourcepub fn set_duty_cycle_ns(&self, duty_cycle_ns: u32) -> Result<()>
pub fn set_duty_cycle_ns(&self, duty_cycle_ns: u32) -> Result<()>
The active time of the PWM signal
Value is in nanoseconds and must be less than the period.
Examples found in repository?
examples/breathe.rs (line 26)
19fn pwm_increase_to_max(pwm: &Pwm,
20 duration_ms: u32,
21 update_period_ms: u32) -> Result<()> {
22 let step: f32 = duration_ms as f32 / update_period_ms as f32;
23 let mut duty_cycle = 0.0;
24 let period_ns: u32 = try!(pwm.get_period_ns());
25 while duty_cycle < 1.0 {
26 try!(pwm.set_duty_cycle_ns((duty_cycle * period_ns as f32) as u32));
27 duty_cycle += step;
28 }
29 pwm.set_duty_cycle_ns(period_ns)
30}
31
32fn pwm_decrease_to_minimum(pwm: &Pwm,
33 duration_ms: u32,
34 update_period_ms: u32) -> Result<()> {
35 let step: f32 = duration_ms as f32 / update_period_ms as f32;
36 let mut duty_cycle = 1.0;
37 let period_ns: u32 = try!(pwm.get_period_ns());
38 while duty_cycle > 0.0 {
39 try!(pwm.set_duty_cycle_ns((duty_cycle * period_ns as f32) as u32));
40 duty_cycle -= step;
41 }
42 pwm.set_duty_cycle_ns(0)
43}
Sourcepub fn get_period_ns(&self) -> Result<u32>
pub fn get_period_ns(&self) -> Result<u32>
Get the currently configured period in nanoseconds
Examples found in repository?
examples/breathe.rs (line 24)
19fn pwm_increase_to_max(pwm: &Pwm,
20 duration_ms: u32,
21 update_period_ms: u32) -> Result<()> {
22 let step: f32 = duration_ms as f32 / update_period_ms as f32;
23 let mut duty_cycle = 0.0;
24 let period_ns: u32 = try!(pwm.get_period_ns());
25 while duty_cycle < 1.0 {
26 try!(pwm.set_duty_cycle_ns((duty_cycle * period_ns as f32) as u32));
27 duty_cycle += step;
28 }
29 pwm.set_duty_cycle_ns(period_ns)
30}
31
32fn pwm_decrease_to_minimum(pwm: &Pwm,
33 duration_ms: u32,
34 update_period_ms: u32) -> Result<()> {
35 let step: f32 = duration_ms as f32 / update_period_ms as f32;
36 let mut duty_cycle = 1.0;
37 let period_ns: u32 = try!(pwm.get_period_ns());
38 while duty_cycle > 0.0 {
39 try!(pwm.set_duty_cycle_ns((duty_cycle * period_ns as f32) as u32));
40 duty_cycle -= step;
41 }
42 pwm.set_duty_cycle_ns(0)
43}
Sourcepub fn set_period_ns(&self, period_ns: u32) -> Result<()>
pub fn set_period_ns(&self, period_ns: u32) -> Result<()>
The period of the PWM signal in Nanoseconds
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pwm
impl RefUnwindSafe for Pwm
impl Send for Pwm
impl Sync for Pwm
impl Unpin for Pwm
impl UnwindSafe for Pwm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more