@@ -79,10 +79,11 @@ pub enum Port {
79
79
PH ,
80
80
}
81
81
82
+ /// Error type used by the GPIO trait impls.
83
+ ///
84
+ /// GPIO operations cannot fail, so this is uninhabited.
82
85
#[ derive( Debug ) ]
83
- pub enum Error {
84
- Foo ,
85
- }
86
+ pub enum Error { }
86
87
87
88
macro_rules! gpio {
88
89
( $GPIOX: ident, $gpiox: ident, $iopxenr: ident, $PXx: ident, [
@@ -134,28 +135,28 @@ macro_rules! gpio {
134
135
}
135
136
136
137
impl <MODE > OutputPin for $PXx<Output <MODE >> {
137
- type Error = ( ) ;
138
+ type Error = super :: Error ;
138
139
139
- fn set_high( & mut self ) -> Result <( ) , ( ) > {
140
+ fn set_high( & mut self ) -> Result <( ) , Self :: Error > {
140
141
// NOTE(unsafe) atomic write to a stateless register
141
142
unsafe { ( * $GPIOX:: ptr( ) ) . bsrr. write( |w| w. bits( 1 << self . i) ) } ;
142
143
Ok ( ( ) )
143
144
}
144
145
145
- fn set_low( & mut self ) -> Result <( ) , ( ) > {
146
+ fn set_low( & mut self ) -> Result <( ) , Self :: Error > {
146
147
// NOTE(unsafe) atomic write to a stateless register
147
148
unsafe { ( * $GPIOX:: ptr( ) ) . bsrr. write( |w| w. bits( 1 << ( self . i + 16 ) ) ) } ;
148
149
Ok ( ( ) )
149
150
}
150
151
}
151
152
152
153
impl <MODE > StatefulOutputPin for $PXx<Output <MODE >> {
153
- fn is_set_high( & self ) -> Result <bool , ( ) > {
154
+ fn is_set_high( & self ) -> Result <bool , Self :: Error > {
154
155
let is_high = self . is_set_low( ) ?;
155
156
Ok ( is_high)
156
157
}
157
158
158
- fn is_set_low( & self ) -> Result <bool , ( ) > {
159
+ fn is_set_low( & self ) -> Result <bool , Self :: Error > {
159
160
// NOTE(unsafe) atomic read with no side effects
160
161
let is_low = unsafe { ( * $GPIOX:: ptr( ) ) . odr. read( ) . bits( ) & ( 1 << self . i) == 0 } ;
161
162
Ok ( is_low)
@@ -165,29 +166,29 @@ macro_rules! gpio {
165
166
impl <MODE > toggleable:: Default for $PXx<Output <MODE >> { }
166
167
167
168
impl <MODE > InputPin for $PXx<Output <MODE >> {
168
- type Error = ( ) ;
169
+ type Error = super :: Error ;
169
170
170
- fn is_high( & self ) -> Result <bool , ( ) > {
171
+ fn is_high( & self ) -> Result <bool , Self :: Error > {
171
172
let is_high = !self . is_low( ) ?;
172
173
Ok ( is_high)
173
174
}
174
175
175
- fn is_low( & self ) -> Result <bool , ( ) > {
176
+ fn is_low( & self ) -> Result <bool , Self :: Error > {
176
177
// NOTE(unsafe) atomic read with no side effects
177
178
let is_low = unsafe { ( * $GPIOX:: ptr( ) ) . idr. read( ) . bits( ) & ( 1 << self . i) == 0 } ;
178
179
Ok ( is_low)
179
180
}
180
181
}
181
182
182
183
impl <MODE > InputPin for $PXx<Input <MODE >> {
183
- type Error = ( ) ;
184
+ type Error = super :: Error ;
184
185
185
- fn is_high( & self ) -> Result <bool , ( ) > {
186
+ fn is_high( & self ) -> Result <bool , Self :: Error > {
186
187
let is_high = !self . is_low( ) ?;
187
188
Ok ( is_high)
188
189
}
189
190
190
- fn is_low( & self ) -> Result <bool , ( ) > {
191
+ fn is_low( & self ) -> Result <bool , Self :: Error > {
191
192
// NOTE(unsafe) atomic read with no side effects
192
193
let is_low = unsafe { ( * $GPIOX:: ptr( ) ) . idr. read( ) . bits( ) & ( 1 << self . i) == 0 } ;
193
194
Ok ( is_low)
@@ -378,15 +379,15 @@ macro_rules! gpio {
378
379
}
379
380
380
381
impl <MODE > OutputPin for $PXi<Output <MODE >> {
381
- type Error = ( ) ;
382
+ type Error = super :: Error ;
382
383
383
- fn set_high( & mut self ) -> Result <( ) , ( ) > {
384
+ fn set_high( & mut self ) -> Result <( ) , Self :: Error > {
384
385
// NOTE(unsafe) atomic write to a stateless register
385
386
unsafe { ( * $GPIOX:: ptr( ) ) . bsrr. write( |w| w. bits( 1 << $i) ) } ;
386
387
Ok ( ( ) )
387
388
}
388
389
389
- fn set_low( & mut self ) -> Result <( ) , ( ) > {
390
+ fn set_low( & mut self ) -> Result <( ) , Self :: Error > {
390
391
// NOTE(unsafe) atomic write to a stateless register
391
392
unsafe { ( * $GPIOX:: ptr( ) ) . bsrr. write( |w| w. bits( 1 << ( $i + 16 ) ) ) } ;
392
393
Ok ( ( ) )
@@ -395,12 +396,12 @@ macro_rules! gpio {
395
396
396
397
impl <MODE > StatefulOutputPin for $PXi<Output <MODE >> {
397
398
398
- fn is_set_high( & self ) -> Result <bool , ( ) > {
399
+ fn is_set_high( & self ) -> Result <bool , Self :: Error > {
399
400
let is_set_high = !self . is_set_low( ) ?;
400
401
Ok ( is_set_high)
401
402
}
402
403
403
- fn is_set_low( & self ) -> Result <bool , ( ) > {
404
+ fn is_set_low( & self ) -> Result <bool , Self :: Error > {
404
405
// NOTE(unsafe) atomic read with no side effects
405
406
let is_set_low = unsafe { ( * $GPIOX:: ptr( ) ) . odr. read( ) . bits( ) & ( 1 << $i) == 0 } ;
406
407
Ok ( is_set_low)
@@ -410,14 +411,14 @@ macro_rules! gpio {
410
411
impl <MODE > toggleable:: Default for $PXi<Output <MODE >> { }
411
412
412
413
impl <MODE > InputPin for $PXi<Output <MODE >> {
413
- type Error = ( ) ;
414
+ type Error = super :: Error ;
414
415
415
- fn is_high( & self ) -> Result <bool , ( ) > {
416
+ fn is_high( & self ) -> Result <bool , Self :: Error > {
416
417
let is_high = !self . is_low( ) ?;
417
418
Ok ( is_high)
418
419
}
419
420
420
- fn is_low( & self ) -> Result <bool , ( ) > {
421
+ fn is_low( & self ) -> Result <bool , Self :: Error > {
421
422
// NOTE(unsafe) atomic read with no side effects
422
423
let is_low = unsafe { ( * $GPIOX:: ptr( ) ) . idr. read( ) . bits( ) & ( 1 << $i) == 0 } ;
423
424
Ok ( is_low)
@@ -440,14 +441,14 @@ macro_rules! gpio {
440
441
441
442
impl <MODE > InputPin for $PXi<Input <MODE >> {
442
443
443
- type Error = ( ) ;
444
+ type Error = super :: Error ;
444
445
445
- fn is_high( & self ) -> Result <bool , ( ) > {
446
+ fn is_high( & self ) -> Result <bool , Self :: Error > {
446
447
let is_high = !self . is_low( ) ?;
447
448
Ok ( is_high)
448
449
}
449
450
450
- fn is_low( & self ) -> Result <bool , ( ) > {
451
+ fn is_low( & self ) -> Result <bool , Self :: Error > {
451
452
// NOTE(unsafe) atomic read with no side effects
452
453
let is_low = unsafe { ( * $GPIOX:: ptr( ) ) . idr. read( ) . bits( ) & ( 1 << $i) == 0 } ;
453
454
Ok ( is_low)
0 commit comments