diff --git a/usermods/sd_card/readme.md b/usermods/sd_card/readme.md index 96390c05ac..9c502f33d2 100644 --- a/usermods/sd_card/readme.md +++ b/usermods/sd_card/readme.md @@ -5,6 +5,7 @@ - choose the way your SD is connected 1. via `-D WLED_USE_SD_MMC` when connected via MMC 2. via `-D WLED_USE_SD_SPI` when connected via SPI (use usermod page to setup SPI pins) + 3. Customize pins with the following `-D UM_SD_SELECT=16 -D UM_SD_CLOCK=14 -D UM_SD_POCI=36 -D UM_SD_PICO=15` ### Test - enable `-D SD_PRINT_HOME_DIR` and `-D WLED_DEBUG` diff --git a/usermods/sd_card/sd_card.cpp b/usermods/sd_card/sd_card.cpp index 4e68b97a34..2e47accd01 100644 --- a/usermods/sd_card/sd_card.cpp +++ b/usermods/sd_card/sd_card.cpp @@ -13,9 +13,34 @@ #include "SPI.h" #endif +#ifndef UM_SD_SELECT + #define UM_SD_SELECT 16; +#endif +#ifndef UM_SD_CLOCK + #define UM_SD_CLOCK 14; +#endif +#ifndef UM_SD_POCI + #define UM_SD_POCI 36; +#endif +#ifndef UM_SD_PICO + #define UM_SD_PICO 15; +#endif + + #ifdef WLED_USE_SD_MMC + // SD_MMC configuration handled elsewhere #elif defined(WLED_USE_SD_SPI) - SPIClass spiPort = SPIClass(VSPI); + #if defined(CONFIG_IDF_TARGET_ESP32S3) + // FSPI (SPI2) is the global SPI used by dotstar/2-pin LED drivers; use HSPI (SPI3) for SD + SPIClass spiPort = SPIClass(HSPI); + #elif defined(WLED_USE_ETHERNET) + #warning "SD card may have conflicts with ethernet." + // Ethernet builds: dotstar uses HSPI (SPI2), so SD uses VSPI (SPI3) + SPIClass spiPort = SPIClass(VSPI); + #else + // Non-Ethernet classic ESP32: dotstar uses global SPI (VSPI/SPI3), so SD uses HSPI (SPI2) + SPIClass spiPort = SPIClass(HSPI); + #endif #endif void listDir( const char * dirname, uint8_t levels); @@ -24,11 +49,14 @@ class UsermodSdCard : public Usermod { private: bool sdInitDone = false; - #ifdef WLED_USE_SD_SPI - int8_t configPinSourceSelect = 16; - int8_t configPinSourceClock = 14; - int8_t configPinPoci = 36; // confusing names? Then have a look :) - int8_t configPinPico = 15; // https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names/ +// confusing names? Then have a look +// https://oshwa.org/resources/a-resolution-to-redefine-spi-signal-names/ +#ifdef WLED_USE_SD_SPI + int8_t configPinSourceSelect = UM_SD_SELECT; + int8_t configPinSourceClock = UM_SD_CLOCK; + int8_t configPinPoci = UM_SD_POCI; + int8_t configPinPico = UM_SD_PICO; + #endif //acquired and initialize the SPI port void init_SD_SPI() @@ -241,4 +269,4 @@ void listDir( const char * dirname, uint8_t levels){ #endif static UsermodSdCard sd_card; -REGISTER_USERMOD(sd_card); \ No newline at end of file +REGISTER_USERMOD(sd_card);