From 9aedaceed87de60eaa120d56e961e7b5196330a9 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Wed, 17 Jun 2020 15:00:31 +0200 Subject: [PATCH] Fix debug always enabled on ESP32 if debug is enabled Add SPI custom pins support in ESP32 FAT and show them when used in debug Allow to add custom SPI PINS in Configuration.h or myconfig.h --- esp3d/src/core/debug_esp3d.h | 14 ++++++-------- esp3d/src/include/esp3d_config.h | 2 +- esp3d/src/include/pins.h | 9 +++++++++ .../src/modules/filesystem/sd/sd_native_esp32.cpp | 2 ++ esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp | 4 ++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/esp3d/src/core/debug_esp3d.h b/esp3d/src/core/debug_esp3d.h index 5ebb0402..0c5cdcb5 100644 --- a/esp3d/src/core/debug_esp3d.h +++ b/esp3d/src/core/debug_esp3d.h @@ -22,17 +22,12 @@ #define _DEBUG_ESP3D_H #include "../include/esp3d_config.h" -#if defined(ARDUINO_ARCH_ESP32) -#define log_esp3d(format, ...) log_d(format, ##__VA_ARGS__) -#define log_esp3dS(format, ...) log_d(format, ##__VA_ARGS__) -#else -#define log_esp3d(format, ...) -#define log_esp3dS(format, ...) -#endif + #define DEBUG_ESP3D_INIT #define DEBUG_ESP3D_NETWORK_INIT #define DEBUG_ESP3D_NETWORK_HANDLE #define DEBUG_ESP3D_NETWORK_END + #if defined(ESP_DEBUG_FEATURE) #if defined(ARDUINO_ARCH_ESP8266) extern const char * pathToFileName(const char * path); @@ -84,6 +79,9 @@ extern WebSocket_Server websocket_debug; #define log_esp3d(format, ...) websocket_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__) #define log_esp3dS(format, ...) websocket_debug.printf(format "\r\n", ##__VA_ARGS__) #endif // DEBUG_OUTPUT_WEBSOCKET - +#else +#define log_esp3d(format, ...) +#define log_esp3dS(format, ...) #endif //ESP_DEBUG_FEATURE + #endif //_DEBUG_ESP3D_H diff --git a/esp3d/src/include/esp3d_config.h b/esp3d/src/include/esp3d_config.h index 6baf0968..05162271 100644 --- a/esp3d/src/include/esp3d_config.h +++ b/esp3d/src/include/esp3d_config.h @@ -22,8 +22,8 @@ #define _ESP3D_CONFIG_H #include #include "../include/defines.h" -#include "../include/pins.h" #include "../../configuration.h" +#include "../include/pins.h" #include "../include/sanity_esp3d.h" #include "../core/hal.h" #include "../core/debug_esp3d.h" diff --git a/esp3d/src/include/pins.h b/esp3d/src/include/pins.h index db1bd516..ec5f983c 100644 --- a/esp3d/src/include/pins.h +++ b/esp3d/src/include/pins.h @@ -166,12 +166,21 @@ //Pins for the support of SD Card Reader //-1 means use default pins of your board defined core +//this are overwrited if defined in configuration.h or myconfig.h +#ifndef ESP_SD_CS_PIN #define ESP_SD_CS_PIN -1 +#endif //ESP_SD_CS_PIN //These are hardcoded on ESP8266 to 12/13/14 //so modifications are ignored on ESP8266 +#ifndef ESP_SD_MISO_PIN #define ESP_SD_MISO_PIN -1 +#endif //ESP_SD_MISO_PIN +#ifndef ESP_SD_MOSI_PIN #define ESP_SD_MOSI_PIN -1 +#endif //ESP_SD_MOSI_PIN +#ifndef ESP_SD_SCK_PIN #define ESP_SD_SCK_PIN -1 +#endif //ESP_SD_SCK_PIN // For SDIO Connect the SD card to the following pins: //SD Card | ESP32 diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp index 7e3cd081..0b4b1d9b 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp @@ -54,6 +54,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 + log_esp3d("Spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN!=-1?ESP_SD_CS_PIN:SS, 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, ESP_SPI_FREQ / _spi_speed_divider)) { if ( SD.cardSize() > 0 ) { _state = ESP_SDCARD_IDLE; @@ -65,6 +66,7 @@ uint8_t ESP_SD::getState(bool refresh) bool ESP_SD::begin() { #if (ESP_SD_CS_PIN != -1) || (ESP_SD_MISO_PIN != -1) || (ESP_SD_MOSI_PIN != -1) || (ESP_SD_SCK_PIN != -1) + log_esp3d("Custom spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_SCK_PIN); SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN); #endif _started = true; diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp index 12db83df..50d57467 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp @@ -86,6 +86,7 @@ uint8_t ESP_SD::getState(bool refresh) } //SD is idle or not detected, let see if still the case _state = ESP_SDCARD_NOT_PRESENT; + log_esp3d("Spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN!=-1?ESP_SD_CS_PIN:SS, 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); //refresh content if card was removed if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SD_SCK_MHZ(FREQMZ/_spi_speed_divider))) { if (SD.card()->cardSize() > 0 ) { @@ -97,6 +98,9 @@ uint8_t ESP_SD::getState(bool refresh) bool ESP_SD::begin() { +#if (ESP_SD_CS_PIN != -1) || (ESP_SD_MISO_PIN != -1) || (ESP_SD_MOSI_PIN != -1) || (ESP_SD_SCK_PIN != -1) + SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN); +#endif _started = true; _state = ESP_SDCARD_NOT_PRESENT; _spi_speed_divider = Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV);