32
32
#define TOKEN_STOP_TRAN (0xFD)
33
33
#define TOKEN_DATA (0xFE)
34
34
35
+ static void common_hal_sdcardio_check_for_deinit (sdcardio_sdcard_obj_t * self ) {
36
+ if (!self -> bus ) {
37
+ raise_deinited_error ();
38
+ }
39
+ }
40
+
35
41
static bool lock_and_configure_bus (sdcardio_sdcard_obj_t * self ) {
42
+ common_hal_sdcardio_check_for_deinit (self );
43
+
36
44
if (!common_hal_busio_spi_try_lock (self -> bus )) {
37
45
return false;
38
46
}
@@ -316,12 +324,6 @@ void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self) {
316
324
common_hal_digitalio_digitalinout_deinit (& self -> cs );
317
325
}
318
326
319
- static void common_hal_sdcardio_check_for_deinit (sdcardio_sdcard_obj_t * self ) {
320
- if (!self -> bus ) {
321
- raise_deinited_error ();
322
- }
323
- }
324
-
325
327
int common_hal_sdcardio_sdcard_get_blockcount (sdcardio_sdcard_obj_t * self ) {
326
328
common_hal_sdcardio_check_for_deinit (self );
327
329
return self -> sectors ;
@@ -341,6 +343,7 @@ static int readinto(sdcardio_sdcard_obj_t *self, void *buf, size_t size) {
341
343
}
342
344
343
345
mp_uint_t sdcardio_sdcard_readblocks (mp_obj_t self_in , uint8_t * buf , uint32_t start_block , uint32_t nblocks ) {
346
+ // deinit check is in lock_and_configure_bus()
344
347
sdcardio_sdcard_obj_t * self = MP_OBJ_TO_PTR (self_in );
345
348
if (!lock_and_configure_bus (self )) {
346
349
return MP_EAGAIN ;
@@ -380,7 +383,6 @@ mp_uint_t sdcardio_sdcard_readblocks(mp_obj_t self_in, uint8_t *buf, uint32_t st
380
383
}
381
384
382
385
int common_hal_sdcardio_sdcard_readblocks (sdcardio_sdcard_obj_t * self , uint32_t start_block , mp_buffer_info_t * buf ) {
383
- common_hal_sdcardio_check_for_deinit (self );
384
386
if (buf -> len % 512 != 0 ) {
385
387
mp_raise_ValueError (MP_ERROR_TEXT ("Buffer length must be a multiple of 512" ));
386
388
}
@@ -434,9 +436,8 @@ static int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t
434
436
}
435
437
436
438
mp_uint_t sdcardio_sdcard_writeblocks (mp_obj_t self_in , uint8_t * buf , uint32_t start_block , uint32_t nblocks ) {
439
+ // deinit check is in lock_and_configure_bus()
437
440
sdcardio_sdcard_obj_t * self = MP_OBJ_TO_PTR (self_in );
438
- common_hal_sdcardio_check_for_deinit (self );
439
-
440
441
if (!lock_and_configure_bus (self )) {
441
442
return MP_EAGAIN ;
442
443
}
@@ -471,15 +472,15 @@ mp_uint_t sdcardio_sdcard_writeblocks(mp_obj_t self_in, uint8_t *buf, uint32_t s
471
472
}
472
473
473
474
int common_hal_sdcardio_sdcard_sync (sdcardio_sdcard_obj_t * self ) {
474
- common_hal_sdcardio_check_for_deinit ( self );
475
+ // deinit check is in lock_and_configure_bus()
475
476
lock_and_configure_bus (self );
476
477
int r = exit_cmd25 (self );
477
478
extraclock_and_unlock_bus (self );
478
479
return r ;
479
480
}
480
481
481
482
int common_hal_sdcardio_sdcard_writeblocks (sdcardio_sdcard_obj_t * self , uint32_t start_block , mp_buffer_info_t * buf ) {
482
- common_hal_sdcardio_check_for_deinit ( self );
483
+ // deinit check is in lock_and_configure_bus()
483
484
if (buf -> len % 512 != 0 ) {
484
485
mp_raise_ValueError (MP_ERROR_TEXT ("Buffer length must be a multiple of 512" ));
485
486
}
0 commit comments