@@ -4,6 +4,7 @@ use embedded_hal::digital::OutputPin;
44use embedded_hal:: spi:: { ErrorType , Operation , SpiBus , SpiDevice } ;
55
66use super :: DeviceError ;
7+ use crate :: spi:: shared:: transaction;
78
89/// `RefCell`-based shared bus [`SpiDevice`] implementation.
910///
6263 fn transaction ( & mut self , operations : & mut [ Operation < ' _ , Word > ] ) -> Result < ( ) , Self :: Error > {
6364 let bus = & mut * self . bus . borrow_mut ( ) ;
6465
65- self . cs . set_low ( ) . map_err ( DeviceError :: Cs ) ?;
66-
67- let op_res = operations. iter_mut ( ) . try_for_each ( |op| match op {
68- Operation :: Read ( buf) => bus. read ( buf) ,
69- Operation :: Write ( buf) => bus. write ( buf) ,
70- Operation :: Transfer ( read, write) => bus. transfer ( read, write) ,
71- Operation :: TransferInPlace ( buf) => bus. transfer_in_place ( buf) ,
72- Operation :: DelayUs ( us) => {
73- bus. flush ( ) ?;
74- self . delay . delay_us ( * us) ;
75- Ok ( ( ) )
76- }
77- } ) ;
78-
79- // On failure, it's important to still flush and deassert CS.
80- let flush_res = bus. flush ( ) ;
81- let cs_res = self . cs . set_high ( ) ;
82-
83- op_res. map_err ( DeviceError :: Spi ) ?;
84- flush_res. map_err ( DeviceError :: Spi ) ?;
85- cs_res. map_err ( DeviceError :: Cs ) ?;
86-
87- Ok ( ( ) )
66+ transaction ( operations, bus, & mut self . delay , & mut self . cs )
8867 }
8968}
0 commit comments