mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 04:15:26 +03:00
parent
7c3ad50e7d
commit
c3388dc65e
24 changed files with 306 additions and 353 deletions
|
@ -325,7 +325,7 @@ set(SRC
|
|||
mixer.cpp
|
||||
stamp.cpp
|
||||
timers.cpp
|
||||
trainer_input.cpp
|
||||
trainer.cpp
|
||||
)
|
||||
|
||||
if(GUI)
|
||||
|
|
|
@ -954,14 +954,14 @@ void checkThrottleStick()
|
|||
}
|
||||
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
uint32_t pwr_check = pwrCheck();
|
||||
if (pwr_check == e_power_off) {
|
||||
uint32_t power = pwrCheck();
|
||||
if (power == e_power_off) {
|
||||
break;
|
||||
}
|
||||
else if (pwr_check == e_power_press) {
|
||||
else if (power == e_power_press) {
|
||||
refresh = true;
|
||||
}
|
||||
else if (pwr_check == e_power_on && refresh) {
|
||||
else if (power == e_power_on && refresh) {
|
||||
RAISE_ALERT(STR_THROTTLEWARN, STR_THROTTLENOTIDLE, STR_PRESSANYKEYTOSKIP, AU_NONE);
|
||||
refresh = false;
|
||||
}
|
||||
|
@ -1886,10 +1886,6 @@ void opentxInit()
|
|||
#endif
|
||||
backlightOn();
|
||||
|
||||
#if defined(PCBSKY9X) && !defined(SIMU)
|
||||
init_trainer_capture();
|
||||
#endif
|
||||
|
||||
startPulses();
|
||||
|
||||
wdt_enable(WDTO_500MS);
|
||||
|
|
|
@ -741,7 +741,7 @@ extern uint8_t g_vbat100mV;
|
|||
#define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms)
|
||||
extern uint8_t g_beepCnt;
|
||||
|
||||
#include "trainer_input.h"
|
||||
#include "trainer.h"
|
||||
|
||||
extern int32_t chans[MAX_OUTPUT_CHANNELS];
|
||||
extern int16_t ex_chans[MAX_OUTPUT_CHANNELS]; // Outputs (before LIMITS) of the last perMain
|
||||
|
|
|
@ -25,10 +25,9 @@
|
|||
#if defined(PCBHORUS)
|
||||
#define SWITCH_WARNING_LIST_X WARNING_LINE_X
|
||||
#define SWITCH_WARNING_LIST_Y WARNING_LINE_Y+3*FH
|
||||
#define SWITCH_WARNING_LIST_INTERVAL 35
|
||||
#elif LCD_W >= 212
|
||||
#define SWITCH_WARNING_LIST_X 60
|
||||
#define SWITCH_WARNING_LIST_Y 4*FH+3
|
||||
#define SWITCH_WARNING_LIST_Y 4*FH+4
|
||||
#else
|
||||
#define SWITCH_WARNING_LIST_X 4
|
||||
#define SWITCH_WARNING_LIST_Y 4*FH+4
|
||||
|
@ -558,6 +557,10 @@ void checkSwitches()
|
|||
uint8_t bad_pots = 0, last_bad_pots = 0xff;
|
||||
#endif
|
||||
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
bool refresh = false;
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
|
@ -642,12 +645,13 @@ void checkSwitches()
|
|||
|
||||
// first - display warning
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
if ((last_bad_switches != switches_states) || (last_bad_pots != bad_pots)) {
|
||||
drawAlertBox(STR_SWITCHWARN, NULL, STR_PRESSANYKEYTOSKIP);
|
||||
if (last_bad_switches != switches_states || last_bad_pots != bad_pots) {
|
||||
drawAlertBox(STR_SWITCHWARN, nullptr, STR_PRESSANYKEYTOSKIP);
|
||||
if (last_bad_switches == 0xff || last_bad_pots == 0xff) {
|
||||
AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT);
|
||||
}
|
||||
int x = SWITCH_WARNING_LIST_X, y = SWITCH_WARNING_LIST_Y;
|
||||
int x = SWITCH_WARNING_LIST_X;
|
||||
int y = SWITCH_WARNING_LIST_Y;
|
||||
int numWarnings = 0;
|
||||
for (int i=0; i<NUM_SWITCHES; ++i) {
|
||||
#if defined(COLORLCD)
|
||||
|
@ -658,10 +662,7 @@ void checkSwitches()
|
|||
// LcdFlags attr = ((states & mask) == (switches_states & mask)) ? TEXT_COLOR : ALARM_COLOR;
|
||||
LcdFlags attr = ALARM_COLOR;
|
||||
drawSwitch(x, y, SWSRC_FIRST_SWITCH+i*3+state-1, attr);
|
||||
x += SWITCH_WARNING_LIST_INTERVAL;
|
||||
}
|
||||
else if (numWarnings == 6) {
|
||||
lcdDrawText(x, y, "...", ALARM_COLOR);
|
||||
x += 35;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -670,59 +671,54 @@ void checkSwitches()
|
|||
swarnstate_t mask = ((swarnstate_t)0x03 << (i*2));
|
||||
LcdFlags attr = ((states & mask) == (switches_states & mask)) ? 0 : INVERS;
|
||||
if (attr) {
|
||||
if (++numWarnings < 7) {
|
||||
if (++numWarnings < 6) {
|
||||
char c = "\300-\301"[(states & mask) >> (i*2)];
|
||||
drawSource(x, y, MIXSRC_FIRST_SWITCH+i, attr);
|
||||
lcdDrawChar(lcdNextPos, y, c, attr);
|
||||
x = lcdNextPos + 3;
|
||||
}
|
||||
else if (numWarnings == 7) {
|
||||
lcdDrawText(x, y, "...", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (g_model.potsWarnMode) {
|
||||
if (y == 4*FH+3) {
|
||||
y = 6*FH-2;
|
||||
x = 60;
|
||||
}
|
||||
for (int i=0; i<NUM_POTS+NUM_SLIDERS; i++) {
|
||||
if (!IS_POT_SLIDER_AVAILABLE(POT1+i)) {
|
||||
continue;
|
||||
}
|
||||
if (!(g_model.potsWarnEnabled & (1 << i))) {
|
||||
if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) {
|
||||
if (++numWarnings < 6) {
|
||||
#if defined(COLORLCD)
|
||||
char s[8];
|
||||
// TODO add an helper
|
||||
strncpy(s, &STR_VSRCRAW[1+(NUM_STICKS+1+i)*STR_VSRCRAW[0]], STR_VSRCRAW[0]);
|
||||
s[int(STR_VSRCRAW[0])] = '\0';
|
||||
lcdDrawText(x, y, s, ALARM_COLOR);
|
||||
x += 40;
|
||||
#else
|
||||
lcdDrawTextAtIndex(x, y, STR_VSRCRAW, NUM_STICKS + 1 + i, INVERS);
|
||||
if (IS_POT(POT1 + i))
|
||||
lcdDrawChar(lcdNextPos, y, g_model.potsWarnPosition[i] > GET_LOWRES_POT_POSITION(i) ? 126 : 127, INVERS);
|
||||
else
|
||||
lcdDrawChar(lcdNextPos, y, g_model.potsWarnPosition[i] > GET_LOWRES_POT_POSITION(i) ? '\300' : '\301', INVERS);
|
||||
#endif
|
||||
#if defined(COLORLCD)
|
||||
if (++numWarnings < 6) {
|
||||
lcdDrawText(x, y, s, ALARM_COLOR);
|
||||
}
|
||||
else if (numWarnings == 6) {
|
||||
lcdDrawText(x, y, "...", ALARM_COLOR);
|
||||
}
|
||||
x += 40;
|
||||
#else
|
||||
x = lcdNextPos + 3;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numWarnings >= 6) {
|
||||
#if defined(COLORLCD)
|
||||
lcdDrawText(x, y, "...", ALARM_COLOR);
|
||||
#else
|
||||
lcdDrawText(x, y, "...", 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_bad_pots = bad_pots;
|
||||
#else
|
||||
if (last_bad_switches != switches_states) {
|
||||
|
@ -747,7 +743,27 @@ void checkSwitches()
|
|||
last_bad_switches = switches_states;
|
||||
}
|
||||
|
||||
if (pwrCheck() == e_power_off || keyDown()) break;
|
||||
if (keyDown())
|
||||
break;
|
||||
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
uint32_t power = pwrCheck();
|
||||
if (power == e_power_off) {
|
||||
break;
|
||||
}
|
||||
else if (power == e_power_press) {
|
||||
refresh = true;
|
||||
}
|
||||
else if (power == e_power_on && refresh) {
|
||||
last_bad_switches = 0xff;
|
||||
last_bad_pots = 0xff;
|
||||
refresh = false;
|
||||
}
|
||||
#else
|
||||
if (pwrCheck() == e_power_off) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
doLoopCommonActions();
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ set(BOOTLOADER_SRC
|
|||
../../../../../targets/${TARGET_DIR}/backlight_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/keys_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/diskio.cpp
|
||||
../../../../../targets/${TARGET_DIR}/board_preinit.cpp
|
||||
../../../../../targets/${TARGET_DIR}/board.cpp
|
||||
../../../../../targets/${TARGET_DIR}/pwr_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/bootloader/boot_menu.cpp
|
||||
../usbd_usr.cpp
|
||||
|
|
|
@ -209,8 +209,8 @@ int main()
|
|||
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph | RCC_APB2Periph_SYSCFG, ENABLE);
|
||||
|
||||
keysInit();
|
||||
|
||||
boardPreInit();
|
||||
pwrInit();
|
||||
pwrOff();
|
||||
|
||||
// wait for inputs to stabilize
|
||||
for (uint32_t i = 0; i < 50000; i += 1) {
|
||||
|
@ -227,7 +227,6 @@ int main()
|
|||
rotaryEncoderInit();
|
||||
#endif
|
||||
|
||||
pwrInit();
|
||||
pwrOn();
|
||||
delaysInit(); // needed for lcdInit()
|
||||
|
||||
|
@ -489,12 +488,7 @@ int main()
|
|||
|
||||
if (state != ST_FLASHING && state != ST_USB) {
|
||||
if (pwrOffPressed()) {
|
||||
lcdClear();
|
||||
lcdOff(); // this drains LCD caps
|
||||
pwrOff();
|
||||
for (;;) {
|
||||
// Wait for power to go off
|
||||
}
|
||||
boardOff();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,10 +108,12 @@ set(GUI_SRC
|
|||
${WIDGETS_SRC}
|
||||
rle.cpp
|
||||
)
|
||||
|
||||
if(DISK_CACHE)
|
||||
set(SRC ${SRC} disk_cache.cpp)
|
||||
add_definitions(-DDISK_CACHE)
|
||||
endif()
|
||||
|
||||
if(INTERNAL_GPS)
|
||||
set(SRC ${SRC} gps.cpp)
|
||||
add_definitions(-DINTERNAL_GPS)
|
||||
|
@ -128,6 +130,7 @@ set(TARGET_SRC
|
|||
led_driver.cpp
|
||||
extmodule_driver.cpp
|
||||
trainer_driver.cpp
|
||||
../common/arm/stm32/heartbeat_driver.cpp
|
||||
../common/arm/stm32/timers_driver.cpp
|
||||
../common/arm/stm32/intmodule_serial_driver.cpp
|
||||
../common/arm/stm32/bluetooth_driver.cpp
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -108,7 +108,6 @@ extern uint16_t sessionTimer;
|
|||
#endif
|
||||
|
||||
// Board driver
|
||||
void boardPreInit(void);
|
||||
void boardInit(void);
|
||||
void boardOff(void);
|
||||
|
||||
|
@ -219,6 +218,9 @@ void init_pxx2(uint8_t module);
|
|||
void disable_pxx2(uint8_t module);
|
||||
void disable_serial(uint8_t module);
|
||||
|
||||
void init_intmodule_heartbeat();
|
||||
void check_intmodule_heartbeat();
|
||||
|
||||
void intmoduleStop();
|
||||
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable);
|
||||
void intmodulePxxStart();
|
||||
|
@ -507,6 +509,8 @@ extern "C" {
|
|||
|
||||
// Power driver
|
||||
#define SOFT_PWR_CTRL
|
||||
extern uint32_t shutdownRequest; // Stores intentional shutdown to avoid reboot loop
|
||||
extern uint32_t shutdownReason; // Used for detecting unexpected reboots regardless of reason
|
||||
void pwrInit(void);
|
||||
uint32_t pwrCheck(void);
|
||||
void pwrOn(void);
|
||||
|
@ -655,9 +659,6 @@ void bluetoothWriteWakeup(void);
|
|||
uint8_t bluetoothIsWriting(void);
|
||||
void bluetoothDisable(void);
|
||||
|
||||
extern uint8_t currentTrainerMode;
|
||||
void checkTrainerSettings(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#include "fifo.h"
|
||||
#include "dmafifo.h"
|
||||
|
|
|
@ -1,25 +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()
|
||||
{
|
||||
}
|
|
@ -630,9 +630,15 @@
|
|||
#endif
|
||||
|
||||
// Heartbeat (not used)
|
||||
#define TRAINER_MODULE_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
|
||||
#define INTMODULE_HEARTBEAT
|
||||
#define INTMODULE_HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
|
||||
#define INTMODULE_HEARTBEAT_GPIO GPIOD
|
||||
#define INTMODULE_HEARTBEAT_GPIO_PIN GPIO_Pin_12 // PD.12
|
||||
#define INTMODULE_HEARTBEAT_GPIO_PIN GPIO_Pin_12
|
||||
#define INTMODULE_HEARTBEAT_EXTI_PortSource EXTI_PortSourceGPIOD
|
||||
#define INTMODULE_HEARTBEAT_EXTI_PinSource GPIO_PinSource12
|
||||
#define INTMODULE_HEARTBEAT_EXTI_LINE EXTI_Line12
|
||||
#define INTMODULE_HEARTBEAT_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER
|
||||
#define INTMODULE_HEARTBEAT_TRIGGER EXTI_Trigger_Falling
|
||||
|
||||
// Trainer Port
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
#include "pwr.h"
|
||||
#include "board.h"
|
||||
|
||||
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
|
||||
|
||||
void pwrInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
@ -86,23 +82,6 @@ void pwrOn()
|
|||
|
||||
void pwrOff()
|
||||
{
|
||||
#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;
|
||||
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
|
||||
}
|
||||
|
||||
|
|
|
@ -498,16 +498,6 @@ void calcConsumption()
|
|||
}
|
||||
}
|
||||
|
||||
void checkTrainerSettings()
|
||||
{
|
||||
if (SLAVE_MODE()) {
|
||||
PIOC->PIO_PDR = PIO_PC22;
|
||||
}
|
||||
else {
|
||||
PIOC->PIO_PER = PIO_PC22;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t getBatteryVoltage()
|
||||
{
|
||||
int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose
|
||||
|
|
|
@ -34,7 +34,6 @@ extern uint16_t ResetReason;
|
|||
#define FIRMWARE_ADDRESS 0x00400000
|
||||
|
||||
// Board driver
|
||||
void boardPreInit(void);
|
||||
void boardInit(void);
|
||||
#define boardOff() pwrOff()
|
||||
|
||||
|
@ -212,8 +211,8 @@ void calcConsumption();
|
|||
// Trainer driver
|
||||
#define SLAVE_MODE() (pwrCheck() == e_power_trainer)
|
||||
#define TRAINER_CONNECTED() (PIOA->PIO_PDSR & PIO_PA8)
|
||||
void checkTrainerSettings();
|
||||
void init_trainer_capture();
|
||||
void stop_trainer_capture();
|
||||
|
||||
// Write Flash driver
|
||||
#define FLASH_PAGESIZE 256
|
||||
|
|
|
@ -82,14 +82,14 @@ extern "C" void TC3_IRQHandler() //capture ppm in at 2MHz
|
|||
|
||||
void init_trainer_capture()
|
||||
{
|
||||
PIOC->PIO_PER = PIO_PC22;
|
||||
start_timer4() ;
|
||||
start_timer3() ;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void stop_trainer_capture()
|
||||
{
|
||||
PIOC->PIO_PDR = PIO_PC22;
|
||||
TC1->TC_CHANNEL[0].TC_IDR = TC_IDR0_LDRAS ;
|
||||
NVIC_DisableIRQ(TC3_IRQn) ;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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();
|
||||
|
||||
// disable interrupts
|
||||
__disable_irq();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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_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
|
||||
}
|
||||
|
||||
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()
|
||||
|
|
|
@ -128,7 +128,7 @@ TASK_FUNCTION(mixerTask)
|
|||
}
|
||||
#else
|
||||
if (isForcePowerOffRequested()) {
|
||||
pwrOff();
|
||||
boardOff();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(GTEST_ROOT /usr CACHE string "Base path to Google Test headers and source.")
|
||||
set(GTEST_ROOT /usr CACHE STRING "Base path to Google Test headers and source.")
|
||||
|
||||
find_path(GTEST_INCDIR gtest/gtest.h HINTS "${GTEST_ROOT}/include" DOC "Path to Google Test header files folder ('gtest/gtest.h').")
|
||||
find_path(GTEST_SRCDIR src/gtest-all.cc HINTS "${GTEST_ROOT}" "${GTEST_ROOT}/src/gtest" DOC "Path of Google Test 'src' folder.")
|
||||
|
|
141
radio/src/trainer.cpp
Normal file
141
radio/src/trainer.cpp
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* 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 "opentx.h"
|
||||
|
||||
int16_t ppmInput[MAX_TRAINER_CHANNELS];
|
||||
uint8_t ppmInputValidityTimer;
|
||||
uint8_t currentTrainerMode = 0xff;
|
||||
|
||||
void checkTrainerSignalWarning()
|
||||
{
|
||||
enum PpmInValidState_t {
|
||||
PPM_IN_IS_NOT_USED=0,
|
||||
PPM_IN_IS_VALID,
|
||||
PPM_IN_INVALID
|
||||
};
|
||||
|
||||
static uint8_t ppmInputValidState = PPM_IN_IS_NOT_USED;
|
||||
|
||||
if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_NOT_USED)) {
|
||||
ppmInputValidState = PPM_IN_IS_VALID;
|
||||
}
|
||||
else if (!ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_VALID)) {
|
||||
ppmInputValidState = PPM_IN_INVALID;
|
||||
AUDIO_TRAINER_LOST();
|
||||
}
|
||||
else if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_INVALID)) {
|
||||
ppmInputValidState = PPM_IN_IS_VALID;
|
||||
AUDIO_TRAINER_BACK();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
void checkTrainerSettings()
|
||||
{
|
||||
uint8_t requiredTrainerMode = SLAVE_MODE();
|
||||
|
||||
if (requiredTrainerMode != currentTrainerMode) {
|
||||
currentTrainerMode = requiredTrainerMode;
|
||||
if (requiredTrainerMode)
|
||||
stop_trainer_capture();
|
||||
else
|
||||
init_trainer_capture();
|
||||
}
|
||||
}
|
||||
#else
|
||||
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;
|
||||
|
||||
#if defined(TRAINER_MODULE_CPPM)
|
||||
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
|
||||
stop_trainer_module_cppm();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(TRAINER_MODULE_SBUS)
|
||||
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
|
||||
stop_trainer_module_sbus();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(TRAINER_BATTERY_COMPARTMENT)
|
||||
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
|
||||
auxSerialStop();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
currentTrainerMode = requiredTrainerMode;
|
||||
|
||||
switch (requiredTrainerMode) {
|
||||
case TRAINER_MODE_SLAVE:
|
||||
init_trainer_ppm();
|
||||
break;
|
||||
|
||||
#if defined(TRAINER_MODULE_CPPM)
|
||||
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
|
||||
init_trainer_module_cppm();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(TRAINER_MODULE_SBUS)
|
||||
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
|
||||
init_trainer_module_sbus();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#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 defined(TRAINER_MODULE_CPPM) || defined(TRAINER_MODULE_SBUS)
|
||||
if (requiredTrainerMode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE || requiredTrainerMode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE)
|
||||
stop_intmodule_heartbeat();
|
||||
else
|
||||
init_intmodule_heartbeat();
|
||||
#else
|
||||
init_intmodule_heartbeat();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -18,10 +18,10 @@
|
|||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _TRAINER_INPUT_H_
|
||||
#define _TRAINER_INPUT_H_
|
||||
#ifndef _TRAINER_H_
|
||||
#define _TRAINER_H_
|
||||
|
||||
#include "opentx.h"
|
||||
#include "dataconstants.h"
|
||||
|
||||
// Trainer input channels
|
||||
extern int16_t ppmInput[MAX_TRAINER_CHANNELS];
|
||||
|
@ -30,9 +30,11 @@ extern int16_t ppmInput[MAX_TRAINER_CHANNELS];
|
|||
#define PPM_IN_VALID_TIMEOUT 100 // 1s
|
||||
extern uint8_t ppmInputValidityTimer;
|
||||
|
||||
extern uint8_t currentTrainerMode;
|
||||
#define IS_TRAINER_INPUT_VALID() (ppmInputValidityTimer != 0)
|
||||
|
||||
void checkTrainerSignalWarning();
|
||||
void checkTrainerSettings();
|
||||
|
||||
// Needs to be inlined to avoid slow function calls in ISR routines
|
||||
inline void captureTrainerPulses(uint16_t capture)
|
||||
|
@ -66,4 +68,4 @@ inline void captureTrainerPulses(uint16_t capture)
|
|||
}
|
||||
}
|
||||
|
||||
#endif // _TRAINER_INPUT_H_
|
||||
#endif // _TRAINER_H_
|
|
@ -1,51 +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 "trainer_input.h"
|
||||
|
||||
int16_t ppmInput[MAX_TRAINER_CHANNELS];
|
||||
uint8_t ppmInputValidityTimer;
|
||||
|
||||
|
||||
#include "audio.h"
|
||||
|
||||
void checkTrainerSignalWarning()
|
||||
{
|
||||
enum PpmInValidState_t {
|
||||
PPM_IN_IS_NOT_USED=0,
|
||||
PPM_IN_IS_VALID,
|
||||
PPM_IN_INVALID
|
||||
};
|
||||
|
||||
static uint8_t ppmInputValidState = PPM_IN_IS_NOT_USED;
|
||||
|
||||
if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_NOT_USED)) {
|
||||
ppmInputValidState = PPM_IN_IS_VALID;
|
||||
}
|
||||
else if (!ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_VALID)) {
|
||||
ppmInputValidState = PPM_IN_INVALID;
|
||||
AUDIO_TRAINER_LOST();
|
||||
}
|
||||
else if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_INVALID)) {
|
||||
ppmInputValidState = PPM_IN_IS_VALID;
|
||||
AUDIO_TRAINER_BACK();
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue