Skip to content

Commit 409343b

Browse files
Update to SdFat 2.0.0
1 parent a9c46d0 commit 409343b

File tree

7 files changed

+46
-34
lines changed

7 files changed

+46
-34
lines changed

Diff for: libraries/ESP8266SdFat

Submodule ESP8266SdFat updated 1282 files

Diff for: libraries/SD/src/SD.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
class SDClass {
3434
public:
35-
boolean begin(uint8_t csPin, SPISettings cfg = SPI_HALF_SPEED) {
35+
boolean begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
3636
SDFS.setConfig(SDFSConfig(csPin, cfg));
3737
return (boolean)SDFS.begin();
3838
}

Diff for: libraries/SDFS/src/SDFS.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
6565
}
6666
free(pathStr);
6767
}
68-
sdfat::File fd = _fs.open(path, flags);
68+
sdfat::File32 fd = _fs.open(path, flags);
6969
if (!fd) {
7070
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
7171
&fd, path, openMode, accessMode);
7272
return FileImplPtr();
7373
}
74-
auto sharedFd = std::make_shared<sdfat::File>(fd);
74+
auto sharedFd = std::make_shared<sdfat::File32>(fd);
7575
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
7676
}
7777

@@ -91,7 +91,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
9191
}
9292
// At this point we have a name of "/blah/blah/blah" or "blah" or ""
9393
// If that references a directory, just open it and we're done.
94-
sdfat::File dirFile;
94+
sdfat::File32 dirFile;
9595
const char *filter = "";
9696
if (!pathStr[0]) {
9797
// openDir("") === openDir("/")
@@ -136,7 +136,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
136136
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
137137
return DirImplPtr();
138138
}
139-
auto sharedDir = std::make_shared<sdfat::File>(dirFile);
139+
auto sharedDir = std::make_shared<sdfat::File32>(dirFile);
140140
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
141141
free(pathStr);
142142
return ret;
@@ -146,9 +146,12 @@ bool SDFSImpl::format() {
146146
if (_mounted) {
147147
return false;
148148
}
149+
return false; // TODO - Update implementation!
150+
#if 0
149151
SDFSFormatter formatter;
150152
bool ret = formatter.format(&_fs, _cfg._csPin, _cfg._spiSettings);
151153
return ret;
154+
#endif
152155
}
153156

154157

Diff for: libraries/SDFS/src/SDFS.h

+25-26
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SDFSConfig : public FSConfig
4747
public:
4848
static constexpr uint32_t FSId = 0x53444653;
4949

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

5252
SDFSConfig setAutoFormat(bool val = true) {
5353
_autoFormat = val;
@@ -57,7 +57,7 @@ class SDFSConfig : public FSConfig
5757
_csPin = pin;
5858
return *this;
5959
}
60-
SDFSConfig setSPI(SPISettings spi) {
60+
SDFSConfig setSPI(uint32_t spi) {
6161
_spiSettings = spi;
6262
return *this;
6363
}
@@ -67,9 +67,9 @@ class SDFSConfig : public FSConfig
6767
}
6868

6969
// Inherit _type and _autoFormat
70-
uint8_t _csPin;
71-
uint8_t _part;
72-
SPISettings _spiSettings;
70+
uint8_t _csPin;
71+
uint8_t _part;
72+
uint32_t _spiSettings;
7373
};
7474

7575
class SDFSImpl : public FSImpl
@@ -97,11 +97,11 @@ class SDFSImpl : public FSImpl
9797
return false;
9898
}
9999
info.maxOpenFiles = 999; // TODO - not valid
100-
info.blockSize = _fs.vol()->blocksPerCluster() * 512;
100+
info.blockSize = _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector();
101101
info.pageSize = 0; // TODO ?
102102
info.maxPathLength = 255; // TODO ?
103-
info.totalBytes =_fs.vol()->volumeBlockCount() * 512LL;
104-
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->blocksPerCluster() * 512LL);
103+
info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
104+
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector());
105105
return true;
106106
}
107107

@@ -156,7 +156,7 @@ class SDFSImpl : public FSImpl
156156
format();
157157
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
158158
}
159-
sdfat::SdFile::dateTimeCallback(dateTimeCB);
159+
sdfat::FsDateTime::setCallback(dateTimeCB);
160160
return _mounted;
161161
}
162162

