Skip to content

Commit b0941a0

Browse files
committed
feat(spi): Set power channel on ESP32P4
1 parent e7df08a commit b0941a0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

libraries/SPI/src/SPI.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include "io_pin_remap.h"
2626
#include "esp32-hal-log.h"
2727

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+
2833
#if !CONFIG_DISABLE_HAL_LOCKS
2934
#define SPI_PARAM_LOCK() \
3035
do { \
@@ -78,6 +83,33 @@ bool SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) {
7883
return false;
7984
}
8085

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+
81113
if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) {
82114
#if CONFIG_IDF_TARGET_ESP32
83115
_sck = (_spi_num == VSPI) ? SCK : 14;

0 commit comments

Comments
 (0)