Browse Source

Specific EEPROM module

fastled^2
Xose Pérez 6 years ago
parent
commit
bc30b9e2f6
7 changed files with 76 additions and 24 deletions
  1. +4
    -0
      code/espurna/config/general.h
  2. +1
    -0
      code/espurna/config/prototypes.h
  3. +58
    -0
      code/espurna/eeprom.ino
  4. +4
    -1
      code/espurna/espurna.ino
  5. +4
    -9
      code/espurna/settings.ino
  6. +0
    -12
      code/espurna/system.ino
  7. +5
    -2
      code/espurna/utils.ino

+ 4
- 0
code/espurna/config/general.h View File

@ -142,6 +142,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#define EEPROM_SIZE 4096 // EEPROM size in bytes #define EEPROM_SIZE 4096 // EEPROM size in bytes
//#define EEPROM_RORATE_SECTORS 2 // Number of sectors to use for EEPROM rotation
// If not defined the firmware will use a number based
// on the number of available sectors
#define EEPROM_RELAY_STATUS 0 // Address for the relay status (1 byte) #define EEPROM_RELAY_STATUS 0 // Address for the relay status (1 byte)
#define EEPROM_ENERGY_COUNT 1 // Address for the energy counter (4 bytes) #define EEPROM_ENERGY_COUNT 1 // Address for the energy counter (4 bytes)
#define EEPROM_CUSTOM_RESET 5 // Address for the reset reason (1 byte) #define EEPROM_CUSTOM_RESET 5 // Address for the reset reason (1 byte)


+ 1
- 0
code/espurna/config/prototypes.h View File

@ -73,6 +73,7 @@ void settingsGetJson(JsonObject& data);
bool settingsRestoreJson(JsonObject& data); bool settingsRestoreJson(JsonObject& data);
void settingsRegisterCommand(const String& name, void (*call)(Embedis*)); void settingsRegisterCommand(const String& name, void (*call)(Embedis*));
void settingsInject(void *data, size_t len); void settingsInject(void *data, size_t len);
Stream & settingsSerial();
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// I2C // I2C


+ 58
- 0
code/espurna/eeprom.ino View File

@ -0,0 +1,58 @@
/*
EEPROM MODULE
*/
#include <EEPROM_Rotate.h>
// -----------------------------------------------------------------------------
String eepromSectors() {
String response;
for (uint32_t i = 0; i < EEPROMr.sectors(); i++) {
if (i > 0) response = response + String(", ");
response = response + String(EEPROMr.base() - i);
}
return response;
}
#if TERMINAL_SUPPORT
void _eepromInitCommands() {
settingsRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) {
EEPROMr.dump(settingsSerial());
DEBUG_MSG_P(PSTR("\n+OK\n"));
});
}
#endif
// -----------------------------------------------------------------------------
void eepromSetup() {
#ifdef EEPROM_ROTATE_SECTORS
EEPROMr.sectors(EEPROM_ROTATE_SECTORS);
#else
uint8_t sectors = 0;
if (EEPROMr.last() > 1000) { // 4Mb boards
sectors = 4;
} else if (EEPROMr.last() > 250) { // 1Mb boards
sectors = 2;
} else {
sectors = 1;
}
EEPROMr.sectors(sectors);
#endif
EEPROMr.offset(EEPROM_ROTATE_DATA);
EEPROMr.begin(EEPROM_SIZE);
#if TERMINAL_SUPPORT
_eepromInitCommands();
#endif
}

+ 4
- 1
code/espurna/espurna.ino View File

