Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update to SdFat 2.0.0
  • Loading branch information
earlephilhower committed Dec 19, 2020
commit 409343b58344b335990f39db12b2be062ce4c2f3
2 changes: 1 addition & 1 deletion libraries/ESP8266SdFat
Submodule ESP8266SdFat updated 1282 files
2 changes: 1 addition & 1 deletion libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class SDClass {
public:
boolean begin(uint8_t csPin, SPISettings cfg = SPI_HALF_SPEED) {
boolean begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
SDFS.setConfig(SDFSConfig(csPin, cfg));
return (boolean)SDFS.begin();
}
Expand Down
11 changes: 7 additions & 4 deletions libraries/SDFS/src/SDFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
}
free(pathStr);
}
sdfat::File fd = _fs.open(path, flags);
sdfat::File32 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<sdfat::File>(fd);
auto sharedFd = std::make_shared<sdfat::File32>(fd);
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
}

Expand All @@ -91,7 +91,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.
sdfat::File dirFile;
sdfat::File32 dirFile;
const char *filter = "";
if (!pathStr[0]) {
// openDir("") === openDir("/")
Expand Down Expand Up @@ -136,7 +136,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
return DirImplPtr();
}
auto sharedDir = std::make_shared<sdfat::File>(dirFile);
auto sharedDir = std::make_shared<sdfat::File32>(dirFile);
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
free(pathStr);
return ret;
Expand All @@ -146,9 +146,12 @@ bool SDFSImpl::format() {
if (_mounted) {
return false;
}
return false; // TODO - Update implementation!
#if 0
SDFSFormatter formatter;
bool ret = formatter.format(&_fs, _cfg._csPin, _cfg._spiSettings);
return ret;
#endif
}


Expand Down
51 changes: 25 additions & 26 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SDFSConfig : public FSConfig
public:
static constexpr uint32_t FSId = 0x53444653;

SDFSConfig(uint8_t csPin = 4, SPISettings spi = SD_SCK_MHZ(10)) : FSConfig(FSId, false), _csPin(csPin), _part(0), _spiSettings(spi) { }
SDFSConfig(uint8_t csPin = 4, uint32_t spi = SD_SCK_MHZ(10)) : FSConfig(FSId, false), _csPin(csPin), _part(0), _spiSettings(spi) { }

SDFSConfig setAutoFormat(bool val = true) {
_autoFormat = val;
Expand All @@ -57,7 +57,7 @@ class SDFSConfig : public FSConfig
_csPin = pin;
return *this;
}
SDFSConfig setSPI(SPISettings spi) {
SDFSConfig setSPI(uint32_t spi) {
_spiSettings = spi;
return *this;
}
Expand All @@ -67,9 +67,9 @@ class SDFSConfig : public FSConfig
}

// Inherit _type and _autoFormat
uint8_t _csPin;
uint8_t _part;
SPISettings _spiSettings;
uint8_t _csPin;
uint8_t _part;
uint32_t _spiSettings;
};

class SDFSImpl : public FSImpl
Expand Down Expand Up @@ -97,11 +97,11 @@ class SDFSImpl : public FSImpl
return false;
}
info.maxOpenFiles = 999; // TODO - not valid
info.blockSize = _fs.vol()->blocksPerCluster() * 512;
info.blockSize = _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector();
info.pageSize = 0; // TODO ?
info.maxPathLength = 255; // TODO ?
info.totalBytes =_fs.vol()->volumeBlockCount() * 512LL;
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->blocksPerCluster() * 512LL);
info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector());
return true;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ class SDFSImpl : public FSImpl
format();
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
}
sdfat::SdFile::dateTimeCallback(dateTimeCB);
sdfat::FsDateTime::setCallback(dateTimeCB);
return _mounted;
}

