diff --git a/.gitmodules b/.gitmodules index 0ad9b795..8b55777d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule "libraries/LittleFS/lib/littlefs"] path = libraries/LittleFS/lib/littlefs url = https://github.com/littlefs-project/littlefs.git -[submodule "libraries/SdFat"] - path = libraries/ESP8266SdFat - url = https://github.com/earlephilhower/ESP8266SdFat.git [submodule "libraries/Keyboard"] path = libraries/HID_Keyboard url = https://github.com/earlephilhower/Keyboard.git @@ -49,3 +46,6 @@ [submodule "libraries/ESPHost"] path = libraries/ESPHost url = https://github.com/Networking-for-Arduino/ESPHost.git +[submodule "libraries/SdFat"] + path = libraries/SdFat + url = https://github.com/greiman/SdFat.git diff --git a/libraries/ESP8266SdFat b/libraries/ESP8266SdFat deleted file mode 160000 index 9e145710..00000000 --- a/libraries/ESP8266SdFat +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9e1457101ca47b9ace198086dbd8854efc573ccf diff --git a/libraries/SD/examples/CardInfo/CardInfo.ino b/libraries/SD/examples/CardInfo/CardInfo.ino index 1f6d5ab3..4fe9ec28 100644 --- a/libraries/SD/examples/CardInfo/CardInfo.ino +++ b/libraries/SD/examples/CardInfo/CardInfo.ino @@ -114,7 +114,7 @@ void setup() { Serial.println(); // print the type and size of the first FAT-type volume - uint32_t volumesize; + uint64_t volumesize; Serial.print("Volume type is: FAT"); Serial.println(SD.fatType(), DEC); @@ -130,7 +130,7 @@ void setup() { Serial.println((float)volumesize / 1024.0); Serial.print("Card size: "); - Serial.println((float)SD.size() / 1000); + Serial.println((float)SD.size64() / 1000); FSInfo fs_info; SDFS.info(fs_info); diff --git a/libraries/SDFS/src/SDFS.cpp b/libraries/SDFS/src/SDFS.cpp index f40653ff..ab9434e8 100644 --- a/libraries/SDFS/src/SDFS.cpp +++ b/libraries/SDFS/src/SDFS.cpp @@ -63,13 +63,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces } free(pathStr); } - File32 fd = _fs.open(path, flags); + FsFile fd = _fs.open(path, flags); if (!fd) { DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d", &fd, path, openMode, accessMode); return FileImplPtr(); } - auto sharedFd = std::make_shared(fd); + auto sharedFd = std::make_shared(fd); return std::make_shared(this, sharedFd, path); } @@ -88,7 +88,7 @@ DirImplPtr SDFSImpl::openDir(const char* path) { } // At this point we have a name of "/blah/blah/blah" or "blah" or "" // If that references a directory, just open it and we're done. - File32 dirFile; + FsFile dirFile; const char *filter = ""; if (!pathStr[0]) { // openDir("") === openDir("/") @@ -133,7 +133,7 @@ DirImplPtr SDFSImpl::openDir(const char* path) { DEBUGV("SDFSImpl::openDir: path=`%s`\n", path); return DirImplPtr(); } - auto sharedDir = std::make_shared(dirFile); + auto sharedDir = std::make_shared(dirFile); auto ret = std::make_shared(filter, this, sharedDir, pathStr); free(pathStr); return ret; diff --git a/libraries/SDFS/src/SDFS.h b/libraries/SDFS/src/SDFS.h index 7f9886b0..0c1c6afa 100644 --- a/libraries/SDFS/src/SDFS.h +++ b/libraries/SDFS/src/SDFS.h @@ -153,8 +153,7 @@ class SDFSImpl : public FSImpl { return false; } bzero(st, sizeof(*st)); - File32 f; - f = _fs.open(path, O_RDONLY); + FsFile f = _fs.open(path, O_RDONLY); if (!f) { return false; } @@ -169,8 +168,8 @@ class SDFSImpl : public FSImpl { if (f.getCreateDateTime(&date, &time)) { st->ctime = FatToTimeT(date, time); } - if (f.getAccessDate(&date)) { - st->atime = FatToTimeT(date, 0); + if (f.getAccessDateTime(&date, &time)) { + st->atime = FatToTimeT(date, time); } f.close(); return true; @@ -272,7 +271,7 @@ class SDFSImpl : public FSImpl { class SDFSFileImpl : public FileImpl { public: - SDFSFileImpl(SDFSImpl *fs, std::shared_ptr fd, const char *name) + SDFSFileImpl(SDFSImpl *fs, std::shared_ptr fd, const char *name) : _fs(fs), _fd(fd), _opened(true) { _name = std::shared_ptr(new char[strlen(name) + 1], std::default_delete()); strcpy(_name.get(), name); @@ -284,7 +283,7 @@ class SDFSFileImpl : public FileImpl { } int availableForWrite() override { - return _opened ? _fd->availableSpaceForWrite() : 0; + return _opened ? _fd->availableForWrite() : 0; } size_t write(const uint8_t *buf, size_t size) override { @@ -373,9 +372,9 @@ class SDFSFileImpl : public FileImpl { time_t getLastWrite() override { time_t ftime = 0; if (_opened && _fd) { - DirFat_t tmp; - if (_fd.get()->dirEntry(&tmp)) { - ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime); + uint16_t date, time; + if (_fd.get()->getModifyDateTime(&date, &time)) { + ftime = SDFSImpl::FatToTimeT(date, time); } } return ftime; @@ -384,9 +383,9 @@ class SDFSFileImpl : public FileImpl { time_t getCreationTime() override { time_t ftime = 0; if (_opened && _fd) { - DirFat_t tmp; - if (_fd.get()->dirEntry(&tmp)) { - ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime); + uint16_t date, time; + if (_fd.get()->getCreateDateTime(&date, &time)) { + ftime = SDFSImpl::FatToTimeT(date, time); } } return ftime; @@ -394,14 +393,14 @@ class SDFSFileImpl : public FileImpl { protected: SDFSImpl* _fs; - std::shared_ptr _fd; + std::shared_ptr _fd; std::shared_ptr _name; bool _opened; }; class SDFSDirImpl : public DirImpl { public: - SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr dir, const char *dirPath = nullptr) + SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr dir, const char *dirPath = nullptr) : _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr) { if (dirPath) { _dirPath = std::shared_ptr(new char[strlen(dirPath) + 1], std::default_delete()); @@ -466,19 +465,22 @@ class SDFSDirImpl : public DirImpl { bool next() override { const int n = _pattern.length(); do { - File32 file; + FsFile file; file.openNext(_dir.get(), O_READ); if (file) { _valid = 1; _size = file.fileSize(); _isFile = file.isFile(); _isDirectory = file.isDir(); - DirFat_t tmp; - if (file.dirEntry(&tmp)) { - _time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime); - _creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime); + uint16_t date, time; + if (file.getModifyDateTime(&date, &time)) { + _time = SDFSImpl::FatToTimeT(date, time); } else { _time = 0; + } + if (file.getCreateDateTime(&date, &time)) { + _creation = SDFSImpl::FatToTimeT(date, time); + } else { _creation = 0; } file.getName(_lfn, sizeof(_lfn)); @@ -499,9 +501,9 @@ class SDFSDirImpl : public DirImpl { protected: String _pattern; SDFSImpl* _fs; - std::shared_ptr _dir; + std::shared_ptr _dir; bool _valid; - char _lfn[64]; + char _lfn[256]; time_t _time; time_t _creation; std::shared_ptr _dirPath; diff --git a/libraries/SdFat b/libraries/SdFat new file mode 160000 index 00000000..67e26476 --- /dev/null +++ b/libraries/SdFat @@ -0,0 +1 @@ +Subproject commit 67e26476f15a3bae5f390d91b6cc01830920c55d diff --git a/platform.txt b/platform.txt index 56781c18..efde705e 100644 --- a/platform.txt +++ b/platform.txt @@ -51,7 +51,7 @@ compiler.warning_flags.all=-Wall -Wextra -Werror=return-type -Wno-ignored-qualif compiler.netdefines={build.libpicowdefs} -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 compiler.psramdefines={build.psram_cs} {build.psram_freq} -compiler.defines={build.led} {build.usbstack_flags} {build.usbpid} {build.usbvid} {build.usbpwr} {compiler.psramdefines} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {compiler.netdefines} {build.variantdefines} -DARDUINO_VARIANT="{build.variant}" -DPICO_FLASH_SIZE_BYTES={build.flash_total} "@{runtime.platform.path}/lib/{build.chip}/platform_def.txt" +compiler.defines={build.led} {build.usbstack_flags} {build.usbpid} {build.usbvid} {build.usbpwr} {compiler.psramdefines} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {compiler.netdefines} {build.sdfatdefines} {build.variantdefines} -DARDUINO_VARIANT="{build.variant}" -DPICO_FLASH_SIZE_BYTES={build.flash_total} "@{runtime.platform.path}/lib/{build.chip}/platform_def.txt" compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/{build.chip}/platform_inc.txt" "@{runtime.platform.path}/lib/core_inc.txt" "-I{runtime.platform.path}/include" compiler.flags={build.toolchainopts} -ffunction-sections -fdata-sections {build.flags.exceptions} {build.flags.stackprotect} {build.picodebugflags} compiler.wrap="@{runtime.platform.path}/lib/{build.chip}/platform_wrap.txt" "@{runtime.platform.path}/lib/core_wrap.txt" @@ -114,6 +114,7 @@ build.espwifitype= build.debugscript=picoprobe_cmsis_dap.tcl build.picodebugflags= build.variantdefines= +build.sdfatdefines=-DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC -DUSE_UTF8_LONG_NAMES=1 -DSDFAT_FILE_TYPE=3 -DDISABLE_FS_H_WARNING=1 # Allow Pico boards to be auto-discovered by the IDE #discovery.rp2040.pattern={runtime.tools.pqt-python3.path}/python3 -I "{runtime.platform.path}/tools/pluggable_discovery.py" diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 026b9589..7f2990a3 100755 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -225,6 +225,14 @@ def is_pio_build(): "-std=gnu++17", ], + CPPDEFINES=[ + # SdFat definitions required for SDFS + ("FILE_COPY_CONSTRUCTOR_SELECT", "FILE_COPY_CONSTRUCTOR_PUBLIC"), + ("USE_UTF8_LONG_NAMES", "1"), + ("SDFAT_FILE_TYPE", "3"), + ("DISABLE_FS_H_WARNING", "1") + ] + CPPPATH=[ os.path.join(FRAMEWORK_DIR, "cores", "rp2040"), os.path.join(FRAMEWORK_DIR, "cores", "rp2040", "api", "deprecated"),