@ -47,7 +47,10 @@ void setup() {
debugSetup(); debugSetup();
#endif #endif
// Init EEPROM, Serial, SPIFFS and system check
// Init EEPROM
eepromSetup();
// Init Serial, SPIFFS and system check
systemSetup(); systemSetup();
// Init persistance and terminal features // Init persistance and terminal features


+ 4
- 9
code/espurna/settings.ino View File

@ -167,10 +167,6 @@ void _settingsFactoryResetCommand() {
EEPROMr.commit(); EEPROMr.commit();
} }
void _settingsDumpCommand() {
EEPROMr.dump(_serial);
}
void _settingsInitCommands() { void _settingsInitCommands() {
#if DEBUG_SUPPORT #if DEBUG_SUPPORT
@ -186,11 +182,6 @@ void _settingsInitCommands() {
DEBUG_MSG_P(PSTR("+OK\n")); DEBUG_MSG_P(PSTR("+OK\n"));
}); });
settingsRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) {
_settingsDumpCommand();
DEBUG_MSG_P(PSTR("\n+OK\n"));
});
settingsRegisterCommand(F("ERASE.CONFIG"), [](Embedis* e) { settingsRegisterCommand(F("ERASE.CONFIG"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n")); DEBUG_MSG_P(PSTR("+OK\n"));
resetReason(CUSTOM_RESET_TERMINAL); resetReason(CUSTOM_RESET_TERMINAL);
@ -343,6 +334,10 @@ void settingsInject(void *data, size_t len) {
_serial.inject((char *) data, len); _serial.inject((char *) data, len);
} }
Stream & settingsSerial() {
return (Stream &) _serial;
}
size_t settingsMaxSize() { size_t settingsMaxSize() {
size_t size = EEPROM_SIZE; size_t size = EEPROM_SIZE;
if (size > SPI_FLASH_SEC_SIZE) size = SPI_FLASH_SEC_SIZE; if (size > SPI_FLASH_SEC_SIZE) size = SPI_FLASH_SEC_SIZE;


+ 0
- 12
code/espurna/system.ino View File

@ -148,18 +148,6 @@ void _systemSetupSpecificHardware() {
void systemSetup() { void systemSetup() {
uint8_t sectors = 0;
if (EEPROMr.last() > 1000) { // 4Mb boards
sectors = 4;
} else if (EEPROMr.last() > 250) { // 1Mb boards
sectors = 2;
} else {
sectors = 1;
}
EEPROMr.offset(EEPROM_ROTATE_DATA);
EEPROMr.rotate(sectors);
EEPROMr.begin(EEPROM_SIZE);
#if SPIFFS_SUPPORT #if SPIFFS_SUPPORT
SPIFFS.begin(); SPIFFS.begin();
#endif #endif


+ 5
- 2
code/espurna/utils.ino View File

@ -240,8 +240,11 @@ void info() {
DEBUG_MSG_P(PSTR("[INIT] Flash size (SDK): %8u bytes / %4d sectors\n"), ESP.getFlashChipSize(), sectors(ESP.getFlashChipSize())); DEBUG_MSG_P(PSTR("[INIT] Flash size (SDK): %8u bytes / %4d sectors\n"), ESP.getFlashChipSize(), sectors(ESP.getFlashChipSize()));
DEBUG_MSG_P(PSTR("[INIT] Firmware size: %8u bytes / %4d sectors\n"), ESP.getSketchSize(), sectors(ESP.getSketchSize())); DEBUG_MSG_P(PSTR("[INIT] Firmware size: %8u bytes / %4d sectors\n"), ESP.getSketchSize(), sectors(ESP.getSketchSize()));
DEBUG_MSG_P(PSTR("[INIT] Max OTA size: %8u bytes / %4d sectors\n"), maxSketchSpace(), sectors(maxSketchSpace())); DEBUG_MSG_P(PSTR("[INIT] Max OTA size: %8u bytes / %4d sectors\n"), maxSketchSpace(), sectors(maxSketchSpace()));
DEBUG_MSG_P(PSTR("[INIT] EEPROM size: %8u bytes / %4d sectors\n"), settingsMaxSize(), sectors(settingsMaxSize()));
DEBUG_MSG_P(PSTR("[INIT] Empty space: %8u bytes / 4 sectors\n"), 4 * SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("[INIT] EEPROM size: %8u bytes / %4d sectors\n"), EEPROMr.sectors() * SPI_FLASH_SEC_SIZE, EEPROMr.sectors());
DEBUG_MSG_P(PSTR("[INIT] Reserved space: %8u bytes / 4 sectors\n"), 4 * SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("\n"));
DEBUG_MSG_P(PSTR("[INIT] EEPROM sectors: %s\n"), (char *) eepromSectors().c_str());
DEBUG_MSG_P(PSTR("\n")); DEBUG_MSG_P(PSTR("\n"));
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------


Loading…
Cancel
Save