@@ -20,6 +20,9 @@ pub struct ExclusiveDevice<BUS, CS, D> {
20
20
bus : BUS ,
21
21
cs : CS ,
22
22
delay : D ,
23
+ /// Implementation of <https://docs.rs/embedded-hal/latest/embedded_hal/spi/index.html#cs-to-clock-delays>
24
+ cs_to_clock_delay_ns : u32 ,
25
+ clock_to_cs_delay_ns : u32 ,
23
26
}
24
27
25
28
impl < BUS , CS , D > ExclusiveDevice < BUS , CS , D > {
@@ -28,12 +31,28 @@ impl<BUS, CS, D> ExclusiveDevice<BUS, CS, D> {
28
31
/// This sets the `cs` pin high, and returns an error if that fails. It is recommended
29
32
/// to set the pin high the moment it's configured as an output, to avoid glitches.
30
33
#[ inline]
31
- pub fn new ( bus : BUS , mut cs : CS , delay : D ) -> Result < Self , CS :: Error >
34
+ pub fn new ( bus : BUS , mut cs : CS , delay : D , cs_to_clock_delay_ns : u32 ) -> Result < Self , CS :: Error >
32
35
where
33
36
CS : OutputPin ,
34
37
{
35
38
cs. set_high ( ) ?;
36
- Ok ( Self { bus, cs, delay } )
39
+ Ok ( Self {
40
+ bus,
41
+ cs,
42
+ delay,
43
+ cs_to_clock_delay_ns : 0 ,
44
+ clock_to_cs_delay_ns : 0 ,
45
+ } )
46
+ }
47
+
48
+ /// Set the delay between the CS pin toggle and the first clock
49
+ pub fn set_cs_to_clock_delay_ns ( & mut self , delay_ns : u32 ) {
50
+ self . cs_to_clock_delay_ns = delay_ns;
51
+ }
52
+
53
+ /// Set the delay between the last clock and the CS pin reset
54
+ pub fn set_clock_to_cs_delay_ns ( & mut self , delay_ns : u32 ) {
55
+ self . clock_to_cs_delay_ns = delay_ns;
37
56
}
38
57
39
58
/// Returns a reference to the underlying bus object.
@@ -79,6 +98,8 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS, super::NoDelay> {
79
98
bus,
80
99
cs,
81
100
delay : super :: NoDelay ,
101
+ cs_to_clock_delay_ns : 0 ,
102
+ clock_to_cs_delay_ns : 0 ,
82
103
} )
83
104
}
84
105
}
@@ -99,7 +120,14 @@ where
99
120
{
100
121
#[ inline]
101
122
fn transaction ( & mut self , operations : & mut [ Operation < ' _ , Word > ] ) -> Result < ( ) , Self :: Error > {
102
- transaction ( operations, & mut self . bus , & mut self . delay , & mut self . cs )
123
+ transaction (
124
+ operations,
125
+ & mut self . bus ,
126
+ & mut self . delay ,
127
+ & mut self . cs ,
128
+ self . cs_to_clock_delay_ns ,
129
+ self . clock_to_cs_delay_ns ,
130
+ )
103
131
}
104
132
}
105
133
0 commit comments