File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ provides mechanisms to obtain multiple `I2c` instances out of a single `I2c` ins
3030
3131## Optional Cargo features
3232
33- - ** ` std ` ** : enable shared bus implementations using ` std::sync::Mutex ` .
33+ - ** ` std ` ** : enable shared bus implementations using ` std::sync::Mutex ` , and implement
34+ ` std::error::Error ` for ` DeviceError ` .
3435- ** ` async ` ** : enable ` embedded-hal-async ` support.
3536- ** ` defmt-03 ` ** : Derive ` defmt::Format ` from ` defmt ` 0.3 for enums and structs.
3637
Original file line number Diff line number Diff line change 11//! `SpiDevice` implementations.
22
3- use core:: fmt:: Debug ;
3+ use core:: fmt:: { self , Debug , Display , Formatter } ;
44use embedded_hal:: spi:: { Error , ErrorKind } ;
55
66mod exclusive;
@@ -29,6 +29,18 @@ pub enum DeviceError<BUS, CS> {
2929 Cs ( CS ) ,
3030}
3131
32+ impl < BUS : Display , CS : Display > Display for DeviceError < BUS , CS > {
33+ fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
34+ match self {
35+ Self :: Spi ( bus) => write ! ( f, "SPI bus error: {}" , bus) ,
36+ Self :: Cs ( cs) => write ! ( f, "SPI CS error: {}" , cs) ,
37+ }
38+ }
39+ }
40+
41+ #[ cfg( feature = "std" ) ]
42+ impl < BUS : Debug + Display , CS : Debug + Display > std:: error:: Error for DeviceError < BUS , CS > { }
43+
3244impl < BUS , CS > Error for DeviceError < BUS , CS >
3345where
3446 BUS : Error + Debug ,
You can’t perform that action at this time.
0 commit comments