@@ -21,6 +21,9 @@ 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 , 
26+     clock_to_cs_delay_ns :  u32 , 
2427} 
2528
2629impl < ' a ,  BUS ,  CS ,  D >  CriticalSectionDevice < ' a ,  BUS ,  CS ,  D >  { 
@@ -34,7 +37,23 @@ impl<'a, BUS, CS, D> CriticalSectionDevice<'a, BUS, CS, D> {
3437        CS :  OutputPin , 
3538    { 
3639        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; 
3857    } 
3958} 
4059
@@ -68,6 +87,8 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> {
6887            bus, 
6988            cs, 
7089            delay :  super :: NoDelay , 
90+             cs_to_clock_delay_ns :  0 , 
91+             clock_to_cs_delay_ns :  0 , 
7192        } ) 
7293    } 
7394} 
@@ -91,7 +112,14 @@ where
91112        critical_section:: with ( |cs| { 
92113            let  bus = & mut  * self . bus . borrow_ref_mut ( cs) ; 
93114
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+             ) 
95123        } ) 
96124    } 
97125} 
0 commit comments