File tree 1 file changed +16
-6
lines changed
1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -145,15 +145,25 @@ where
145
145
SPI : SpiX ,
146
146
{
147
147
fn read ( & mut self , words : & mut [ u8 ] ) -> Result < ( ) , Infallible > {
148
- let rxdata = self . spi . rxdata . read ( ) ;
149
- // TODO: send 00 ??
148
+ let mut iwrite = 0 ;
149
+ let mut iread = 0 ;
150
+
151
+ // Ensure that RX FIFO is empty
152
+ self . wait_for_rxfifo ( ) ;
150
153
151
- for word in words {
152
- if rxdata. empty ( ) . bit_is_set ( ) {
153
- break ;
154
+ while iwrite < words. len ( ) || iread < words. len ( ) {
155
+ if iwrite < words. len ( ) && self . spi . txdata . read ( ) . full ( ) . bit_is_clear ( ) {
156
+ iwrite += 1 ;
157
+ self . spi . txdata . write ( |w| unsafe { w. data ( ) . bits ( 0x00 ) } ) ;
154
158
}
155
159
156
- * word = rxdata. data ( ) . bits ( ) ;
160
+ if iread < iwrite {
161
+ let data = self . spi . rxdata . read ( ) ;
162
+ if data. empty ( ) . bit_is_clear ( ) {
163
+ unsafe { * words. get_unchecked_mut ( iread) = data. data ( ) . bits ( ) } ;
164
+ iread += 1 ;
165
+ }
166
+ }
157
167
}
158
168
159
169
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments