|
|
@ -55,12 +55,7 @@ static int32_t checksum(uint8_t *data, int32_t n) { |
|
|
|
|
|
|
|
bool ConfigService::initialize() { |
|
|
|
mutex.init(); |
|
|
|
|
|
|
|
AppHal::MX_I2C1_Init(); |
|
|
|
eeprom.initialize(&hi2c1); |
|
|
|
if (!eeprom.isOnline()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
static_assert(kcfg_max == CFG_MAX_INDEX, ""); |
|
|
|
if (!checkcfg()) { |
|
|
@ -74,7 +69,7 @@ bool ConfigService::initialize() { |
|
|
|
} |
|
|
|
|
|
|
|
cfgcache.checksum = CHECKSUM(); |
|
|
|
eeprom.write(CONFIG_EEPROM_ADD, (uint8_t *)&cfgcache, sizeof(cfgcache)); |
|
|
|
AppHardware::ins()->eeprom.write(CONFIG_EEPROM_ADD, (uint8_t *)&cfgcache, sizeof(cfgcache)); |
|
|
|
flashall(); |
|
|
|
} |
|
|
|
bool suc = checkcfg(); |
|
|
@ -182,7 +177,7 @@ const char *ConfigService::_getcfg(config_index_t index, CfgItermCache *cache) { |
|
|
|
} |
|
|
|
|
|
|
|
bool ConfigService::checkcfg() { |
|
|
|
eeprom.read(CONFIG_EEPROM_ADD, (uint8_t *)&cfgcache, sizeof(cfgcache)); |
|
|
|
AppHardware::ins()->eeprom.read(CONFIG_EEPROM_ADD, (uint8_t *)&cfgcache, sizeof(cfgcache)); |
|
|
|
|
|
|
|
int32_t checksumval = CHECKSUM(); |
|
|
|
|
|
|
@ -195,10 +190,10 @@ bool ConfigService::checkcfg() { |
|
|
|
bool ConfigService::flashIndex(int32_t index) { |
|
|
|
// for (int i = 0; i < sizeof(cfg_content_t); i += 4) {
|
|
|
|
// uint32_t wdata = cfgcache.cfg[index].u32s[i / 4];
|
|
|
|
// eeprom.write32(TO_EEPROM_ADD(index) + i, wdata);
|
|
|
|
// AppHardware::ins()->eeprom.write32(TO_EEPROM_ADD(index) + i, wdata);
|
|
|
|
// }
|
|
|
|
eeprom.write(TO_EEPROM_ADD(index), (uint8_t *)&cfgcache.cfg[index], sizeof(cfg_content_t)); |
|
|
|
eeprom.write32(CONFIG_EEPROM_ADD + 4 * 1, (uint32_t)cfgcache.checksum); |
|
|
|
AppHardware::ins()->eeprom.write(TO_EEPROM_ADD(index), (uint8_t *)&cfgcache.cfg[index], sizeof(cfg_content_t)); |
|
|
|
AppHardware::ins()->eeprom.write32(CONFIG_EEPROM_ADD + 4 * 1, (uint32_t)cfgcache.checksum); |
|
|
|
return true; |
|
|
|
} |
|
|
|
bool ConfigService::flashall() { eeprom.write(CONFIG_EEPROM_ADD, (uint8_t *)&cfgcache, sizeof(cfgcache)); } |
|
|
|
bool ConfigService::flashall() { AppHardware::ins()->eeprom.write(CONFIG_EEPROM_ADD, (uint8_t *)&cfgcache, sizeof(cfgcache)); } |