File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -220,4 +220,28 @@ impl Pwm {
220
220
period_file. write_all ( format ! ( "{}" , period_ns) . as_bytes ( ) ) ?;
221
221
Ok ( ( ) )
222
222
}
223
+
224
+ /// Set the polarity of the PWM signal
225
+ pub fn set_polarity ( & self , polarity : Polarity ) -> Result < ( ) > {
226
+ let mut polarity_file = pwm_file_wo ( & self . chip , self . number , "polarity" ) ?;
227
+ match polarity {
228
+ Polarity :: Normal => polarity_file. write_all ( "normal" . as_bytes ( ) ) ?,
229
+ Polarity :: Inverse => polarity_file. write_all ( "inversed" . as_bytes ( ) ) ?,
230
+ } ;
231
+ Ok ( ( ) )
232
+ }
233
+
234
+ /// Get the polarity of the PWM signal
235
+ pub fn get_polarity ( & self ) -> Result < Polarity > {
236
+ let mut polarity_file = pwm_file_ro ( & self . chip , self . number , "polarity" ) ?;
237
+ let mut s = String :: new ( ) ;
238
+ polarity_file. read_to_string ( & mut s) ?;
239
+ match s. trim ( ) {
240
+ "normal" => Ok ( Polarity :: Normal ) ,
241
+ "inversed" => Ok ( Polarity :: Inverse ) ,
242
+ _ => Err ( Error :: Unexpected ( format ! (
243
+ "Unexpected polarity file contents: {:?}" ,
244
+ s) ) ) ,
245
+ }
246
+ }
223
247
}
You can’t perform that action at this time.
0 commit comments