@@ -33,10 +33,10 @@ static int check_pins(const mcu_pin_obj_t *clock, const mcu_pin_obj_t *command,
33
33
// ESP32-S3 and P4 can use any pin for any SDMMC func in either slot
34
34
// Default to SLOT_1 for SD cards
35
35
ESP_LOGI (TAG , "Using chip with CONFIG_SOC_SDMMC_USE_GPIO_MATRIX" );
36
- if (!slot_in_use [1 ]) {
37
- return SDMMC_HOST_SLOT_1 ;
38
- } else {
36
+ if (!slot_in_use [0 ]) {
39
37
return SDMMC_HOST_SLOT_0 ;
38
+ } else if (!slot_in_use [1 ]) {
39
+ return SDMMC_HOST_SLOT_1 ;
40
40
}
41
41
#else
42
42
if (command -> number == GPIO_NUM_11 && clock -> number == GPIO_NUM_6 && data [0 ]-> number == GPIO_NUM_7 ) {
@@ -50,8 +50,8 @@ static int check_pins(const mcu_pin_obj_t *clock, const mcu_pin_obj_t *command,
50
50
return SDMMC_HOST_SLOT_1 ;
51
51
}
52
52
}
53
- return -1 ;
54
53
#endif
54
+ return -1 ;
55
55
}
56
56
57
57
uint8_t get_slot_index (sdioio_sdcard_obj_t * self ) {
@@ -106,9 +106,11 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
106
106
slot_config .width , slot_config .clk , slot_config .cmd ,
107
107
slot_config .d0 , slot_config .d1 , slot_config .d2 , slot_config .d3 );
108
108
109
- err = sdmmc_host_init ();
110
- if (err != ESP_OK ) {
111
- mp_raise_OSError_msg_varg (MP_ERROR_TEXT ("SDIO Init Error %x" ), err );
109
+ if (!slot_in_use [0 ] && !slot_in_use [1 ]) {
110
+ err = sdmmc_host_init ();
111
+ if (err != ESP_OK ) {
112
+ mp_raise_OSError_msg_varg (MP_ERROR_TEXT ("SDIO Init Error %x" ), err );
113
+ }
112
114
}
113
115
114
116
err = sdmmc_host_init_slot (sd_slot , & slot_config );
@@ -208,7 +210,10 @@ void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self) {
208
210
never_reset_sdio [get_slot_index (self )] = false;
209
211
slot_in_use [get_slot_index (self )] = false;
210
212
211
- sdmmc_host_deinit ();
213
+ if (!slot_in_use [0 ] && !slot_in_use [1 ]) {
214
+ sdmmc_host_deinit ();
215
+ }
216
+
212
217
reset_pin_number (self -> command );
213
218
self -> command = COMMON_HAL_MCU_NO_PIN ;
214
219
reset_pin_number (self -> clock );
@@ -246,5 +251,8 @@ void sdioio_reset() {
246
251
slot_in_use [i ] = false;
247
252
}
248
253
}
254
+
255
+ // don't we have to deinit any currently used slots here?
256
+
249
257
return ;
250
258
}
0 commit comments