From 1c8a7634961f1e96eaee70984305cbc56d693683 Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 15 Apr 2025 14:29:50 +0200 Subject: [PATCH] SD software SPI control --- src/FSCommon.cpp | 5 +++-- variants/elecrow_panel/pins_arduino.h | 8 ++++++++ variants/elecrow_panel/platformio.ini | 13 ++++++++++--- variants/elecrow_panel/variant.h | 12 ------------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 68f18b815..f215be80f 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -12,7 +12,8 @@ #include "SPILock.h" #include "configuration.h" -#ifdef HAS_SDCARD +// Software SPI is used by MUI so disable SD card here until it's also implemented +#if defined(HAS_SDCARD) && !defined(SDCARD_USE_SOFT_SPI) #include #include @@ -306,7 +307,7 @@ void fsInit() */ void setupSDCard() { -#ifdef HAS_SDCARD +#if defined(HAS_SDCARD) && !defined(SDCARD_USE_SOFT_SPI) concurrency::LockGuard g(spiLock); SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI); if (!SD.begin(SDCARD_CS, SDHandler, SD_SPI_FREQUENCY)) { diff --git a/variants/elecrow_panel/pins_arduino.h b/variants/elecrow_panel/pins_arduino.h index 300f0e0f5..b98530378 100644 --- a/variants/elecrow_panel/pins_arduino.h +++ b/variants/elecrow_panel/pins_arduino.h @@ -17,6 +17,14 @@ static const uint8_t MOSI = 48; static const uint8_t MISO = 47; static const uint8_t SCK = 41; +#ifndef CROW_SELECT +static const uint8_t SPI_MOSI = 6; +static const uint8_t SPI_SCK = 5; +static const uint8_t SPI_MISO = 4; +static const uint8_t SPI_CS = 7; // SD does not support -1 +static const uint8_t SDCARD_CS = SPI_CS; +#endif + static const uint8_t A0 = 1; static const uint8_t A1 = 2; static const uint8_t A2 = 3; diff --git a/variants/elecrow_panel/platformio.ini b/variants/elecrow_panel/platformio.ini index 1a50acee7..e0d174cd7 100644 --- a/variants/elecrow_panel/platformio.ini +++ b/variants/elecrow_panel/platformio.ini @@ -3,7 +3,6 @@ extends = esp32s3_base board = crowpanel board_check = true -board_level = extra upload_protocol = esptool build_flags = ${esp32s3_base.build_flags} @@ -83,8 +82,10 @@ build_flags = ${crowpanel_base_tft.build_flags} -D TFT_HEIGHT=320 ; needed in variant.h -D HAS_SDCARD + -D SDCARD_USE_SOFT_SPI + -D SPI_DRIVER_SELECT=2 -D USE_I2S_BUZZER -; -D INPUTDRIVER_BUTTON_TYPE=0 + -D INPUTDRIVER_BUTTON_TYPE=0 -D LGFX_DRIVER_TEMPLATE -D LGFX_DRIVER=LGFX_GENERIC -D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_GENERIC.h\" @@ -128,8 +129,10 @@ build_flags = ${crowpanel_base_tft.build_flags} -D TFT_HEIGHT=480 ; needed in variant.h -D HAS_SDCARD + -D SDCARD_USE_SOFT_SPI + -D SPI_DRIVER_SELECT=2 -D USE_I2S_BUZZER -; -D INPUTDRIVER_BUTTON_TYPE=0 + -D INPUTDRIVER_BUTTON_TYPE=0 -D LV_CACHE_DEF_SIZE=2097152 -D LGFX_DRIVER_TEMPLATE -D LGFX_DRIVER=LGFX_GENERIC @@ -159,6 +162,7 @@ build_flags = # 4.3 inch 800x480 IPS ST7265 [env:elecrow-43] extends = crowpanel_base +board_level = extra build_flags = ${crowpanel_base.build_flags} @@ -172,6 +176,7 @@ build_flags = # 5 inch 800x480 IPS ST7262 [env:elecrow-50] extends = crowpanel_base +board_level = extra build_flags = ${crowpanel_base.build_flags} @@ -185,6 +190,7 @@ build_flags = # 7 inch 800x480 IPS SC7277 [env:elecrow-70] extends = crowpanel_base +board_level = extra build_flags = ${crowpanel_base.build_flags} @@ -197,6 +203,7 @@ build_flags = [env:elecrow-70-tft] extends = crowpanel_base_tft +board_level = extra build_flags = ${crowpanel_base_tft.build_flags} diff --git a/variants/elecrow_panel/variant.h b/variants/elecrow_panel/variant.h index 0a7949deb..ec3994a19 100644 --- a/variants/elecrow_panel/variant.h +++ b/variants/elecrow_panel/variant.h @@ -135,18 +135,6 @@ #define GPS_RX_PIN 18 #define GPS_TX_PIN 17 -#if TFT_HEIGHT == 320 || TFT_HEIGHT == 480 -// SDCard 2.4 - 3.5 TFT -// #define HAS_SDCARD -> must be defined in platformio.ini -#define SPI_SCK 5 -#define SPI_MISO 4 -#define SPI_MOSI 6 -#define SDCARD_CS 7 // SD does not support -1 -#else -// SDCard (from 4.3 only if LoRa is disabled) - -#endif - // Extension Slot Layout, viewed from above (2.4-3.5) // DIO1/IO1 o o IO2/NRESET // SCK/IO10 o o IO16/NC