1#[cfg(not(feature = "host"))]
2use core::convert::Infallible;
3
4use derive_more::derive::{Display, Error};
5use esp_hal_mfrc522::consts::PCDErrorCode;
6
7pub type Result<T, E = Error> = core::result::Result<T, E>;
9
10#[expect(missing_docs, reason = "The variants are self-explanatory.")]
12#[derive(Debug, Display, Error)]
13pub enum Error {
14 #[display("{_0:?}")]
20 TaskSpawn(#[error(not(source))] embassy_executor::SpawnError),
21
22 #[display("bits_to_indexes does not have enough preallocated space")]
23 BitsToIndexesNotEnoughSpace,
24
25 #[display("BitsToIndexes is full")]
26 BitsToIndexesFull,
27
28 #[display("Error setting output state")]
29 CannotSetOutputState,
30
31 #[display("Index out of bounds")]
32 IndexOutOfBounds,
33
34 #[display("MFRC522 initialization failed: {_0:?}")]
35 Mfrc522Init(#[error(not(source))] PCDErrorCode),
36
37 #[display("MFRC522 version read failed: {_0:?}")]
38 Mfrc522Version(#[error(not(source))] PCDErrorCode),
39
40 #[display("Format error")]
41 FormatError,
42
43 #[display("Custom WiFi Auto field missing")]
44 MissingCustomWifiAutoField,
45
46 #[display("Network Time Protocol (NTP) error: {_0}")]
47 Ntp(#[error(not(source))] &'static str),
48
49 #[cfg(not(feature = "host"))]
50 #[display("Flash operation failed: {_0:?}")]
51 Flash(#[error(not(source))] embassy_rp::flash::Error),
52
53 #[display("Storage is invalid or corrupted")]
54 StorageCorrupted,
55
56 #[display("animation disabled (max_frames = {_0})")]
57 AnimationDisabled(#[error(not(source))] usize),
58}
59
60impl From<()> for Error {
61 fn from(_: ()) -> Self {
62 Self::FormatError
63 }
64}
65
66#[cfg(not(feature = "host"))]
67impl From<Infallible> for Error {
68 fn from(value: Infallible) -> Self {
69 match value {}
70 }
71}
72
73impl From<embassy_executor::SpawnError> for Error {
74 fn from(err: embassy_executor::SpawnError) -> Self {
75 Self::TaskSpawn(err)
76 }
77}