Expand All @@ -176,7 +176,7 @@ class SDFSImpl : public FSImpl
return _fs.vol()->fatType();
}
size_t blocksPerCluster() {
return _fs.vol()->blocksPerCluster();
return _fs.vol()->sectorsPerCluster();
}
size_t totalClusters() {
return _fs.vol()->clusterCount();
Expand All @@ -185,7 +185,7 @@ class SDFSImpl : public FSImpl
return (totalClusters() / blocksPerCluster());
}
size_t clusterSize() {
return blocksPerCluster() * 512; // 512b block size
return blocksPerCluster() * _fs.vol()->bytesPerSector();
}
size_t size() {
return (clusterSize() * totalClusters());
Expand Down Expand Up @@ -264,7 +264,7 @@ class SDFSImpl : public FSImpl
class SDFSFileImpl : public FileImpl
{
public:
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File> fd, const char *name)
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File32> fd, const char *name)
: _fs(fs), _fd(fd), _opened(true)
{
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
Expand Down Expand Up @@ -295,7 +295,6 @@ class SDFSFileImpl : public FileImpl
void flush() override
{
if (_opened) {
_fd->flush();
_fd->sync();
}
}
Expand Down Expand Up @@ -375,15 +374,15 @@ class SDFSFileImpl : public FileImpl

bool isDirectory() const override
{
return _opened ? _fd->isDirectory() : false;
return _opened ? _fd->isDir() : false;
}

time_t getLastWrite() override {
time_t ftime = 0;
if (_opened && _fd) {
sdfat::dir_t tmp;
sdfat::DirFat_t tmp;
if (_fd.get()->dirEntry(&tmp)) {
ftime = SDFSImpl::FatToTimeT(tmp.lastWriteDate, tmp.lastWriteTime);
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
}
}
return ftime;
Expand All @@ -392,9 +391,9 @@ class SDFSFileImpl : public FileImpl
time_t getCreationTime() override {
time_t ftime = 0;
if (_opened && _fd) {
sdfat::dir_t tmp;
sdfat::DirFat_t tmp;
if (_fd.get()->dirEntry(&tmp)) {
ftime = SDFSImpl::FatToTimeT(tmp.creationDate, tmp.creationTime);
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
}
}
return ftime;
Expand All @@ -404,15 +403,15 @@ class SDFSFileImpl : public FileImpl

protected:
SDFSImpl* _fs;
std::shared_ptr<sdfat::File> _fd;
std::shared_ptr<sdfat::File32> _fd;
std::shared_ptr<char> _name;
bool _opened;
};

class SDFSDirImpl : public DirImpl
{
public:
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File> dir, const char *dirPath = nullptr)
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File32> dir, const char *dirPath = nullptr)
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
{
if (dirPath) {
Expand Down Expand Up @@ -487,17 +486,17 @@ class SDFSDirImpl : public DirImpl
{
const int n = _pattern.length();
do {
sdfat::File file;
sdfat::File32 file;
file.openNext(_dir.get(), sdfat::O_READ);
if (file) {
_valid = 1;
_size = file.fileSize();
_isFile = file.isFile();
_isDirectory = file.isDirectory();
sdfat::dir_t tmp;
_isDirectory = file.isDir();
sdfat::DirFat_t tmp;
if (file.dirEntry(&tmp)) {
_time = SDFSImpl::FatToTimeT(tmp.lastWriteDate, tmp.lastWriteTime);
_creation = SDFSImpl::FatToTimeT(tmp.creationDate, tmp.creationTime);
_time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
_creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
} else {
_time = 0;
_creation = 0;
Expand All @@ -521,7 +520,7 @@ class SDFSDirImpl : public DirImpl
protected:
String _pattern;
SDFSImpl* _fs;
std::shared_ptr<sdfat::File> _dir;
std::shared_ptr<sdfat::File32> _dir;
bool _valid;
char _lfn[64];
time_t _time;
Expand Down
4 changes: 4 additions & 0 deletions libraries/SDFS/src/SDFSFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace sdfs {

class SDFSFormatter {
#if 0
private:
// Taken from main FS object
sdfat::Sd2Card *card;
Expand Down Expand Up @@ -397,6 +398,9 @@ class SDFSFormatter {
return makeFat32();
}
}


#endif
}; // class SDFSFormatter

}; // namespace sdfs
Expand Down
1 change: 1 addition & 0 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function skip_ino()
/SoftwareSpi/
/STM32Test/
/extras/
/ESP8266SdFat/
EOL
echo $ino | grep -q -F "$skiplist"
echo $(( 1 - $? ))
Expand Down
9 changes: 7 additions & 2 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ CORE_CPP_FILES := \
FatLib/FatFilePrint.cpp \
FatLib/FatFileSFN.cpp \
FatLib/FatVolume.cpp \
FatLib/FmtNumber.cpp \
FatLib/StdioStream.cpp \
FatLib/FatPartition.cpp \
common/FmtNumber.cpp \
common/FsStructs.cpp \
common/FsDateTime.cpp \
common/PrintBasic.cpp \
SdCard/SdSpiCard.cpp \
SpiDriver/SdSpiESP.cpp \
) \
$(abspath $(LIBRARIES_PATH)/SDFS/src/SDFS.cpp) \
$(abspath $(LIBRARIES_PATH)/SD/src/SD.cpp) \
Expand Down