Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esp3d/src/include/esp3d_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H

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

#endif //_VERSION_ESP3D_H
6 changes: 4 additions & 2 deletions esp3d/src/modules/filesystem/esp_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <time.h>

#include "esp_sd.h"

/*
#define ESP_MAX_SD_OPENHANDLE 4
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
#define FS_NO_GLOBALS
Expand Down Expand Up @@ -62,7 +62,7 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
#else
#include <FS.h>
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
#endif
#endif*/

#if defined(ESP3DLIB_ENV)
#include "../../include/Marlin/cardreader.h"
Expand Down Expand Up @@ -138,6 +138,8 @@ bool ESP_SD::disableSharedSD() {
bool ESP_SD::_started = false;
uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT;
uint8_t ESP_SD::_spi_speed_divider = 1;


bool ESP_SD::_sizechanged = true;
uint8_t ESP_SD::setState(uint8_t flag) {
_state = flag;
Expand Down
7 changes: 1 addition & 6 deletions esp3d/src/modules/filesystem/esp_sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@

#ifndef _ESP_SD_H
#define _ESP_SD_H
#include <time.h>

#include "../../core/esp3d_message.h"
#include "../../include/esp3d_config.h"

#define ESP_SD_FS_HEADER "/SD"

#define ESP_MAX_SD_OPENHANDLE 4
#include "sd/esp_sd_common.h"

class ESP_SDFile {
public:
Expand Down
85 changes: 85 additions & 0 deletions esp3d/src/modules/filesystem/sd/esp_sd_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
esp_sd_common.h - ESP3D SD support class

Copyright (c) 2014 Luc Lebosse. All rights reserved.

This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once
#include "../../../include/esp3d_config.h"

#define ESP_SD_FS_HEADER "/SD"

#define ESP_MAX_SD_OPENHANDLE 4


#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
#define FS_NO_GLOBALS
#define NO_GLOBAL_SD
#include <SD.h>
using ESP3D_File = fs::File;
using ESP3D_SD_Class = SDClass;
#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266

#if ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP8266)
#define FS_NO_GLOBALS
#define NO_GLOBAL_SD
#define DISABLE_FS_H_WARNING 1
#include <SdFat.h>
#if SDFAT_FILE_TYPE == 1
using ESP3D_File = File32;
#elif SDFAT_FILE_TYPE == 2
using ESP3D_File = ExFile;
#elif SDFAT_FILE_TYPE == 3
using ESP3D_File = FsFile;
#else // SDFAT_FILE_TYPE
#error Invalid SDFAT_FILE_TYPE
#endif // SDFAT_FILE_TYPE
using ESP3D_SD_Class = SdFat;
#endif // ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP8266

#if ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP32)
#define DISABLE_FS_H_WARNING 1
#include <SdFat.h>
#if SDFAT_FILE_TYPE == 1
using ESP3D_File = File32;
#elif SDFAT_FILE_TYPE == 2
using ESP3D_File = ExFile;
#elif SDFAT_FILE_TYPE == 3
using ESP3D_File = FsFile;
#else // SDFAT_FILE_TYPE
#error Invalid SDFAT_FILE_TYPE
#endif // SDFAT_FILE_TYPE
using ESP3D_SD_Class = SdFat;
#endif // ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP32

#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <SD.h>
using ESP3D_File = fs::File;
using ESP3D_SD_Class = fs::SDFS;
#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32

#if (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <SD_MMC.h>
using ESP3D_File = fs::File;
using ESP3D_SD_Class = fs::SDMMCFS;
#endif // (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32


extern ESP3D_SD_Class ESP3D_SD_Card;
extern ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
49 changes: 24 additions & 25 deletions esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ sd_native_esp32.cpp - ESP3D sd support class

#include "../../../core/esp3d_settings.h"
#include "../esp_sd.h"
#include "FS.h"
#include "SD.h"

// TBC: base frequency
// or use (1000000 * ESP.getCpuFreqMHz())
#define ESP_SPI_FREQ 4000000

extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
ESP3D_SD_Class ESP3D_SD_Card = SD;
ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];

uint8_t ESP_SD::getState(bool refresh) {
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
Expand All @@ -53,7 +52,7 @@ uint8_t ESP_SD::getState(bool refresh) {
}
// SD is idle or not detected, let see if still the case

SD.end();
ESP3D_SD_Card.end();
_state = ESP_SDCARD_NOT_PRESENT;
// using default value for speed ? should be parameter
// refresh content if card was removed
Expand All @@ -62,9 +61,9 @@ uint8_t ESP_SD::getState(bool refresh) {
ESP_SD_MISO_PIN != -1 ? ESP_SD_MISO_PIN : MISO,
ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI,
ESP_SD_SCK_PIN != -1 ? ESP_SD_SCK_PIN : SCK);
if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SPI,
if (ESP3D_SD_Card.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SPI,
ESP_SPI_FREQ / _spi_speed_divider)) {
if (SD.cardSize() > 0) {
if (ESP3D_SD_Card.cardSize() > 0) {
_state = ESP_SDCARD_IDLE;
}
}
Expand Down Expand Up @@ -114,7 +113,7 @@ bool ESP_SD::begin() {
}

void ESP_SD::end() {
SD.end();
ESP3D_SD_Card.end();
_state = ESP_SDCARD_NOT_PRESENT;
_started = false;
}
Expand All @@ -129,7 +128,7 @@ void ESP_SD::refreshStats(bool force) {
uint64_t ESP_SD::totalBytes(bool refresh) {
static uint64_t _totalBytes = 0;
if (refresh || _totalBytes == 0) {
_totalBytes = SD.totalBytes();
_totalBytes = ESP3D_SD_Card.totalBytes();
;
}
return _totalBytes;
Expand All @@ -138,7 +137,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) {
uint64_t ESP_SD::usedBytes(bool refresh) {
static uint64_t _usedBytes = 0;
if (refresh || _usedBytes == 0) {
_usedBytes = SD.usedBytes();
_usedBytes = ESP3D_SD_Card.usedBytes();
}
return _usedBytes;
}
Expand All @@ -151,7 +150,7 @@ uint ESP_SD::maxPathLength() { return 255; }

bool ESP_SD::rename(const char *oldpath, const char *newpath) {
esp3d_log("rename %s to %s", oldpath, newpath);
return SD.rename(oldpath, newpath);
return ESP3D_SD_Card.rename(oldpath, newpath);
}

bool ESP_SD::format() {
Expand Down Expand Up @@ -180,7 +179,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
return ESP_SDFile();
}
}
File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
: FILE_APPEND);
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),
Expand All @@ -198,23 +197,23 @@ bool ESP_SD::exists(const char *path) {
if (p.endsWith("/")) {
p.remove(p.length() - 1, 1);
}
res = SD.exists(p);
res = ESP3D_SD_Card.exists(p);
if (!res) {
// check if it is a directory
p += '/';
res = SD.exists(p);
res = ESP3D_SD_Card.exists(p);
}
return res;
}

bool ESP_SD::remove(const char *path) { return SD.remove(path); }
bool ESP_SD::remove(const char *path) { return ESP3D_SD_Card.remove(path); }

bool ESP_SD::mkdir(const char *path) {
String p = path;
if (p.endsWith("/")) {
p.remove(p.length() - 1, 1);
}
return SD.mkdir(p.c_str());
return ESP3D_SD_Card.mkdir(p.c_str());
}

bool ESP_SD::rmdir(const char *path) {
Expand All @@ -234,8 +233,8 @@ bool ESP_SD::rmdir(const char *path) {
std::stack<String> pathlist;
pathlist.push(p);
while (pathlist.size() > 0 && res) {
File dir = SD.open(pathlist.top().c_str());
File f = dir.openNextFile();
ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str());
ESP3D_File f = dir.openNextFile();
bool candelete = true;
while (f && res) {
if (f.isDirectory()) {
Expand All @@ -244,20 +243,20 @@ bool ESP_SD::rmdir(const char *path) {
newdir += f.name();
pathlist.push(newdir);
f.close();
f = File();
f =ESP3D_File();
} else {
String filepath = pathlist.top() + '/';
filepath += f.name();
f.close();
if (!SD.remove(filepath.c_str())) {
if (!ESP3D_SD_Card.remove(filepath.c_str())) {
res = false;
}
f = dir.openNextFile();
}
}
if (candelete) {
if (pathlist.top() != "/") {
res = SD.rmdir(pathlist.top().c_str());
res = ESP3D_SD_Card.rmdir(pathlist.top().c_str());
}
pathlist.pop();
}
Expand All @@ -271,7 +270,7 @@ bool ESP_SD::rmdir(const char *path) {
void ESP_SD::closeAll() {
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
tSDFile_handle[i].close();
tSDFile_handle[i] = File();
tSDFile_handle[i] =ESP3D_File();
}
}

Expand All @@ -291,7 +290,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
bool set = false;
for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
if (!tSDFile_handle[i]) {
tSDFile_handle[i] = *((File *)handle);
tSDFile_handle[i] = *((ESP3D_File *)handle);
// filename
_name = tSDFile_handle[i].name();
_filename = path;
Expand Down Expand Up @@ -331,14 +330,14 @@ void ESP_SDFile::close() {
// reopen if mode = write
// udate size + date
if (_iswritemode && !_isdir) {
File ftmp = SD.open(_filename.c_str());
ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
_lastwrite = ftmp.getLastWrite();
ftmp.close();
}
}
tSDFile_handle[_index] = File();
tSDFile_handle[_index] =ESP3D_File();
// esp3d_log("Closing File at index %d",_index);
_index = -1;
}
Expand All @@ -349,7 +348,7 @@ ESP_SDFile ESP_SDFile::openNextFile() {
esp3d_log("openNextFile failed");
return ESP_SDFile();
}
File tmp = tSDFile_handle[_index].openNextFile();
ESP3D_File tmp = tSDFile_handle[_index].openNextFile();
if (tmp) {
esp3d_log("tmp name :%s %s %s", tmp.name(),
(tmp.isDirectory()) ? "isDir" : "isFile", _filename.c_str());
Expand Down
Loading