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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::motion_control;

/// Unified error type
///
/// Unifies the two types of errors that can happen while using [`Stepper`]:
/// Signal errors and motion control errors.
///
/// [`Stepper`]: crate::Stepper
#[derive(Debug, Eq, PartialEq)]
pub enum Error<PinUnavailableError, PinError, DelayToTicksError, TimerError> {
    /// A signal error
    Signal(SignalError<PinUnavailableError, PinError, TimerError>),

    /// A motion control error
    MotionControl(
        motion_control::Error<
            PinUnavailableError,
            PinError,
            PinUnavailableError,
            PinError,
            TimerError,
            DelayToTicksError,
        >,
    ),
}

impl<PinUnavailableError, PinError, DelayToTicksError, TimerError>
    From<SignalError<PinUnavailableError, PinError, TimerError>>
    for Error<PinUnavailableError, PinError, DelayToTicksError, TimerError>
{
    fn from(
        err: SignalError<PinUnavailableError, PinError, TimerError>,
    ) -> Self {
        Self::Signal(err)
    }
}

impl<PinUnavailableError, PinError, DelayToTicksError, TimerError>
    From<
        motion_control::Error<
            PinUnavailableError,
            PinError,
            PinUnavailableError,
            PinError,
            TimerError,
            DelayToTicksError,
        >,
    > for Error<PinUnavailableError, PinError, DelayToTicksError, TimerError>
{
    fn from(
        err: motion_control::Error<
            PinUnavailableError,
            PinError,
            PinUnavailableError,
            PinError,
            TimerError,
            DelayToTicksError,
        >,
    ) -> Self {
        Self::MotionControl(err)
    }
}

/// An error that can occur while using this API
#[derive(Debug, Eq, PartialEq)]
pub enum SignalError<PinUnavailableError, PinError, TimerError> {
    /// A pin was not accessible
    PinUnavailable(PinUnavailableError),

    /// An error originated from using the [`OutputPin`] trait
    ///
    /// [`OutputPin`]: embedded_hal::digital::blocking::OutputPin
    Pin(PinError),

    /// An error originated from working with a timer
    Timer(TimerError),
}