remove unused eeprom settings code

This commit is contained in:
King Kévin 2022-06-22 12:49:40 +02:00
parent 13e8d3b5d4
commit d3b5533f57
1 changed files with 0 additions and 84 deletions

84
main.c
View File

@ -73,90 +73,6 @@ static const uint8_t nibble_reverse_bit_order_lut[] = {
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf,
};
/*
struct settings_t {
uint8_t i2c_slave_addr;
} settings;
// start address of EEPROM
#define EEPROM_ADDR 0x4000
void load_settings(void)
{
uint8_t* eeprom = (uint8_t*)EEPROM_ADDR; // address where the settings are saved
// check if magic header is present
if (0x42 != *(eeprom + 0)) {
goto error;
}
// check if checksum is correct
uint8_t crc = 0;
for (uint8_t i = 0; i < sizeof(struct settings_t) + 2; i++) {
crc ^= *(eeprom + i);
}
if (0 != crc) {
goto error;
}
// now we can load the settings
for (uint8_t i = 0; i < sizeof(struct settings_t); i++) {
*(((uint8_t*)settings) + 0) = *(eeprom + 1 + i);
}
return;
error: // use default in case of error
settings.i2c_slave_addr = 0x28;
}
bool save_settings(void)
{
uint8_t* eeprom = (uint8_t*)EEPROM_ADDR; // address where the settings are saved
uint8_t i; // index variable
bool to_return = false; // if settings have been saved
if (!(FLASH_IAPSR & FLASH_IAPSR_DUL)) { // write protection is enabled
// disable DATA (e.g. EEPROM) write protection
FLASH_DUKR = FLASH_DUKR_KEY1;
FLASH_DUKR = FLASH_DUKR_KEY2;
if (!(FLASH_IAPSR & FLASH_IAPSR_DUL)) { // un-protecting failed
return false;
}
}
// write magic header
if (0x42 != *(eeprom + 0)) {
*(eeprom + 0) = 0x42;
if (!(FLASH_IAPSR & FLASH_IAPSR_EOP)) { // write failed
goto end;
}
}
// write settings
for (i = 0; i < sizeof(struct settings_t); i++) {
if (*(eeprom + 1 + i) != *(((uint8_t*)settings) + 0)) {
*(eeprom + 1 + i) = *(((uint8_t*)settings) + 0);
if (!(FLASH_IAPSR & FLASH_IAPSR_EOP)) { // write failed
goto end;
}
}
}
// write checksum
uint8_t crc = 0;
for (i = 0; i < 1 + sizeof(struct settings_t); i++) {
crc ^= *(eeprom + i);
}
if (*(eeprom + 1 + sizeof(struct settings_t)) != crc) {
*(eeprom + 1 + sizeof(struct settings_t)) = crc;
if (!(FLASH_IAPSR & FLASH_IAPSR_EOP)) { // write failed
goto end;
}
}
to_return = true; // saving settings succeeded
end:
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
return to_return;
}
*/
/**
* @warning only up to UINT32_MAX / 10 to be safe
*/