stepper/stepper/
error.rs

1use crate::motion_control;
2
3/// Unified error type
4///
5/// Unifies the two types of errors that can happen while using [`Stepper`]:
6/// Signal errors and motion control errors.
7///
8/// [`Stepper`]: crate::Stepper
9#[derive(Debug, Eq, PartialEq)]
10pub enum Error<PinUnavailableError, PinError, DelayToTicksError, TimerError> {
11    /// A signal error
12    Signal(SignalError<PinUnavailableError, PinError, TimerError>),
13
14    /// A motion control error
15    MotionControl(
16        motion_control::Error<
17            PinUnavailableError,
18            PinError,
19            PinUnavailableError,
20            PinError,
21            TimerError,
22            DelayToTicksError,
23        >,
24    ),
25}
26
27impl<PinUnavailableError, PinError, DelayToTicksError, TimerError>
28    From<SignalError<PinUnavailableError, PinError, TimerError>>
29    for Error<PinUnavailableError, PinError, DelayToTicksError, TimerError>
30{
31    fn from(
32        err: SignalError<PinUnavailableError, PinError, TimerError>,
33    ) -> Self {
34        Self::Signal(err)
35    }
36}
37
38impl<PinUnavailableError, PinError, DelayToTicksError, TimerError>
39    From<
40        motion_control::Error<
41            PinUnavailableError,
42            PinError,
43            PinUnavailableError,
44            PinError,
45            TimerError,
46            DelayToTicksError,
47        >,
48    > for Error<PinUnavailableError, PinError, DelayToTicksError, TimerError>
49{
50    fn from(
51        err: motion_control::Error<
52            PinUnavailableError,
53            PinError,
54            PinUnavailableError,
55            PinError,
56            TimerError,
57            DelayToTicksError,
58        >,
59    ) -> Self {
60        Self::MotionControl(err)
61    }
62}
63
64/// An error that can occur while using this API
65#[derive(Debug, Eq, PartialEq)]
66pub enum SignalError<PinUnavailableError, PinError, TimerError> {
67    /// A pin was not accessible
68    PinUnavailable(PinUnavailableError),
69
70    /// An error originated from using the [`OutputPin`] trait
71    ///
72    /// [`OutputPin`]: embedded_hal::digital::blocking::OutputPin
73    Pin(PinError),
74
75    /// An error originated from working with a timer
76    Timer(TimerError),
77}