1pub type Result<T> = core::result::Result<T, Error>;
3
4#[repr(usize)]
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum Error {
8    TimedOut,
9    Unimplemented,
10    InvalidVariant(usize),
11    Sdmmc(sdmmc::Error),
12    #[cfg(feature = "jh7110")]
13    Jh7110(jh71xx_hal::mmc::Error),
14}
15
16impl Error {
17    pub const fn timed_out() -> Self {
19        Self::TimedOut
20    }
21
22    pub const fn unimplemented() -> Self {
24        Self::Unimplemented
25    }
26
27    pub const fn sdmmc(err: sdmmc::Error) -> Self {
29        Self::Sdmmc(err)
30    }
31
32    pub const fn invalid_variant(val: usize) -> Self {
34        Self::InvalidVariant(val)
35    }
36
37    #[cfg(feature = "jh7110")]
38    pub const fn jh7110(err: jh71xx_hal::mmc::Error) -> Self {
40        Self::Jh7110(err)
41    }
42}
43
44impl core::fmt::Display for Error {
45    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46        match self {
47            Self::TimedOut => write!(f, "operation timed out"),
48            Self::Unimplemented => write!(f, "unimplemented"),
49            Self::Sdmmc(err) => write!(f, "sdmmc error: {err}"),
50            Self::InvalidVariant(err) => write!(f, "invalid variant: {err}"),
51            #[cfg(feature = "jh7110")]
52            Self::Jh7110(err) => write!(f, "jh7110 error: {err}"),
53        }
54    }
55}
56
57impl core::error::Error for Error {}
58
59impl From<sdmmc::Error> for Error {
60    fn from(err: sdmmc::Error) -> Self {
61        Self::Sdmmc(err)
62    }
63}
64
65#[cfg(feature = "jh7110")]
66impl From<jh71xx_hal::mmc::Error> for Error {
67    fn from(err: jh71xx_hal::mmc::Error) -> Self {
68        Self::Jh7110(err)
69    }
70}