File tree 2 files changed +15
-2
lines changed
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
30
30
31
31
## Optional Cargo features
32
32
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 ` .
34
35
- ** ` async ` ** : enable ` embedded-hal-async ` support.
35
36
- ** ` defmt-03 ` ** : Derive ` defmt::Format ` from ` defmt ` 0.3 for enums and structs.
36
37
Original file line number Diff line number Diff line change 1
1
//! `SpiDevice` implementations.
2
2
3
- use core:: fmt:: Debug ;
3
+ use core:: fmt:: { self , Debug , Display , Formatter } ;
4
4
use embedded_hal:: spi:: { Error , ErrorKind } ;
5
5
6
6
mod exclusive;
@@ -29,6 +29,18 @@ pub enum DeviceError<BUS, CS> {
29
29
Cs ( CS ) ,
30
30
}
31
31
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
+
32
44
impl < BUS , CS > Error for DeviceError < BUS , CS >
33
45
where
34
46
BUS : Error + Debug ,
You can’t perform that action at this time.
0 commit comments