10000 only init/deinit host periperal if both slots are currently unused · eric321/circuitpython@ad519ad · GitHub
[go: up one dir, main page]

Skip to content

Commit ad519ad

Browse files
committed
only init/deinit host periperal if both slots are currently unused
1 parent 36c956a commit ad519ad

File tree

1 file changed

+16
-8
lines changed
  • ports/espressif/common-hal/sdioio

1 file changed

+16
-8
lines changed

ports/espressif/common-hal/sdioio/SDCard.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ static int check_pins(const mcu_pin_obj_t *clock, const mcu_pin_obj_t *command,
3333
// ESP32-S3 and P4 can use any pin for any SDMMC func in either slot
3434
// Default to SLOT_1 for SD cards
3535
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]) {
3937
return SDMMC_HOST_SLOT_0;
38+
} else if (!slot_in_use[1]) {
39+
return SDMMC_HOST_SLOT_1;
4040
}
4141
#else
4242
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,
5050
return SDMMC_HOST_SLOT_1;
5151
}
5252
}
53-
return -1;
5453
#endif
54+
return -1;
5555
}
5656

5757
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,
106106
slot_config.width, slot_config.clk, slot_config.cmd,
107107
slot_config.d0, slot_config.d1, slot_config.d2, slot_config.d3);
108108

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+
}
112114
}
113115

114116
err = sdmmc_host_init_slot(sd_slot, &slot_config);
@@ -208,7 +210,10 @@ void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self) {
208210
never_reset_sdio[get_slot_index(self)] = false;
209211
slot_in_use[get_slot_index(self)] = false;
210212

211-
sdmmc_host_deinit();
213+
if (!slot_in_use[0] && !slot_in_use[1]) {
214+
sdmmc_host_deinit();
215+
}
216+
212217
reset_pin_number(self->command);
213218
self->command = COMMON_HAL_MCU_NO_PIN;
214219
reset_pin_number(self->clock);
@@ -246,5 +251,8 @@ void sdioio_reset() {
246251
slot_in_use[i] = false;
247252
}
248253
}
254+
255+
// don't we have to deinit any currently used slots here?
256+
249257
return;
250258
}

0 commit comments

Comments
 (0)
0