#pragma once #include #include #include #define SD_CS 4 extern uint16_t SDCard_Size; bool SD_Init(); /** * True only after the last SD_Init() completed successfully (SD.begin + valid cardType). * Use this to gate capture — do NOT rely on SD.cardType() alone after WiFi on ESP32-C6: * with LCD+SD sharing SPI, cardType() can spuriously read CARD_NONE and falsely show "insert SD". */ bool SD_IsReady(); bool SD_WriteFileAtomic(const char* path, const uint8_t* data, size_t len); /** Append one line (caller supplies \\n if desired). Uses same SPI lock as other SD ops. */ bool SD_AppendLine(const char* path, const char* line); typedef void (*SD_LineCallback)(const char* line, void* user); /** Read text file line-by-line; missing file is OK (returns true). */ bool SD_ForEachLine(const char* path, SD_LineCallback cb, void* user);