|
25 | 25 | #include "io_pin_remap.h" |
26 | 26 | #include "esp32-hal-log.h" |
27 | 27 |
|
| 28 | +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL |
| 29 | +#include "sd_pwr_ctrl_by_on_chip_ldo.h" |
| 30 | +#include "soc/sdmmc_pins.h" |
| 31 | +#endif |
| 32 | + |
28 | 33 | #if !CONFIG_DISABLE_HAL_LOCKS |
29 | 34 | #define SPI_PARAM_LOCK() \ |
30 | 35 | do { \ |
@@ -78,6 +83,33 @@ bool SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { |
78 | 83 | return false; |
79 | 84 | } |
80 | 85 |
|
| 86 | +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL |
| 87 | + bool intersection = false; |
| 88 | + int8_t requested[] = {sck, miso, mosi, ss}; |
| 89 | + int8_t ldo_ctrld[] = {SDMMC_SLOT0_IOMUX_PIN_NUM_CLK, SDMMC_SLOT0_IOMUX_PIN_NUM_CMD, SDMMC_SLOT0_IOMUX_PIN_NUM_D0, SDMMC_SLOT0_IOMUX_PIN_NUM_D1, SDMMC_SLOT0_IOMUX_PIN_NUM_D2, SDMMC_SLOT0_IOMUX_PIN_NUM_D3}; |
| 90 | + for (int i=0; i<4; i++) { |
| 91 | + for (int j=0; j<6; j++) { |
| 92 | + if (requested[i] == ldo_ctrld[j]) { |
| 93 | + intersection = true; |
| 94 | + break; |
| 95 | + } |
| 96 | + } |
| 97 | + if (intersection) break; |
| 98 | + } |
| 99 | + if (intersection) { |
| 100 | + sd_pwr_ctrl_ldo_config_t ldo_config; |
| 101 | + ldo_config.ldo_chan_id = BOARD_SDMMC_POWER_CHANNEL; |
| 102 | + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; |
| 103 | + sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle); |
| 104 | + if (sd_pwr_ctrl_set_io_voltage(pwr_ctrl_handle, 3300)) { |
| 105 | + log_e("Unable to set power control to 3V3"); |
| 106 | + return false; |
| 107 | + } |
| 108 | + pinMode(BOARD_SDMMC_POWER_PIN, OUTPUT); |
| 109 | + digitalWrite(BOARD_SDMMC_POWER_PIN, BOARD_SDMMC_POWER_ON_LEVEL); |
| 110 | + } |
| 111 | +#endif |
| 112 | + |
81 | 113 | if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) { |
82 | 114 | #if CONFIG_IDF_TARGET_ESP32 |
83 | 115 | _sck = (_spi_num == VSPI) ? SCK : 14; |
|
0 commit comments