Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(spi): Set power channel on ESP32P4 #12079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lbernstone wants to merge 4 commits into espressif:master
base: master
Choose a base branch
Loading
from lbernstone:spi_esp32p4
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
59 changes: 59 additions & 0 deletions cores/esp32/esp32-hal-spi.c
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#include "esp_system.h"
#include "esp_intr_alloc.h"

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

#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
#include "soc/dport_reg.h"
#include "esp32/rom/ets_sys.h"
Expand Down Expand Up @@ -256,6 +261,48 @@ static bool spiDetachBus_SS(void *bus) {
return true;
}

#ifdef SOC_SDMMC_IO_POWER_EXTERNAL //ESP32-P4
static void setLDOPower(int8_t pin) {
if (pin<0) {
return;
}

#ifdef BOARD_SDMMC_POWER_PIN
if (perimanPinIsValid(BOARD_SDMMC_POWER_PIN) && perimanGetPinBusType(BOARD_SDMMC_POWER_PIN)) {
if (strcmp(perimanGetPinBusExtraType(BOARD_SDMMC_POWER_PIN), "SDMMC POWER") == 0) {
return;
}
}
#endif

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,
SDMMC_SLOT0_IOMUX_PIN_NUM_D4, SDMMC_SLOT0_IOMUX_PIN_NUM_D5,
SDMMC_SLOT0_IOMUX_PIN_NUM_D6, SDMMC_SLOT0_IOMUX_PIN_NUM_D7
};
for (int j=0; j<10; j++) {
if (pin == ldo_ctrld[j]) {
#ifdef BOARD_SDMMC_POWER_PIN
pinMode(BOARD_SDMMC_POWER_PIN, OUTPUT);
digitalWrite(BOARD_SDMMC_POWER_PIN, BOARD_SDMMC_POWER_ON_LEVEL);
perimanSetPinBusExtraType(BOARD_SDMMC_POWER_PIN, "SDMMC POWER");
#endif
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;
}
break;
}
}
}
#endif

bool spiAttachSCK(spi_t *spi, int8_t sck) {
if (!spi || sck < 0) {
return false;
Expand All @@ -264,6 +311,9 @@ bool spiAttachSCK(spi_t *spi, int8_t sck) {
if (bus != NULL && !perimanClearPinBus(sck)) {
return false;
}
#ifdef SOC_SDMMC_IO_POWER_EXTERNAL //ESP32-P4
setLDOPower(sck);
#endif
pinMode(sck, OUTPUT);
pinMatrixOutAttach(sck, SPI_CLK_IDX(spi->num), false, false);
spi->sck = sck;
Expand All @@ -283,6 +333,9 @@ bool spiAttachMISO(spi_t *spi, int8_t miso) {
if (bus != NULL && !perimanClearPinBus(miso)) {
return false;
}
#ifdef SOC_SDMMC_IO_POWER_EXTERNAL //ESP32-P4
setLDOPower(miso);
#endif
pinMode(miso, INPUT);
pinMatrixInAttach(miso, SPI_MISO_IDX(spi->num), false);
spi->miso = miso;
Expand All @@ -302,6 +355,9 @@ bool spiAttachMOSI(spi_t *spi, int8_t mosi) {
if (bus != NULL && !perimanClearPinBus(mosi)) {
return false;
}
#ifdef SOC_SDMMC_IO_POWER_EXTERNAL //ESP32-P4
setLDOPower(mosi);
#endif
pinMode(mosi, OUTPUT);
pinMatrixOutAttach(mosi, SPI_MOSI_IDX(spi->num), false, false);
spi->mosi = mosi;
Expand Down Expand Up @@ -360,6 +416,9 @@ bool spiAttachSS(spi_t *spi, uint8_t ss_num, int8_t ss) {
if (bus != NULL && !perimanClearPinBus(ss)) {
return false;
}
#ifdef SOC_SDMMC_IO_POWER_EXTERNAL //ESP32-P4
setLDOPower(ss);
#endif
pinMode(ss, OUTPUT);
pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), spi->ss_invert, false);
spiEnableSSPins(spi, (1 << ss_num));
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /