@@ -233,9 +233,10 @@ impl<SPI: Instance, PINS> Spi<SPI, PINS> {
233
233
core:: hint:: spin_loop ( )
234
234
}
235
235
// wait for idle
236
- Ok ( while self . spi . sr ( ) . read ( ) . bsy ( ) . bit ( ) {
236
+ while self . spi . sr ( ) . read ( ) . bsy ( ) . bit ( ) {
237
237
core:: hint:: spin_loop ( )
238
- } )
238
+ }
239
+ Ok ( ( ) )
239
240
}
240
241
}
241
242
@@ -346,22 +347,24 @@ impl<SPI: Instance, PINS: Pins<SPI>> embedded_hal::spi::SpiBus<u8> for Spi<SPI,
346
347
words[ odd_idx] = nb:: block!( self . nb_read_no_err( ) ) . unwrap ( ) ;
347
348
}
348
349
349
- Ok ( for r in words[ odd_idx + pair_left..] . iter_mut ( ) {
350
+ for r in words[ odd_idx + pair_left..] . iter_mut ( ) {
350
351
* r = nb:: block!( self . nb_read( ) ) ?;
351
- } )
352
+ }
353
+ Ok ( ( ) )
352
354
}
353
355
354
356
fn write ( & mut self , words : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
355
357
self . set_tx_only ( ) ;
356
- Ok ( for w in words {
358
+ for w in words {
357
359
nb:: block!( self . nb_write( * w) ) ?
358
- } )
360
+ }
361
+ Ok ( ( ) )
359
362
}
360
363
361
364
fn transfer ( & mut self , read : & mut [ u8 ] , write : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
362
- if read. len ( ) == 0 {
365
+ if read. is_empty ( ) {
363
366
return self . write ( write) ;
364
- } else if write. len ( ) == 0 {
367
+ } else if write. is_empty ( ) {
365
368
return self . read ( read) ;
366
369
}
367
370
@@ -449,7 +452,7 @@ impl<SPI: Instance, PINS: Pins<SPI>> embedded_hal::spi::SpiBus<u8> for Spi<SPI,
449
452
core:: slice:: from_raw_parts_mut ( ptr as * mut [ u8 ; 2 ] , half_len)
450
453
} ;
451
454
452
- for b in words_alias. into_iter ( ) . take ( prefill as usize ) {
455
+ for b in words_alias. iter_mut ( ) . take ( prefill as usize ) {
453
456
nb:: block!( self . nb_write( u16 :: from_le_bytes( * b) ) ) ?;
454
457
}
455
458
@@ -474,9 +477,10 @@ impl<SPI: Instance, PINS: Pins<SPI>> embedded_hal::spi::SpiBus<u8> for Spi<SPI,
474
477
}
475
478
476
479
// read words left in the fifo
477
- Ok ( for r in words. iter_mut ( ) . skip ( len - 2 * prefill) {
480
+ for r in words. iter_mut ( ) . skip ( len - 2 * prefill) {
478
481
* r = nb:: block!( self . nb_read( ) ) ?;
479
- } )
482
+ }
483
+ Ok ( ( ) )
480
484
}
481
485
fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
482
486
self . flush_inner ( )
@@ -505,20 +509,22 @@ impl<SPI: Instance, PINS: Pins<SPI>> embedded_hal::spi::SpiBus<u16> for Spi<SPI,
505
509
* w = nb:: block!( self . nb_read_no_err( ) ) . unwrap ( ) ;
506
510
nb:: block!( self . nb_write( 0u16 ) ) ?;
507
511
}
508
- Ok ( for w in & mut words[ len - prefill..] {
512
+ for w in & mut words[ len - prefill..] {
509
513
* w = nb:: block!( self . nb_read( ) ) ?;
510
- } )
514
+ }
515
+ Ok ( ( ) )
511
516
}
512
517
fn write ( & mut self , words : & [ u16 ] ) -> Result < ( ) , Self :: Error > {
513
518
self . set_tx_only ( ) ;
514
- Ok ( for w in words {
519
+ for w in words {
515
520
nb:: block!( self . nb_write( * w) ) ?
516
- } )
521
+ }
522
+ Ok ( ( ) )
517
523
}
518
524
fn transfer ( & mut self , read : & mut [ u16 ] , write : & [ u16 ] ) -> Result < ( ) , Self :: Error > {
519
- if read. len ( ) == 0 {
525
+ if read. is_empty ( ) {
520
526
return self . write ( write) ;
521
- } else if write. len ( ) == 0 {
527
+ } else if write. is_empty ( ) {
522
528
return self . read ( read) ;
523
529
}
524
530
@@ -532,12 +538,12 @@ impl<SPI: Instance, PINS: Pins<SPI>> embedded_hal::spi::SpiBus<u16> for Spi<SPI,
532
538
// same prefill as in read, this time with actual data
533
539
let prefill = core:: cmp:: min ( self . tx_fifo_cap ( ) as usize / 2 , common_len) ;
534
540
535
- let mut write_iter = write. into_iter ( ) ;
541
+ let mut write_iter = write. iter ( ) ;
536
542
for w in write_iter. by_ref ( ) . take ( prefill) {
537
543
nb:: block!( self . nb_write( * w) ) ?;
538
544
}
539
545
540
- let zipped = read. into_iter ( ) . zip ( write_iter) . take ( common_len - prefill) ;
546
+ let zipped = read. iter_mut ( ) . zip ( write_iter) . take ( common_len - prefill) ;
541
547
for ( r, w) in zipped {
542
548
* r = nb:: block!( self . nb_read_no_err( ) ) . unwrap ( ) ;
543
549
nb:: block!( self . nb_write( * w) ) ?;
@@ -576,9 +582,10 @@ impl<SPI: Instance, PINS: Pins<SPI>> embedded_hal::spi::SpiBus<u16> for Spi<SPI,
576
582
nb:: block!( self . nb_write( words[ write_idx] ) ) ?;
577
583
}
578
584
579
- Ok ( for r in & mut words[ len - prefill..] {
585
+ for r in & mut words[ len - prefill..] {
580
586
* r = nb:: block!( self . nb_read( ) ) ?;
581
- } )
587
+ }
588
+ Ok ( ( ) )
582
589
}
583
590
fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
584
591
self . flush_inner ( )
0 commit comments