Skip to content

Commit 73e4bd3

Browse files
committed
Sync code with latest ESP3D
1 parent a74608a commit 73e4bd3

File tree

10 files changed

+217
-226
lines changed

10 files changed

+217
-226
lines changed

src/include/esp3d_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define _VERSION_ESP3D_H
2323

2424
// version and sources location
25-
#define FW_VERSION "3.0.0.4b1"
25+
#define FW_VERSION "3.0.0.5b1"
2626
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
2727

2828
#endif //_VERSION_ESP3D_H

src/modules/filesystem/esp_sd.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,6 @@
2424

2525
#include "esp_sd.h"
2626

27-
#define ESP_MAX_SD_OPENHANDLE 4
28-
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
29-
#define FS_NO_GLOBALS
30-
#include <SD.h>
31-
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
32-
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && \
33-
defined(ARDUINO_ARCH_ESP8266)
34-
#define FS_NO_GLOBALS
35-
#define NO_GLOBAL_SD
36-
#include <SdFat.h>
37-
#if SDFAT_FILE_TYPE == 1
38-
typedef File32 File;
39-
#elif SDFAT_FILE_TYPE == 2
40-
typedef ExFile File;
41-
#elif SDFAT_FILE_TYPE == 3
42-
typedef FsFile File;
43-
#else // SDFAT_FILE_TYPE
44-
#error Invalid SDFAT_FILE_TYPE
45-
#endif // SDFAT_FILE_TYPE
46-
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
47-
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && \
48-
defined(ARDUINO_ARCH_ESP32)
49-
#include <SdFat.h>
50-
#if (SD_DEVICE == ESP_SDFAT2)
51-
#if SDFAT_FILE_TYPE == 1
52-
typedef File32 File;
53-
#elif SDFAT_FILE_TYPE == 2
54-
typedef ExFile File;
55-
#elif SDFAT_FILE_TYPE == 3
56-
typedef FsFile File;
57-
#else // SDFAT_FILE_TYPE
58-
#error Invalid SDFAT_FILE_TYPE
59-
#endif // SDFAT_FILE_TYPE
60-
#endif
61-
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
62-
#else
63-
#include <FS.h>
64-
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
65-
#endif
6627

6728
#if defined(ESP3DLIB_ENV)
6829
#include "../../include/Marlin/cardreader.h"

src/modules/filesystem/esp_sd.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@
2020

2121
#ifndef _ESP_SD_H
2222
#define _ESP_SD_H
23-
#include <time.h>
2423

25-
#include "../../core/esp3d_message.h"
2624
#include "../../include/esp3d_config.h"
27-
28-
#define ESP_SD_FS_HEADER "/SD"
29-
30-
#define ESP_MAX_SD_OPENHANDLE 4
25+
#include "sd/esp_sd_common.h"
3126

3227
class ESP_SDFile {
3328
public:
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
esp_sd_common.h - ESP3D SD support class
3+
4+
Copyright (c) 2014 Luc Lebosse. All rights reserved.
5+
6+
This code is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This code is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with This code; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#pragma once
22+
#include "../../../include/esp3d_config.h"
23+
24+
#define ESP_SD_FS_HEADER "/SD"
25+
26+
#define ESP_MAX_SD_OPENHANDLE 4
27+
28+
29+
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
30+
#define FS_NO_GLOBALS
31+
#define NO_GLOBAL_SD
32+
#include <SD.h>
33+
using ESP3D_File = fs::File;
34+
using ESP3D_SD_Class = SDClass;
35+
#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266
36+
37+
#if ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP8266)
38+
#define FS_NO_GLOBALS
39+
#define NO_GLOBAL_SD
40+
#define DISABLE_FS_H_WARNING 1
41+
#include <SdFat.h>
42+
#if SDFAT_FILE_TYPE == 1
43+
using ESP3D_File = File32;
44+
#elif SDFAT_FILE_TYPE == 2
45+
using ESP3D_File = ExFile;
46+
#elif SDFAT_FILE_TYPE == 3
47+
using ESP3D_File = FsFile;
48+
#else // SDFAT_FILE_TYPE
49+
#error Invalid SDFAT_FILE_TYPE
50+
#endif // SDFAT_FILE_TYPE
51+
using ESP3D_SD_Class = SdFat;
52+
#endif // ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP8266
53+
54+
#if ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP32)
55+
#define DISABLE_FS_H_WARNING 1
56+
#include <SdFat.h>
57+
#if SDFAT_FILE_TYPE == 1
58+
using ESP3D_File = File32;
59+
#elif SDFAT_FILE_TYPE == 2
60+
using ESP3D_File = ExFile;
61+
#elif SDFAT_FILE_TYPE == 3
62+
using ESP3D_File = FsFile;
63+
#else // SDFAT_FILE_TYPE
64+
#error Invalid SDFAT_FILE_TYPE
65+
#endif // SDFAT_FILE_TYPE
66+
using ESP3D_SD_Class = SdFat;
67+
#endif // ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP32
68+
69+
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32)
70+
#include <FS.h>
71+
#include <SD.h>
72+
using ESP3D_File = fs::File;
73+
using ESP3D_SD_Class = fs::SDFS;
74+
#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32
75+
76+
#if (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32)
77+
#include <FS.h>
78+
#include <SD_MMC.h>
79+
using ESP3D_File = fs::File;
80+
using ESP3D_SD_Class = fs::SDMMCFS;
81+
#endif // (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32
82+
83+
84+
extern ESP3D_SD_Class ESP3D_SD_Card;
85+
extern ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];

src/modules/filesystem/sd/sd_native_esp32.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3635
uint8_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

116115
void 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) {
129128
uint64_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) {
138137
uint64_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

152151
bool 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

157156
bool 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

212211
bool 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

220219
bool 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) {
271270
void 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

Comments
 (0)