diff --git a/src/main/config/config_eeprom.c b/src/main/config/config_eeprom.c index 2850700c5..295cd77b9 100644 --- a/src/main/config/config_eeprom.c +++ b/src/main/config/config_eeprom.c @@ -47,6 +47,8 @@ PG_REGISTER(dummyConfig_t, dummyConfig, PG_DUMMY_CONFIG, 0); extern uint8_t __config_start; // configured via linker script when building binaries. extern uint8_t __config_end; +static uint16_t eepromConfigSize; + typedef enum { CR_CLASSICATION_SYSTEM = 0, CR_CLASSICATION_PROFILE1 = 1, @@ -111,7 +113,7 @@ static uint8_t updateChecksum(uint8_t chk, const void *data, uint32_t length) } // Scan the EEPROM config. Returns true if the config is valid. -static bool scanEEPROM(void) +bool isEEPROMContentValid(void) { uint8_t chk = 0; const uint8_t *p = &__config_start; @@ -148,7 +150,15 @@ static bool scanEEPROM(void) chk = updateChecksum(chk, footer, sizeof(*footer)); p += sizeof(*footer); chk = ~chk; - return chk == *p; + const uint8_t checkSum = *p; + p += sizeof(checkSum); + eepromConfigSize = p - &__config_start; + return chk == checkSum; +} + +uint16_t getEEPROMConfigSize(void) +{ + return eepromConfigSize; } // find config record for reg + classification (profile info) in EEPROM @@ -207,11 +217,6 @@ bool loadEEPROM(void) return true; } -bool isEEPROMContentValid(void) -{ - return scanEEPROM(); -} - static bool writeSettingsToEEPROM(void) { config_streamer_t streamer; diff --git a/src/main/config/config_eeprom.h b/src/main/config/config_eeprom.h index a6aafc3ca..62c8c6181 100644 --- a/src/main/config/config_eeprom.h +++ b/src/main/config/config_eeprom.h @@ -17,8 +17,12 @@ #pragma once +#include +#include + #define EEPROM_CONF_VERSION 154 bool isEEPROMContentValid(void); bool loadEEPROM(void); void writeConfigToEEPROM(void); +uint16_t getEEPROMConfigSize(void); diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 1bbd9894b..63f5dc6a6 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -29,12 +29,18 @@ #include "cms/cms.h" -#include "common/color.h" #include "common/axis.h" -#include "common/maths.h" +#include "common/color.h" #include "common/filter.h" +#include "common/maths.h" + +#include "config/config_eeprom.h" +#include "config/config_master.h" +#include "config/config_profile.h" +#include "config/feature.h" +#include "config/parameter_group.h" +#include "config/parameter_group_ids.h" -#include "drivers/sensor.h" #include "drivers/accgyro.h" #include "drivers/compass.h" #include "drivers/io.h" @@ -45,6 +51,7 @@ #include "drivers/rx_pwm.h" #include "drivers/rx_spi.h" #include "drivers/sdcard.h" +#include "drivers/sensor.h" #include "drivers/serial.h" #include "drivers/sound_beeper.h" #include "drivers/system.h" @@ -56,43 +63,37 @@ #include "fc/rc_curves.h" #include "fc/runtime_config.h" -#include "sensors/sensors.h" -#include "sensors/gyro.h" -#include "sensors/compass.h" -#include "sensors/acceleration.h" -#include "sensors/barometer.h" -#include "sensors/battery.h" -#include "sensors/boardalignment.h" +#include "flight/altitudehold.h" +#include "flight/failsafe.h" +#include "flight/imu.h" +#include "flight/mixer.h" +#include "flight/navigation.h" +#include "flight/pid.h" +#include "flight/servos.h" #include "io/beeper.h" -#include "io/serial.h" #include "io/gimbal.h" -#include "io/motors.h" -#include "io/servos.h" -#include "io/ledstrip.h" #include "io/gps.h" +#include "io/ledstrip.h" +#include "io/motors.h" #include "io/osd.h" +#include "io/serial.h" +#include "io/servos.h" #include "io/vtx.h" #include "rx/rx.h" #include "rx/rx_spi.h" +#include "sensors/acceleration.h" +#include "sensors/barometer.h" +#include "sensors/battery.h" +#include "sensors/boardalignment.h" +#include "sensors/compass.h" +#include "sensors/gyro.h" +#include "sensors/sensors.h" + #include "telemetry/telemetry.h" -#include "flight/mixer.h" -#include "flight/servos.h" -#include "flight/pid.h" -#include "flight/imu.h" -#include "flight/failsafe.h" -#include "flight/altitudehold.h" -#include "flight/navigation.h" - -#include "config/config_eeprom.h" -#include "config/config_profile.h" -#include "config/config_master.h" -#include "config/feature.h" -#include "config/parameter_group.h" - #ifndef DEFAULT_RX_FEATURE #define DEFAULT_RX_FEATURE FEATURE_RX_PARALLEL_PWM #endif @@ -1159,6 +1160,12 @@ void writeEEPROM(void) resumeRxSignal(); } +void resetEEPROM(void) +{ + resetConfigs(); + writeEEPROM(); +} + void ensureEEPROMContainsValidData(void) { if (isEEPROMContentValid()) { @@ -1167,12 +1174,6 @@ void ensureEEPROMContainsValidData(void) resetEEPROM(); } -void resetEEPROM(void) -{ - resetConfigs(); - writeEEPROM(); -} - void saveConfigAndNotify(void) { writeEEPROM(); diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 6466507e6..7a85b8538 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -17,8 +17,11 @@ #pragma once +#include #include +#include "config/parameter_group.h" + #if FLASH_SIZE <= 128 #define MAX_PROFILE_COUNT 2 #else