@@ -176,6 +176,31 @@ pub trait InputPin {
176
176
}
177
177
178
178
/// Single pin that can switch from input to output mode, and vice-versa.
179
+ ///
180
+ /// Example use (assumes the Error type is the same for IoPin, InputPin, and
181
+ /// OutputPin):
182
+ ///
183
+ /// ```
184
+ /// use core::time::Duration;
185
+ /// use embedded_hal::digital::{IoPin, InputPin, OutputPin, PinState};
186
+ ///
187
+ /// pub fn ping_and_read<TIoPin, TInputPin, TOutputPin, TError>(
188
+ /// pin: TIoPin, delay_fn: &dyn Fn(Duration) -> ()) -> Result<bool, TError>
189
+ /// where TIoPin : IoPin<TInputPin, TOutputPin, Error = TError>,
190
+ /// TInputPin : InputPin<Error = TError> + IoPin<TInputPin, TOutputPin, Error = TError>,
191
+ /// TOutputPin : OutputPin<Error = TError> + IoPin<TInputPin, TOutputPin, Error = TError> {
192
+ ///
193
+ /// // Ping
194
+ /// let mut pin = pin.try_into_output_pin(PinState::Low)?;
195
+ /// delay_fn(Duration::from_millis(10));
196
+ /// pin.try_set_high()?;
197
+ ///
198
+ /// // Read
199
+ /// let pin = pin.try_into_input_pin()?;
200
+ /// delay_fn(Duration::from_millis(10));
201
+ /// pin.try_is_high()
202
+ /// }
203
+ /// ```
179
204
pub trait IoPin < TInput , TOutput >
180
205
where TInput : InputPin + IoPin < TInput , TOutput > ,
181
206
TOutput : OutputPin + IoPin < TInput , TOutput > {
0 commit comments