Skip to content

Commit a0c01ab

Browse files
committed
Mass rename on sd_sdfat2_esp32.cpp
Remove namespace in common for code simplification
1 parent 2993a5a commit a0c01ab

File tree

3 files changed

+29
-45
lines changed

3 files changed

+29
-45
lines changed

esp3d/src/modules/filesystem/esp_sd.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
6262
#else
6363
#include <FS.h>
6464
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
65-
#endif
65+
#endif*/
6666

6767
#if defined(ESP3DLIB_ENV)
6868
#include "../../include/Marlin/cardreader.h"
@@ -138,7 +138,7 @@ bool ESP_SD::disableSharedSD() {
138138
bool ESP_SD::_started = false;
139139
uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT;
140140
uint8_t ESP_SD::_spi_speed_divider = 1;
141-
*/
141+
142142

143143
bool ESP_SD::_sizechanged = true;
144144
uint8_t ESP_SD::setState(uint8_t flag) {

esp3d/src/modules/filesystem/sd/esp_sd_common.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#define ESP_MAX_SD_OPENHANDLE 4
2727

28-
namespace ESP3D_SD {
2928

3029
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
3130
#define FS_NO_GLOBALS
@@ -87,6 +86,4 @@ using ESP3D_SD_Class = SDMMCFS;
8786

8887

8988
extern ESP3D_SD_Class ESP3D_SD_Card;
90-
extern ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
91-
92-
}
89+
extern ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];

esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp

+26-39
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,11 @@ sd_sdfat2_esp32.cpp - ESP3D sd support class
2121
#if defined(ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
2222
#if (SD_DEVICE == ESP_SDFAT2)
2323

24-
#include <SdFat.h>
2524
#include <sdios.h>
26-
2725
#include <stack>
28-
2926
#include "../../../core/esp3d_settings.h"
3027
#include "../esp_sd.h"
3128

32-
#if SDFAT_FILE_TYPE == 1
33-
typedef File32 File;
34-
#elif SDFAT_FILE_TYPE == 2
35-
typedef ExFile File;
36-
#elif SDFAT_FILE_TYPE == 3
37-
typedef FsFile File;
38-
#else // SDFAT_FILE_TYPE
39-
#error Invalid SDFAT_FILE_TYPE
40-
#endif // SDFAT_FILE_TYPE
41-
4229
// Try to select the best SD card configuration.
4330
#if HAS_SDIO_CLASS
4431
#define SD_CONFIG SdioConfig(FIFO_SDIO)
@@ -50,11 +37,11 @@ typedef FsFile File;
5037
SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SHARED_SPI)
5138
#endif // HAS_SDIO_CLASS
5239

53-
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
40+
ESP3D_SD_Class ESP3D_SD_Card;
41+
ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
5442

5543
// Max Freq Working
5644
#define FREQMZ 40
57-
SdFat SD;
5845
#undef FILE_WRITE
5946
#undef FILE_READ
6047
#undef FILE_APPEND
@@ -72,7 +59,7 @@ void dateTime(uint16_t* date, uint16_t* dtime) {
7259
*dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
7360
}
7461

