@@ -326,6 +326,37 @@ impl Device {
326
326
} )
327
327
}
328
328
329
+ /// Blocking/synchronous SPI data transfers
330
+ ///
331
+ /// This call may only be used from a context that may sleep. The sleep
332
+ /// is non-interruptible, and has no timeout. Low-overhead controller
333
+ /// drivers may DMA directly into and out of the message buffers.
334
+ ///
335
+ /// # Safety
336
+ /// `tx_buf` and `rx_buf` must be DMA-safe otherwise UB.
337
+ pub unsafe fn sync ( & self , tx_buf : & [ u8 ] , rx_buf : & mut [ u8 ] ) -> Result {
338
+ let mut tx_transfer = bindings:: spi_transfer {
339
+ tx_buf : tx_buf. as_ptr ( ) as _ ,
340
+ len : tx_buf. len ( ) as _ ,
341
+ ..Default :: default ( )
342
+ } ;
343
+ let mut rx_transfer = bindings:: spi_transfer {
344
+ rx_buf : rx_buf. as_mut_ptr ( ) as _ ,
345
+ len : rx_buf. len ( ) as _ ,
346
+ ..Default :: default ( )
347
+ } ;
348
+
349
+ let mut message: bindings:: spi_message = Default :: default ( ) ;
350
+ unsafe {
351
+ bindings:: spi_message_init ( & mut message as _ ) ;
352
+ bindings:: spi_message_add_tail ( & mut tx_transfer as _ , & mut message as _ ) ;
353
+ bindings:: spi_message_add_tail ( & mut rx_transfer as _ , & mut message as _ ) ;
354
+
355
+ // SAFETY: `Device` is alive until it gets dropped
356
+ to_result ( bindings:: spi_sync ( self . 0 , & mut message as _ ) )
357
+ }
358
+ }
359
+
329
360
/// SPI synchronous write
330
361
pub fn write ( & self , tx_buf : & [ u8 ] ) -> Result {
331
362
to_result ( unsafe {
0 commit comments