Skip to content

Commit a918c7d

Browse files
committed
Fix SDIO
Fix typo in esp32 native
1 parent b372f9b commit a918c7d

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ using ESP3D_SD_Class = fs::SDFS;
7676
#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32
7777

7878
#if (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32)
79-
#define FS_NO_GLOBALS
80-
#define NO_GLOBAL_SD
8179
#include <FS.h>
8280
#include <SD_MMC.h>
8381
using ESP3D_File = fs::File;
84-
using ESP3D_SD_Class = SDMMCFS;
82+
using ESP3D_SD_Class = fs::SDMMCFS;
8583
#endif // (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32
8684

8785

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ bool ESP_SD::rmdir(const char *path) {
243243
newdir += f.name();
244244
pathlist.push(newdir);
245245
f.close();
246-
f = File();
246+
f =ESP3D_File();
247247
} else {
248248
String filepath = pathlist.top() + '/';
249249
filepath += f.name();
@@ -270,7 +270,7 @@ bool ESP_SD::rmdir(const char *path) {
270270
void ESP_SD::closeAll() {
271271
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
272272
tSDFile_handle[i].close();
273-
tSDFile_handle[i] = File();
273+
tSDFile_handle[i] =ESP3D_File();
274274
}
275275
}
276276

@@ -337,7 +337,7 @@ void ESP_SDFile::close() {
337337
ftmp.close();
338338
}
339339
}
340-
tSDFile_handle[_index] = File();
340+
tSDFile_handle[_index] =ESP3D_File();
341341
// esp3d_log("Closing File at index %d",_index);
342342
_index = -1;
343343
}

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

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ sdio_esp32.cpp - ESP3D sd support class
2424

2525
#include "../../../core/esp3d_settings.h"
2626
#include "../esp_sd.h"
27-
#include "FS.h"
28-
#include "SD_MMC.h"
2927

30-
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
28+
ESP3D_SD_Class ESP3D_SD_Card = SD_MMC;
29+
ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
3130

3231
#define SDMMC_FORCE_BEGIN
3332

