@@ -21,6 +21,9 @@ 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 ,
26
+ clock_to_cs_delay_ns : u32 ,
24
27
}
25
28
26
29
impl < ' a , BUS , CS , D > CriticalSectionDevice < ' a , BUS , CS , D > {
@@ -34,7 +37,23 @@ impl<'a, BUS, CS, D> CriticalSectionDevice<'a, BUS, CS, D> {
34
37
CS : OutputPin ,
35
38
{
36
39
cs. set_high ( ) ?;
37
- Ok ( Self { bus, cs, delay } )
40
+ Ok ( Self {
41
+ bus,
42
+ cs,
43
+ delay,
44
+ cs_to_clock_delay_ns : 0 ,
45
+ clock_to_cs_delay_ns : 0 ,
46
+ } )
47
+ }
48
+
49
+ /// Set the delay between the CS pin toggle and the first clock
50
+ pub fn set_cs_to_clock_delay_ns ( & mut self , delay_ns : u32 ) {
51
+ self . cs_to_clock_delay_ns = delay_ns;
52
+ }
53
+
54
+ /// Set the delay between the last clock and the CS pin reset
55
+ pub fn set_clock_to_cs_delay_ns ( & mut self , delay_ns : u32 ) {
56
+ self . clock_to_cs_delay_ns = delay_ns;
38
57
}
39
58
}
40
59
@@ -68,6 +87,8 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> {
68
87
bus,
69
88
cs,
70
89
delay : super :: NoDelay ,
90
+ cs_to_clock_delay_ns : 0 ,
91
+ clock_to_cs_delay_ns : 0 ,
71
92
} )
72
93
}
73
94
}
@@ -91,7 +112,14 @@ where
91
112
critical_section:: with ( |cs| {
92
113
let bus = & mut * self . bus . borrow_ref_mut ( cs) ;
93
114
94
- transaction ( operations, bus, & mut self . delay , & mut self . cs )
115
+ transaction (
116
+ operations,
117
+ bus,
118
+ & mut self . delay ,
119
+ & mut self . cs ,
120
+ self . cs_to_clock_delay_ns ,
121
+ self . clock_to_cs_delay_ns ,
122
+ )
95
123
} )
96
124
}
97
125
}
0 commit comments