@@ -21,6 +21,8 @@ pub struct CriticalSectionDevice<'a, BUS, CS, D> {
21
21
bus : & ' a Mutex < RefCell < BUS > > ,
22
22
cs : CS ,
23
23
delay : D ,
24
+ /// Implementation of https://docs.rs/embedded-hal/latest/embedded_hal/spi/index.html#cs-to-clock-delays
25
+ cs_to_clock_delay_ns : u32 ,
24
26
}
25
27
26
28
impl < ' a , BUS , CS , D > CriticalSectionDevice < ' a , BUS , CS , D > {
@@ -29,12 +31,22 @@ impl<'a, BUS, CS, D> CriticalSectionDevice<'a, BUS, CS, D> {
29
31
/// This sets the `cs` pin high, and returns an error if that fails. It is recommended
30
32
/// to set the pin high the moment it's configured as an output, to avoid glitches.
31
33
#[ inline]
32
- pub fn new ( bus : & ' a Mutex < RefCell < BUS > > , mut cs : CS , delay : D ) -> Result < Self , CS :: Error >
34
+ pub fn new (
35
+ bus : & ' a Mutex < RefCell < BUS > > ,
36
+ mut cs : CS ,
37
+ delay : D ,
38
+ cs_to_clock_delay_ns : u32 ,
39
+ ) -> Result < Self , CS :: Error >
33
40
where
34
41
CS : OutputPin ,
35
42
{
36
43
cs. set_high ( ) ?;
37
- Ok ( Self { bus, cs, delay } )
44
+ Ok ( Self {
45
+ bus,
46
+ cs,
47
+ delay,
48
+ cs_to_clock_delay_ns,
49
+ } )
38
50
}
39
51
}
40
52
@@ -68,6 +80,7 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> {
68
80
bus,
69
81
cs,
70
82
delay : super :: NoDelay ,
83
+ cs_to_clock_delay_ns : 0 ,
71
84
} )
72
85
}
73
86
}
@@ -91,7 +104,13 @@ where
91
104
critical_section:: with ( |cs| {
92
105
let bus = & mut * self . bus . borrow_ref_mut ( cs) ;
93
106
94
- transaction ( operations, bus, & mut self . delay , & mut self . cs )
107
+ transaction (
108
+ operations,
109
+ bus,
110
+ & mut self . delay ,
111
+ & mut self . cs ,
112
+ self . cs_to_clock_delay_ns ,
113
+ )
95
114
} )
96
115
}
97
116
}
0 commit comments