22
33use core:: { convert:: From , ops:: Not } ;
44
5+ /// GPIO error type trait
6+ ///
7+ /// This just defines the error type, to be used by the other traits.
8+ pub trait ErrorType {
9+ /// Error type
10+ type Error : core:: fmt:: Debug ;
11+ }
12+
13+ impl < T : ErrorType > ErrorType for & T {
14+ type Error = T :: Error ;
15+ }
16+ impl < T : ErrorType > ErrorType for & mut T {
17+ type Error = T :: Error ;
18+ }
19+
520/// Digital output pin state
621///
722/// Conversion from `bool` and logical negation are also implemented
@@ -45,10 +60,7 @@ pub mod blocking {
4560 use super :: PinState ;
4661
4762 /// Single digital push-pull output pin
48- pub trait OutputPin {
49- /// Error type
50- type Error : core:: fmt:: Debug ;
51-
63+ pub trait OutputPin : super :: ErrorType {
5264 /// Drives the pin low
5365 ///
5466 /// *NOTE* the actual electrical state of the pin may not actually be low, e.g. due to external
@@ -74,8 +86,6 @@ pub mod blocking {
7486 }
7587
7688 impl < T : OutputPin > OutputPin for & mut T {
77- type Error = T :: Error ;
78-
7989 fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > {
8090 T :: set_low ( self )
8191 }
@@ -113,27 +123,19 @@ pub mod blocking {
113123 }
114124
115125 /// Output pin that can be toggled
116- pub trait ToggleableOutputPin {
117- /// Error type
118- type Error : core:: fmt:: Debug ;
119-
126+ pub trait ToggleableOutputPin : super :: ErrorType {
120127 /// Toggle pin output.
121128 fn toggle ( & mut self ) -> Result < ( ) , Self :: Error > ;
122129 }
123130
124131 impl < T : ToggleableOutputPin > ToggleableOutputPin for & mut T {
125- type Error = T :: Error ;
126-
127132 fn toggle ( & mut self ) -> Result < ( ) , Self :: Error > {
128133 T :: toggle ( self )
129134 }
130135 }
131136
132137 /// Single digital input pin
133- pub trait InputPin {
134- /// Error type
135- type Error : core:: fmt:: Debug ;
136-
138+ pub trait InputPin : super :: ErrorType {
137139 /// Is the input pin high?
138140 fn is_high ( & self ) -> Result < bool , Self :: Error > ;
139141
@@ -142,8 +144,6 @@ pub mod blocking {
142144 }
143145
144146 impl < T : InputPin > InputPin for & T {
145- type Error = T :: Error ;
146-
147147 fn is_high ( & self ) -> Result < bool , Self :: Error > {
148148 T :: is_high ( self )
149149 }
0 commit comments