flash: cleanup
@@ -32,19 +32,18 @@ void flash_hard_coded_pid_identifier(void) {
}
void flash_save(void) {
-
fmc_unlock();
fmc_erase();
- unsigned long addresscount = 0;
+ uint32_t addr = 0;
- fmc_write(addresscount++, FMC_HEADER);
+ fmc_write(addr++, FMC_HEADER);
- fmc_write_float(addresscount++, initial_pid_identifier);
+ fmc_write_float(addr++, initial_pid_identifier);
- fmc_write_float(addresscount++, accelcal[0]);
- fmc_write_float(addresscount++, accelcal[1]);
- fmc_write_float(addresscount++, accelcal[2]);
+ fmc_write_float(addr++, accelcal[0]);
+ fmc_write_float(addr++, accelcal[1]);
+ fmc_write_float(addr++, accelcal[2]);
#ifdef RX_BAYANG_PROTOCOL_TELEMETRY_AUTOBIND
// autobind info
@@ -124,6 +123,7 @@ void flash_save(void) {
}
}
#endif
+
{
uint8_t buffer[PROFILE_FLASH_SIZE];
memset(buffer, 0, PROFILE_FLASH_SIZE);
@@ -143,16 +143,18 @@ void flash_save(void) {
}
void flash_load(void) {
-
- unsigned long addresscount = 0;
// check if saved data is present
- if (FMC_HEADER == fmc_read(addresscount++) && FMC_HEADER == fmc_read(256 + (PROFILE_FLASH_SIZE / 8))) {
+ uint32_t addr = 0;
+ if (FMC_HEADER != fmc_read(addr++) || FMC_HEADER != fmc_read(256 + (PROFILE_FLASH_SIZE / 8))) {
+ // Flash was empty, load defaults?
+ return;
+ }
- float saved_pid_identifier = fmc_read_float(addresscount++);
+ float saved_pid_identifier = fmc_read_float(addr++);
- accelcal[0] = fmc_read_float(addresscount++);
- accelcal[1] = fmc_read_float(addresscount++);
- accelcal[2] = fmc_read_float(addresscount++);
+ accelcal[0] = fmc_read_float(addr++);
+ accelcal[1] = fmc_read_float(addr++);
+ accelcal[2] = fmc_read_float(addr++);
#ifdef RX_BAYANG_PROTOCOL_TELEMETRY_AUTOBIND
extern char rfchannel[4];
@@ -201,7 +203,6 @@ void flash_load(void) {
} else {
rx_serial_protocol = fmc_read(50);
}
-
#endif
#ifdef SWITCHABLE_FEATURE_1
@@ -245,8 +246,4 @@ void flash_load(void) {
profile.pid = default_profile.pid;
}
}
-
- } else {
- // Flash was empty, load defaults?
- }
}
