@@ -21,6 +21,8 @@ pub struct CriticalSectionDevice<'a, BUS, CS, D> {
2121 bus : & ' a Mutex < RefCell < BUS > > ,
2222 cs : CS ,
2323 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 ,
2426}
2527
2628impl < ' a , BUS , CS , D > CriticalSectionDevice < ' a , BUS , CS , D > {
@@ -29,12 +31,22 @@ impl<'a, BUS, CS, D> CriticalSectionDevice<'a, BUS, CS, D> {
2931 /// This sets the `cs` pin high, and returns an error if that fails. It is recommended
3032 /// to set the pin high the moment it's configured as an output, to avoid glitches.
3133 #[ 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 >
3340 where
3441 CS : OutputPin ,
3542 {
3643 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+ } )
3850 }
3951}
4052
@@ -68,6 +80,7 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> {
6880 bus,
6981 cs,
7082 delay : super :: NoDelay ,
83+ cs_to_clock_delay_ns : 0 ,
7184 } )
7285 }
7386}
@@ -91,7 +104,13 @@ where
91104 critical_section:: with ( |cs| {
92105 let bus = & mut * self . bus . borrow_ref_mut ( cs) ;
93106
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+ )
95114 } )
96115 }
97116}
0 commit comments