Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc487ca5

Browse files
Update to SdFat 2.0.2, speed SD access (#7779)
* Update to upstream SdFat 2.0.2Increases the read/write performance for SD card accessesby a significant amount, up to 5x (3+MB/s) in testing.Fixes#7772 * Add SDFS::availableForWrite handlerPeek into the sector cache to determine the maximum number ofbytes that can be written w/o needing a (slow) SD operation.Fixes#7650
1 parent9de8373 commitc487ca5

File tree

7 files changed

+58
-452
lines changed

7 files changed

+58
-452
lines changed

‎libraries/ESP8266SdFat‎

SubmoduleESP8266SdFat updated1282 files

‎libraries/SD/src/SD.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

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

‎libraries/SDFS/src/SDFS.cpp‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2626
*/
2727
#include"SDFS.h"
28-
#include"SDFSFormatter.h"
2928
#include<FS.h>
3029

3130
usingnamespacefs;
@@ -65,13 +64,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
6564
}
6665
free(pathStr);
6766
}
68-
sdfat::File fd = _fs.open(path, flags);
67+
sdfat::File32 fd = _fs.open(path, flags);
6968
if (!fd) {
7069
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
7170
&fd, path, openMode, accessMode);
7271
returnFileImplPtr();
7372
}
74-
auto sharedFd = std::make_shared<sdfat::File>(fd);
73+
auto sharedFd = std::make_shared<sdfat::File32>(fd);
7574
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
7675
}
7776

@@ -91,7 +90,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
9190
}
9291
// At this point we have a name of "/blah/blah/blah" or "blah" or ""
9392
// If that references a directory, just open it and we're done.
94-
sdfat::File dirFile;
93+
sdfat::File32 dirFile;
9594
constchar *filter ="";
9695
if (!pathStr[0]) {
9796
// openDir("") === openDir("/")
@@ -136,7 +135,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
136135
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
137136
returnDirImplPtr();
138137
}
139-
auto sharedDir = std::make_shared<sdfat::File>(dirFile);
138+
auto sharedDir = std::make_shared<sdfat::File32>(dirFile);
140139
auto ret = std::make_shared<SDFSDirImpl>(filter,this, sharedDir, pathStr);
141140
free(pathStr);
142141
return ret;
@@ -146,8 +145,15 @@ bool SDFSImpl::format() {
146145
if (_mounted) {
147146
returnfalse;
148147
}
149-
SDFSFormatter formatter;
150-
bool ret = formatter.format(&_fs, _cfg._csPin, _cfg._spiSettings);
148+
sdfat::SdCardFactory cardFactory;
149+
sdfat::SdCard* card = cardFactory.newCard(sdfat::SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
150+
if (!card || card->errorCode()) {
151+
returnfalse;
152+
}
153+
sdfat::FatFormatter fatFormatter;
154+
uint8_t *sectorBuffer =newuint8_t[512];
155+
bool ret = fatFormatter.format(card, sectorBuffer,nullptr);
156+
delete[] sectorBuffer;
151157
return ret;
152158
}
153159

‎libraries/SDFS/src/SDFS.h‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SDFSConfig : public FSConfig
4747
public:
4848
staticconstexpruint32_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
SDFSConfigsetAutoFormat(bool val =true) {
5353
_autoFormat = val;
@@ -57,7 +57,7 @@ class SDFSConfig : public FSConfig
5757
_csPin = pin;
5858
return *this;
5959
}
60-
SDFSConfigsetSPI(SPISettings spi) {
60+
SDFSConfigsetSPI(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
classSDFSImpl :publicFSImpl
@@ -97,11 +97,11 @@ class SDFSImpl : public FSImpl
9797
returnfalse;
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
returntrue;
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_tblocksPerCluster() {
179-
return _fs.vol()->blocksPerCluster();
179+
return _fs.vol()->sectorsPerCluster();
180180
}
181181
size_ttotalClusters() {
182182
return _fs.vol()->clusterCount();
@@ -185,7 +185,7 @@ class SDFSImpl : public FSImpl
185185
return (totalClusters() /blocksPerCluster());
186186
}
187187
size_tclusterSize() {
188-
returnblocksPerCluster() *512;// 512b block size
188+
returnblocksPerCluster() *_fs.vol()->bytesPerSector();
189189
}
190190
size_tsize() {
191191
return (clusterSize() *totalClusters());
@@ -264,7 +264,7 @@ class SDFSImpl : public FSImpl
264264
classSDFSFileImpl :publicFileImpl
265265
{
266266
public:
267-
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File> fd,constchar *name)
267+
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File32> fd,constchar *name)
268268
: _fs(fs), _fd(fd), _opened(true)
269269
{
270270
_name = std::shared_ptr<char>(newchar[strlen(name) +1], std::default_delete<char[]>());
@@ -279,7 +279,7 @@ class SDFSFileImpl : public FileImpl
279279

280280
intavailableForWrite()override
281281
{
282-
return _opened ? _fd->availableForWrite() :0;
282+
return _opened ? _fd->availableSpaceForWrite() :0;
283283
}
284284

285285
size_twrite(constuint8_t *buf,size_t size)override
@@ -295,7 +295,6 @@ class SDFSFileImpl : public FileImpl
295295
voidflush()override
296296
{
297297
if (_opened) {
298-
_fd->flush();
299298
_fd->sync();
300299
}
301300
}
@@ -375,15 +374,15 @@ class SDFSFileImpl : public FileImpl
375374

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

381380
time_tgetLastWrite()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,27 +391,25 @@ class SDFSFileImpl : public FileImpl
392391
time_tgetCreationTime()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;
401400
}
402401

403-
404-
405402
protected:
406403
SDFSImpl* _fs;
407-
std::shared_ptr<sdfat::File> _fd;
404+
std::shared_ptr<sdfat::File32> _fd;
408405
std::shared_ptr<char> _name;
409406
bool _opened;
410407
};
411408

412409
classSDFSDirImpl :publicDirImpl
413410
{
414411
public:
415-
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File> dir,constchar *dirPath =nullptr)
412+
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File32> dir,constchar *dirPath =nullptr)
416413
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
417414
{
418415
if (dirPath) {
@@ -487,17 +484,17 @@ class SDFSDirImpl : public DirImpl
487484
{
488485
constint n = _pattern.length();
489486
do {
490-
sdfat::File file;
487+
sdfat::File32 file;
491488
file.openNext(_dir.get(), sdfat::O_READ);
492489
if (file) {
493490
_valid =1;
494491
_size = file.fileSize();
495492
_isFile = file.isFile();
496-
_isDirectory = file.isDirectory();
497-
sdfat::dir_t tmp;
493+
_isDirectory = file.isDir();
494+
sdfat::DirFat_t tmp;
498495
if (file.dirEntry(&tmp)) {
499-
_time =SDFSImpl::FatToTimeT(tmp.lastWriteDate,tmp.lastWriteTime);
500-
_creation =SDFSImpl::FatToTimeT(tmp.creationDate,tmp.creationTime);
496+
_time =SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
497+
_creation =SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
501498
}else {
502499
_time =0;
503500
_creation =0;
@@ -521,7 +518,7 @@ class SDFSDirImpl : public DirImpl
521518
protected:
522519
String _pattern;
523520
SDFSImpl* _fs;
524-
std::shared_ptr<sdfat::File> _dir;
521+
std::shared_ptr<sdfat::File32> _dir;
525522
bool _valid;
526523
char _lfn[64];
527524
time_t _time;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp