diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 98dad92cc..d80ec7668 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1817,7 +1817,8 @@ void opentxInit() #endif #if defined(EEPROM) - storageReadRadioSettings(); + storageClearRadioSetting(); + storageReadRadioSettings(false); #endif BACKLIGHT_ENABLE(); // we start the backlight during the startup animation @@ -1876,6 +1877,7 @@ void opentxInit() #endif #if defined(EEPROM) + storageReadRadioSettings(true); storageReadCurrentModel(); #endif diff --git a/radio/src/storage/eeprom_common.cpp b/radio/src/storage/eeprom_common.cpp index e25533bab..b31115e30 100644 --- a/radio/src/storage/eeprom_common.cpp +++ b/radio/src/storage/eeprom_common.cpp @@ -86,9 +86,17 @@ void eeLoadModelHeaders() } } -void storageReadRadioSettings() +void storageClearRadioSetting() { - if (!eepromOpen() || !eeLoadGeneral()) { + memclear(&g_eeGeneral, sizeof(RadioData)); +} + +void storageReadRadioSettings(bool allowConversion) +{ + if (g_eeGeneral.version != 0) + return; + + if (!eepromOpen() || !eeLoadGeneral(allowConversion)) { storageEraseAll(true); } else { @@ -110,7 +118,7 @@ void storageReadCurrentModel() void storageReadAll() { - storageReadRadioSettings(); + storageReadRadioSettings(true); storageReadCurrentModel(); } diff --git a/radio/src/storage/eeprom_common.h b/radio/src/storage/eeprom_common.h index 00c840c03..bab56b07a 100644 --- a/radio/src/storage/eeprom_common.h +++ b/radio/src/storage/eeprom_common.h @@ -32,6 +32,7 @@ void selectModel(uint8_t sub); void eeLoadModelHeader(uint8_t id, ModelHeader *header); void eeLoadModelHeaders(); -void storageReadRadioSettings(); +void storageClearRadioSetting(); +void storageReadRadioSettings(bool allowConversion); void storageReadCurrentModel(); diff --git a/radio/src/storage/eeprom_raw.cpp b/radio/src/storage/eeprom_raw.cpp index 3e286ec49..1d329b1e3 100644 --- a/radio/src/storage/eeprom_raw.cpp +++ b/radio/src/storage/eeprom_raw.cpp @@ -256,13 +256,18 @@ void writeModel(int index) writeFile(index+1, (uint8_t *)&g_model, sizeof(g_model)); } -bool eeLoadGeneral() +bool eeLoadGeneral(bool allowConversion) { eeLoadGeneralSettingsData(); if (g_eeGeneral.version != EEPROM_VER) { TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER); #if defined(PCBSKY9X) + if (!allowConversion) { + storageClearRadioSetting(); + return true; // prevent eeprom from being wiped + } + if (!eeConvert()) { return false; } diff --git a/radio/src/storage/eeprom_raw.h b/radio/src/storage/eeprom_raw.h index ca2b50f82..b8f63c191 100644 --- a/radio/src/storage/eeprom_raw.h +++ b/radio/src/storage/eeprom_raw.h @@ -24,8 +24,8 @@ #include #include -bool eeLoadGeneral( void ) ; -void eeDeleteModel( uint8_t id ) ; +bool eeLoadGeneral(bool allowConversion); +void eeDeleteModel( uint8_t id ); bool eeCopyModel(uint8_t dst, uint8_t src); void eeSwapModels(uint8_t id1, uint8_t id2); diff --git a/radio/src/storage/eeprom_rlc.cpp b/radio/src/storage/eeprom_rlc.cpp index 2534a544a..6c458f088 100644 --- a/radio/src/storage/eeprom_rlc.cpp +++ b/radio/src/storage/eeprom_rlc.cpp @@ -757,7 +757,7 @@ uint16_t eeLoadModelData(uint8_t index) return theFile.readRlc((uint8_t*)&g_model, sizeof(g_model)); } -bool eeLoadGeneral() +bool eeLoadGeneral(bool allowConversion) { theFile.openRlc(FILE_GENERAL); if (theFile.readRlc((uint8_t*)&g_eeGeneral, 3) == 3 && g_eeGeneral.version == EEPROM_VER) { @@ -796,6 +796,10 @@ bool eeLoadGeneral() #endif #if defined(EEPROM_CONVERSIONS) if (g_eeGeneral.version != EEPROM_VER) { + if (!allowConversion) { + storageClearRadioSetting(); + return true; // prevent eeprom from being wiped + } TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER); if (!eeConvert()) { return false; diff --git a/radio/src/storage/eeprom_rlc.h b/radio/src/storage/eeprom_rlc.h index ab9d1a639..50ce38625 100644 --- a/radio/src/storage/eeprom_rlc.h +++ b/radio/src/storage/eeprom_rlc.h @@ -180,7 +180,7 @@ void loadModel(int index, bool alarms=true); bool eepromOpen(); void eeLoadModelName(uint8_t id, char *name); -bool eeLoadGeneral(); +bool eeLoadGeneral(bool allow_conversion); // For EEPROM backup/restore inline bool isEepromStart(const void * buffer)