@@ -18,6 +18,7 @@ use std::io::prelude::*;
18
18
use std:: os:: unix:: prelude:: * ;
19
19
use std:: fs:: File ;
20
20
use std:: fs;
21
+ use std:: cmp:: { min, max} ;
21
22
22
23
mod error;
23
24
pub use error:: Error ;
@@ -33,6 +34,12 @@ pub struct Pwm {
33
34
number : u32 ,
34
35
}
35
36
37
+ #[ derive( Debug ) ]
38
+ pub enum Polarity {
39
+ Normal ,
40
+ Inverse ,
41
+ }
42
+
36
43
pub type Result < T > = :: std:: result:: Result < T , error:: Error > ;
37
44
38
45
impl PwmChip {
@@ -105,4 +112,33 @@ impl Pwm {
105
112
self . chip . unexport ( self . number )
106
113
}
107
114
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
+
108
144
}
0 commit comments