Skip to content

Commit

Permalink
reduce write cycles to flash (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
elral authored Sep 5, 2024
1 parent ddc92cf commit 5967300
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void OnResetConfig()

void OnSaveConfig()
{
MFeeprom.commit();
cmdMessenger.sendCmd(kConfigSaved, F("OK"));
}

Expand Down
5 changes: 1 addition & 4 deletions src/MF_Modules/MFEEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MFEEPROM::MFEEPROM() {}

void MFEEPROM::init(void)
{
#if defined(ARDUINO_ARCH_RP2040)
#if !defined(ARDUINO_ARCH_AVR)
EEPROM.begin(4096);
#endif
_eepromLength = EEPROM.length();
Expand All @@ -33,9 +33,6 @@ bool MFEEPROM::write_byte(uint16_t adr, const uint8_t data)
{
if (adr >= _eepromLength) return false;
EEPROM.write(adr, data);
#if defined(ARDUINO_ARCH_RP2040)
EEPROM.commit();
#endif
return true;
}

Expand Down
11 changes: 5 additions & 6 deletions src/MF_Modules/MFEEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class MFEEPROM
uint16_t get_length(void);
uint8_t read_byte(uint16_t adr);
bool write_byte(uint16_t adr, const uint8_t data);
void commit() {
#if !defined(ARDUINO_ARCH_AVR)
EEPROM.commit();
#endif
}

template <typename T>
bool read_block(uint16_t adr, T &t)
Expand All @@ -44,9 +49,6 @@ class MFEEPROM
{
if (adr + sizeof(T) > _eepromLength) return false;
EEPROM.put(adr, t);
#if defined(ARDUINO_ARCH_RP2040)
EEPROM.commit();
#endif
return true;
}

Expand All @@ -57,9 +59,6 @@ class MFEEPROM
for (uint16_t i = 0; i < len; i++) {
EEPROM.put(adr + i, t[i]);
}
#if defined(ARDUINO_ARCH_RP2040)
EEPROM.commit();
#endif
return true;
}
};
Expand Down

0 comments on commit 5967300

Please sign in to comment.