embedded_error/
lib.rs

1#![no_std]
2
3pub mod mci;
4
5/// This crate contains a variety of universal error types which can be used to universally model
6/// conditions which can typically arise for certain peripherals.
7///
8/// When used by HAL implementations, they allow drivers and applications alike to generically
9/// handle those situations without the error handling being specific to the hardware it is
10/// supposed to run on (which is usually not possible to implement in drivers).
11///
12/// All of the enums in this crate are marked as `#[non_exhaustive]` to allow for additions of new
13/// error kinds without requiring a breaking change and version bump.
14
15/// A GPIO (General input/output) specific error.
16///
17/// This error type contains errors specific to GPIO peripherals. Also it has an `Impl` kind to
18/// pass through implementation specific errors occuring while trying to use a GPIO peripheral.
19#[derive(Debug, Clone)]
20#[non_exhaustive]
21pub enum GpioError {
22    /// The peripheral is in the wrong operational mode for the intended operation
23    WrongMode,
24    /// Implementation specific error (shared across all peripheral specific error kinds)
25    Impl(ImplError),
26}
27
28
29/// A USB specific error.
30///
31/// This error type contains errors specific to USB peripherals. Also it has an `Impl` kind to pass
32/// through implementation specific errors occuring while trying to use a USB peripheral.
33#[derive(Debug, Clone)]
34#[non_exhaustive]
35pub enum UsbError {
36    /// An operation would block because the device is currently busy or there is no data available.
37    WouldBlock,
38    /// Parsing failed due to invalid input.
39    ParseError,
40    /// A buffer too short for the data to read was passed, or provided data cannot fit within
41    /// length constraints.
42    BufferOverflow,
43    /// Classes attempted to allocate more endpoints than the peripheral supports.
44    EndpointOverflow,
45    /// Classes attempted to allocate more packet buffer memory than the peripheral supports. This
46    /// can be caused by either a single class trying to allocate a packet buffer larger than the
47    /// peripheral supports per endpoint, or multiple allocated endpoints together using more memory
48    /// than the peripheral has available for the buffers.
49    EndpointMemoryOverflow,
50    /// The endpoint address is invalid or already used.
51    InvalidEndpoint,
52    /// Operation is not supported by device or configuration.
53    Unsupported,
54    /// Operation is not valid in the current state of the object.
55    InvalidState,
56    /// Implementation specific error (shared across all peripheral specific error kinds)
57    Impl(ImplError),
58}
59
60
61/// A SPI specific error.
62///
63/// This error type contains errors specific to SPI peripherals. Also it has an `Impl` kind to pass
64/// through implementation specific errors occuring while trying to use a SPI peripheral.
65#[derive(Debug, Clone)]
66#[non_exhaustive]
67pub enum SpiError {
68    /// The peripheral receive buffer was overrun
69    Overrun,
70    /// Multiple devices on the SPI bus are trying across each other, e.g. in a multi-master setup
71    ModeFault,
72    /// CRC does not match the received data
73    CRCError,
74    /// Received data does not conform to the peripheral configuration
75    FrameFormat,
76    /// Implementation specific error (shared across all peripheral specific error kinds)
77    Impl(ImplError),
78}
79
80/// A Serial specific error.
81///
82/// This error type contains errors specific to Serial peripherals. Also it has an `Impl` kind to pass
83/// through implementation specific errors occurring while trying to use a Serial peripheral.
84#[derive(Debug, Clone)]
85#[non_exhaustive]
86pub enum SerialError {
87    /// The peripheral receive buffer was overrun.
88    Overrun,
89    /// Received data does not conform to the peripheral configuration.
90    /// Can be caused by a misconfigured device on either end of the serial line.
91    FrameFormat,
92    /// Parity check failed.
93    Parity,
94    /// Serial line is too noisy to read valid data.
95    Noise,
96    /// Implementation specific error (shared across all peripheral specific error kinds).
97    Impl(ImplError),
98}
99
100/// An I2C specific error.
101///
102/// This error type contains errors specific to I2C peripherals. Also it has an `Impl` kind to pass
103/// through implementation specific errors occurring while trying to use an I2C peripheral.
104#[derive(Debug, Clone)]
105#[non_exhaustive]
106pub enum I2cError {
107    /// An unspecific bus error occured
108    Bus,
109    /// The arbitration was lost, e.g. electrical problems with the clock signal
110    ArbitrationLoss,
111    /// A bus operation received a NACK, e.g. due to the addressed device not being available on
112    /// the bus or device not being ready to process any requests at the moment
113    NACK,
114    /// The peripheral receive buffer was overrun
115    Overrun,
116    /// The peripheral send buffer ran out of data
117    Underrun,
118    /// SMBus Error checking byte mismatch
119    PacketErrorChecking,
120    /// SMBus Timeout error
121    Timeout,
122    /// SMBus Alert received
123    Alert,
124    /// Implementation specific error (shared across all peripheral specific error kinds)
125    Impl(ImplError),
126}
127
128/// A universal implementation specific error.
129///
130/// These error kinds can be used to signal implementation specific errors unrelated to the
131/// specific peripheral. This will be used for all sorts of connectivity problems, e.g. if an
132/// adapter to the peripheral is used or the target peripheral is connected to indirectly (like bus
133/// expanders) or an operating system is controlling the access and denying access.
134#[derive(Debug, Clone)]
135#[non_exhaustive]
136pub enum ImplError {
137    /// Unspecified internal driver error
138    Internal,
139    /// Connection lost, e.g. device adapter was unplugged
140    Disconnected,
141    /// Ran out of memory while trying to allocate required buffers
142    OutOfMemory,
143    /// Operation timed out, please retry
144    TimedOut,
145    /// Peripheral is sleeping or in standby
146    Asleep,
147    /// Peripheral is powered down
148    PowerDown,
149    /// The peripheral cannot work with the specified settings
150    InvalidConfiguration,
151    /// Could not open connection to peripheral
152    CouldNotOpen,
153    /// No sufficient permissions to connect to peripheral
154    PermissionDenied,
155}