@@ -24,14 +24,13 @@ sd_native_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.h"
2927
3028// TBC: base frequency
3129// or use (1000000 * ESP.getCpuFreqMHz())
3230#define ESP_SPI_FREQ 4000000
3331
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];
3534
3635uint8_t ESP_SD::getState (bool refresh) {
3736#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
@@ -53,7 +52,7 @@ uint8_t ESP_SD::getState(bool refresh) {
5352 }
5453 // SD is idle or not detected, let see if still the case
5554
56- SD .end ();
55+ ESP3D_SD_Card .end ();
5756 _state = ESP_SDCARD_NOT_PRESENT;
5857 // using default value for speed ? should be parameter
5958 // refresh content if card was removed
@@ -62,9 +61,9 @@ uint8_t ESP_SD::getState(bool refresh) {
6261 ESP_SD_MISO_PIN != -1 ? ESP_SD_MISO_PIN : MISO,
6362 ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI,
6463 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,
6665 ESP_SPI_FREQ / _spi_speed_divider)) {
67- if (SD .cardSize () > 0 ) {
66+ if (ESP3D_SD_Card .cardSize () > 0 ) {
6867 _state = ESP_SDCARD_IDLE;
6968 }
7069 }
@@ -114,7 +113,7 @@ bool ESP_SD::begin() {
114113}
115114
116115void ESP_SD::end () {
117- SD .end ();
116+ ESP3D_SD_Card .end ();
118117 _state = ESP_SDCARD_NOT_PRESENT;
119118 _started = false ;
120119}
@@ -129,7 +128,7 @@ void ESP_SD::refreshStats(bool force) {
129128uint64_t ESP_SD::totalBytes (bool refresh) {
130129 static uint64_t _totalBytes = 0 ;
131130 if (refresh || _totalBytes == 0 ) {
132- _totalBytes = SD .totalBytes ();
131+ _totalBytes = ESP3D_SD_Card .totalBytes ();
133132 ;
134133 }
135134 return _totalBytes;
@@ -138,7 +137,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) {
138137uint64_t ESP_SD::usedBytes (bool refresh) {
139138 static uint64_t _usedBytes = 0 ;
140139 if (refresh || _usedBytes == 0 ) {
141- _usedBytes = SD .usedBytes ();
140+ _usedBytes = ESP3D_SD_Card .usedBytes ();
142141 }
143142 return _usedBytes;
144143}
@@ -151,7 +150,7 @@ uint ESP_SD::maxPathLength() { return 255; }
151150
152151bool ESP_SD::rename (const char *oldpath, const char *newpath) {
153152 esp3d_log (" rename %s to %s" , oldpath, newpath);
154- return SD .rename (oldpath, newpath);
153+ return ESP3D_SD_Card .rename (oldpath, newpath);
155154}
156155
157156bool ESP_SD::format () {
@@ -180,7 +179,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
180179 return ESP_SDFile ();
181180 }
182181 }
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
184183 : (mode == ESP_FILE_WRITE) ? FILE_WRITE
185184 : FILE_APPEND);
186185 ESP_SDFile esptmp (&tmp, tmp.isDirectory (),
@@ -198,23 +197,23 @@ bool ESP_SD::exists(const char *path) {
198197 if (p.endsWith (" /" )) {
199198 p.remove (p.length () - 1 , 1 );
200199 }
201- res = SD .exists (p);
200+ res = ESP3D_SD_Card .exists (p);
202201 if (!res) {
203202 // check if it is a directory
204203 p += ' /' ;
205- res = SD .exists (p);
204+ res = ESP3D_SD_Card .exists (p);
206205 }
207206 return res;
208207}
209208
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); }
211210
212211bool ESP_SD::mkdir (const char *path) {
213212 String p = path;
214213 if (p.endsWith (" /" )) {
215214 p.remove (p.length () - 1 , 1 );
216215 }
217- return SD .mkdir (p.c_str ());
216+ return ESP3D_SD_Card .mkdir (p.c_str ());
218217}
219218
220219bool ESP_SD::rmdir (const char *path) {
@@ -234,8 +233,8 @@ bool ESP_SD::rmdir(const char *path) {
234233 std::stack<String> pathlist;
235234 pathlist.push (p);
236235 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 ();
239238 bool candelete = true ;
240239 while (f && res) {
241240 if (f.isDirectory ()) {
@@ -244,20 +243,20 @@ bool ESP_SD::rmdir(const char *path) {
244243 newdir += f.name ();
245244 pathlist.push (newdir);
246245 f.close ();
247- f = File ();
246+ f =ESP3D_File ();
248247 } else {
249248 String filepath = pathlist.top () + ' /' ;
250249 filepath += f.name ();
251250 f.close ();
252- if (!SD .remove (filepath.c_str ())) {
251+ if (!ESP3D_SD_Card .remove (filepath.c_str ())) {
253252 res = false ;
254253 }
255254 f = dir.openNextFile ();
256255 }
257256 }
258257 if (candelete) {
259258 if (pathlist.top () != " /" ) {
260- res = SD .rmdir (pathlist.top ().c_str ());
259+ res = ESP3D_SD_Card .rmdir (pathlist.top ().c_str ());
261260 }
262261 pathlist.pop ();
263262 }
@@ -271,7 +270,7 @@ bool ESP_SD::rmdir(const char *path) {
271270void ESP_SD::closeAll () {
272271 for (uint8_t i = 0 ; i < ESP_MAX_SD_OPENHANDLE; i++) {
273272 tSDFile_handle[i].close ();
274- tSDFile_handle[i] = File ();
273+ tSDFile_handle[i] =ESP3D_File ();
275274 }
276275}
277276
@@ -291,7 +290,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
291290 bool set = false ;
292291 for (uint8_t i = 0 ; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
293292 if (!tSDFile_handle[i]) {
294- tSDFile_handle[i] = *((File *)handle);
293+ tSDFile_handle[i] = *((ESP3D_File *)handle);
295294 // filename
296295 _name = tSDFile_handle[i].name ();
297296 _filename = path;
@@ -331,14 +330,14 @@ void ESP_SDFile::close() {
331330 // reopen if mode = write
332331 // udate size + date
333332 if (_iswritemode && !_isdir) {
334- File ftmp = SD .open (_filename.c_str ());
333+ ESP3D_File ftmp = ESP3D_SD_Card .open (_filename.c_str ());
335334 if (ftmp) {
336335 _size = ftmp.size ();
337336 _lastwrite = ftmp.getLastWrite ();
338337 ftmp.close ();
339338 }
340339 }
341- tSDFile_handle[_index] = File ();
340+ tSDFile_handle[_index] =ESP3D_File ();
342341 // esp3d_log("Closing File at index %d",_index);
343342 _index = -1 ;
344343 }
@@ -349,7 +348,7 @@ ESP_SDFile ESP_SDFile::openNextFile() {
349348 esp3d_log (" openNextFile failed" );
350349 return ESP_SDFile ();
351350 }
352- File tmp = tSDFile_handle[_index].openNextFile ();
351+ ESP3D_File tmp = tSDFile_handle[_index].openNextFile ();
353352 if (tmp) {
354353 esp3d_log (" tmp name :%s %s %s" , tmp.name (),
355354 (tmp.isDirectory ()) ? " isDir" : " isFile" , _filename.c_str ());
0 commit comments