File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ where
401
401
// Assert CS
402
402
s. cs_low ( ) ?;
403
403
// Enter SPI mode.
404
- let mut delay = Delay :: new_command ( ) ;
404
+ let mut delay = Delay :: new ( s . options . acquire_retries ) ;
405
405
for attempts in 1 .. {
406
406
trace ! ( "Enter SPI mode, attempt: {}.." , attempts) ;
407
407
match s. card_command ( CMD0 , 0 ) {
@@ -586,11 +586,18 @@ pub struct AcquireOpts {
586
586
/// On by default because without it you might get silent data corruption on
587
587
/// your card.
588
588
pub use_crc : bool ,
589
+
590
+ /// Sets the number of times we will retry to acquire the card before giving up and returning
591
+ /// `Err(Error::CardNotFound)`. By default, card acquisition will be retried 50 times.
592
+ pub acquire_retries : u32 ,
589
593
}
590
594
591
595
impl Default for AcquireOpts {
592
596
fn default ( ) -> Self {
593
- AcquireOpts { use_crc : true }
597
+ AcquireOpts {
598
+ use_crc : true ,
599
+ acquire_retries : 50 ,
600
+ }
594
601
}
595
602
}
596
603
@@ -708,12 +715,13 @@ impl Delay {
708
715
T : embedded_hal:: blocking:: delay:: DelayUs < u8 > ,
709
716
{
710
717
if self . retries_left == 0 {
711
- Err ( err)
718
+ return Err ( err) ;
712
719
} else {
713
720
delayer. delay_us ( 10 ) ;
714
721
self . retries_left -= 1 ;
715
- Ok ( ( ) )
716
722
}
723
+
724
+ Ok ( ( ) )
717
725
}
718
726
}
719
727
You can’t perform that action at this time.
0 commit comments