Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include "io_pin_remap.h"
#include "esp32-hal-log.h"

#ifdef SOC_SDMMC_IO_POWER_EXTERNAL
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
#include "soc/sdmmc_pins.h"
#endif

#if !CONFIG_DISABLE_HAL_LOCKS
#define SPI_PARAM_LOCK() \
do { \
Expand Down Expand Up @@ -78,6 +83,33 @@ bool SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) {
return false;
}

#ifdef SOC_SDMMC_IO_POWER_EXTERNAL
bool intersection = false;
int8_t requested[] = {sck, miso, mosi, ss};
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};
for (int i=0; i<4; i++) {
for (int j=0; j<6; j++) {
if (requested[i] == ldo_ctrld[j]) {
intersection = true;
break;
}
}
if (intersection) break;
}
if (intersection) {
sd_pwr_ctrl_ldo_config_t ldo_config;
ldo_config.ldo_chan_id = BOARD_SDMMC_POWER_CHANNEL;
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
if (sd_pwr_ctrl_set_io_voltage(pwr_ctrl_handle, 3300)) {
log_e("Unable to set power control to 3V3");
return false;
}
pinMode(BOARD_SDMMC_POWER_PIN, OUTPUT);
digitalWrite(BOARD_SDMMC_POWER_PIN, BOARD_SDMMC_POWER_ON_LEVEL);
}
#endif

if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) {
#if CONFIG_IDF_TARGET_ESP32
_sck = (_spi_num == VSPI) ? SCK : 14;
Expand Down
Loading