Skip to content
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
20 changes: 13 additions & 7 deletions libraries/SDFS/src/SDFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "SDFS.h"
#include "SDFSFormatter.h"
#include <FS.h>

using namespace fs;
Expand Down Expand Up @@ -65,13 +64,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 +90,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 +135,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,8 +145,15 @@ bool SDFSImpl::format() {
if (_mounted) {
return false;
}
SDFSFormatter formatter;
bool ret = formatter.format(&_fs, _cfg._csPin, _cfg._spiSettings);
sdfat::SdCardFactory cardFactory;
sdfat::SdCard* card = cardFactory.newCard(sdfat::SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
if (!card || card->errorCode()) {
return false;
}
sdfat::FatFormatter fatFormatter;
uint8_t *sectorBuffer = new uint8_t[512];
bool ret = fatFormatter.format(card, sectorBuffer, nullptr);
delete[] sectorBuffer;
return ret;
}

Expand Down
55 changes: 26 additions & 29 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 All @@ -279,7 +279,7 @@ class SDFSFileImpl : public FileImpl

int availableForWrite() override
{
return _opened ? _fd->availableForWrite() : 0;
return _opened ? _fd->availableSpaceForWrite() : 0;
}

size_t write(const uint8_t *buf, size_t size) override
Expand All @@ -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,27 +391,25 @@ 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;
}



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 +484,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 +518,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
Loading