75-
time_t getDateTimeFile(File& filehandle) {
62+
time_t getDateTimeFile(ESP3D_File& filehandle) {
7663
static time_t dt = 0;
7764
#ifdef SD_TIMESTAMP_FEATURE
7865
struct tm timefile;
@@ -127,7 +114,7 @@ uint8_t ESP_SD::getState(bool refresh) {
127114
ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI,
128115
ESP_SD_SCK_PIN != -1 ? ESP_SD_SCK_PIN : SCK);
129116
// refresh content if card was removed
130-
if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN,
117+
if (ESP3D_SD_Card.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN,
131118
SD_SCK_MHZ(FREQMZ / _spi_speed_divider))) {
132119
_state = ESP_SDCARD_IDLE;
133120
}
@@ -180,12 +167,12 @@ void ESP_SD::refreshStats(bool force) {
180167

181168
uint64_t ESP_SD::totalBytes(bool refresh) {
182169
static uint64_t _totalBytes = 0;
183-
if (!SD.volumeBegin()) {
170+
if (!ESP3D_SD_Card.volumeBegin()) {
184171
return 0;
185172
}
186173
if (refresh || _totalBytes == 0) {
187-
_totalBytes = SD.clusterCount();
188-
uint8_t sectors = SD.sectorsPerCluster();
174+
_totalBytes = ESP3D_SD_Card.clusterCount();
175+
uint8_t sectors = ESP3D_SD_Card.sectorsPerCluster();
189176
_totalBytes = _totalBytes * sectors * 512;
190177
}
191178
return _totalBytes;
@@ -197,12 +184,12 @@ uint64_t ESP_SD::usedBytes(bool refresh) {
197184

198185
uint64_t ESP_SD::freeBytes(bool refresh) {
199186
static uint64_t _freeBytes = 0;
200-
if (!SD.volumeBegin()) {
187+
if (!ESP3D_SD_Card.volumeBegin()) {
201188
return 0;
202189
}
203190
if (refresh || _freeBytes == 0) {
204-
_freeBytes = SD.freeClusterCount();
205-
uint8_t sectors = SD.sectorsPerCluster();
191+
_freeBytes = ESP3D_SD_Card.freeClusterCount();
192+
uint8_t sectors = ESP3D_SD_Card.sectorsPerCluster();
206193
_freeBytes = _freeBytes * sectors * 512;
207194
}
208195
return _freeBytes;
@@ -211,7 +198,7 @@ uint64_t ESP_SD::freeBytes(bool refresh) {
211198
uint ESP_SD::maxPathLength() { return 255; }
212199

213200
bool ESP_SD::rename(const char* oldpath, const char* newpath) {
214-
return SD.rename(oldpath, newpath);
201+
return ESP3D_SD_Card.rename(oldpath, newpath);
215202
}
216203

217204
bool ESP_SD::format() {
@@ -305,7 +292,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
305292
return ESP_SDFile();
306293
}
307294
}
308-
File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
295+
ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ
309296
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
310297
: FILE_WRITE);
311298
if (tmp) {
@@ -325,7 +312,7 @@ bool ESP_SD::exists(const char* path) {
325312
if (strcmp(path, "/") == 0) {
326313
return _started;
327314
}
328-
res = SD.exists(path);
315+
res = ESP3D_SD_Card.exists(path);
329316
if (!res) {
330317
ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ);
331318
if (root) {
@@ -337,10 +324,10 @@ bool ESP_SD::exists(const char* path) {
337324

338325
bool ESP_SD::remove(const char* path) {
339326
_sizechanged = true;
340-
return SD.remove(path);
327+
return ESP3D_SD_Card.remove(path);
341328
}
342329

343-
bool ESP_SD::mkdir(const char* path) { return SD.mkdir(path); }
330+
bool ESP_SD::mkdir(const char* path) { return ESP3D_SD_Card.mkdir(path); }
344331

345332
bool ESP_SD::rmdir(const char* path) {
346333
String p = path;
@@ -357,9 +344,9 @@ bool ESP_SD::rmdir(const char* path) {
357344
std::stack<String> pathlist;
358345
pathlist.push(p);
359346
while (pathlist.size() > 0 && res) {
360-
File dir = SD.open(pathlist.top().c_str());
347+
ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str());
361348
dir.rewindDirectory();
362-
File f = dir.openNextFile();
349+
ESP3D_File f = dir.openNextFile();
363350
bool candelete = true;
364351
while (f && res) {
365352
if (f.isDir()) {
@@ -371,22 +358,22 @@ bool ESP_SD::rmdir(const char* path) {
371358
newdir += "/";
372359
pathlist.push(newdir);
373360
f.close();
374-
f = File();
361+
f = ESP3D_File();
375362
} else {
376363
char tmp[255];
377364
f.getName(tmp, 254);
378365
_sizechanged = true;
379366
String filepath = pathlist.top() + tmp;
380367
f.close();
381-
if (!SD.remove(filepath.c_str())) {
368+
if (!ESP3D_SD_Card.remove(filepath.c_str())) {
382369
res = false;
383370
}
384371
f = dir.openNextFile();
385372
}
386373
}
387374
if (candelete) {
388375
if (pathlist.top() != "/") {
389-
res = SD.rmdir(pathlist.top().c_str());
376+
res = ESP3D_SD_Card.rmdir(pathlist.top().c_str());
390377
}
391378
pathlist.pop();
392379
}
@@ -400,7 +387,7 @@ bool ESP_SD::rmdir(const char* path) {
400387
void ESP_SD::closeAll() {
401388
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
402389
tSDFile_handle[i].close();
403-
tSDFile_handle[i] = File();
390+
tSDFile_handle[i] = ESP3D_File();
404391
}
405392
}
406393

@@ -427,7 +414,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode,
427414
bool set = false;
428415
for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
429416
if (!tSDFile_handle[i]) {
430-
tSDFile_handle[i] = *((File*)handle);
417+
tSDFile_handle[i] = *((ESP3D_File*)handle);
431418
// filename
432419
char tmp[255];
433420
tSDFile_handle[i].getName(tmp, 254);
@@ -470,7 +457,7 @@ const char* ESP_SDFile::shortname() const {
470457
return _name.c_str();
471458
#else
472459
static char sname[13];
473-
File ftmp = SD.open(_filename.c_str());
460+
ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str());
474461
if (ftmp) {
475462
ftmp.getSFN(sname, 12);
476463
ftmp.close();
@@ -491,14 +478,14 @@ void ESP_SDFile::close() {
491478
// reopen if mode = write
492479
// udate size + date
493480
if (_iswritemode && !_isdir) {
494-
File ftmp = SD.open(_filename.c_str());
481+
ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str());
495482
if (ftmp) {
496483
_size = ftmp.size();
497484
_lastwrite = getDateTimeFile(ftmp);
498485
ftmp.close();
499486
}
500487
}
501-
tSDFile_handle[_index] = File();
488+
tSDFile_handle[_index] = ESP3D_File();
502489
// esp3d_log("Closing File at index %d",_index);
503490
_index = -1;
504491
}
@@ -509,7 +496,7 @@ ESP_SDFile ESP_SDFile::openNextFile() {
509496
esp3d_log("openNextFile failed");
510497
return ESP_SDFile();
511498
}
512-
File tmp = tSDFile_handle[_index].openNextFile();
499+
ESP3D_File tmp = tSDFile_handle[_index].openNextFile();
513500
if (tmp) {
514501
char tmps[255];
515502
tmp.getName(tmps, 254);

0 commit comments

Comments
 (0)