Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB

  1. /*
  2. EEPROM MODULE
  3. */
  4. #include <EEPROM_Rotate.h>
  5. // -----------------------------------------------------------------------------
  6. bool eepromBackup() {
  7. DEBUG_MSG_P(PSTR("[EEPROM] Backing up data to last sector\n"));
  8. return EEPROMr.backup();
  9. }
  10. String eepromSectors() {
  11. String response;
  12. for (uint32_t i = 0; i < EEPROMr.pool(); i++) {
  13. if (i > 0) response = response + String(", ");
  14. response = response + String(EEPROMr.base() - i);
  15. }
  16. return response;
  17. }
  18. #if TERMINAL_SUPPORT
  19. void _eepromInitCommands() {
  20. settingsRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) {
  21. EEPROMr.dump(settingsSerial());
  22. DEBUG_MSG_P(PSTR("\n+OK\n"));
  23. });
  24. }
  25. #endif
  26. // -----------------------------------------------------------------------------
  27. void eepromSetup() {
  28. #ifdef EEPROM_ROTATE_SECTORS
  29. EEPROMr.pool(EEPROM_ROTATE_SECTORS);
  30. #else
  31. uint8_t sectors = 0;
  32. if (EEPROMr.last() > 1000) { // 4Mb boards
  33. sectors = 4;
  34. } else if (EEPROMr.last() > 250) { // 1Mb boards
  35. sectors = 2;
  36. } else {
  37. sectors = 1;
  38. }
  39. EEPROMr.pool(sectors);
  40. #endif
  41. EEPROMr.offset(EEPROM_ROTATE_DATA);
  42. EEPROMr.begin(EEPROM_SIZE);
  43. #if TERMINAL_SUPPORT
  44. _eepromInitCommands();
  45. #endif
  46. }