1
1
//! SPI bus sharing mechanisms.
2
2
3
+ use core:: convert:: Infallible ;
4
+
3
5
use embedded_hal:: delay:: DelayNs ;
4
6
use embedded_hal:: digital:: OutputPin ;
5
7
use embedded_hal:: spi:: { ErrorType , Operation , SpiBus , SpiDevice } ;
@@ -10,7 +12,6 @@ use embedded_hal_async::{
10
12
} ;
11
13
12
14
use super :: shared:: transaction;
13
- use super :: DeviceError ;
14
15
15
16
/// [`SpiDevice`] implementation with exclusive access to the bus (not shared).
16
17
///
@@ -72,15 +73,15 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS, super::NoDelay> {
72
73
impl < BUS , CS , D > ErrorType for ExclusiveDevice < BUS , CS , D >
73
74
where
74
75
BUS : ErrorType ,
75
- CS : OutputPin ,
76
+ CS : OutputPin < Error = Infallible > ,
76
77
{
77
- type Error = DeviceError < BUS :: Error , CS :: Error > ;
78
+ type Error = BUS :: Error ;
78
79
}
79
80
80
81
impl < Word : Copy + ' static , BUS , CS , D > SpiDevice < Word > for ExclusiveDevice < BUS , CS , D >
81
82
where
82
83
BUS : SpiBus < Word > ,
83
- CS : OutputPin ,
84
+ CS : OutputPin < Error = Infallible > ,
84
85
D : DelayNs ,
85
86
{
86
87
#[ inline]
@@ -94,15 +95,17 @@ where
94
95
impl < Word : Copy + ' static , BUS , CS , D > AsyncSpiDevice < Word > for ExclusiveDevice < BUS , CS , D >
95
96
where
96
97
BUS : AsyncSpiBus < Word > ,
97
- CS : OutputPin ,
98
+ CS : OutputPin < Error = Infallible > ,
98
99
D : AsyncDelayNs ,
99
100
{
100
101
#[ inline]
101
102
async fn transaction (
102
103
& mut self ,
103
104
operations : & mut [ Operation < ' _ , Word > ] ,
104
105
) -> Result < ( ) , Self :: Error > {
105
- self . cs . set_low ( ) . map_err ( DeviceError :: Cs ) ?;
106
+ use crate :: spi:: shared:: into_ok;
107
+
108
+ into_ok ( self . cs . set_low ( ) ) ;
106
109
107
110
let op_res = ' ops: {
108
111
for op in operations {
@@ -128,12 +131,8 @@ where
128
131
129
132
// On failure, it's important to still flush and deassert CS.
130
133
let flush_res = self . bus . flush ( ) . await ;
131
- let cs_res = self . cs . set_high ( ) ;
132
-
133
- op_res. map_err ( DeviceError :: Spi ) ?;
134
- flush_res. map_err ( DeviceError :: Spi ) ?;
135
- cs_res. map_err ( DeviceError :: Cs ) ?;
134
+ into_ok ( self . cs . set_high ( ) ) ;
136
135
137
- Ok ( ( ) )
136
+ op_res . and ( flush_res )
138
137
}
139
138
}
0 commit comments