1use core::fmt::{self, Debug, Display};
2use embedded_hal::blocking::spi::Transfer;
3use embedded_hal::digital::v2::OutputPin;
4
5mod private {
6 #[derive(Debug)]
7 pub enum Private {}
8}
9
10pub enum Error<SPI: Transfer<u8>, GPIO: OutputPin> {
15 Spi(SPI::Error),
17
18 Gpio(GPIO::Error),
20
21 UnexpectedStatus,
27
28 #[doc(hidden)]
29 __NonExhaustive(private::Private),
30}
31
32impl<SPI: Transfer<u8>, GPIO: OutputPin> Debug for Error<SPI, GPIO>
33where
34 SPI::Error: Debug,
35 GPIO::Error: Debug,
36{
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match self {
39 Error::Spi(spi) => write!(f, "Error::Spi({:?})", spi),
40 Error::Gpio(gpio) => write!(f, "Error::Gpio({:?})", gpio),
41 Error::UnexpectedStatus => f.write_str("Error::UnexpectedStatus"),
42 Error::__NonExhaustive(_) => unreachable!(),
43 }
44 }
45}
46
47impl<SPI: Transfer<u8>, GPIO: OutputPin> Display for Error<SPI, GPIO>
48where
49 SPI::Error: Display,
50 GPIO::Error: Display,
51{
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 match self {
54 Error::Spi(spi) => write!(f, "SPI error: {}", spi),
55 Error::Gpio(gpio) => write!(f, "GPIO error: {}", gpio),
56 Error::UnexpectedStatus => f.write_str("unexpected value in status register"),
57 Error::__NonExhaustive(_) => unreachable!(),
58 }
59 }
60}