Skip to content

Commit 67942a1

Browse files
committed
esp32/sdcard: Make LDO channel configurable.
Can now call machine.SDCard(ldo=...) to specify LDO channel. Channel defaults to MICROPY_HW_SDMMC_LDO_CHAN_ID if defined, otherwise -1 (disabled). Signed-off-by: Dryw Wade <[email protected]>
1 parent effd609 commit 67942a1

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

ports/esp32/machine_sdcard.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#if SOC_SDMMC_HOST_SUPPORTED
3737
#include "driver/sdmmc_host.h"
38-
#if SOC_SDMMC_IO_POWER_EXTERNAL && defined(MICROPY_HW_SDMMC_LDO_CHAN_ID)
38+
#if SOC_SDMMC_IO_POWER_EXTERNAL
3939
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
4040
#endif
4141
#endif
@@ -212,6 +212,9 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
212212
ARG_cmd,
213213
ARG_data,
214214
#endif
215+
#if SOC_SDMMC_IO_POWER_EXTERNAL
216+
ARG_ldo,
217+
#endif
215218
ARG_freq,
216219
};
217220
#if SOC_SDMMC_HOST_SUPPORTED
@@ -234,6 +237,13 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
234237
{ MP_QSTR_cmd, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
235238
{ MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
236239
#endif
240+
#if SOC_SDMMC_IO_POWER_EXTERNAL
241+
#ifdef MICROPY_HW_SDMMC_LDO_CHAN_ID
242+
{ MP_QSTR_ldo, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = MICROPY_HW_SDMMC_LDO_CHAN_ID} },
243+
#else
244+
{ MP_QSTR_ldo, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
245+
#endif
246+
#endif
237247
// freq is valid for both SPI and SDMMC interfaces
238248
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 20000000} },
239249
};
@@ -313,13 +323,15 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
313323
self->host = _temp_host;
314324
}
315325
#endif
316-
#if SOC_SDMMC_IO_POWER_EXTERNAL && defined(MICROPY_HW_SDMMC_LDO_CHAN_ID)
317-
sd_pwr_ctrl_ldo_config_t ldo_config = {
318-
.ldo_chan_id = MICROPY_HW_SDMMC_LDO_CHAN_ID,
319-
};
320-
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
321-
check_esp_err(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle));
322-
self->host.pwr_ctrl_handle = pwr_ctrl_handle;
326+
#if SOC_SDMMC_IO_POWER_EXTERNAL
327+
if (arg_vals[ARG_ldo].u_int != -1) {
328+
sd_pwr_ctrl_ldo_config_t ldo_config = {
329+
.ldo_chan_id = arg_vals[ARG_ldo].u_int,
330+
};
331+
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
332+
check_esp_err(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle));
333+
self->host.pwr_ctrl_handle = pwr_ctrl_handle;
334+
}
323335
#endif
324336

325337
DEBUG_printf(" Calling host.init()");
@@ -442,7 +454,7 @@ static mp_obj_t sd_deinit(mp_obj_t self_in) {
442454
// SD card used a (dedicated) SPI bus, so free that SPI bus.
443455
spi_bus_free(self->host.slot);
444456
}
445-
#if SOC_SDMMC_IO_POWER_EXTERNAL && defined(MICROPY_HW_SDMMC_LDO_CHAN_ID)
457+
#if SOC_SDMMC_IO_POWER_EXTERNAL
446458
if (self->host.pwr_ctrl_handle) {
447459
check_esp_err(sd_pwr_ctrl_del_on_chip_ldo(self->host.pwr_ctrl_handle));
448460
}

0 commit comments

Comments
 (0)