mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-02 22:10:39 +08:00
Some refactoring for SD support
put SPI SD divider in EEPROM
This commit is contained in:
parent
7384b4f28e
commit
9fe3c1a615
@ -107,7 +107,7 @@
|
||||
//ESP_SD_NATIVE 1 //esp32 only
|
||||
//ESP_SDIO 2 //Not available yet
|
||||
//ESP_SDFAT 3 //Not available yet
|
||||
//#define SD_DEVICE ESP_SD_NATIVE
|
||||
#define SD_DEVICE ESP_SD_NATIVE
|
||||
|
||||
//pin if reader has insert detection feature
|
||||
//let -1 or comment if none
|
||||
@ -175,7 +175,7 @@
|
||||
//ESP_AUTOSTART_SCRIPT : to do some actions / send GCODE at start, need ESP_GCODE_HOST_FEATURE enabled
|
||||
//can be a line od several GCODES separated by `\n` e.g. "M21\nM117 SD mounted\n"
|
||||
//can be a file name, if exists, commands inside will be processed, e.g "/FS:/autostart.esp"
|
||||
#define ESP_AUTOSTART_SCRIPT "M117 Mouning SD\nM21\n"
|
||||
//#define ESP_AUTOSTART_SCRIPT "M117 Mouning SD\nM21\n"
|
||||
|
||||
//ESP_LUA_INTERPRETER_FEATURE : add lua scripting feature
|
||||
//#define ESP_LUA_INTERPRETER_FEATURE
|
||||
|
@ -463,14 +463,21 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printf (",{\"Telnet\":\"%d\"}", ESP_TELNET_CLIENT);
|
||||
#endif //TELNET_FEATURE
|
||||
output->printLN ("]}");
|
||||
#ifdef SDCARD_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
//Direct SD
|
||||
output->print(",{\"F\":\"printer\",\"P\":\"");
|
||||
output->print(ESP_IS_DIRECT_SD);
|
||||
output->print(ESP_SD_DEVICE_TYPE);
|
||||
output->print("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_IS_DIRECT_SD));
|
||||
output->print("\",\"H\":\"Direct SD access\",\"O\":[{\"No\":\"0\"},{\"Yes\":\"1\"}]}");
|
||||
#endif //SDCARD_FEATURE
|
||||
output->print (Settings_ESP3D::read_byte(ESP_SD_DEVICE_TYPE));
|
||||
//hard coded for readibility but should use ESP_NO_SD / ESP_DIRECT_SD / ESP_SHARED_SD
|
||||
output->printLN("\",\"H\":\"SD Device\",\"O\":[{\"None\":\"0\"},{\"Direct\":\"1\"},{\"Shared\":\"2\"}]}");
|
||||
//SPI SD Divider
|
||||
output->print(",{\"F\":\"printer\",\"P\":\"");
|
||||
output->print(ESP_SD_SPEED_DIV);
|
||||
output->print("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV));
|
||||
output->print("\",\"H\":\"SD speed divider\",\"O\":[{\"1\":\"1\"},{\"2\":\"2\"},{\"3\":\"3\"},{\"4\":\"4\"},{\"6\":\"6\"},{\"8\":\"8\"},{\"16\":\"16\"},{\"32\":\"32\"}]}");
|
||||
#endif //SD_DEVICE
|
||||
|
||||
output->printLN ("]}");
|
||||
|
||||
|
@ -37,6 +37,9 @@
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "../../modules/notifications/notifications_service.h"
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
#include "../../modules/filesystem/esp_sd.h"
|
||||
#endif //SD_DEVICE
|
||||
//Set EEPROM setting
|
||||
//[ESP401]P=<position> T=<type> V=<value> pwd=<user/admin password>
|
||||
bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
@ -73,6 +76,14 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
|
||||
case ESP_TARGET_FW:
|
||||
Settings_ESP3D::GetFirmwareTarget(true);
|
||||
break;
|
||||
#ifdef SD_DEVICE
|
||||
case ESP_SD_DEVICE_TYPE:
|
||||
Settings_ESP3D::GetSDDevice(true);
|
||||
break;
|
||||
case ESP_SD_SPEED_DIV:
|
||||
ESP_SD::setSPISpeedDivider(sval.toInt());
|
||||
break;
|
||||
#endif //SD_DEVICE
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
case ESP_INTERNET_TIME:
|
||||
timeserver.begin();
|
||||
|
@ -62,6 +62,9 @@
|
||||
#ifdef CAMERA_DEVICE
|
||||
#include "../../modules/camera/camera.h"
|
||||
#endif //CAMERA_DEVICE
|
||||
#ifdef SD_DEVICE
|
||||
#include "../../modules/filesystem/esp_sd.h"
|
||||
#endif //SD_DEVICE
|
||||
|
||||
//Get ESP current status
|
||||
//output is JSON or plain text according parameter
|
||||
@ -1055,6 +1058,26 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
}
|
||||
output->print ("SD Card");
|
||||
if (!plain) {
|
||||
output->print ("\",\"value\":\"");
|
||||
} else {
|
||||
output->print (": ");
|
||||
}
|
||||
output->print ((Settings_ESP3D::GetSDDevice() == ESP_DIRECT_SD)?"Direct":(Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD)?"Shared":"None");
|
||||
output->print ("(");
|
||||
output->print (ESP_SD::FilesystemName());
|
||||
output->print (")");
|
||||
if (!plain) {
|
||||
output->print ("\"}");
|
||||
} else {
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#if defined (DHT_DEVICE)
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
|
@ -43,8 +43,8 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
|
||||
parameter = "/";
|
||||
}
|
||||
int8_t state = ESP_SD::getState(false);
|
||||
if (state != ESP_SDCARD_IDLE){
|
||||
state = ESP_SD::getState(true);
|
||||
if (state != ESP_SDCARD_IDLE) {
|
||||
state = ESP_SD::getState(true);
|
||||
}
|
||||
if (state == ESP_SDCARD_NOT_PRESENT) {
|
||||
output->printERROR ("No SD card");
|
||||
|
@ -41,8 +41,8 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
|
||||
(void)auth_type;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
int8_t state = ESP_SD::getState(false);
|
||||
if (state != ESP_SDCARD_IDLE){
|
||||
state = ESP_SD::getState(true);
|
||||
if (state != ESP_SDCARD_IDLE) {
|
||||
state = ESP_SD::getState(true);
|
||||
}
|
||||
if (state == ESP_SDCARD_NOT_PRESENT) {
|
||||
output->printERROR ("No SD card");
|
||||
|
@ -102,19 +102,18 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
|
||||
} else {
|
||||
output->print(",\"SDConnection\":\"");
|
||||
}
|
||||
output->print((Settings_ESP3D::isDirectSD())?"Direct":"Serial");
|
||||
if (Settings_ESP3D::GetSDDevice() == ESP_DIRECT_SD) {
|
||||
output->print("direct");
|
||||
} else if (Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD) {
|
||||
output->print("shared");
|
||||
} else {
|
||||
output->print("None");
|
||||
}
|
||||
if(plain) {
|
||||
output->printLN("");
|
||||
} else {
|
||||
output->print("\"");
|
||||
}
|
||||
if (Settings_ESP3D::isDirectSD()) {
|
||||
//TODO
|
||||
//Primary SD
|
||||
|
||||
//TODO
|
||||
//Secondary SD
|
||||
}
|
||||
//Authentication
|
||||
if (plain) {
|
||||
output->print("Authentication:");
|
||||
|
@ -97,12 +97,11 @@
|
||||
#define DEFAULT_FW UNKNOWN_FW
|
||||
#define DEFAULT_TIME_ZONE 0
|
||||
#define DEFAULT_TIME_DST 0
|
||||
#define DEFAULT_PRIMARY_SD 2
|
||||
#define DEFAULT_SECONDARY_SD 1
|
||||
#define DEFAULT_SD_MOUNT ESP_SD_ROOT
|
||||
#define DEFAULT_DIRECT_SD_CHECK 0
|
||||
#define DEFAULT_SD_CHECK_UPDATE_AT_BOOT 1
|
||||
#define DEFAULT_DHT_TYPE 0
|
||||
#define DEFAULT_IS_DIRECT_SD 0
|
||||
#define DEFAULT_DHT_TYPE NO_DHT_DEVICE
|
||||
#define DEFAULT_SD_DEVICE_TYPE ESP_NO_SD
|
||||
#define DEFAULT_HTTP_ON 1
|
||||
#define DEFAULT_TELNET_ON 1
|
||||
#define DEFAULT_WEBSOCKET_ON 1
|
||||
@ -156,7 +155,7 @@ const uint8_t DEFAULT_ADDRESS_VALUE[] = {0, 0, 0, 0};
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE
|
||||
|
||||
uint8_t Settings_ESP3D::_FirmwareTarget = UNKNOWN_FW;
|
||||
bool Settings_ESP3D::_directSD = false;
|
||||
bool Settings_ESP3D::_SDdevice = ESP_NO_SD;
|
||||
|
||||
Settings_ESP3D::Settings_ESP3D()
|
||||
{
|
||||
@ -172,8 +171,8 @@ bool Settings_ESP3D::begin()
|
||||
}
|
||||
//get target FW
|
||||
Settings_ESP3D::GetFirmwareTarget(true);
|
||||
//is direct SD
|
||||
Settings_ESP3D::isDirectSD(true);
|
||||
//get SD device if any
|
||||
Settings_ESP3D::GetSDDevice(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -185,16 +184,16 @@ uint8_t Settings_ESP3D::GetFirmwareTarget(bool fromsettings)
|
||||
return _FirmwareTarget;
|
||||
}
|
||||
|
||||
bool Settings_ESP3D::isDirectSD(bool fromsettings)
|
||||
uint8_t Settings_ESP3D::GetSDDevice(bool fromsettings)
|
||||
{
|
||||
if(fromsettings) {
|
||||
#ifdef SDCARD_FEATURE
|
||||
_directSD = read_byte (ESP_IS_DIRECT_SD);
|
||||
#else // !SDCARD_FEATURE
|
||||
_directSD = false;
|
||||
#endif //SDCARD_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
_SDdevice = read_byte (ESP_SD_DEVICE_TYPE);
|
||||
#else // !SD_DEVICE
|
||||
_SDdevice = ESP_NO_SD;
|
||||
#endif //SD_DEVICE
|
||||
}
|
||||
return _directSD;
|
||||
return _SDdevice;
|
||||
}
|
||||
|
||||
const char* Settings_ESP3D::GetFirmwareTargetShortName()
|
||||
@ -285,15 +284,12 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
res = DEFAULT_WEBSOCKET_ON;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#ifdef SDCARD_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
case ESP_SD_SPEED_DIV:
|
||||
res = DEFAULT_SDREADER_SPEED;
|
||||
break;
|
||||
case ESP_PRIMARY_SD:
|
||||
res = DEFAULT_PRIMARY_SD;
|
||||
break;
|
||||
case ESP_SECONDARY_SD:
|
||||
res = DEFAULT_SECONDARY_SD;
|
||||
case ESP_SD_MOUNT:
|
||||
res = DEFAULT_SD_MOUNT;
|
||||
break;
|
||||
case ESP_DIRECT_SD_CHECK:
|
||||
res = DEFAULT_DIRECT_SD_CHECK;
|
||||
@ -301,10 +297,10 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
case ESP_SD_CHECK_UPDATE_AT_BOOT:
|
||||
res = DEFAULT_SD_CHECK_UPDATE_AT_BOOT;
|
||||
break;
|
||||
case ESP_IS_DIRECT_SD:
|
||||
res = DEFAULT_IS_DIRECT_SD;
|
||||
case ESP_SD_DEVICE_TYPE:
|
||||
res = DEFAULT_SD_DEVICE_TYPE;
|
||||
break;
|
||||
#endif //SDCARD_FEATURE
|
||||
#endif //SD_DEVICE
|
||||
case ESP_TARGET_FW:
|
||||
res = DEFAULT_FW;
|
||||
break;
|
||||
@ -1100,10 +1096,12 @@ bool Settings_ESP3D::reset()
|
||||
Settings_ESP3D::write_byte(ESP_TARGET_FW,Settings_ESP3D::get_default_byte_value(ESP_TARGET_FW));
|
||||
//Output flag
|
||||
Settings_ESP3D::write_byte(ESP_OUTPUT_FLAG,Settings_ESP3D::get_default_byte_value(ESP_OUTPUT_FLAG));
|
||||
#ifdef SDCARD_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
//Direct SD
|
||||
Settings_ESP3D::write_byte(ESP_IS_DIRECT_SD,Settings_ESP3D::get_default_byte_value(ESP_IS_DIRECT_SD));
|
||||
#endif //SDCARD_FEATURE
|
||||
Settings_ESP3D::write_byte(ESP_SD_DEVICE_TYPE,Settings_ESP3D::get_default_byte_value(ESP_SD_DEVICE_TYPE));
|
||||
//SPI SD Divider
|
||||
Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV,Settings_ESP3D::get_default_byte_value(ESP_SD_SPEED_DIV));
|
||||
#endif //SD_DEVICE
|
||||
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
//Internet time
|
||||
|
@ -75,9 +75,9 @@
|
||||
#define ESP_TIME_SERVER1 464 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_IS_DIRECT_SD 850 //1 bytes = flag
|
||||
#define ESP_PRIMARY_SD 851 //1 bytes = flag
|
||||
#define ESP_SECONDARY_SD 852 //1 bytes = flag
|
||||
#define ESP_SD_DEVICE_TYPE 850 //1 bytes = flag
|
||||
#define ESP_SD_MOUNT 851 //1 bytes = flag
|
||||
#define ESP_FREE_BYTE 852 //1 bytes = flag
|
||||
#define ESP_DIRECT_SD_CHECK 853 //1 bytes = flag
|
||||
#define ESP_SD_CHECK_UPDATE_AT_BOOT 854//1 bytes = flag
|
||||
#define ESP_NOTIFICATION_SETTINGS 855 //128 bytes 127+1 = string ; warning does not support multibyte char like chinese
|
||||
@ -124,7 +124,7 @@ public:
|
||||
static bool reset();
|
||||
static int8_t GetSettingsVersion();
|
||||
static uint8_t GetFirmwareTarget(bool fromsettings = false);
|
||||
static bool isDirectSD(bool fromsettings = false);
|
||||
static uint8_t GetSDDevice(bool fromsettings = false);
|
||||
static const char* GetFirmwareTargetShortName();
|
||||
static String IPtoString(uint32_t ip_int);
|
||||
static uint32_t StringtoIP(const char *s);
|
||||
@ -133,7 +133,7 @@ public:
|
||||
private:
|
||||
static bool is_string(const char * s, uint len);
|
||||
static uint8_t _FirmwareTarget;
|
||||
static bool _directSD;
|
||||
static bool _SDdevice;
|
||||
};
|
||||
|
||||
|
||||
|
@ -50,6 +50,15 @@
|
||||
#define UI_COLORED 1
|
||||
#define UI_MONOCHROME 2
|
||||
|
||||
//SD connection
|
||||
#define ESP_NO_SD 0
|
||||
#define ESP_DIRECT_SD 1
|
||||
#define ESP_SHARED_SD 2
|
||||
|
||||
//SD mount point
|
||||
#define ESP_SD_ROOT 1
|
||||
#define ESP_SD_SUB_SD 2
|
||||
#define ESP_SD_SUB_EXT 3
|
||||
|
||||
//Touch
|
||||
#define XPT2046_SPI 1
|
||||
@ -78,6 +87,7 @@
|
||||
#define ESP_LINE_NOTIFICATION 3
|
||||
|
||||
//DHT
|
||||
#define NO_DHT_DEVICE 0
|
||||
#define DHT11_DEVICE 1
|
||||
#define DHT22_DEVICE 2
|
||||
#define USE_CELSIUS 1
|
||||
|
@ -32,6 +32,7 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
|
||||
bool ESP_SD::_started = false;
|
||||
uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT;
|
||||
uint8_t ESP_SD::_spi_speed_divider = 1;
|
||||
|
||||
uint8_t ESP_SD::setState(uint8_t flag)
|
||||
{
|
||||
@ -198,4 +199,13 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ESP_SD::setSPISpeedDivider(uint8_t speeddivider)
|
||||
{
|
||||
if (speeddivider > 0) {
|
||||
_spi_speed_divider = speeddivider;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif //SD_DEVICE
|
||||
|
@ -92,9 +92,15 @@ public:
|
||||
static bool mkdir(const char *path);
|
||||
static bool rmdir(const char *path);
|
||||
static void closeAll();
|
||||
static uint8_t getSPISpeedDivider()
|
||||
{
|
||||
return _spi_speed_divider;
|
||||
}
|
||||
static bool setSPISpeedDivider(uint8_t speeddivider);
|
||||
private:
|
||||
static bool _started;
|
||||
static uint8_t _state;
|
||||
static uint8_t _spi_speed_divider;
|
||||
};
|
||||
|
||||
|
||||
|
@ -22,14 +22,12 @@ sd_native_esp32.cpp - ESP3D sd support class
|
||||
#if (SD_DEVICE == ESP_SD_NATIVE)
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
|
||||
#define ESP_SPI_FREQ 4000000
|
||||
|
||||
//TODO read this from EEPROM/Preferences
|
||||
#define ESP_SD_SPEED_DIVIDER 1
|
||||
|
||||
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
|
||||
uint8_t ESP_SD::getState(bool refresh)
|
||||
@ -54,7 +52,7 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
//using default value for speed ? should be parameter
|
||||
//refresh content if card was removed
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SPI, ESP_SPI_FREQ / ESP_SD_SPEED_DIVIDER)) {
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SPI, ESP_SPI_FREQ / _spi_speed_divider)) {
|
||||
if ( SD.cardSize() > 0 ) {
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
}
|
||||
@ -69,6 +67,11 @@ bool ESP_SD::begin()
|
||||
#endif
|
||||
_started = true;
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_spi_speed_divider = Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV);
|
||||
//sanity check
|
||||
if (_spi_speed_divider <= 0) {
|
||||
_spi_speed_divider = 1;
|
||||
}
|
||||
return _started;
|
||||
}
|
||||
|
||||
@ -94,11 +97,6 @@ uint64_t ESP_SD::freeBytes()
|
||||
return (SD.totalBytes() - SD.usedBytes());
|
||||
};
|
||||
|
||||
const char * ESP_SD::FilesystemName()
|
||||
{
|
||||
return "SD Native";
|
||||
}
|
||||
|
||||
bool ESP_SD::format()
|
||||
{
|
||||
//not available yet
|
||||
@ -336,6 +334,10 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
||||
return ESP_SDFile();
|
||||
}
|
||||
|
||||
const char * ESP_SD::FilesystemName()
|
||||
{
|
||||
return "SD native";
|
||||
}
|
||||
|
||||
#endif //SD_DEVICE == ESP_SD_NATIVE
|
||||
#endif //ARCH_ESP32 && SD_DEVICE
|
||||
|
Loading…
x
Reference in New Issue
Block a user