#[cfg(not(feature = "host"))]
use core::convert::Infallible;
use derive_more::derive::{Display, Error};
use device_envoy_core::lcd_text::LcdTextError;
use device_envoy_core::wifi_auto::WifiAutoError;
use esp_hal_mfrc522::consts::PCDErrorCode;
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[expect(missing_docs, reason = "The variants are self-explanatory.")]
#[derive(Debug, Display, Error)]
pub enum Error {
#[display("{_0:?}")]
TaskSpawn(#[error(not(source))] embassy_executor::SpawnError),
#[display("bits_to_indexes does not have enough preallocated space")]
BitsToIndexesNotEnoughSpace,
#[display("BitsToIndexes is full")]
BitsToIndexesFull,
#[display("Error setting output state")]
CannotSetOutputState,
#[display("Index out of bounds")]
IndexOutOfBounds,
#[display("MFRC522 initialization failed: {_0:?}")]
Mfrc522Init(#[error(not(source))] PCDErrorCode),
#[display("MFRC522 version read failed: {_0:?}")]
Mfrc522Version(#[error(not(source))] PCDErrorCode),
#[display("Format error")]
FormatError,
#[display("Character LCD operation failed: {_0:?}")]
LcdText(#[error(not(source))] LcdTextError),
#[display("Custom WiFi Auto field missing")]
MissingCustomWifiAutoField,
#[display("Network Time Protocol (NTP) error: {_0}")]
Ntp(#[error(not(source))] &'static str),
#[cfg(not(feature = "host"))]
#[display("Flash operation failed: {_0:?}")]
Flash(#[error(not(source))] embassy_rp::flash::Error),
#[display("Storage is invalid or corrupted")]
StorageCorrupted,
#[display("{_0:?}")]
Core(#[error(not(source))] device_envoy_core::Error),
}
impl From<()> for Error {
fn from(_: ()) -> Self {
Self::FormatError
}
}
#[cfg(not(feature = "host"))]
impl From<Infallible> for Error {
fn from(value: Infallible) -> Self {
match value {}
}
}
impl From<embassy_executor::SpawnError> for Error {
fn from(err: embassy_executor::SpawnError) -> Self {
Self::TaskSpawn(err)
}
}
impl From<device_envoy_core::Error> for Error {
fn from(error: device_envoy_core::Error) -> Self {
match error {
device_envoy_core::Error::TaskSpawn(spawn_error) => Self::TaskSpawn(spawn_error),
core_error => Self::Core(core_error),
}
}
}
impl From<device_envoy_core::led4::Led4BitsToIndexesError> for Error {
fn from(error: device_envoy_core::led4::Led4BitsToIndexesError) -> Self {
match error {
device_envoy_core::led4::Led4BitsToIndexesError::Full => Self::BitsToIndexesFull,
}
}
}
impl From<WifiAutoError> for Error {
fn from(error: WifiAutoError) -> Self {
match error {
WifiAutoError::FormatError => Self::FormatError,
WifiAutoError::StorageCorrupted => Self::StorageCorrupted,
WifiAutoError::MissingCustomWifiAutoField => Self::MissingCustomWifiAutoField,
}
}
}
impl From<LcdTextError> for Error {
fn from(error: LcdTextError) -> Self {
Self::LcdText(error)
}
}