From 4b4be4c9db0b87f03ea60d2bf6d36240b1fa1149 Mon Sep 17 00:00:00 2001 From: acidvegas Date: Wed, 5 Jun 2024 19:32:59 -0400 Subject: [PATCH] Added SD card support --- src/main.ino | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main.ino b/src/main.ino index 45e32e5..8d405e5 100644 --- a/src/main.ino +++ b/src/main.ino @@ -8,6 +8,7 @@ #include "nvs_flash.h" #include // Power management #include +#include #include #include #include @@ -851,6 +852,43 @@ void setBrightness(uint8_t value) { } +bool setupSD() { + digitalWrite(BOARD_SDCARD_CS, HIGH); + digitalWrite(RADIO_CS_PIN, HIGH); + digitalWrite(BOARD_TFT_CS, HIGH); + + if (SD.begin(BOARD_SDCARD_CS, SPI, 800000U)) { + uint8_t cardType = SD.cardType(); + + if (cardType == CARD_NONE) { + Serial.println("No SD_MMC card attached"); + return false; + } else { + Serial.print("SD_MMC Card Type: "); + if (cardType == CARD_MMC) + Serial.println("MMC"); + else if (cardType == CARD_SD) + Serial.println("SDSC"); + else if (cardType == CARD_SDHC) + Serial.println("SDHC"); + else + Serial.println("UNKNOWN"); + + uint32_t cardSize = SD.cardSize() / (1024 * 1024); + uint32_t cardTotal = SD.totalBytes() / (1024 * 1024); + uint32_t cardUsed = SD.usedBytes() / (1024 * 1024); + Serial.printf("SD Card Size: %lu MB\n", cardSize); + Serial.printf("Total space: %lu MB\n", cardTotal); + Serial.printf("Used space: %lu MB\n", cardUsed); + + return true; + } + } + + return false; +} + + void turnOffScreen() { Serial.println("Screen turned off"); tft.writecommand(TFT_DISPOFF);