Optimize MarlinSettings with template methods (#21426)

This commit is contained in:
Ramiro Polla
2021-03-24 13:32:08 +01:00
committed by GitHub
parent 2d2291d00e
commit 3ced55aa93
2 changed files with 48 additions and 19 deletions

View File

@@ -76,12 +76,15 @@ class MarlinSettings {
//static void delete_mesh(); // necessary if we have a MAT
//static void defrag_meshes(); // "
#endif
#else
#else // !EEPROM_SETTINGS
FORCE_INLINE
static bool load() { reset(); report(); return true; }
FORCE_INLINE
static void first_load() { (void)load(); }
#endif
#endif // !EEPROM_SETTINGS
#if DISABLED(DISABLE_M503)
static void report(const bool forReplay=false);
@@ -105,7 +108,42 @@ class MarlinSettings {
static bool _load();
static bool size_error(const uint16_t size);
#endif
static int eeprom_index;
static uint16_t working_crc;
static bool EEPROM_START(int eeprom_offset) {
if (!persistentStore.access_start()) { SERIAL_ECHO_MSG("No EEPROM."); return false; }
eeprom_index = eeprom_offset;
working_crc = 0;
return true;
}
static void EEPROM_FINISH(void) { persistentStore.access_finish(); }
template<typename T>
static void EEPROM_SKIP(const T &VAR) { eeprom_index += sizeof(VAR); }
template<typename T>
static void EEPROM_WRITE(const T &VAR) {
persistentStore.write_data(eeprom_index, (const uint8_t *) &VAR, sizeof(VAR), &working_crc);
}
template<typename T>
static void EEPROM_READ(T &VAR) {
persistentStore.read_data(eeprom_index, (uint8_t *) &VAR, sizeof(VAR), &working_crc, !validating);
}
static void EEPROM_READ(uint8_t *VAR, size_t sizeof_VAR) {
persistentStore.read_data(eeprom_index, VAR, sizeof_VAR, &working_crc, !validating);
}
template<typename T>
static void EEPROM_READ_ALWAYS(T &VAR) {
persistentStore.read_data(eeprom_index, (uint8_t *) &VAR, sizeof(VAR), &working_crc);
}
#endif // EEPROM_SETTINGS
};
extern MarlinSettings settings;