From d3b5533f571a74aec00733c39c2ffc2be2d939ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 22 Jun 2022 12:49:40 +0200 Subject: [PATCH] remove unused eeprom settings code --- main.c | 84 ---------------------------------------------------------- 1 file changed, 84 deletions(-) diff --git a/main.c b/main.c index 834136e..120a23b 100644 --- a/main.c +++ b/main.c @@ -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 */