Skip to main content

w25q_async/
error.rs

1use core::fmt::{Debug, Display};
2
3/// The error type used by this library.
4///
5/// This can encapsulate an SPI or GPIO error, and adds its own protocol errors
6/// on top of that.
7#[derive(Debug)]
8pub enum Error<SpiError> {
9    /// An SPI transfer failed.
10    Spi(SpiError),
11
12    /// Status register contained unexpected flags.
13    ///
14    /// This can happen when the chip is faulty, incorrectly connected, or the
15    /// driver wasn't constructed or destructed properly (eg. while there is
16    /// still a write in progress).
17    UnexpectedStatus,
18
19    /// Received an invalid response from the flash memory.
20    InvalidResponse,
21}
22
23impl<SpiError: Display> Display for Error<SpiError> {
24    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
25        match self {
26            Error::Spi(e) => write!(f, "SPI error: {e}"),
27            Error::UnexpectedStatus => f.write_str("unexpected value in status register"),
28            Error::InvalidResponse => f.write_str("invalid response"),
29        }
30    }
31}