@@ -25,7 +25,7 @@ pub use error::Error;
25
25
26
26
#[ derive( Debug ) ]
27
27
pub struct PwmChip {
28
- chip : u32
28
+ chip : u32 ,
29
29
}
30
30
31
31
#[ derive( Debug ) ]
@@ -55,14 +55,15 @@ impl PwmChip {
55
55
try!( npwm_file. read_to_string ( & mut s) ) ;
56
56
match s. parse :: < u32 > ( ) {
57
57
Ok ( n) => Ok ( n) ,
58
- Err ( _) => Err ( Error :: Unexpected (
59
- format ! ( "Unexpected npwm contents: {:?}" , s) ) ) ,
58
+ Err ( _) => Err ( Error :: Unexpected ( format ! ( "Unexpected npwm contents: {:?}" , s) ) ) ,
60
59
}
61
60
}
62
61
63
62
pub fn export ( & self , number : u32 ) -> Result < ( ) > {
64
63
// only export if not already exported
65
- if let Err ( _) = fs:: metadata ( & format ! ( "/sys/class/pwm/pwmchip{}/pwm{}" , self . chip, number) ) {
64
+ if let Err ( _) = fs:: metadata ( & format ! ( "/sys/class/pwm/pwmchip{}/pwm{}" ,
65
+ self . chip,
66
+ number) ) {
66
67
let path = format ! ( "/sys/class/pwm/pwmchip{}/export" , self . chip) ;
67
68
let mut export_file = try!( File :: create ( & path) ) ;
68
69
let _ = export_file. write_all ( format ! ( "{}" , number) . as_bytes ( ) ) ;
@@ -81,19 +82,21 @@ impl PwmChip {
81
82
}
82
83
83
84
impl Pwm {
84
-
85
85
/// Create a new Pwm wiht the provided chip/number
86
86
///
87
87
/// This function does not export the Pwm pin
88
88
pub fn new ( chip : u32 , number : u32 ) -> Result < Pwm > {
89
89
let chip: PwmChip = try!( PwmChip :: new ( chip) ) ;
90
- Ok ( Pwm { chip : chip, number : number } )
90
+ Ok ( Pwm {
91
+ chip : chip,
92
+ number : number,
93
+ } )
91
94
}
92
95
93
96
/// Run a closure with the GPIO exported
94
97
#[ inline]
95
- pub fn with_exported < F > ( & self , closure : F ) -> Result < ( ) > where
96
- F : FnOnce ( ) -> Result < ( ) >
98
+ pub fn with_exported < F > ( & self , closure : F ) -> Result < ( ) >
99
+ where F : FnOnce ( ) -> Result < ( ) >
97
100
{
98
101
try!( self . export ( ) ) ;
99
102
match closure ( ) {
@@ -133,12 +136,12 @@ impl Pwm {
133
136
///
134
137
/// Value is in nanoseconds and must be less than the period.
135
138
pub fn set_duty_cycle_ns ( & self , duty_cycle_ns : u32 ) -> Result < ( ) > {
139
+
136
140
Ok ( ( ) )
137
141
}
138
142
139
143
/// The period of the PWM signal in Nanoseconds
140
144
pub fn set_period_ns ( & self , period_ns : u32 ) -> Result < ( ) > {
141
145
Ok ( ( ) )
142
146
}
143
-
144
147
}
0 commit comments