@@ -24,14 +24,13 @@ sd_native_esp32.cpp - ESP3D sd support class
24
24
25
25
#include " ../../../core/esp3d_settings.h"
26
26
#include " ../esp_sd.h"
27
- #include " FS.h"
28
- #include " SD.h"
29
27
30
28
// TBC: base frequency
31
29
// or use (1000000 * ESP.getCpuFreqMHz())
32
30
#define ESP_SPI_FREQ 4000000
33
31
34
- extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
32
+ ESP3D_SD_Class ESP3D_SD_Card = SD;
33
+ ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
35
34
36
35
uint8_t ESP_SD::getState (bool refresh) {
37
36
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
@@ -53,7 +52,7 @@ uint8_t ESP_SD::getState(bool refresh) {
53
52
}
54
53
// SD is idle or not detected, let see if still the case
55
54
56
- SD .end ();
55
+ ESP3D_SD_Card .end ();
57
56
_state = ESP_SDCARD_NOT_PRESENT;
58
57
// using default value for speed ? should be parameter
59
58
// refresh content if card was removed
@@ -62,9 +61,9 @@ uint8_t ESP_SD::getState(bool refresh) {
62
61
ESP_SD_MISO_PIN != -1 ? ESP_SD_MISO_PIN : MISO,
63
62
ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI,
64
63
ESP_SD_SCK_PIN != -1 ? ESP_SD_SCK_PIN : SCK);
65
- if (SD .begin ((ESP_SD_CS_PIN == -1 ) ? SS : ESP_SD_CS_PIN, SPI,
64
+ if (ESP3D_SD_Card .begin ((ESP_SD_CS_PIN == -1 ) ? SS : ESP_SD_CS_PIN, SPI,
66
65
ESP_SPI_FREQ / _spi_speed_divider)) {
67
- if (SD .cardSize () > 0 ) {
66
+ if (ESP3D_SD_Card .cardSize () > 0 ) {
68
67
_state = ESP_SDCARD_IDLE;
69
68
}
70
69
}
@@ -114,7 +113,7 @@ bool ESP_SD::begin() {
114
113
}
115
114
116
115
void ESP_SD::end () {
117
- SD .end ();
116
+ ESP3D_SD_Card .end ();
118
117
_state = ESP_SDCARD_NOT_PRESENT;
119
118
_started = false ;
120
119
}
@@ -129,7 +128,7 @@ void ESP_SD::refreshStats(bool force) {
129
128
uint64_t ESP_SD::totalBytes (bool refresh) {
130
129
static uint64_t _totalBytes = 0 ;
131
130
if (refresh || _totalBytes == 0 ) {
132
- _totalBytes = SD .totalBytes ();
131
+ _totalBytes = ESP3D_SD_Card .totalBytes ();
133
132
;
134
133
}
135
134
return _totalBytes;
@@ -138,7 +137,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) {
138
137
uint64_t ESP_SD::usedBytes (bool refresh) {
139
138
static uint64_t _usedBytes = 0 ;
140
139
if (refresh || _usedBytes == 0 ) {
141
- _usedBytes = SD .usedBytes ();
140
+ _usedBytes = ESP3D_SD_Card .usedBytes ();
142
141
}
143
142
return _usedBytes;
144
143
}
@@ -151,7 +150,7 @@ uint ESP_SD::maxPathLength() { return 255; }
151
150
152
151
bool ESP_SD::rename (const char *oldpath, const char *newpath) {
153
152
esp3d_log (" rename %s to %s" , oldpath, newpath);
154
- return SD .rename (oldpath, newpath);
153
+ return ESP3D_SD_Card .rename (oldpath, newpath);
155
154
}
156
155
157
156
bool ESP_SD::format () {
@@ -180,7 +179,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
180
179
return ESP_SDFile ();
181
180
}
182
181
}
183
- File tmp = SD .open (path, (mode == ESP_FILE_READ) ? FILE_READ
182
+ ESP3D_File tmp = ESP3D_SD_Card .open (path, (mode == ESP_FILE_READ) ? FILE_READ
184
183
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
185
184
: FILE_APPEND);
186
185
ESP_SDFile esptmp (&tmp, tmp.isDirectory (),
@@ -198,23 +197,23 @@ bool ESP_SD::exists(const char *path) {
198
197
if (p.endsWith (" /" )) {
199
198
p.remove (p.length () - 1 , 1 );
200
199
}
201
- res = SD .exists (p);
200
+ res = ESP3D_SD_Card .exists (p);
202
201
if (!res) {
203
202
// check if it is a directory
204
203
p += ' /' ;
205
- res = SD .exists (p);
204
+ res = ESP3D_SD_Card .exists (p);
206
205
}
207
206
return res;
208
207
}
209
208
210
- bool ESP_SD::remove (const char *path) { return SD .remove (path); }
209
+ bool ESP_SD::remove (const char *path) { return ESP3D_SD_Card .remove (path); }
211
210
212
211
bool ESP_SD::mkdir (const char *path) {
213
212
String p = path;
214
213
if (p.endsWith (" /" )) {
215
214
p.remove (p.length () - 1 , 1 );
216
215
}
217
- return SD .mkdir (p.c_str ());
216
+ return ESP3D_SD_Card .mkdir (p.c_str ());
218
217
}
219
218
220
219
bool ESP_SD::rmdir (const char *path) {
@@ -234,8 +233,8 @@ bool ESP_SD::rmdir(const char *path) {
234
233
std::stack<String> pathlist;
235
234
pathlist.push (p);
236
235
while (pathlist.size () > 0 && res) {
237
- File dir = SD .open (pathlist.top ().c_str ());
238
- File f = dir.openNextFile ();
236
+ ESP3D_File dir = ESP3D_SD_Card .open (pathlist.top ().c_str ());
237
+ ESP3D_File f = dir.openNextFile ();
239
238
bool candelete = true ;
240
239
while (f && res) {
241
240
if (f.isDirectory ()) {
@@ -244,20 +243,20 @@ bool ESP_SD::rmdir(const char *path) {
244
243
newdir += f.name ();
245
244
pathlist.push (newdir);
246
245
f.close ();
247
- f = File ();
246
+ f =ESP3D_File ();
248
247
} else {
249
248
String filepath = pathlist.top () + ' /' ;
250
249
filepath += f.name ();
251
250
f.close ();
252
- if (!SD .remove (filepath.c_str ())) {
251
+ if (!ESP3D_SD_Card .remove (filepath.c_str ())) {
253
252
res = false ;
254
253
}
255
254
f = dir.openNextFile ();
256
255
}
257
256
}
258
257
if (candelete) {
259
258
if (pathlist.top () != " /" ) {
260
- res = SD .rmdir (pathlist.top ().c_str ());
259
+ res = ESP3D_SD_Card .rmdir (pathlist.top ().c_str ());
261
260
}
262
261
pathlist.pop ();
263
262
}
@@ -271,7 +270,7 @@ bool ESP_SD::rmdir(const char *path) {
271
270
void ESP_SD::closeAll () {
272
271
for (uint8_t i = 0 ; i < ESP_MAX_SD_OPENHANDLE; i++) {
273
272
tSDFile_handle[i].close ();
274
- tSDFile_handle[i] = File ();
273
+ tSDFile_handle[i] =ESP3D_File ();
275
274
}
276
275
}
277
276
@@ -291,7 +290,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
291
290
bool set = false ;
292
291
for (uint8_t i = 0 ; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
293
292
if (!tSDFile_handle[i]) {
294
- tSDFile_handle[i] = *((File *)handle);
293
+ tSDFile_handle[i] = *((ESP3D_File *)handle);
295
294
// filename
296
295
_name = tSDFile_handle[i].name ();
297
296
_filename = path;
@@ -331,14 +330,14 @@ void ESP_SDFile::close() {
331
330
// reopen if mode = write
332
331
// udate size + date
333
332
if (_iswritemode && !_isdir) {
334
- File ftmp = SD .open (_filename.c_str ());
333
+ ESP3D_File ftmp = ESP3D_SD_Card .open (_filename.c_str ());
335
334
if (ftmp) {
336
335
_size = ftmp.size ();
337
336
_lastwrite = ftmp.getLastWrite ();
338
337
ftmp.close ();
339
338
}
340
339
}
341
- tSDFile_handle[_index] = File ();
340
+ tSDFile_handle[_index] =ESP3D_File ();
342
341
// esp3d_log("Closing File at index %d",_index);
343
342
_index = -1 ;
344
343
}
@@ -349,7 +348,7 @@ ESP_SDFile ESP_SDFile::openNextFile() {
349
348
esp3d_log (" openNextFile failed" );
350
349
return ESP_SDFile ();
351
350
}
352
- File tmp = tSDFile_handle[_index].openNextFile ();
351
+ ESP3D_File tmp = tSDFile_handle[_index].openNextFile ();
353
352
if (tmp) {
354
353
esp3d_log (" tmp name :%s %s %s" , tmp.name (),
355
354
(tmp.isDirectory ()) ? " isDir" : " isFile" , _filename.c_str ());
0 commit comments