Merge pull request #186 from elmo128/SDspi_update
SPI support for SD card access, display for esp32cam, minor changes.
This commit is contained in:
commit
e2ec393036
@ -90,12 +90,12 @@ After programming, you will only need to setup your Wifi and BTC address.
|
||||
1. Create a file named "config.json" in your card's root, containing the the following structure. Adjust the settings to your needs:
|
||||
{
|
||||
"SSID": "myWifiSSID",
|
||||
"PW": "myWifiPassword",
|
||||
"WifiPW": "myWifiPassword",
|
||||
"PoolUrl": "public-pool.io",
|
||||
"PoolPort": 21496,
|
||||
"BtcWallet": "walletID",
|
||||
"Timezone": 2,
|
||||
"saveStats": false
|
||||
"SaveStats": false
|
||||
}
|
||||
1. Insert the SD card.
|
||||
1. Hold down the "reset configurations" button as described below to reset the configurations and/or boot without settings in your nvmemory.
|
||||
|
@ -149,6 +149,9 @@
|
||||
#ifdef NERMINER_S3_DONGLE
|
||||
#include <User_Setups/Setup209_LilyGo_T_Dongle_S3.h> // For the LilyGo T-Dongle S3 based ESP32 with ST7735 80 x 160 TFT
|
||||
#endif
|
||||
#ifdef ESP32_CAM
|
||||
#include <User_Setups/Setup212_ESP32Cam_DongleDisplay.h> // For the LilyGo T-Dongle S3 based ESP32 with ST7735 80 x 160 TFT
|
||||
#endif
|
||||
//#include <User_Setups/Setup301_BW16_ST7735.h> // Setup file for Bw16-based boards with ST7735 160 x 80 TFT
|
||||
|
||||
//#include <User_Setups/SetupX_Template.h> // Template file for a setup
|
||||
|
56
lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h
Normal file
56
lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h
Normal file
@ -0,0 +1,56 @@
|
||||
// Config for esp32cam, using dongledriver w ESP32 and ST7735 80 x 160 display
|
||||
#define USER_SETUP_ID 212
|
||||
|
||||
#define ST7735_DRIVER // Configure all registers
|
||||
|
||||
#define TFT_WIDTH 80
|
||||
#define TFT_HEIGHT 160
|
||||
|
||||
// #define ST7735_INITB
|
||||
// #define ST7735_GREENTAB
|
||||
// #define ST7735_GREENTAB2
|
||||
// #define ST7735_GREENTAB3
|
||||
// #define ST7735_GREENTAB128 // For 128 x 128 display
|
||||
#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
|
||||
// #define ST7735_REDTAB
|
||||
//#define ST7735_BLACKTAB
|
||||
// #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset
|
||||
|
||||
//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
|
||||
#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
|
||||
|
||||
//#define TFT_INVERSION_ON
|
||||
//#define TFT_INVERSION_OFF
|
||||
|
||||
// Generic ESP32 setup
|
||||
#define TFT_MISO 2
|
||||
#define TFT_MOSI 15
|
||||
#define TFT_SCLK 14
|
||||
#define TFT_CS 12
|
||||
#define TFT_DC 0
|
||||
#define TFT_RST 22 // Connect reset to ensure display initialises (not really required).
|
||||
|
||||
#if (TFT_MISO == 16) || (TFT_MOSI == 16)|| (TFT_SCLK == 16)|| (TFT_CS == 16)|| (TFT_DC == 16)|| (TFT_RST == 16)
|
||||
#warning: Using GPIO16 for display might crash on initializing the display!
|
||||
#endif
|
||||
|
||||
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
|
||||
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
|
||||
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
|
||||
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
|
||||
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
|
||||
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
|
||||
|
||||
#define SMOOTH_FONT
|
||||
|
||||
|
||||
#define SPI_FREQUENCY 27000000
|
||||
//#define SPI_FREQUENCY 40000000
|
||||
|
||||
#define SPI_READ_FREQUENCY 20000000
|
||||
|
||||
//#define SPI_TOUCH_FREQUENCY 2500000
|
||||
|
||||
// #define SUPPORT_TRANSACTIONS
|
@ -12,6 +12,8 @@
|
||||
globallib_dir = lib
|
||||
default_envs = esp32cam, ESP32-2432S028R, NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:NerminerV2]
|
||||
platform = espressif32
|
||||
board = esp32-s3-devkitc-1
|
||||
@ -38,11 +40,13 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:ESP32-devKitv1]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
@ -62,10 +66,12 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:TTGO-T-Display]
|
||||
platform = espressif32
|
||||
board = esp32dev ;esp-wrover-kit
|
||||
@ -85,11 +91,13 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:NerminerV2-S3-AMOLED]
|
||||
platform = espressif32
|
||||
board = lilygo-t-amoled
|
||||
@ -102,11 +110,13 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:NerminerV2-S3-DONGLE]
|
||||
platform = espressif32
|
||||
board = esp32-s3-devkitc-1
|
||||
@ -119,12 +129,14 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
https://github.com/FastLED/FastLED
|
||||
;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:esp32cam]
|
||||
platform = espressif32 ;(ESP32-D0WD-V3)
|
||||
board = esp32cam
|
||||
@ -136,17 +148,23 @@ monitor_filters =
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
board_build.partitions = huge_app.csv
|
||||
board_build.arduino.memory_type = dio_qspi
|
||||
build_flags =
|
||||
-D ESP32_CAM
|
||||
-D BOARD_HAS_PSRAM
|
||||
-D MONITOR_SPEED=${this.monitor_speed}
|
||||
;-D DEBUG_MINING
|
||||
;-D DEBUG_MEMORY
|
||||
lib_deps =
|
||||
;https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
lib_ignore =
|
||||
TFT_eSPI
|
||||
;TFT_eSPI
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:NerminerV2-T-QT]
|
||||
platform = espressif32
|
||||
@ -167,10 +185,12 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:ESP32-2432S028R]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
@ -208,12 +228,14 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
arduino-libraries/NTPClient
|
||||
bodmer/TFT_eSPI @ ^2.5.31
|
||||
https://github.com/achillhasler/TFT_eTouch
|
||||
|
||||
;--------------------------------------------------------------------
|
||||
|
||||
[env:NerdminerV2-T-Display_V1]
|
||||
platform = espressif32
|
||||
board = ttgo-lora32-v1
|
||||
@ -231,7 +253,6 @@ build_flags =
|
||||
lib_deps =
|
||||
https://github.com/takkaO/OpenFontRender
|
||||
bblanchon/ArduinoJson@^6.21.2
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
|
||||
mathertel/OneButton @ ^2.0.3
|
||||
https://github.com/arduino-libraries/NTPClient
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "mining.h"
|
||||
#include "monitor.h"
|
||||
#include "drivers/displays/display.h"
|
||||
#include "drivers/storage/SDCard.h"
|
||||
|
||||
//3 seconds WDT
|
||||
#define WDT_TIMEOUT 3
|
||||
@ -25,9 +26,10 @@
|
||||
OneButton button2(PIN_BUTTON_2);
|
||||
#endif
|
||||
|
||||
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
SDCard SDCrd = SDCard();
|
||||
|
||||
/**********************⚡ GLOBAL Vars *******************************/
|
||||
|
||||
unsigned long start = millis();
|
||||
|
@ -4,9 +4,16 @@
|
||||
#define PIN_BUTTON_1 0
|
||||
#define LED_PIN 33
|
||||
|
||||
#define NO_DISPLAY
|
||||
#define DONGLE_DISPLAY // NO_DISPLAY
|
||||
|
||||
// SDMMC interface: 1-bit mode (might cause issues):
|
||||
// example how to configure SD card.
|
||||
// if you would define everything,
|
||||
// to select 1 bit mode, make sure SDMMC_D1-3 are undefined
|
||||
// to use spi mode, make sure all SDMMC_x pins are undefined
|
||||
|
||||
/*
|
||||
// use SDMMC interface:
|
||||
// 1-bit mode (might cause issues):
|
||||
#define SDMMC_CLK 14
|
||||
#define SDMMC_CMD 15
|
||||
#define SDMMC_D0 2
|
||||
@ -14,5 +21,16 @@
|
||||
#define SDMMC_D1 4
|
||||
#define SDMMC_D2 12
|
||||
#define SDMMC_D3 13
|
||||
*/
|
||||
|
||||
// use SPI interface
|
||||
// (default SPI unit provided by <SPI.h>)
|
||||
// setup SPI pins.
|
||||
#define SDSPI_CS 13
|
||||
// The following pins can be retreived from the TFT_eSPI lib,
|
||||
// if a display that is using it is activated.
|
||||
#define SDSPI_CLK 14
|
||||
#define SDSPI_MOSI 15
|
||||
#define SDSPI_MISO 2
|
||||
|
||||
#endif // _ESP32_CAM_H_
|
||||
|
@ -9,7 +9,10 @@
|
||||
#include "version.h"
|
||||
#include "monitor.h"
|
||||
#include "OpenFontRender.h"
|
||||
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
|
||||
#define WIDTH 160
|
||||
#define HEIGHT 80
|
||||
@ -26,6 +29,7 @@ OpenFontRender render;
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
TFT_eSprite background = TFT_eSprite(&tft);
|
||||
|
||||
#ifdef USE_LED
|
||||
#define MAX_BRIGHTNESS 16
|
||||
#define SLOW_FADE 1;
|
||||
#define FAST_FADE 4;
|
||||
@ -34,6 +38,7 @@ CRGB leds(0, 0, 0);
|
||||
int brightness = 0;
|
||||
int fadeDirection = 1;
|
||||
int fadeAmount = 0;
|
||||
#endif // USE_LED
|
||||
|
||||
extern monitor_data mMonitor;
|
||||
|
||||
@ -74,8 +79,10 @@ extern monitor_data mMonitor;
|
||||
|
||||
void dongleDisplay_Init(void)
|
||||
{
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<APA102, LED_DI_PIN, LED_CI_PIN, BGR>(&leds, 1);
|
||||
FastLED.show();
|
||||
#endif // USE_LED
|
||||
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#include <FS.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <WiFi.h>
|
||||
@ -9,41 +8,78 @@
|
||||
#include "SDCard.h"
|
||||
|
||||
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)
|
||||
|
||||
#include <SD_MMC.h>
|
||||
#elif defined (BUILD_SDSPI)
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
#endif // interface type
|
||||
|
||||
SDCard::SDCard()
|
||||
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) || defined (BUILD_SDSPI)
|
||||
|
||||
/// @param int ID only relevant in SPI mode, if you want to set up a custom SPI unit. Ignored in SD bus mode.
|
||||
SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false)
|
||||
{
|
||||
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)
|
||||
iSD_ = &SD_MMC;
|
||||
#elif defined (BUILD_SDSPI)
|
||||
#error You chose to run the sd card in SPI mode. This is not implemented yet.
|
||||
#endif
|
||||
if(ID>=0)
|
||||
{
|
||||
ispi_ = new SPIClass(ID);
|
||||
newInstance_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ispi_ = &SPI;
|
||||
newInstance_ = false;
|
||||
}
|
||||
iSD_ = &SD;
|
||||
#endif // interface type
|
||||
initSDcard();
|
||||
}
|
||||
|
||||
SDCard::~SDCard()
|
||||
{
|
||||
unmount();
|
||||
iSD_->end();
|
||||
#ifdef BUILD_SDSPI
|
||||
if(newInstance_)
|
||||
{
|
||||
ispi_->end();
|
||||
delete ispi_;
|
||||
}
|
||||
#endif // BUILD_SDSPI
|
||||
Serial.println("SDCard: Unmounted");
|
||||
}
|
||||
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem)
|
||||
/// @brief Check if the card is accessed right now.
|
||||
/// @return true if active
|
||||
bool SDCard::cardBusy()
|
||||
{
|
||||
TSettings Settings;
|
||||
if (loadConfigFile(&Settings))
|
||||
return cardBusy_;
|
||||
}
|
||||
|
||||
/// @brief Transfer settings from config file on a SD card to the device.
|
||||
/// @param nvMemory* where to save
|
||||
/// @param TSettings* passing a struct is required, to save memory
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings)
|
||||
{
|
||||
nvMem->saveConfig(&Settings);
|
||||
WiFi.begin(Settings.WifiSSID, Settings.WifiPW);
|
||||
if (loadConfigFile(Settings))
|
||||
{
|
||||
nvMem->saveConfig(Settings);
|
||||
WiFi.begin(Settings->WifiSSID, Settings->WifiPW);
|
||||
Serial.println("SDCard: Settings transfered to internal memory. Restarting now.");
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Retreives settings from a config file on a SD card.
|
||||
/// @param TSettings* Struct to update with new Settings
|
||||
/// @return true on success
|
||||
bool SDCard::loadConfigFile(TSettings* Settings)
|
||||
{
|
||||
// Load existing configuration file
|
||||
// Read configuration from FS json
|
||||
|
||||
if (initSDcard())
|
||||
if (cardAvailable())
|
||||
{
|
||||
if (iSD_->exists(JSON_CONFIG_FILE))
|
||||
{
|
||||
@ -51,18 +87,19 @@ bool SDCard::loadConfigFile(TSettings* Settings)
|
||||
File configFile = iSD_->open(JSON_CONFIG_FILE, "r");
|
||||
if (configFile)
|
||||
{
|
||||
cardBusy_ = true;
|
||||
StaticJsonDocument<512> json;
|
||||
DeserializationError error = deserializeJson(json, configFile);
|
||||
configFile.close();
|
||||
cardBusy_ = false;
|
||||
Serial.println("SDCard: Loading config file");
|
||||
serializeJsonPretty(json, Serial);
|
||||
Serial.print('\n');
|
||||
unmount();
|
||||
if (!error)
|
||||
{
|
||||
strcpy(Settings->WifiSSID, json[JSON_KEY_SSID] | Settings->WifiSSID);
|
||||
strcpy(Settings->WifiPW, json[JSON_KEY_PASW] | Settings->WifiPW);
|
||||
strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress);
|
||||
serializeJsonPretty(json, Serial);
|
||||
Serial.print('\n');
|
||||
Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID;
|
||||
Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW;
|
||||
Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress;
|
||||
strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet);
|
||||
if (json.containsKey(JSON_KEY_POOLPORT))
|
||||
Settings->PoolPort = json[JSON_KEY_POOLPORT].as<int>();
|
||||
@ -87,71 +124,72 @@ bool SDCard::loadConfigFile(TSettings* Settings)
|
||||
{
|
||||
Serial.println("SDCard: No config file available!");
|
||||
}
|
||||
unmount();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SDCard::unmount()
|
||||
/// @brief Check if a SD card is inserted.
|
||||
/// @return true if inserted.
|
||||
bool SDCard::cardAvailable()
|
||||
{
|
||||
iSD_->end();
|
||||
Serial.println("SDCard: Unmounted");
|
||||
}
|
||||
|
||||
bool SDCard::initSDcard()
|
||||
if (cardInitialized_)
|
||||
{
|
||||
if (iSD_->cardType() != CARD_NONE)
|
||||
{
|
||||
Serial.println("SDCard: Already mounted.");
|
||||
return true;
|
||||
}
|
||||
Serial.println("SDCard: Mounting card.");
|
||||
|
||||
bool cardInitialized = false;
|
||||
#if defined (BUILD_SDMMC_4)
|
||||
if (iSD_->cardType() == CARD_NONE)
|
||||
{
|
||||
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3);
|
||||
Serial.println("SDCard: 4-Bit Mode.");
|
||||
cardInitialized = iSD_->begin("/sd", false);
|
||||
}
|
||||
#elif defined (BUILD_SDMMC_1)
|
||||
#warning SDMMC : 1 - bit mode is not always working.If you experience issues, try other modes.
|
||||
if (iSD_->cardType() == CARD_NONE)
|
||||
{
|
||||
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
|
||||
Serial.println("SDCard: 1-Bit Mode.");
|
||||
cardInitialized = iSD_->begin("/sd", true);
|
||||
}
|
||||
#elif defined (BUILD_SDSPI)
|
||||
#error You chose to run the sd card in SPI mode. This is not implemented yet.
|
||||
#else
|
||||
Serial.println("SDCard: interface not available.");
|
||||
return false;
|
||||
#endif // dataPinsDefined
|
||||
if (cardInitialized)
|
||||
{
|
||||
if (iSD_->cardType() != CARD_NONE)
|
||||
{
|
||||
Serial.println("SDCard: Mounted.");
|
||||
Serial.println("SDCard: Inserted.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("SDCard: Mounting failed.");
|
||||
iSD_->end();
|
||||
Serial.println("SDCard: Not inserted.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("SDCard: Interface not initialized.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Init SD card interface. Normaly not required, as this is called by the constructor.
|
||||
/// @return true on success
|
||||
bool SDCard::initSDcard()
|
||||
{
|
||||
if (!cardAvailable())
|
||||
{
|
||||
Serial.println("SDCard: init SD card interface.");
|
||||
#if defined (BUILD_SDMMC_4)
|
||||
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3);
|
||||
cardInitialized_ = iSD_->begin("/sd", false);
|
||||
Serial.println("SDCard: 4-Bit Mode.");
|
||||
}
|
||||
#elif defined (BUILD_SDMMC_1)
|
||||
#warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes.
|
||||
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
|
||||
cardInitialized_ = iSD_->begin("/sd", true);
|
||||
Serial.println("SDCard: 1-Bit Mode.");
|
||||
}
|
||||
#elif defined (BUILD_SDSPI)
|
||||
ispi_->begin(SDSPI_CLK, SDSPI_MISO, SDSPI_MOSI, SDSPI_CS);
|
||||
cardInitialized_ = iSD_->begin(SDSPI_CS, *ispi_);
|
||||
Serial.println("SDCard: SPI mode.");
|
||||
}
|
||||
#else
|
||||
Serial.println("SDCard: interface not defined.");
|
||||
return false;
|
||||
#endif // dataPinsDefined
|
||||
cardAvailable();
|
||||
return cardInitialized_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
SDCard::SDCard() {}
|
||||
SDCard::SDCard(int ID) {}
|
||||
SDCard::~SDCard() {}
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem) {};
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {};
|
||||
bool SDCard::loadConfigFile(TSettings* Settings) { return false; }
|
||||
bool SDCard::initSDcard() { return false; }
|
||||
void unmount() {}
|
||||
bool SDCard::cardAvailable() { return false; }
|
||||
bool SDCard::cardBusy() { return false; }
|
||||
|
||||
#endif //BUILD_SDMMC
|
@ -5,33 +5,66 @@
|
||||
#include "nvMemory.h"
|
||||
#include "..\devices\device.h"
|
||||
|
||||
// configuration example and description in /devices/esp32cam.h
|
||||
|
||||
// select interface and options according to provided pins
|
||||
#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)
|
||||
#define BUILD_SDMMC_4
|
||||
#undef BUILD_SDMMC_1
|
||||
#undef BUILD_SDSPI
|
||||
#include <SD_MMC.h>
|
||||
#warning SD card support in 4-Bit mode enabled!
|
||||
#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3))
|
||||
#define BUILD_SDMMC_1
|
||||
#undef BUILD_SDMMC_4
|
||||
#undef BUILD_SDSPI
|
||||
#include <SD_MMC.h>
|
||||
#else
|
||||
#warning SD card support disabled!
|
||||
#warning SD card support in 1-Bit mode enabled!
|
||||
#elif defined (SDSPI_CS)
|
||||
#undef BUILD_SDMMC_1
|
||||
#undef BUILD_SDMMC_4
|
||||
#define BUILD_SDSPI
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
#include "..\lib\TFT_eSPI\User_Setup_Select.h"
|
||||
|
||||
#ifndef NO_DISPLAY
|
||||
#if !defined(SDSPI_CLK) && defined(TFT_CLK)
|
||||
#define SDSPI_CLK TFT_CLK
|
||||
#endif // SDSPI_CLK
|
||||
#if !defined(SDSPI_MOSI) && defined(TFT_MOSI)
|
||||
#define SDSPI_MOSI TFT_MOSI
|
||||
#endif // SDSPI_MOSI
|
||||
#if !defined(SDSPI_MISO) && defined(TFT_MISO)
|
||||
#define SDSPI_MISO TFT_MISO
|
||||
#endif // SDSPI_MISO
|
||||
#elif !defined(SDSPI_CLK) || !defined(SDSPI_MOSI) || !defined(SDSPI_MISO)
|
||||
#error: Please define SDSPI pins!
|
||||
#endif // NO_DISPLAY
|
||||
|
||||
#warning SD card support in SPI mode enabled!
|
||||
#endif
|
||||
|
||||
// Handles the transfer of settings from sd card to nv memory (wifi credentials are handled by wifimanager)
|
||||
class SDCard
|
||||
{
|
||||
public:
|
||||
SDCard();
|
||||
SDCard(int ID=-1);
|
||||
~SDCard();
|
||||
void SD2nvMemory(nvMemory* nvMem);
|
||||
void SD2nvMemory(nvMemory* nvMem, TSettings* Settings);
|
||||
bool loadConfigFile(TSettings* Settings);
|
||||
bool cardAvailable();
|
||||
bool cardBusy();
|
||||
private:
|
||||
bool initSDcard();
|
||||
void unmount();
|
||||
|
||||
bool cardInitialized_;
|
||||
bool cardBusy_;
|
||||
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)
|
||||
fs::SDMMCFS* iSD_;
|
||||
#elif defined (BUILD_SDSPI)
|
||||
#error You chose to run the SD card in SPI mode. This is not implemented yet.
|
||||
SPIClass* ispi_;
|
||||
fs::SDFS* iSD_;
|
||||
bool newInstance_;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -9,10 +9,7 @@
|
||||
#include "..\devices\device.h"
|
||||
#include "storage.h"
|
||||
|
||||
nvMemory::nvMemory()
|
||||
{
|
||||
Initialized_ = false;
|
||||
}
|
||||
nvMemory::nvMemory() : Initialized_(false){};
|
||||
|
||||
nvMemory::~nvMemory()
|
||||
{
|
||||
@ -20,6 +17,9 @@ nvMemory::~nvMemory()
|
||||
SPIFFS.end();
|
||||
};
|
||||
|
||||
/// @brief Save settings to config file on SPIFFS
|
||||
/// @param TSettings* Settings to be saved.
|
||||
/// @return true on success
|
||||
bool nvMemory::saveConfig(TSettings* Settings)
|
||||
{
|
||||
if (init())
|
||||
@ -29,11 +29,11 @@ bool nvMemory::saveConfig(TSettings* Settings)
|
||||
|
||||
// Create a JSON document
|
||||
StaticJsonDocument<512> json;
|
||||
json[JSON_KEY_POOLURL] = Settings->PoolAddress;
|
||||
json[JSON_KEY_POOLPORT] = Settings->PoolPort;
|
||||
json[JSON_KEY_WALLETID] = Settings->BtcWallet;
|
||||
json[JSON_KEY_TIMEZONE] = Settings->Timezone;
|
||||
json[JSON_KEY_STATS2NV] = Settings->saveStats;
|
||||
json[JSON_SPIFFS_KEY_POOLURL] = Settings->PoolAddress;
|
||||
json[JSON_SPIFFS_KEY_POOLPORT] = Settings->PoolPort;
|
||||
json[JSON_SPIFFS_KEY_WALLETID] = Settings->BtcWallet;
|
||||
json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone;
|
||||
json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats;
|
||||
|
||||
// Open config file
|
||||
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w");
|
||||
@ -60,6 +60,9 @@ bool nvMemory::saveConfig(TSettings* Settings)
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Load settings from config file located in SPIFFS.
|
||||
/// @param TSettings* Struct to update with new settings.
|
||||
/// @return true on success
|
||||
bool nvMemory::loadConfig(TSettings* Settings)
|
||||
{
|
||||
// Uncomment if we need to format filesystem
|
||||
@ -84,14 +87,14 @@ bool nvMemory::loadConfig(TSettings* Settings)
|
||||
Serial.print('\n');
|
||||
if (!error)
|
||||
{
|
||||
strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress);
|
||||
strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet);
|
||||
if (json.containsKey(JSON_KEY_POOLPORT))
|
||||
Settings->PoolPort = json[JSON_KEY_POOLPORT].as<int>();
|
||||
if (json.containsKey(JSON_KEY_TIMEZONE))
|
||||
Settings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
|
||||
if (json.containsKey(JSON_KEY_STATS2NV))
|
||||
Settings->saveStats = json[JSON_KEY_STATS2NV].as<bool>();
|
||||
Settings->PoolAddress = json[JSON_SPIFFS_KEY_POOLURL] | Settings->PoolAddress;
|
||||
strcpy(Settings->BtcWallet, json[JSON_SPIFFS_KEY_WALLETID] | Settings->BtcWallet);
|
||||
if (json.containsKey(JSON_SPIFFS_KEY_POOLPORT))
|
||||
Settings->PoolPort = json[JSON_SPIFFS_KEY_POOLPORT].as<int>();
|
||||
if (json.containsKey(JSON_SPIFFS_KEY_TIMEZONE))
|
||||
Settings->Timezone = json[JSON_SPIFFS_KEY_TIMEZONE].as<int>();
|
||||
if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV))
|
||||
Settings->saveStats = json[JSON_SPIFFS_KEY_STATS2NV].as<bool>();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -113,12 +116,16 @@ bool nvMemory::loadConfig(TSettings* Settings)
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Delete config file from SPIFFS
|
||||
/// @return true on successs
|
||||
bool nvMemory::deleteConfig()
|
||||
{
|
||||
Serial.println("SPIFS: Erasing config file..");
|
||||
return SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero
|
||||
}
|
||||
|
||||
/// @brief Prepare and mount SPIFFS
|
||||
/// @return true on success
|
||||
bool nvMemory::init()
|
||||
{
|
||||
if (!Initialized_)
|
||||
|
@ -21,9 +21,7 @@ private:
|
||||
bool Initialized_;
|
||||
};
|
||||
|
||||
#ifdef NVMEM_SPIFFS
|
||||
#define ESP_DRD_USE_SPIFFS true
|
||||
#else
|
||||
#ifndef NVMEM_SPIFFS
|
||||
#error We need some kind of permanent storage implementation!
|
||||
#endif //NVMEM_TYPE
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#ifndef _STORAGE_H_
|
||||
#define _STORAGE_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
// config files
|
||||
|
||||
// default settings
|
||||
#define DEFAULT_SSID "NerdMinerAP"
|
||||
#define DEFAULT_WIFIPW "MineYourCoins"
|
||||
#define DEFAULT_POOLURL "public-pool.io"
|
||||
@ -11,24 +14,34 @@
|
||||
#define DEFAULT_TIMEZONE 2
|
||||
#define DEFAULT_SAVESTATS false
|
||||
|
||||
// JSON config file
|
||||
// JSON config files
|
||||
#define JSON_CONFIG_FILE "/config.json"
|
||||
|
||||
// JSON config file SD card (for user interaction, readme.md)
|
||||
#define JSON_KEY_SSID "SSID"
|
||||
#define JSON_KEY_PASW "PW"
|
||||
#define JSON_KEY_PASW "WifiPW"
|
||||
#define JSON_KEY_POOLURL "PoolUrl"
|
||||
#define JSON_KEY_WALLETID "BtcWallet"
|
||||
#define JSON_KEY_POOLPORT "PoolPort"
|
||||
#define JSON_KEY_TIMEZONE "Timezone"
|
||||
#define JSON_KEY_STATS2NV "saveStats"
|
||||
#define JSON_KEY_STATS2NV "SaveStats"
|
||||
|
||||
// JSON config file SPIFFS (different for backward compatibility with existing devices)
|
||||
#define JSON_SPIFFS_KEY_POOLURL "poolString"
|
||||
#define JSON_SPIFFS_KEY_POOLPORT "portNumber"
|
||||
#define JSON_SPIFFS_KEY_WALLETID "btcString"
|
||||
#define JSON_SPIFFS_KEY_TIMEZONE "gmtZone"
|
||||
#define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS"
|
||||
|
||||
// settings
|
||||
struct TSettings
|
||||
{
|
||||
char WifiSSID[80]{ DEFAULT_SSID };
|
||||
char WifiPW[80]{ DEFAULT_WIFIPW };
|
||||
char PoolAddress[80]{ DEFAULT_POOLURL };
|
||||
String WifiSSID{ DEFAULT_SSID };
|
||||
String WifiPW{ DEFAULT_WIFIPW };
|
||||
String PoolAddress{ DEFAULT_POOLURL };
|
||||
char BtcWallet[80]{ DEFAULT_WALLETID };
|
||||
uint32_t PoolPort{ DEFAULT_POOLPORT };
|
||||
uint32_t Timezone{ DEFAULT_TIMEZONE };
|
||||
int PoolPort{ DEFAULT_POOLPORT };
|
||||
int Timezone{ DEFAULT_TIMEZONE };
|
||||
bool saveStats{ DEFAULT_SAVESTATS };
|
||||
};
|
||||
|
||||
|
@ -59,14 +59,14 @@ bool checkPoolConnection(void) {
|
||||
|
||||
//Resolve first time pool DNS and save IP
|
||||
if(serverIP == IPAddress(1,1,1,1)) {
|
||||
WiFi.hostByName(Settings.PoolAddress, serverIP);
|
||||
WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP);
|
||||
Serial.printf("Resolved DNS and save ip (first time) got: %s\n", serverIP.toString());
|
||||
}
|
||||
|
||||
//Try connecting pool IP
|
||||
if (!client.connect(serverIP, Settings.PoolPort)) {
|
||||
Serial.println("Imposible to connect to : " + String(Settings.PoolAddress));
|
||||
WiFi.hostByName(Settings.PoolAddress, serverIP);
|
||||
Serial.println("Imposible to connect to : " + Settings.PoolAddress);
|
||||
WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP);
|
||||
Serial.printf("Resolved DNS got: %s\n", serverIP.toString());
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
return false;
|
||||
@ -116,7 +116,7 @@ void runStratumWorker(void *name) {
|
||||
Serial.printf("\n[WORKER] Started. Running %s on core %d\n", (char *)name, xPortGetCoreID());
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
Serial.printf("### [Total Heap / Free heap]: %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap());
|
||||
Serial.printf("### [Total Heap / Free heap / Min free heap]: %d / %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap());
|
||||
#endif
|
||||
|
||||
// connect to pool
|
||||
@ -452,7 +452,7 @@ void runMonitor(void *name)
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
Serial.printf("### [Total Heap / Free heap]: %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap());
|
||||
Serial.printf("### [Total Heap / Free heap / Min free heap]: %d / %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap());
|
||||
Serial.printf("### Max stack usage: %d\n", uxTaskGetStackHighWaterMark(NULL));
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#define ESP_DRD_USE_SPIFFS true
|
||||
|
||||
// Include Libraries
|
||||
//#include ".h"
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
#include <WiFiManager.h>
|
||||
@ -25,6 +27,8 @@ extern monitor_data mMonitor;
|
||||
|
||||
nvMemory nvMem;
|
||||
|
||||
extern SDCard SDCrd;
|
||||
|
||||
void saveConfigCallback()
|
||||
// Callback notifying us of the need to save configuration
|
||||
{
|
||||
@ -85,11 +89,10 @@ void init_WifiManager()
|
||||
if (!nvMem.loadConfig(&Settings))
|
||||
{
|
||||
//No config file on internal flash.
|
||||
SDCard SDCrd;
|
||||
if (SDCrd.loadConfigFile(&Settings))
|
||||
{
|
||||
//Config file on SD card.
|
||||
SDCrd.SD2nvMemory(&nvMem); // reboot on success.
|
||||
SDCrd.SD2nvMemory(&nvMem, &Settings); // reboot on success.
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -122,7 +125,7 @@ void init_WifiManager()
|
||||
// Custom elements
|
||||
|
||||
// Text box (String) - 80 characters maximum
|
||||
WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress, 80);
|
||||
WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress.c_str(), 80);
|
||||
|
||||
// Need to convert numerical input to string to display the default value.
|
||||
char convertedValue[6];
|
||||
@ -168,7 +171,7 @@ void init_WifiManager()
|
||||
{
|
||||
//Could be break forced after edditing, so save new config
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress));
|
||||
Settings.PoolAddress = pool_text_box.getValue();
|
||||
Settings.PoolPort = atoi(port_text_box_num.getValue());
|
||||
strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet));
|
||||
Settings.Timezone = atoi(time_text_box_num.getValue());
|
||||
@ -187,7 +190,7 @@ void init_WifiManager()
|
||||
//Tratamos de conectar con la configuración inicial ya almacenada
|
||||
mMonitor.NerdStatus = NM_Connecting;
|
||||
wm.setCaptivePortalEnable(false); // disable captive portal redirection
|
||||
if (!wm.autoConnect(Settings.WifiSSID, Settings.WifiPW))
|
||||
if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str()))
|
||||
{
|
||||
Serial.println("Failed to connect and hit timeout");
|
||||
//delay(3000);
|
||||
@ -210,7 +213,8 @@ void init_WifiManager()
|
||||
// Lets deal with the user config values
|
||||
|
||||
// Copy the string value
|
||||
strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress));
|
||||
Settings.PoolAddress = pool_text_box.getValue();
|
||||
//strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress));
|
||||
Serial.print("PoolString: ");
|
||||
Serial.println(Settings.PoolAddress);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user