Skip to main content

device_envoy_core/
error.rs

1//! Shared error and result types for `device-envoy-core`.
2
3use core::convert::Infallible;
4
5/// A specialized `Result` where the error is this crate's [`Error`] type.
6pub type Result<T, E = Error> = core::result::Result<T, E>;
7
8/// Extension for unwrapping a `Result` whose error type is [`Infallible`].
9pub trait UnwrapInfallible {
10    /// Success value produced by the result.
11    type Output;
12
13    /// Unwrap a `Result<T, Infallible>` without a possible panic path.
14    fn unwrap_infallible(self) -> Self::Output;
15}
16
17impl<T> UnwrapInfallible for core::result::Result<T, Infallible> {
18    type Output = T;
19
20    fn unwrap_infallible(self) -> T {
21        match self {
22            Ok(value) => value,
23            Err(never) => match never {},
24        }
25    }
26}
27
28/// Unified error type for `device-envoy-core`.
29#[derive(Debug, derive_more::From)]
30#[non_exhaustive]
31pub enum Error {
32    /// Spawning an Embassy task failed.
33    #[cfg(feature = "wifi")]
34    TaskSpawn(embassy_executor::SpawnError),
35
36    /// A pixel copy's source slice length did not match the destination frame length.
37    CopySize {
38        /// Length of the source pixel slice.
39        src_len: usize,
40        /// Length of the destination frame.
41        frame_len: usize,
42    },
43
44    /// An I2C write to the character LCD's expander failed for the given address.
45    LcdI2cWrite {
46        /// The 7-bit I2C address that failed to write.
47        address: u8,
48    },
49
50    /// Attempted to set the character LCD cursor to an out-of-range row.
51    LcdRowOutOfBounds {
52        /// The out-of-range row index.
53        row: usize,
54    },
55
56    /// Touch calibration input geometry was degenerate and could not be solved.
57    CalibrationDegenerateGeometry,
58
59    /// Touch calibration solved, but the residual error was too large to accept.
60    CalibrationResidualTooLarge {
61        /// The worst observed residual, in pixels.
62        worst_residual_pixels: f32,
63    },
64
65    /// Captive-portal data or rendering format was invalid.
66    WifiAutoFormat,
67
68    /// Stored Wi-Fi auto state is invalid for expected runtime flow.
69    WifiAutoStorageCorrupted,
70
71    /// A required custom field is missing from the Wi-Fi auto setup.
72    WifiAutoMissingCustomField,
73}