Bsongis/x9lite pwr fix (#6501)

X9 Pwr fix
This commit is contained in:
Bertrand Songis
2019-06-14 21:19:26 +02:00
committed by GitHub
parent 7c3ad50e7d
commit c3388dc65e
24 changed files with 306 additions and 353 deletions
+25 -37
View File
@@ -29,6 +29,10 @@ extern "C" {
}
#endif
uint32_t shutdownRequest; // Stores intentional shutdown to avoid reboot loop
uint32_t shutdownReason; // Used for detecting unexpected reboots regardless of reason
uint32_t powerupReason __NOINIT; // Stores power up reason beyond initialization for emergency mode activation
HardwareOptions hardwareOptions;
void watchdogInit(unsigned int duration)
@@ -122,6 +126,7 @@ void boardInit()
ENABLE);
pwrInit();
pwrOn();
delaysInit();
#if defined(DEBUG)
@@ -184,52 +189,35 @@ void boardInit()
void boardOff()
{
BACKLIGHT_DISABLE();
backlightEnable(0);
while (pwrPressed()) {
wdt_reset();
}
SysTick->CTRL = 0; // turn off systick
#if defined(PCBX12S)
// Shutdown the Audio amp
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = AUDIO_SHUTDOWN_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN);
#endif
// Shutdown the Haptic
hapticDone();
shutdownRequest = SHUTDOWN_REQUEST;
shutdownReason = NORMAL_POWER_OFF;
pwrOff();
}
uint8_t currentTrainerMode = 0xff;
void checkTrainerSettings()
{
uint8_t requiredTrainerMode = g_model.trainerData.mode;
if (requiredTrainerMode != currentTrainerMode) {
switch (currentTrainerMode) {
case TRAINER_MODE_MASTER_TRAINER_JACK:
stop_trainer_capture();
break;
case TRAINER_MODE_SLAVE:
stop_trainer_ppm();
break;
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
auxSerialStop();
}
currentTrainerMode = requiredTrainerMode;
switch (requiredTrainerMode) {
case TRAINER_MODE_SLAVE:
init_trainer_ppm();
break;
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER) {
auxSerialSbusInit();
break;
}
// no break
default:
// master is default
init_trainer_capture();
break;
}
}
}
uint16_t getBatteryVoltage()
{
int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose