@@ -103,6 +103,21 @@ impl Delay {
103
103
}
104
104
}
105
105
106
+ /// Options for acquiring the card.
107
+ #[ derive( Debug ) ]
108
+ pub struct AcquireOpts {
109
+ /// Some cards don't support CRC mode. At least a 512MiB Transcend one.
110
+ pub require_crc : bool ,
111
+ }
112
+
113
+ impl Default for AcquireOpts {
114
+ fn default ( ) -> Self {
115
+ AcquireOpts {
116
+ require_crc : true ,
117
+ }
118
+ }
119
+ }
120
+
106
121
impl < SPI , CS > SdMmcSpi < SPI , CS >
107
122
where
108
123
SPI : embedded_hal:: blocking:: spi:: Transfer < u8 > ,
@@ -139,6 +154,16 @@ where
139
154
/// This routine must be performed with an SPI clock speed of around 100 - 400 kHz.
140
155
/// Afterwards you may increase the SPI clock speed.
141
156
pub fn init ( & mut self ) -> Result < ( ) , Error > {
157
+ self . init_with_opts ( Default :: default ( ) )
158
+ }
159
+
160
+ /// De-init the card so it can't be used
161
+ pub fn deinit ( & mut self ) {
162
+ self . state = State :: NoInit ;
163
+ }
164
+
165
+ /// Initializes the card into a known state
166
+ pub fn init_with_opts ( & mut self , options : AcquireOpts ) -> Result < ( ) , Error > {
142
167
let f = |s : & mut Self | {
143
168
// Assume it hasn't worked
144
169
s. state = State :: Error ;
@@ -172,7 +197,9 @@ where
172
197
return Err ( Error :: CardNotFound ) ;
173
198
}
174
199
// Enable CRC
175
- if s. card_command ( CMD59 , 1 ) ? != R1_IDLE_STATE {
200
+ if s. card_command ( CMD59 , 1 ) ? != R1_IDLE_STATE
201
+ && options. require_crc
202
+ {
176
203
return Err ( Error :: CantEnableCRC ) ;
177
204
}
178
205
// Check card version
@@ -224,11 +251,6 @@ where
224
251
result
225
252
}
226
253
227
- /// De-init the card so it can't be used
228
- pub fn deinit ( & mut self ) {
229
- self . state = State :: NoInit ;
230
- }
231
-
232
254
/// Return the usable size of this SD card in bytes.
233
255
pub fn card_size_bytes ( & self ) -> Result < u64 , Error > {
234
256
self . check_state ( ) ?;
0 commit comments