@@ -18,6 +18,7 @@ use std::io::prelude::*;
1818use std:: os:: unix:: prelude:: * ;
1919use std:: fs:: File ;
2020use std:: fs;
21+ use std:: cmp:: { min, max} ;
2122
2223mod error;
2324pub use error:: Error ;
@@ -33,6 +34,12 @@ pub struct Pwm {
3334 number : u32 ,
3435}
3536
37+ #[ derive( Debug ) ]
38+ pub enum Polarity {
39+ Normal ,
40+ Inverse ,
41+ }
42+
3643pub type Result < T > = :: std:: result:: Result < T , error:: Error > ;
3744
3845impl PwmChip {
@@ -105,4 +112,33 @@ impl Pwm {
105112 self . chip . unexport ( self . number )
106113 }
107114
115+ /// Enable/Disable the PWM Signal
116+ pub fn set_active ( active : bool ) -> Result < ( ) > {
117+ Ok ( ( ) )
118+ }
119+
120+ /// Set the duty cycle as a percentage of time active
121+ ///
122+ /// This value is expected to be a floating point value
123+ /// between 0.0 and 1.0. It maps to a value with resolution 0 -
124+ /// 1000. Values < 0 or > 1.0 are capped at the minimum or
125+ /// maximum respectively.
126+ pub fn set_duty_cycle ( & self , percent : f32 ) -> Result < ( ) > {
127+ let raw_percent_adj: u32 = ( percent * 1000.0 ) . floor ( ) as u32 ;
128+ let percent_adj: u32 = max ( 0 , min ( raw_percent_adj, 1000 ) ) ;
129+ Ok ( ( ) )
130+ }
131+
132+ /// The active time of the PWM signal
133+ ///
134+ /// Value is in nanoseconds and must be less than the period.
135+ pub fn set_duty_cycle_ns ( & self , duty_cycle_ns : u32 ) -> Result < ( ) > {
136+ Ok ( ( ) )
137+ }
138+
139+ /// The period of the PWM signal in Nanoseconds
140+ pub fn set_period_ns ( & self , period_ns : u32 ) -> Result < ( ) > {
141+ Ok ( ( ) )
142+ }
143+
108144}
0 commit comments