1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Compatibility code to help use Stepper on more platforms

use core::fmt;

use embedded_hal::digital::blocking::OutputPin;
use embedded_hal::digital::ErrorType;
use embedded_hal_stable::digital::v2::OutputPin as StableOutputPin;

/// Wrapper around a pin
///
/// Provides an implementation of [`embedded_hal::digital::blocking::OutputPin`]
/// (that is, the `OutputPin` from the latest alpha version of `embedded-hal`)
/// for all types that implement `OutputPin` from the latest stable version of
/// `embedded-hal`.
pub struct Pin<T>(pub T);

impl<T> ErrorType for Pin<T> where T: StableOutputPin, T::Error: fmt::Debug { type Error = T::Error; }

impl<T> OutputPin for Pin<T>
where
    T: StableOutputPin,
    T::Error: fmt::Debug,
{
    fn set_low(&mut self) -> Result<(), Self::Error> {
        self.0.set_low()
    }

    fn set_high(&mut self) -> Result<(), Self::Error> {
        self.0.set_high()
    }
}