@@ -60,10 +59,10 @@ uint8_t ESP_SD::getState(bool refresh) {
6059
// refresh content if card was removed
6160
if (!lastinitok) {
6261
esp3d_log("last init was failed try sd_mmc begin");
63-
SD_MMC.end();
64-
if (SD_MMC.begin("/sdcard", SDIO_BIT_MODE)) {
62+
ESP3D_SD_Card.end();
63+
if (ESP3D_SD_Card.begin("/sdcard", SDIO_BIT_MODE)) {
6564
esp3d_log("sd_mmc begin succeed");
66-
if (SD_MMC.cardType() != CARD_NONE) {
65+
if (ESP3D_SD_Card.cardType() != CARD_NONE) {
6766
_state = ESP_SDCARD_IDLE;
6867
lastinitok = true;
6968
esp3d_log("sd_mmc card type succeed");
@@ -75,16 +74,16 @@ uint8_t ESP_SD::getState(bool refresh) {
7574
}
7675
} else {
7776
esp3d_log("last init was ok try card type");
78-
if (SD_MMC.cardType() != CARD_NONE) {
77+
if (ESP3D_SD_Card.cardType() != CARD_NONE) {
7978
esp3d_log("checking sd_mmc card type succeed");
8079
_state = ESP_SDCARD_IDLE;
8180
} else {
8281
lastinitok = false;
8382
esp3d_log_e("Soft sd check failed");
84-
SD_MMC.end();
85-
if (SD_MMC.begin("/sdcard", SDIO_BIT_MODE)) {
83+
ESP3D_SD_Card.end();
84+
if (ESP3D_SD_Card.begin("/sdcard", SDIO_BIT_MODE)) {
8685
esp3d_log("new sd_mmc begin succeed");
87-
if (SD_MMC.cardType() != CARD_NONE) {
86+
if (ESP3D_SD_Card.cardType() != CARD_NONE) {
8887
_state = ESP_SDCARD_IDLE;
8988
lastinitok = true;
9089
esp3d_log("new sd_mmc card type succeed");
@@ -103,13 +102,13 @@ bool ESP_SD::begin() {
103102
#if SDIO_BIT_MODE == SD_ONE_BIT_MODE
104103
#if (ESP_SDIO_CLK_PIN != -1) || (ESP_SDIO_CMD_PIN != -1) || \
105104
(ESP_SDIO_D0_PIN != -1)
106-
SD_MMC.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN);
105+
ESP3D_SD_Card.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN);
107106
#endif //(ESP_SDIO_CLK_PIN != -1)
108107
#else
109108
#if (ESP_SDIO_CLK_PIN != -1) || (ESP_SDIO_CMD_PIN != -1) || \
110109
(ESP_SDIO_D0_PIN != -1) || (ESP_SDIO_D1_PIN != -1) || \
111110
(ESP_SDIO_D2_PIN != -1) || (ESP_SDIO_D3_PIN != -1)
112-
SD_MMC.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN,
111+
ESP3D_SD_Card.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN,
113112
ESP_SDIO_D1_PIN, ESP_SDIO_D2_PIN, ESP_SDIO_D3_PIN);
114113
#endif //(ESP_SDIO_CLK_PIN != -1)
115114
#endif // SD_ONE_BIT_MODE
@@ -125,7 +124,7 @@ bool ESP_SD::begin() {
125124
}
126125

127126
void ESP_SD::end() {
128-
SD_MMC.end();
127+
ESP3D_SD_Card.end();
129128
_state = ESP_SDCARD_NOT_PRESENT;
130129
_started = false;
131130
}
@@ -140,7 +139,7 @@ void ESP_SD::refreshStats(bool force) {
140139
uint64_t ESP_SD::totalBytes(bool refresh) {
141140
static uint64_t _totalBytes = 0;
142141
if (refresh || _totalBytes == 0) {
143-
_totalBytes = SD_MMC.totalBytes();
142+
_totalBytes = ESP3D_SD_Card.totalBytes();
144143
;
145144
}
146145
return _totalBytes;
@@ -149,7 +148,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) {
149148
uint64_t ESP_SD::usedBytes(bool refresh) {
150149
static uint64_t _usedBytes = 0;
151150
if (refresh || _usedBytes == 0) {
152-
_usedBytes = SD_MMC.usedBytes();
151+
_usedBytes = ESP3D_SD_Card.usedBytes();
153152
}
154153
return _usedBytes;
155154
}
@@ -161,7 +160,7 @@ uint64_t ESP_SD::freeBytes(bool refresh) {
161160
uint ESP_SD::maxPathLength() { return 255; }
162161

163162
bool ESP_SD::rename(const char *oldpath, const char *newpath) {
164-
return SD_MMC.rename(oldpath, newpath);
163+
return ESP3D_SD_Card.rename(oldpath, newpath);
165164
}
166165

167166
bool ESP_SD::format() {
@@ -193,7 +192,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
193192
return ESP_SDFile();
194193
}
195194
}
196-
File tmp = SD_MMC.open(path, (mode == ESP_FILE_READ) ? FILE_READ
195+
ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ
197196
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
198197
: FILE_APPEND);
199198
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),
@@ -212,7 +211,7 @@ bool ESP_SD::exists(const char *path) {
212211
if (p.endsWith("/")) {
213212
p.remove(p.length() - 1, 1);
214213
}
215-
res = SD_MMC.exists(p);
214+
res = ESP3D_SD_Card.exists(p);
216215
if (!res) {
217216
ESP_SDFile root = ESP_SD::open(p.c_str(), ESP_FILE_READ);
218217
if (root) {
@@ -222,14 +221,14 @@ bool ESP_SD::exists(const char *path) {
222221
return res;
223222
}
224223

225-
bool ESP_SD::remove(const char *path) { return SD_MMC.remove(path); }
224+
bool ESP_SD::remove(const char *path) { return ESP3D_SD_Card.remove(path); }
226225

227226
bool ESP_SD::mkdir(const char *path) {
228227
String p = path;
229228
if (p.endsWith("/")) {
230229
p.remove(p.length() - 1, 1);
231230
}
232-
return SD_MMC.mkdir(p.c_str());
231+
return ESP3D_SD_Card.mkdir(p.c_str());
233232
}
234233

235234
bool ESP_SD::rmdir(const char *path) {
@@ -244,8 +243,8 @@ bool ESP_SD::rmdir(const char *path) {
244243
}
245244
pathlist.push(p);
246245
while (pathlist.size() > 0 && res) {
247-
File dir = SD_MMC.open(pathlist.top().c_str());
248-
File f = dir.openNextFile();
246+
ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str());
247+
ESP3D_File f = dir.openNextFile();
249248
bool candelete = true;
250249
while (f && res) {
251250
if (f.isDirectory()) {
@@ -254,20 +253,20 @@ bool ESP_SD::rmdir(const char *path) {
254253
newdir += f.name();
255254
pathlist.push(newdir);
256255
f.close();
257-
f = File();
256+
f =ESP3D_File();
258257
} else {
259258
String filepath = pathlist.top() + '/';
260259
filepath += f.name();
261260
f.close();
262-
if (!SD_MMC.remove(filepath.c_str())) {
261+
if (!ESP3D_SD_Card.remove(filepath.c_str())) {
263262
res = false;
264263
}
265264
f = dir.openNextFile();
266265
}
267266
}
268267
if (candelete) {
269268
if (pathlist.top() != "/") {
270-
res = SD_MMC.rmdir(pathlist.top().c_str());
269+
res = ESP3D_SD_Card.rmdir(pathlist.top().c_str());
271270
}
272271
pathlist.pop();
273272
}
@@ -281,7 +280,7 @@ bool ESP_SD::rmdir(const char *path) {
281280
void ESP_SD::closeAll() {
282281
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
283282
tSDFile_handle[i].close();
284-
tSDFile_handle[i] = File();
283+
tSDFile_handle[i] =ESP3D_File();
285284
}
286285
}
287286

@@ -301,7 +300,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
301300
bool set = false;
302301
for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
303302
if (!tSDFile_handle[i]) {
304-
tSDFile_handle[i] = *((File *)handle);
303+
tSDFile_handle[i] = *((ESP3D_File *)handle);
305304
// filename
306305
_name = tSDFile_handle[i].name();
307306
_filename = path;
@@ -331,7 +330,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
331330
}
332331

333332
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) {
334-
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
333+
return tSDFile_handle[_index].seek(pos, (fs::SeekMode)mode);
335334
}
336335

337336
void ESP_SDFile::close() {
@@ -341,14 +340,14 @@ void ESP_SDFile::close() {
341340
// reopen if mode = write
342341
// udate size + date
343342
if (_iswritemode && !_isdir) {
344-
File ftmp = SD_MMC.open(_filename.c_str());
343+
ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str());
345344
if (ftmp) {
346345
_size = ftmp.size();
347346
_lastwrite = ftmp.getLastWrite();
348347
ftmp.close();
349348
}
350349
}
351-
tSDFile_handle[_index] = File();
350+
tSDFile_handle[_index] =ESP3D_File();
352351
// esp3d_log("Closing File at index %d",_index);
353352
_index = -1;
354353
}
@@ -359,7 +358,7 @@ ESP_SDFile ESP_SDFile::openNextFile() {
359358
esp3d_log("openNextFile failed");
360359
return ESP_SDFile();
361360
}
362-
File tmp = tSDFile_handle[_index].openNextFile();
361+
ESP3D_File tmp = tSDFile_handle[_index].openNextFile();
363362
if (tmp) {
364363
esp3d_log("tmp name :%s %s %s", tmp.name(),
365364
(tmp.isDirectory()) ? "isDir" : "isFile", _filename.c_str());

0 commit comments

Comments
 (0)