@@ -176,7 +176,7 @@ class SDFSImpl : public FSImpl
176176
return _fs.vol()->fatType();
177177
}
178178
size_t blocksPerCluster() {
179-
return _fs.vol()->blocksPerCluster();
179+
return _fs.vol()->sectorsPerCluster();
180180
}
181181
size_t totalClusters() {
182182
return _fs.vol()->clusterCount();
@@ -185,7 +185,7 @@ class SDFSImpl : public FSImpl
185185
return (totalClusters() / blocksPerCluster());
186186
}
187187
size_t clusterSize() {
188-
return blocksPerCluster() * 512; // 512b block size
188+
return blocksPerCluster() * _fs.vol()->bytesPerSector();
189189
}
190190
size_t size() {
191191
return (clusterSize() * totalClusters());
@@ -264,7 +264,7 @@ class SDFSImpl : public FSImpl
264264
class SDFSFileImpl : public FileImpl
265265
{
266266
public:
267-
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File> fd, const char *name)
267+
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File32> fd, const char *name)
268268
: _fs(fs), _fd(fd), _opened(true)
269269
{
270270
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
@@ -295,7 +295,6 @@ class SDFSFileImpl : public FileImpl
295295
void flush() override
296296
{
297297
if (_opened) {
298-
_fd->flush();
299298
_fd->sync();
300299
}
301300
}
@@ -375,15 +374,15 @@ class SDFSFileImpl : public FileImpl
375374

376375
bool isDirectory() const override
377376
{
378-
return _opened ? _fd->isDirectory() : false;
377+
return _opened ? _fd->isDir() : false;
379378
}
380379

381380
time_t getLastWrite() override {
382381
time_t ftime = 0;
383382
if (_opened && _fd) {
384-
sdfat::dir_t tmp;
383+
sdfat::DirFat_t tmp;
385384
if (_fd.get()->dirEntry(&tmp)) {
386-
ftime = SDFSImpl::FatToTimeT(tmp.lastWriteDate, tmp.lastWriteTime);
385+
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
387386
}
388387
}
389388
return ftime;
@@ -392,9 +391,9 @@ class SDFSFileImpl : public FileImpl
392391
time_t getCreationTime() override {
393392
time_t ftime = 0;
394393
if (_opened && _fd) {
395-
sdfat::dir_t tmp;
394+
sdfat::DirFat_t tmp;
396395
if (_fd.get()->dirEntry(&tmp)) {
397-
ftime = SDFSImpl::FatToTimeT(tmp.creationDate, tmp.creationTime);
396+
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
398397
}
399398
}
400399
return ftime;
@@ -404,15 +403,15 @@ class SDFSFileImpl : public FileImpl
404403

405404
protected:
406405
SDFSImpl* _fs;
407-
std::shared_ptr<sdfat::File> _fd;
406+
std::shared_ptr<sdfat::File32> _fd;
408407
std::shared_ptr<char> _name;
409408
bool _opened;
410409
};
411410

412411
class SDFSDirImpl : public DirImpl
413412
{
414413
public:
415-
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File> dir, const char *dirPath = nullptr)
414+
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File32> dir, const char *dirPath = nullptr)
416415
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
417416
{
418417
if (dirPath) {
@@ -487,17 +486,17 @@ class SDFSDirImpl : public DirImpl
487486
{
488487
const int n = _pattern.length();
489488
do {
490-
sdfat::File file;
489+
sdfat::File32 file;
491490
file.openNext(_dir.get(), sdfat::O_READ);
492491
if (file) {
493492
_valid = 1;
494493
_size = file.fileSize();
495494
_isFile = file.isFile();
496-
_isDirectory = file.isDirectory();
497-
sdfat::dir_t tmp;
495+
_isDirectory = file.isDir();
496+
sdfat::DirFat_t tmp;
498497
if (file.dirEntry(&tmp)) {
499-
_time = SDFSImpl::FatToTimeT(tmp.lastWriteDate, tmp.lastWriteTime);
500-
_creation = SDFSImpl::FatToTimeT(tmp.creationDate, tmp.creationTime);
498+
_time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
499+
_creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
501500
} else {
502501
_time = 0;
503502
_creation = 0;
@@ -521,7 +520,7 @@ class SDFSDirImpl : public DirImpl
521520
protected:
522521
String _pattern;
523522
SDFSImpl* _fs;
524-
std::shared_ptr<sdfat::File> _dir;
523+
std::shared_ptr<sdfat::File32> _dir;
525524
bool _valid;
526525
char _lfn[64];
527526
time_t _time;

Diff for: libraries/SDFS/src/SDFSFormatter.h

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace sdfs {
3131

3232
class SDFSFormatter {
33+
#if 0
3334
private:
3435
// Taken from main FS object
3536
sdfat::Sd2Card *card;
@@ -397,6 +398,9 @@ class SDFSFormatter {
397398
return makeFat32();
398399
}
399400
}
401+
402+
403+
#endif
400404
}; // class SDFSFormatter
401405

402406
}; // namespace sdfs

Diff for: tests/common.sh

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function skip_ino()
1717
/SoftwareSpi/
1818
/STM32Test/
1919
/extras/
20+
/ESP8266SdFat/
2021
EOL
2122
echo $ino | grep -q -F "$skiplist"
2223
echo $(( 1 - $? ))

Diff for: tests/host/Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ CORE_CPP_FILES := \
103103
FatLib/FatFilePrint.cpp \
104104
FatLib/FatFileSFN.cpp \
105105
FatLib/FatVolume.cpp \
106-
FatLib/FmtNumber.cpp \
107-
FatLib/StdioStream.cpp \
106+
FatLib/FatPartition.cpp \
107+
common/FmtNumber.cpp \
108+
common/FsStructs.cpp \
109+
common/FsDateTime.cpp \
110+
common/PrintBasic.cpp \
111+
SdCard/SdSpiCard.cpp \
112+
SpiDriver/SdSpiESP.cpp \
108113
) \
109114
$(abspath $(LIBRARIES_PATH)/SDFS/src/SDFS.cpp) \
110115
$(abspath $(LIBRARIES_PATH)/SD/src/SD.cpp) \

0 commit comments

Comments
 (0)