@@ -20,6 +20,9 @@ pub struct ExclusiveDevice<BUS, CS, D> {
2020 bus : BUS ,
2121 cs : CS ,
2222 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 ,
2326}
2427
2528impl < BUS , CS , D > ExclusiveDevice < BUS , CS , D > {
@@ -28,12 +31,28 @@ impl<BUS, CS, D> ExclusiveDevice<BUS, CS, D> {
2831 /// This sets the `cs` pin high, and returns an error if that fails. It is recommended
2932 /// to set the pin high the moment it's configured as an output, to avoid glitches.
3033 #[ 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 >
3235 where
3336 CS : OutputPin ,
3437 {
3538 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;
3756 }
3857
3958 /// Returns a reference to the underlying bus object.
@@ -79,6 +98,8 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS, super::NoDelay> {
7998 bus,
8099 cs,
81100 delay : super :: NoDelay ,
101+ cs_to_clock_delay_ns : 0 ,
102+ clock_to_cs_delay_ns : 0 ,
82103 } )
83104 }
84105}
@@ -99,7 +120,14 @@ where
99120{
100121 #[ inline]
101122 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+ )
103131 }
104132}
105133
0 commit comments