diff --git a/App/app/aircopy.c b/App/app/aircopy.c index a9e7f227..f555484d 100644 --- a/App/app/aircopy.c +++ b/App/app/aircopy.c @@ -88,7 +88,7 @@ DECLARE_AIRCOPY_BANK(1) // For settings only static const AIRCOPY_Segment_t AIRCOPY_Segments_Settings[] = { - { 0xA000, 0xA160, AIRCOPY_WRITE_BYTES }, + { 0xA000, 0xA170, AIRCOPY_WRITE_BYTES }, }; static const AIRCOPY_TransferMap_t AIRCOPY_Map_Settings = { diff --git a/App/driver/eeprom_compat.c b/App/driver/eeprom_compat.c index b61aadb3..60bfa8db 100644 --- a/App/driver/eeprom_compat.c +++ b/App/driver/eeprom_compat.c @@ -52,7 +52,7 @@ static const AddrMapping_t ADDR_MAPPINGS[] = { _MK_MAPPING(0x009000, 0x009000, 0x0090D6), // 14 VFO * 16 Bytes (ex 0x001000) - _MK_MAPPING(0x00A000, 0x00A000, 0x00A160), // Settings * 16 Bytes (ex 0x004000) 0x00A000 -> 0x00A010 + _MK_MAPPING(0x00A000, 0x00A000, 0x00A170), // Settings * 16 Bytes (ex 0x004000) 0x00A000 -> 0x00A010 // Settings * 16 Bytes (ex 0x005000) 0x00A010 -> 0x00A020 // Settings FM * 8 Bytes (0x006000) 0x00A020 -> 0x00A028 // MR FM * 128 Bytes (0x003000) 0x00A028 -> 0x00A0A8 @@ -62,6 +62,7 @@ static const AddrMapping_t ADDR_MAPPINGS[] = { // Settings AES * 16 Bytes (0x00A000) 0x00A140 -> 0x00A150 // Settings * 8 Bytes (0x00B000) 0x00A150 -> 0x00A158 // Settings F4HWN * 8 Bytes (0x00C000) 0x00A158 -> 0x00A160 + // Settings Version * 16 Bytes 0x00A160 -> 0x00A170 _MK_MAPPING(0x010000, 0x00B000, 0x00B200), // Calibration 512 Bytes!!! }; diff --git a/App/settings.c b/App/settings.c index 86afbdf5..ef166388 100644 --- a/App/settings.c +++ b/App/settings.c @@ -33,6 +33,46 @@ EEPROM_Config_t gEeprom = { 0 }; void SETTINGS_InitEEPROM(void) { uint8_t Data[16] = {0}; + + // + // Version check + // Read stored version from EEPROM and compare with VERSION_STRING_2 + // + { + char storedVersion[16] = {0}; + PY25Q16_ReadBuffer(0x00A160, storedVersion, sizeof(storedVersion)); + + // Compare with current version + if (strncmp(storedVersion, VERSION_STRING_2, sizeof(storedVersion)) != 0) + { + // Different version: new install or firmware update + + // 1. Write new version to EEPROM + char newVersion[16] = {0}; + strncpy(newVersion, VERSION_STRING_2, sizeof(newVersion)); + PY25Q16_WriteBuffer(0x00A160, newVersion, sizeof(newVersion), false); + + // 2. Reset sensitive parameters (MENU_LOCK, etc.) + uint8_t configByte[8] = {0}; + PY25Q16_ReadBuffer(0x00A000, configByte, sizeof(configByte)); + + configByte[4] &= (uint8_t)~0x01; // KEY_LOCK = 0 + configByte[4] &= (uint8_t)~0x02; // MENU_LOCK = 0 + configByte[4] &= (uint8_t)~0x3C; // SET_KEY = 0 + configByte[4] &= (uint8_t)~0x40; // SET_NAV = 0 + + PY25Q16_WriteBuffer(0x00A000, configByte, sizeof(configByte), false); + + // 3. Reset display inversion (SET_INV = 0) + uint8_t displayByte[8] = {0}; + PY25Q16_ReadBuffer(0x00A158, displayByte, sizeof(displayByte)); + + displayByte[5] &= (uint8_t)~0x10; // Clear bit 4 (SET_INV) + + PY25Q16_WriteBuffer(0x00A158, displayByte, sizeof(displayByte), false); + } + } + // 0E70..0E77 PY25Q16_ReadBuffer(0x00A000, Data, 8); #ifdef ENABLE_FEAT_F4HWN_AUDIO