@@ -8,6 +8,8 @@ pub use embedded_hal::spi::{
88    Error ,  ErrorKind ,  ErrorType ,  Mode ,  Operation ,  Phase ,  Polarity ,  MODE_0 ,  MODE_1 ,  MODE_2 ,  MODE_3 , 
99} ; 
1010
11+ use  crate :: delay:: DelayUs ; 
12+ 
1113/// SPI device trait 
1214/// 
1315/// `SpiDevice` represents ownership over a single SPI device on a (possibly shared) bus, selected 
@@ -195,30 +197,32 @@ where
195197/// 
196198/// This is the most straightforward way of obtaining an [`SpiDevice`] from an [`SpiBus`], 
197199/// ideal for when no sharing is required (only one SPI device is present on the bus). 
198- pub  struct  ExclusiveDevice < BUS ,  CS >  { 
200+ pub  struct  ExclusiveDevice < BUS ,  CS ,   D >  { 
199201    bus :  BUS , 
200202    cs :  CS , 
203+     delay :  D , 
201204} 
202205
203- impl < BUS ,  CS >  ExclusiveDevice < BUS ,  CS >  { 
206+ impl < BUS ,  CS ,   D >  ExclusiveDevice < BUS ,  CS ,   D >  { 
204207    /// Create a new ExclusiveDevice 
205-      pub  fn  new ( bus :  BUS ,  cs :  CS )  -> Self  { 
206-         Self  {  bus,  cs } 
208+      pub  fn  new ( bus :  BUS ,  cs :  CS ,   delay :   D )  -> Self  { 
209+         Self  {  bus,  cs,  delay  } 
207210    } 
208211} 
209212
210- impl < BUS ,  CS >  ErrorType  for  ExclusiveDevice < BUS ,  CS > 
213+ impl < BUS ,  CS ,   D >  ErrorType  for  ExclusiveDevice < BUS ,  CS ,   D > 
211214where 
212215    BUS :  ErrorType , 
213216    CS :  OutputPin , 
214217{ 
215218    type  Error  = ExclusiveDeviceError < BUS :: Error ,  CS :: Error > ; 
216219} 
217220
218- impl < Word :  Copy  + ' static ,  BUS ,  CS >  blocking:: SpiDevice < Word >  for  ExclusiveDevice < BUS ,  CS > 
221+ impl < Word :  Copy  + ' static ,  BUS ,  CS ,   D >  blocking:: SpiDevice < Word >  for  ExclusiveDevice < BUS ,  CS ,   D > 
219222where 
220223    BUS :  blocking:: SpiBus < Word > , 
221224    CS :  OutputPin , 
225+     D :  embedded_hal:: delay:: DelayUs , 
222226{ 
223227    fn  transaction ( & mut  self ,  operations :  & mut  [ Operation < ' _ ,  Word > ] )  -> Result < ( ) ,  Self :: Error >  { 
224228        self . cs . set_low ( ) . map_err ( ExclusiveDeviceError :: Cs ) ?; 
@@ -230,6 +234,7 @@ where
230234                    Operation :: Write ( buf)  => self . bus . write ( buf) , 
231235                    Operation :: Transfer ( read,  write)  => self . bus . transfer ( read,  write) , 
232236                    Operation :: TransferInPlace ( buf)  => self . bus . transfer_in_place ( buf) , 
237+                     Operation :: DelayUs ( us)  => Ok ( self . delay . delay_us ( * us) ) , 
233238                } ; 
234239                if  let  Err ( e)  = res { 
235240                    break  ' ops Err ( e) ; 
@@ -250,10 +255,11 @@ where
250255    } 
251256} 
252257
253- impl < Word :  Copy  + ' static ,  BUS ,  CS >  SpiDevice < Word >  for  ExclusiveDevice < BUS ,  CS > 
258+ impl < Word :  Copy  + ' static ,  BUS ,  CS ,   D >  SpiDevice < Word >  for  ExclusiveDevice < BUS ,  CS ,   D > 
254259where 
255260    BUS :  SpiBus < Word > , 
256261    CS :  OutputPin , 
262+     D :  DelayUs , 
257263{ 
258264    async  fn  transaction ( 
259265        & mut  self , 
@@ -268,6 +274,7 @@ where
268274                    Operation :: Write ( buf)  => self . bus . write ( buf) . await , 
269275                    Operation :: Transfer ( read,  write)  => self . bus . transfer ( read,  write) . await , 
270276                    Operation :: TransferInPlace ( buf)  => self . bus . transfer_in_place ( buf) . await , 
277+                     Operation :: DelayUs ( us)  => Ok ( self . delay . delay_us ( * us) . await ) , 
271278                } ; 
272279                if  let  Err ( e)  = res { 
273280                    break  ' ops Err ( e) ; 
0 commit comments