@@ -269,13 +269,13 @@ void boardInit()
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
#if defined(STATUS_LEDS)
|
||||
#if defined(STATUS_LEDS) && !defined(BOOT)
|
||||
ledOff();
|
||||
#endif
|
||||
|
||||
BACKLIGHT_DISABLE();
|
||||
|
||||
#if defined(TOPLCD_GPIO)
|
||||
#if defined(TOPLCD_GPIO) && !defined(BOOT)
|
||||
toplcdOff();
|
||||
#endif
|
||||
|
||||
@@ -288,64 +288,33 @@ void boardOff()
|
||||
lcdOff();
|
||||
SysTick->CTRL = 0; // turn off systick
|
||||
pwrOff();
|
||||
}
|
||||
|
||||
uint8_t currentTrainerMode = 0xff;
|
||||
// disable interrupts
|
||||
__disable_irq();
|
||||
|
||||
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_CPPM_EXTERNAL_MODULE:
|
||||
stop_trainer_module_cppm();
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
|
||||
stop_trainer_module_sbus();
|
||||
break;
|
||||
#if defined(TRAINER_BATTERY_COMPARTMENT)
|
||||
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
|
||||
auxSerialStop();
|
||||
break;
|
||||
#endif
|
||||
while (1) {
|
||||
wdt_reset();
|
||||
#if defined(SIMU)
|
||||
return;
|
||||
#elif defined(PWR_BUTTON_PRESS)
|
||||
// X9E/X7 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()) {
|
||||
// Put the CPU into sleep to reduce the consumption,
|
||||
// it might help with the RTC reset issue
|
||||
PWR->CR |= PWR_CR_CWUF;
|
||||
/* Select STANDBY mode */
|
||||
PWR->CR |= PWR_CR_PDDS;
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
/* Request Wait For Event */
|
||||
__WFE();
|
||||
}
|
||||
|
||||
currentTrainerMode = requiredTrainerMode;
|
||||
switch (requiredTrainerMode) {
|
||||
case TRAINER_MODE_SLAVE:
|
||||
init_trainer_ppm();
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
|
||||
init_trainer_module_cppm();
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
|
||||
init_trainer_module_sbus();
|
||||
break;
|
||||
#if defined(TRAINER_BATTERY_COMPARTMENT)
|
||||
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
|
||||
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER) {
|
||||
auxSerialSbusInit();
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
#endif
|
||||
default:
|
||||
// master is default
|
||||
init_trainer_capture();
|
||||
break;
|
||||
}
|
||||
|
||||
if (requiredTrainerMode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE || requiredTrainerMode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE)
|
||||
stop_intmodule_heartbeat();
|
||||
else
|
||||
init_intmodule_heartbeat();
|
||||
}
|
||||
|
||||
// this function must not return!
|
||||
}
|
||||
|
||||
uint16_t getBatteryVoltage()
|
||||
|
||||
@@ -120,7 +120,6 @@ void rotaryEncoderCheck(void);
|
||||
extern uint16_t sessionTimer;
|
||||
|
||||
// Board driver
|
||||
void boardPreInit(void);
|
||||
void boardInit(void);
|
||||
void boardOff(void);
|
||||
|
||||
@@ -249,10 +248,10 @@ void extmoduleSendNextFrame();
|
||||
#define TRAINER_CONNECTED() (GPIO_ReadInputDataBit(TRAINER_DETECT_GPIO, TRAINER_DETECT_GPIO_PIN) == Bit_RESET)
|
||||
#endif
|
||||
#if defined(TRAINER_GPIO)
|
||||
void init_trainer_ppm(void);
|
||||
void stop_trainer_ppm(void);
|
||||
void init_trainer_capture(void);
|
||||
void stop_trainer_capture(void);
|
||||
void init_trainer_ppm();
|
||||
void stop_trainer_ppm();
|
||||
void init_trainer_capture();
|
||||
void stop_trainer_capture();
|
||||
#else
|
||||
#define init_trainer_ppm()
|
||||
#define stop_trainer_ppm()
|
||||
@@ -260,15 +259,15 @@ void extmoduleSendNextFrame();
|
||||
#define stop_trainer_capture()
|
||||
#endif
|
||||
#if defined(TRAINER_MODULE_CPPM)
|
||||
void init_trainer_module_cppm(void);
|
||||
void stop_trainer_module_cppm(void);
|
||||
void init_trainer_module_cppm();
|
||||
void stop_trainer_module_cppm();
|
||||
#else
|
||||
#define init_trainer_module_cppm()
|
||||
#define stop_trainer_module_cppm()
|
||||
#endif
|
||||
#if defined(TRAINER_MODULE_SBUS)
|
||||
void init_trainer_module_sbus(void);
|
||||
void stop_trainer_module_sbus(void);
|
||||
void init_trainer_module_sbus();
|
||||
void stop_trainer_module_sbus();
|
||||
#else
|
||||
#define init_trainer_module_sbus()
|
||||
#define stop_trainer_module_sbus()
|
||||
@@ -877,9 +876,6 @@ void setTopBatteryValue(uint32_t volts);
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
extern uint8_t currentTrainerMode;
|
||||
void checkTrainerSettings(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#include "fifo.h"
|
||||
#include "dmafifo.h"
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
|
||||
void boardPreInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
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;
|
||||
|
||||
// Board PWR kept OFF
|
||||
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_ON_GPIO_PIN;
|
||||
GPIO_Init(PWR_ON_GPIO, &GPIO_InitStructure);
|
||||
|
||||
#if defined(INTMODULE_BOOTCMD_GPIO)
|
||||
GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_BOOTCMD_GPIO_PIN;
|
||||
GPIO_Init(INTMODULE_BOOTCMD_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
}
|
||||
@@ -28,16 +28,30 @@ void pwrInit()
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
|
||||
// Board PWR
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_ON_GPIO_PIN;
|
||||
GPIO_Init(PWR_ON_GPIO, &GPIO_InitStructure);
|
||||
|
||||
#if defined(INTMODULE_BOOTCMD_GPIO)
|
||||
GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_BOOTCMD_GPIO_PIN;
|
||||
GPIO_Init(INTMODULE_BOOTCMD_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
// Internal module power
|
||||
GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
|
||||
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
|
||||
|
||||
// External module power
|
||||
EXTERNAL_MODULE_PWR_OFF();
|
||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN;
|
||||
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_SWITCH_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
|
||||
// PWR switch
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_SWITCH_GPIO_PIN;
|
||||
GPIO_Init(PWR_SWITCH_GPIO, &GPIO_InitStructure);
|
||||
|
||||
#if defined(TRAINER_DETECT_GPIO_PIN)
|
||||
@@ -67,30 +81,6 @@ void pwrOn()
|
||||
void pwrOff()
|
||||
{
|
||||
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
|
||||
|
||||
// disable interrupts
|
||||
__disable_irq();
|
||||
|
||||
while (1) {
|
||||
wdt_reset();
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
// X9E/X7 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()) {
|
||||
// Put the CPU into sleep to reduce the consumption,
|
||||
// it might help with the RTC reset issue
|
||||
PWR->CR |= PWR_CR_CWUF;
|
||||
/* Select STANDBY mode */
|
||||
PWR->CR |= PWR_CR_PDDS;
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
/* Request Wait For Event */
|
||||
__WFE();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// this function must not return!
|
||||
}
|
||||
|
||||
uint32_t pwrPressed()
|
||||
|
||||
Reference in New Issue
Block a user