Skip to content

Commit 9b19b4e

Browse files
committed
Add example use to IoPin docs
1 parent 5ef6520 commit 9b19b4e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/digital.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,31 @@ pub trait InputPin {
176176
}
177177

178178
/// 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+
/// ```
179204
pub trait IoPin<TInput, TOutput>
180205
where TInput : InputPin + IoPin<TInput, TOutput>,
181206
TOutput : OutputPin + IoPin<TInput, TOutput> {

0 commit comments

Comments
 (0)