From 39ea315c97e218705a36476f200144a9df8462d5 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Tue, 21 Nov 2017 07:25:38 +0100 Subject: [PATCH] Fix X10 power loop (fix #5270) (#5391) * Fix X10 power loop (fix #5270) * "EMERGENCY MODE" text wasn't visible anymore since d4a00dec3b3bb643bb322a1088812f4f9b908404 --- radio/src/gui/480x272/themes/default.cpp | 2 +- radio/src/targets/horus/board.h | 2 +- radio/src/targets/horus/pwr_driver.cpp | 25 ++++++++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/radio/src/gui/480x272/themes/default.cpp b/radio/src/gui/480x272/themes/default.cpp index 3c91aad8e..429f6ee0b 100644 --- a/radio/src/gui/480x272/themes/default.cpp +++ b/radio/src/gui/480x272/themes/default.cpp @@ -264,7 +264,7 @@ class DefaultTheme: public Theme virtual void update() const { uint32_t color = g_eeGeneral.themeData.options[1].unsignedValue; - uint32_t bg_color = g_eeGeneral.themeData.options[0].unsignedValue; + uint32_t bg_color = UNEXPECTED_SHUTDOWN() ? WHITE : g_eeGeneral.themeData.options[0].unsignedValue; lcdColorTable[TEXT_BGCOLOR_INDEX] = bg_color; lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = color; diff --git a/radio/src/targets/horus/board.h b/radio/src/targets/horus/board.h index 7d07af1ef..f298da4b1 100644 --- a/radio/src/targets/horus/board.h +++ b/radio/src/targets/horus/board.h @@ -421,7 +421,7 @@ uint32_t pwrPressedDuration(void); #if defined(SIMU) || defined(NO_UNEXPECTED_SHUTDOWN) #define UNEXPECTED_SHUTDOWN() (false) #else - #define UNEXPECTED_SHUTDOWN() (powerupReason == DIRTY_SHUTDOWN) + #define UNEXPECTED_SHUTDOWN() ((powerupReason == DIRTY_SHUTDOWN) || WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) #endif // Led driver diff --git a/radio/src/targets/horus/pwr_driver.cpp b/radio/src/targets/horus/pwr_driver.cpp index 65e60199c..e7d9fbfde 100644 --- a/radio/src/targets/horus/pwr_driver.cpp +++ b/radio/src/targets/horus/pwr_driver.cpp @@ -70,7 +70,16 @@ void pwrInit() void pwrOn() { + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = PWR_ON_GPIO_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; + GPIO_Init(PWR_GPIO, &GPIO_InitStructure); + GPIO_SetBits(PWR_GPIO, PWR_ON_GPIO_PIN); + shutdownRequest = NO_SHUTDOWN_REQUEST; shutdownReason = DIRTY_SHUTDOWN; } @@ -131,20 +140,16 @@ void pwrResetHandler() // powerupReason is there to cater for that, and is what is used in the firmware to decide whether we have to enter emergency mode. // This variable needs to be in a RAM section that is not initialized or zeroed, since once we exit this pwrResetHandler() function the // C runtime would otherwise overwrite it during program init. + // Only for X12, X10 power circuit causes inability to shut down on some samples. - if (shutdownRequest != SHUTDOWN_REQUEST) { - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = PWR_ON_GPIO_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(PWR_GPIO, &GPIO_InitStructure); - +#if defined(PCBX12S) + if (shutdownRequest != SHUTDOWN_REQUEST || WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) { if (shutdownReason == DIRTY_SHUTDOWN) { powerupReason = DIRTY_SHUTDOWN; } - +#else + if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) { +#endif pwrOn(); } }