Improve SD card code

This commit is contained in:
Thomas Hooge 2025-01-17 15:04:47 +01:00
parent 2fd11c72b6
commit ff867beb9d
4 changed files with 45 additions and 22 deletions

View File

@ -10,7 +10,7 @@
"-DBOARD_HAS_PSRAM",
"-DARDUINO_ESP32S3_DEV",
"-DARDUINO_USB_MODE=1",
"-DARDUINO_USB_CDC_ON_BOOT=1",
"-DARDUINO_USB_CDC_ON_BOOT=0",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1"
],

View File

@ -573,6 +573,21 @@
"obp60":"true"
}
},
{
"name": "useSDCard",
"label": "SD Card",
"type": "boolean",
"default": "off",
"description": "Use internal SD card interface [off|on]",
"list": [
"off",
"on"
],
"category": "OBP60 Hardware",
"capabilities": {
"obp60":"true"
}
},
{
"name": "powerMode",
"label": "Power Mode",

View File

@ -37,6 +37,9 @@ int taskRunCounter = 0; // Task couter for loop section
//####################################################################################
void OBP60Init(GwApi *api){
GwLog *logger = api->getLogger();
GwConfigHandler *config = api->getConfig();
// Set a new device name and hidden the original name in the main config
String devicename = api->getConfig()->getConfigItem(api->getConfig()->deviceName,true)->asString();
api->getConfig()->setValue(GwConfigDefinitions::systemName, devicename, GwConfigInterface::ConfigType::HIDDEN);
@ -49,6 +52,31 @@ void OBP60Init(GwApi *api){
// Init hardware
hardwareInit(api);
String sdcard = config->getConfigItem(config->useSDCard, true)->asString();
if (sdcard == "on") {
setPortPin(OBP_POWER_SD, true); // Power on SD
delay(10);
SPIClass SD_SPI = SPIClass(HSPI);
SD_SPI.begin(SD_SPI_CLK, SD_SPI_MISO, SD_SPI_MOSI);
if (SD.begin(SD_SPI_CS, SD_SPI, 80000000)) {
String sdtype = "unknown";
uint8_t cardType = SD.cardType();
switch (cardType) {
case CARD_MMC:
sdtype = "MMC";
break;
case CARD_SD:
sdtype = "SDSC";
break;
case CARD_SDHC:
sdtype = "SDHC";
break;
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
LOG_DEBUG(GwLog::LOG,"SD card type %s of size %d MB detected", sdtype, cardSize);
}
}
// Init power rail 5.0V
String powermode = api->getConfig()->getConfigItem(api->getConfig()->powerMode,true)->asString();
api->getLogger()->logDebug(GwLog::DEBUG,"Power Mode is: %s", powermode.c_str());
@ -414,26 +442,6 @@ void OBP60Task(GwApi *api){
doImageRequest(api, &pageNumber, pages, request);
});
// SD-Card: init an check
SPI.begin(SD_SPI_CLK, SD_SPI_MISO, SD_SPI_MOSI, SD_SPI_CS);
if (SD.begin(SD_SPI_CS)) {
String sdtype = "unknown";
uint8_t cardType = SD.cardType();
switch (cardType) {
case CARD_MMC:
sdtype = "MMC";
break;
case CARD_SD:
sdtype = "SDSC";
break;
case CARD_SDHC:
sdtype = "SDHC";
break;
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
LOG_DEBUG(GwLog::DEBUG,"SD card type %s of size %d MB detected", sdtype, cardSize);
}
//now we have prepared the page data
//we start a separate task that will fetch our keys...
MyData allParameters;

View File

@ -41,7 +41,7 @@ lib_deps =
build_flags=
#https://thingpulse.com/usb-settings-for-logging-with-the-esp32-s3-in-platformio/?srsltid=AfmBOopGskbkr4GoeVkNlFaZXe_zXkLceKF6Rn-tmoXABCeAR2vWsdHL
# -D ARDUINO_USB_MODE=1 #0=OTG (to implement other external devices), 1=CDC (is a serial device)
-D ARDUINO_USB_CDC_ON_BOOT=0 #0=JTAG, 1=CDC (serial device)
# -D ARDUINO_USB_CDC_ON_BOOT=0 #0=JTAG, 1=CDC (serial device)
# -D CORE_DEBUG_LEVEL=1 #Debug level for CPU core via CDC (seral device)
# -D TIME=$UNIX_TIME #Set PC time for RTC (only settable via VSC)
-D DISABLE_DIAGNOSTIC_OUTPUT #Disable diagnostic output for GxEPD2 lib