Skip to content

Commit

Permalink
Merge pull request #775 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed broken SD functionality
  • Loading branch information
forkineye authored Jul 15, 2024
2 parents e4529c1 + df6ef4d commit 6f841ea
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 22 deletions.
24 changes: 15 additions & 9 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
#include "FileMgr.hpp"
#include "network/NetworkMgr.hpp"

SdFat sd;
SdFs sd;
const int8_t DISABLE_CS_PIN = -1;

#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(16))
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(16))
#endif // HAS_SDIO_CLASS

oflag_t XlateFileMode[3] = { O_READ , O_WRITE | O_CREAT, O_WRITE | O_APPEND };
#ifdef SUPPORT_FTP
Expand Down Expand Up @@ -373,16 +382,13 @@ void c_FileMgr::SetSpiIoPins ()
// DEBUG_V();
pinMode(miso_pin, INPUT);
# endif // def USE_MISO_PULLUP
SPI.begin (clk_pin, miso_pin, mosi_pin, cs_pin);
SPI.begin (clk_pin, miso_pin, mosi_pin, cs_pin); // uses HSPI by default
# else // ESP8266
SPI.end ();
SPI.begin ();
# endif // ! ARDUINO_ARCH_ESP32
// DEBUG_V();
ResetSdCard();

// DEBUG_V();
if (!ESP_SD.begin (SdSpiConfig(cs_pin, SHARED_SPI, SD_CARD_CLK_MHZ, &SPI)))
if (!ESP_SD.begin (SdSpiConfig(cs_pin, SHARED_SPI, SD_SCK_MHZ(16))))
#endif // !def SUPPORT_SD_MMC
{
// DEBUG_V();
Expand Down Expand Up @@ -1192,11 +1198,11 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil

// DEBUG_V ();

// DEBUG_V (String("FileName: '") + FileNamePrefix + FileName + "'");
// DEBUG_V (String("FileName: '") + FileName + "'");

if (FileMode::FileRead == Mode)
{
// DEBUG_V (String("Read FIle"));
// DEBUG_V (String("Read mode"));
if (false == ESP_SD.exists (FileName))
{
logcon (String (F ("ERROR: Cannot find '")) + FileName + F ("' for reading. File does not exist."));
Expand All @@ -1221,7 +1227,7 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil
FileHandle = FileList[FileListIndex].handle;
}

// did we get an index
// DEBUG_V("did we get an index");
if (-1 != FileListIndex)
{
// DEBUG_V(String("Valid FileListIndex: ") + String(FileListIndex));
Expand Down
9 changes: 6 additions & 3 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,15 @@ size_t c_WebMgr::GetFseqFileListChunk(uint8_t *buffer, size_t maxlen, size_t ind
}
break;
}
// is it a new request

// DEBUG_V("is it a new request");
if (index == 0)
{
NumberOfBytesTransfered = 0; // reset the log line index when we get a new request
TotalFileSizeToTransfer = 0;
buffer[0] = '\0';

// Try to open the file
// DEBUG_V("Try to open the file");
if(!FileMgr.OpenSdFile(FSEQFILELIST, c_FileMgr::FileMode::FileRead, FileHandle))
{
logcon(F("ERROR: Could not open List of Fseq files for reading"));
Expand All @@ -665,6 +666,7 @@ size_t c_WebMgr::GetFseqFileListChunk(uint8_t *buffer, size_t maxlen, size_t ind
break;
}

// DEBUG_V("Get the file size");
TotalFileSizeToTransfer = FileMgr.GetSdFileSize(FileHandle);
}

Expand Down Expand Up @@ -696,14 +698,15 @@ size_t c_WebMgr::GetFseqFileListChunk(uint8_t *buffer, size_t maxlen, size_t ind
break;
}

// DEBUG_V("Read a chunk");
memset(buffer, 0x0, maxlen-1);
FileMgr.ReadSdFile(FileHandle,
buffer,
DataToSendThisChunk);
// buffer[DataToSendThisChunk] = 'A';
NumberOfBytesTransfered += DataToSendThisChunk;
response = DataToSendThisChunk;
// DEBUG_VV(String("buffer: ") + String((char*)buffer));
// DEBUG_V(String("buffer: ") + String((char*)buffer));

} while(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_27
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#include <ETH.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_16
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_17
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_27
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_16
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_17
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_SPI_DEVICE HSPI_HOST
#define DEFAULT_SPI_DEVICE VSPI_HOST

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_21
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_22
Expand Down
11 changes: 9 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ lib_deps =
bblanchon/ArduinoJson @ 6.18.5
djgrrr/Int64String @ 1.1.1
https://github.com/esphome/ESPAsyncWebServer#4fd0a1fdf421664214a27373c0eb0247f94b7a79
https://github.com/MartinMueller2003/ESPAsyncE131
https://github.com/forkineye/ESPAsyncE131
ottowinter/AsyncMqttClient-esphome @ 0.8.6
https://github.com/MartinMueller2003/Artnet
https://github.com/MartinMueller2003/Espalexa ; pull latest
https://github.com/PaulStoffregen/Time
https://github.com/greiman/SdFat
https://github.com/greiman/SdFat @ 2.2.3
https://github.com/MartinMueller2003/SimpleFTPServer
extra_scripts =
.scripts/download_fs.py
.scripts/CopyTargets.py
pre:.scripts/pio-version.py
build_flags =
; -D ENABLE_DEDICATED_SPI=1 ; instruct SdFat to take ownership of the spi device
-D SDFAT_FILE_TYPE=3 ; SdFat full support
-D USE_LONG_FILE_NAMES=1 ; SdFat
-D MAINTAIN_FREE_CLUSTER_COUNT=1 ; SdFat
-D CHECK_FLASH_PROGRAMMING=0 ; SdFat
-D INCLUDE_SDIOS=1 ; SdFat
; -D USE_DBG_MACROS=2 ; SdFat
-D SUPPORT_FTP
; -D FTP_SERVER_DEBUG
; -D FTP_ADDITIONAL_DEBUG
Expand Down

0 comments on commit 6f841ea

Please sign in to comment.