configuration_store.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef CONFIGURATION_STORE_H
  23. #define CONFIGURATION_STORE_H
  24. #include "MarlinConfig.h"
  25. class MarlinSettings {
  26. public:
  27. MarlinSettings() { }
  28. static uint16_t datasize();
  29. static void reset();
  30. static bool save(); // Return 'true' if data was saved
  31. FORCE_INLINE static bool init_eeprom() {
  32. reset();
  33. #if ENABLED(EEPROM_SETTINGS)
  34. const bool success = save();
  35. #if ENABLED(EEPROM_CHITCHAT)
  36. if (success) report();
  37. #endif
  38. return success;
  39. #else
  40. return true;
  41. #endif
  42. }
  43. #if ENABLED(EEPROM_SETTINGS)
  44. static bool load(); // Return 'true' if data was loaded ok
  45. static bool validate(); // Return 'true' if EEPROM data is ok
  46. #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
  47. // That can store is enabled
  48. static uint16_t meshes_start_index();
  49. FORCE_INLINE static uint16_t meshes_end_index() { return meshes_end; }
  50. static uint16_t calc_num_meshes();
  51. static int mesh_slot_offset(const int8_t slot);
  52. static void store_mesh(const int8_t slot);
  53. static void load_mesh(const int8_t slot, void * const into=NULL);
  54. //static void delete_mesh(); // necessary if we have a MAT
  55. //static void defrag_meshes(); // "
  56. #endif
  57. #else
  58. FORCE_INLINE
  59. static bool load() { reset(); report(); return true; }
  60. #endif
  61. #if DISABLED(DISABLE_M503)
  62. static void report(const bool forReplay=false);
  63. #else
  64. FORCE_INLINE
  65. static void report(const bool forReplay=false) { UNUSED(forReplay); }
  66. #endif
  67. private:
  68. static void postprocess();
  69. #if ENABLED(EEPROM_SETTINGS)
  70. static bool eeprom_error, validating;
  71. #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
  72. // That can store is enabled
  73. static constexpr uint16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
  74. // live at the very end of the eeprom
  75. #endif
  76. static bool _load();
  77. static void write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
  78. static void read_data(int &pos, uint8_t *value, uint16_t size, uint16_t *crc, const bool force=false);
  79. static bool size_error(const uint16_t size);
  80. #endif
  81. };
  82. extern MarlinSettings settings;
  83. #endif // CONFIGURATION_STORE_H