Bsongis/issue 3600 emergency shutdown (#3602)

* [ARM] Fixes #3600 - Emergency shutdown

* Compilation fix

* Function renamed

* Compilation fix

* Compilation fix

* Compilation fix

* Suggestion from projectkk2glider
This commit is contained in:
Bertrand Songis
2016-06-17 07:32:33 +02:00
committed by GitHub
parent 238943f4a2
commit 4445f7cdec
7 changed files with 89 additions and 41 deletions
@@ -286,6 +286,9 @@ void pwrOff(void);
#if defined(REV9E)
uint32_t pwrPressed(void);
uint32_t pwrPressedDuration(void);
#define pwroffPressed() pwrPressed()
#else
uint32_t pwroffPressed(void);
#endif
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
+12 -11
View File
@@ -2,7 +2,7 @@
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
@@ -18,7 +18,7 @@
* GNU General Public License for more details.
*/
#include "../../pwr.h"
#include "pwr.h"
#include "board_taranis.h"
void pwrInit()
@@ -43,12 +43,12 @@ void pwrInit()
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TRAINER_GPIO_PIN_DETECT;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(TRAINER_GPIO_DETECT, &GPIO_InitStructure);
@@ -71,7 +71,7 @@ void pwrOff()
while(1) {
wdt_reset();
#if defined(REV9E)
// 9E needs watchdog reset because CPU is still running while
// 9E needs watchdog reset because CPU is still running while
// the power key is held pressed by the user.
// The power key should be released by now, but we must make sure
if (!pwrPressed()) {
@@ -87,7 +87,7 @@ void pwrOff()
}
#endif
}
//this function must not return!
// this function must not return!
}
#if defined(REV9E)
@@ -95,20 +95,21 @@ uint32_t pwrPressed()
{
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET;
}
#else
uint32_t pwroffPressed()
{
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_SWITCH_GPIO_PIN) != Bit_RESET;
}
#endif
#if !defined(REV9E)
uint32_t pwrCheck()
{
#if defined(SIMU)
return e_power_on;
#else
if (GPIO_ReadInputDataBit(PWR_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET)
if (!pwroffPressed())
return e_power_on;
else if (usbPlugged())
return e_power_usb;
else
return e_power_off;
#endif
}
#endif