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
This commit is contained in:
Luc 2020-06-17 15:00:31 +02:00
parent ce5761344d
commit 9aedaceed8
5 changed files with 22 additions and 9 deletions

View File

@ -22,17 +22,12 @@
#define _DEBUG_ESP3D_H #define _DEBUG_ESP3D_H
#include "../include/esp3d_config.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_INIT
#define DEBUG_ESP3D_NETWORK_INIT #define DEBUG_ESP3D_NETWORK_INIT
#define DEBUG_ESP3D_NETWORK_HANDLE #define DEBUG_ESP3D_NETWORK_HANDLE
#define DEBUG_ESP3D_NETWORK_END #define DEBUG_ESP3D_NETWORK_END
#if defined(ESP_DEBUG_FEATURE) #if defined(ESP_DEBUG_FEATURE)
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
extern const char * pathToFileName(const char * path); 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_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__) #define log_esp3dS(format, ...) websocket_debug.printf(format "\r\n", ##__VA_ARGS__)
#endif // DEBUG_OUTPUT_WEBSOCKET #endif // DEBUG_OUTPUT_WEBSOCKET
#else
#define log_esp3d(format, ...)
#define log_esp3dS(format, ...)
#endif //ESP_DEBUG_FEATURE #endif //ESP_DEBUG_FEATURE
#endif //_DEBUG_ESP3D_H #endif //_DEBUG_ESP3D_H

View File

@ -22,8 +22,8 @@
#define _ESP3D_CONFIG_H #define _ESP3D_CONFIG_H
#include <Arduino.h> #include <Arduino.h>
#include "../include/defines.h" #include "../include/defines.h"
#include "../include/pins.h"
#include "../../configuration.h" #include "../../configuration.h"
#include "../include/pins.h"
#include "../include/sanity_esp3d.h" #include "../include/sanity_esp3d.h"
#include "../core/hal.h" #include "../core/hal.h"
#include "../core/debug_esp3d.h" #include "../core/debug_esp3d.h"

View File

@ -166,12 +166,21 @@
//Pins for the support of SD Card Reader //Pins for the support of SD Card Reader
//-1 means use default pins of your board defined core //-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 #define ESP_SD_CS_PIN -1
#endif //ESP_SD_CS_PIN
//These are hardcoded on ESP8266 to 12/13/14 //These are hardcoded on ESP8266 to 12/13/14
//so modifications are ignored on ESP8266 //so modifications are ignored on ESP8266
#ifndef ESP_SD_MISO_PIN
#define ESP_SD_MISO_PIN -1 #define ESP_SD_MISO_PIN -1
#endif //ESP_SD_MISO_PIN
#ifndef ESP_SD_MOSI_PIN
#define ESP_SD_MOSI_PIN -1 #define ESP_SD_MOSI_PIN -1
#endif //ESP_SD_MOSI_PIN
#ifndef ESP_SD_SCK_PIN
#define ESP_SD_SCK_PIN -1 #define ESP_SD_SCK_PIN -1
#endif //ESP_SD_SCK_PIN
// For SDIO Connect the SD card to the following pins: // For SDIO Connect the SD card to the following pins:
//SD Card | ESP32 //SD Card | ESP32

View File

@ -54,6 +54,7 @@ uint8_t ESP_SD::getState(bool refresh)
_state = ESP_SDCARD_NOT_PRESENT; _state = ESP_SDCARD_NOT_PRESENT;
//using default value for speed ? should be parameter //using default value for speed ? should be parameter
//refresh content if card was removed //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.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SPI, ESP_SPI_FREQ / _spi_speed_divider)) {
if ( SD.cardSize() > 0 ) { if ( SD.cardSize() > 0 ) {
_state = ESP_SDCARD_IDLE; _state = ESP_SDCARD_IDLE;
@ -65,6 +66,7 @@ uint8_t ESP_SD::getState(bool refresh)
bool ESP_SD::begin() 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) #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); SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN);
#endif #endif
_started = true; _started = true;

View File

@ -86,6 +86,7 @@ uint8_t ESP_SD::getState(bool refresh)
} }
//SD is idle or not detected, let see if still the case //SD is idle or not detected, let see if still the case
_state = ESP_SDCARD_NOT_PRESENT; _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 //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.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SD_SCK_MHZ(FREQMZ/_spi_speed_divider))) {
if (SD.card()->cardSize() > 0 ) { if (SD.card()->cardSize() > 0 ) {
@ -97,6 +98,9 @@ uint8_t ESP_SD::getState(bool refresh)
bool ESP_SD::begin() 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; _started = true;
_state = ESP_SDCARD_NOT_PRESENT; _state = ESP_SDCARD_NOT_PRESENT;
_spi_speed_divider = Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV); _spi_speed_divider = Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV);