@@ -73,6 +73,26 @@ impl CdevPin<Input> {
73
73
mode : PhantomData ,
74
74
} )
75
75
}
76
+
77
+ /// Converts this input pin into an output pin with the given `initial_state`.
78
+ pub fn into_output < P > ( self , initial_state : PinState ) -> Result < CdevPin < Output > , CdevPinError > {
79
+ let new_value = self . state_to_value ( initial_state) ;
80
+
81
+ let req = self . req ;
82
+ let mut new_config = req. as_ref ( ) . config ( ) ;
83
+ new_config. as_output ( new_value) ;
84
+ req. as_ref ( ) . reconfigure ( & new_config) ?;
85
+
86
+ let line = self . line ;
87
+ let line_config = new_config. line_config ( line) . unwrap ( ) . clone ( ) ;
88
+
89
+ Ok ( CdevPin {
90
+ req,
91
+ line,
92
+ line_config,
93
+ mode : PhantomData ,
94
+ } )
95
+ }
76
96
}
77
97
78
98
impl CdevPin < Output > {
@@ -118,6 +138,24 @@ impl CdevPin<Output> {
118
138
mode : PhantomData ,
119
139
} )
120
140
}
141
+
142
+ /// Converts this output pin into an input pin.
143
+ pub fn into_input < P > ( self ) -> Result < CdevPin < Output > , CdevPinError > {
144
+ let req = self . req ;
145
+ let mut new_config = req. as_ref ( ) . config ( ) ;
146
+ new_config. as_input ( ) ;
147
+ req. as_ref ( ) . reconfigure ( & new_config) ?;
148
+
149
+ let line = self . line ;
150
+ let line_config = new_config. line_config ( line) . unwrap ( ) . clone ( ) ;
151
+
152
+ Ok ( CdevPin {
153
+ req,
154
+ line,
155
+ line_config,
156
+ mode : PhantomData ,
157
+ } )
158
+ }
121
159
}
122
160
123
161
impl < MODE > CdevPin < MODE > {
@@ -242,10 +280,11 @@ impl embedded_hal_async::digital::Wait for CdevPin<Input> {
242
280
self . line_config. edge_detection,
243
281
Some ( EdgeDetection :: RisingEdge | EdgeDetection :: BothEdges )
244
282
) {
245
- let mut new_config = self . req . as_ref ( ) . config ( ) ;
283
+ let req = self . req . as_ref ( ) ;
284
+ let mut new_config = req. config ( ) ;
246
285
new_config. with_edge_detection ( EdgeDetection :: RisingEdge ) ;
247
- self . req . as_ref ( ) . reconfigure ( & new_config) ?;
248
- self . line_config . edge_detection = Some ( EdgeDetection :: RisingEdge ) ;
286
+ req. reconfigure ( & new_config) ?;
287
+ self . line_config = Some ( EdgeDetection :: RisingEdge ) ;
249
288
}
250
289
251
290
loop {
0 commit comments