From feab0bcb81d00eaf8dc3691375e1da696d7f88be Mon Sep 17 00:00:00 2001 From: jflyper Date: Mon, 10 Dec 2018 22:04:14 +0900 Subject: [PATCH] Speed up the first boot on generic firmware --- src/main/fc/config.c | 31 +++++++++++++++++++++++++++---- src/main/fc/config.h | 3 +++ src/main/fc/init.c | 4 +++- src/main/target/common_post.h | 6 ++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 840030f70a..e31f72cfe4 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -87,6 +87,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig, .powerOnArmingGraceTime = 5, .boardIdentifier = TARGET_BOARD_IDENTIFIER, .hseMhz = SYSTEM_HSE_VALUE, // Not used for non-F4 targets + .configured = false, ); uint8_t getCurrentPidProfileIndex(void) @@ -527,30 +528,43 @@ bool readEEPROM(void) return success; } -void writeEEPROM(void) +static void ValidateAndWriteConfigToEEPROM(bool setConfigured) { validateAndFixConfig(); suspendRxPwmPpmSignal(); +#ifdef USE_CONFIGURATION_STATE + if (setConfigured) { + systemConfigMutable()->configured = true; + } +#else + UNUSED(setConfigured); +#endif + writeConfigToEEPROM(); resumeRxPwmPpmSignal(); } +void writeEEPROM(void) +{ + ValidateAndWriteConfigToEEPROM(true); +} + void writeEEPROMWithFeatures(uint32_t features) { featureDisableAll(); featureEnable(features); - writeEEPROM(); + ValidateAndWriteConfigToEEPROM(true); } void resetEEPROM(void) { resetConfigs(); - writeEEPROM(); + ValidateAndWriteConfigToEEPROM(false); activateConfig(); } @@ -565,7 +579,7 @@ void ensureEEPROMStructureIsValid(void) void saveConfigAndNotify(void) { - writeEEPROM(); + ValidateAndWriteConfigToEEPROM(true); readEEPROM(); beeperConfirmationBeeps(1); } @@ -581,3 +595,12 @@ void changePidProfile(uint8_t pidProfileIndex) beeperConfirmationBeeps(pidProfileIndex + 1); } + +bool isSystemConfigured(void) +{ +#ifdef USE_CONFIGURATION_STATE + return systemConfig()->configured; +#else + return true; +#endif +} diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 7816a8eb0b..168b52c5e8 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -43,6 +43,7 @@ typedef struct systemConfig_s { uint8_t powerOnArmingGraceTime; // in seconds char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1]; uint8_t hseMhz; // Not used for non-F4 targets + uint8_t configured; } systemConfig_t; PG_DECLARE(systemConfig_t, systemConfig); @@ -75,3 +76,5 @@ uint16_t getCurrentMinthrottle(void); void resetConfigs(void); void targetConfiguration(void); void targetValidateConfiguration(void); + +bool isSystemConfigured(void); diff --git a/src/main/fc/init.c b/src/main/fc/init.c index 016214ef9e..61975cd7be 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -503,7 +503,9 @@ void init(void) if (!sensorsAutodetect()) { // if gyro was not detected due to whatever reason, notify and don't arm. - indicateFailure(FAILURE_MISSING_ACC, 2); + if (isSystemConfigured()) { + indicateFailure(FAILURE_MISSING_ACC, 2); + } setArmingDisabled(ARMING_DISABLED_NO_GYRO); } diff --git a/src/main/target/common_post.h b/src/main/target/common_post.h index 8fa15bf231..41c4e0e49c 100644 --- a/src/main/target/common_post.h +++ b/src/main/target/common_post.h @@ -205,9 +205,11 @@ #define USE_RX_XN297 #endif +#ifdef GENERIC_TARGET +#define USE_CONFIGURATION_STATE + // Setup crystal frequency for backward compatibility // Should be set to zero for generic targets and set with CLI variable set system_hse_value. -#ifdef GENERIC_TARGET #define SYSTEM_HSE_VALUE 0 #else #ifdef TARGET_XTAL_MHZ @@ -215,7 +217,7 @@ #else #define SYSTEM_HSE_VALUE (HSE_VALUE/1000000U) #endif -#endif +#endif // GENERIC_TARGET // Number of pins that needs pre-init #ifdef USE_SPI