1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 12:25:12 +03:00

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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 306 additions and 353 deletions

View file

@ -325,7 +325,7 @@ set(SRC
mixer.cpp mixer.cpp
stamp.cpp stamp.cpp
timers.cpp timers.cpp
trainer_input.cpp trainer.cpp
) )
if(GUI) if(GUI)

View file

@ -954,14 +954,14 @@ void checkThrottleStick()
} }
#if defined(PWR_BUTTON_PRESS) #if defined(PWR_BUTTON_PRESS)
uint32_t pwr_check = pwrCheck(); uint32_t power = pwrCheck();
if (pwr_check == e_power_off) { if (power == e_power_off) {
break; break;
} }
else if (pwr_check == e_power_press) { else if (power == e_power_press) {
refresh = true; 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); RAISE_ALERT(STR_THROTTLEWARN, STR_THROTTLENOTIDLE, STR_PRESSANYKEYTOSKIP, AU_NONE);
refresh = false; refresh = false;
} }
@ -1886,10 +1886,6 @@ void opentxInit()
#endif #endif
backlightOn(); backlightOn();
#if defined(PCBSKY9X) && !defined(SIMU)
init_trainer_capture();
#endif
startPulses(); startPulses();
wdt_enable(WDTO_500MS); wdt_enable(WDTO_500MS);

View file

@ -741,7 +741,7 @@ extern uint8_t g_vbat100mV;
#define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms) #define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms)
extern uint8_t g_beepCnt; extern uint8_t g_beepCnt;
#include "trainer_input.h" #include "trainer.h"
extern int32_t chans[MAX_OUTPUT_CHANNELS]; extern int32_t chans[MAX_OUTPUT_CHANNELS];
extern int16_t ex_chans[MAX_OUTPUT_CHANNELS]; // Outputs (before LIMITS) of the last perMain extern int16_t ex_chans[MAX_OUTPUT_CHANNELS]; // Outputs (before LIMITS) of the last perMain

View file

@ -25,10 +25,9 @@
#if defined(PCBHORUS) #if defined(PCBHORUS)
#define SWITCH_WARNING_LIST_X WARNING_LINE_X #define SWITCH_WARNING_LIST_X WARNING_LINE_X
#define SWITCH_WARNING_LIST_Y WARNING_LINE_Y+3*FH #define SWITCH_WARNING_LIST_Y WARNING_LINE_Y+3*FH
#define SWITCH_WARNING_LIST_INTERVAL 35
#elif LCD_W >= 212 #elif LCD_W >= 212
#define SWITCH_WARNING_LIST_X 60 #define SWITCH_WARNING_LIST_X 60
#define SWITCH_WARNING_LIST_Y 4*FH+3 #define SWITCH_WARNING_LIST_Y 4*FH+4
#else #else
#define SWITCH_WARNING_LIST_X 4 #define SWITCH_WARNING_LIST_X 4
#define SWITCH_WARNING_LIST_Y 4*FH+4 #define SWITCH_WARNING_LIST_Y 4*FH+4
@ -558,6 +557,10 @@ void checkSwitches()
uint8_t bad_pots = 0, last_bad_pots = 0xff; uint8_t bad_pots = 0, last_bad_pots = 0xff;
#endif #endif
#if defined(PWR_BUTTON_PRESS)
bool refresh = false;
#endif
while (1) { while (1) {
#if defined(PCBTARANIS) || defined(PCBHORUS) #if defined(PCBTARANIS) || defined(PCBHORUS)
@ -642,12 +645,13 @@ void checkSwitches()
// first - display warning // first - display warning
#if defined(PCBTARANIS) || defined(PCBHORUS) #if defined(PCBTARANIS) || defined(PCBHORUS)
if ((last_bad_switches != switches_states) || (last_bad_pots != bad_pots)) { if (last_bad_switches != switches_states || last_bad_pots != bad_pots) {
drawAlertBox(STR_SWITCHWARN, NULL, STR_PRESSANYKEYTOSKIP); drawAlertBox(STR_SWITCHWARN, nullptr, STR_PRESSANYKEYTOSKIP);
if (last_bad_switches == 0xff || last_bad_pots == 0xff) { if (last_bad_switches == 0xff || last_bad_pots == 0xff) {
AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT); 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; int numWarnings = 0;
for (int i=0; i<NUM_SWITCHES; ++i) { for (int i=0; i<NUM_SWITCHES; ++i) {
#if defined(COLORLCD) #if defined(COLORLCD)
@ -658,10 +662,7 @@ void checkSwitches()
// LcdFlags attr = ((states & mask) == (switches_states & mask)) ? TEXT_COLOR : ALARM_COLOR; // LcdFlags attr = ((states & mask) == (switches_states & mask)) ? TEXT_COLOR : ALARM_COLOR;
LcdFlags attr = ALARM_COLOR; LcdFlags attr = ALARM_COLOR;
drawSwitch(x, y, SWSRC_FIRST_SWITCH+i*3+state-1, attr); drawSwitch(x, y, SWSRC_FIRST_SWITCH+i*3+state-1, attr);
x += SWITCH_WARNING_LIST_INTERVAL; x += 35;
}
else if (numWarnings == 6) {
lcdDrawText(x, y, "...", ALARM_COLOR);
} }
} }
} }
@ -670,59 +671,54 @@ void checkSwitches()
swarnstate_t mask = ((swarnstate_t)0x03 << (i*2)); swarnstate_t mask = ((swarnstate_t)0x03 << (i*2));
LcdFlags attr = ((states & mask) == (switches_states & mask)) ? 0 : INVERS; LcdFlags attr = ((states & mask) == (switches_states & mask)) ? 0 : INVERS;
if (attr) { if (attr) {
if (++numWarnings < 7) { if (++numWarnings < 6) {
char c = "\300-\301"[(states & mask) >> (i*2)]; char c = "\300-\301"[(states & mask) >> (i*2)];
drawSource(x, y, MIXSRC_FIRST_SWITCH+i, attr); drawSource(x, y, MIXSRC_FIRST_SWITCH+i, attr);
lcdDrawChar(lcdNextPos, y, c, attr); lcdDrawChar(lcdNextPos, y, c, attr);
x = lcdNextPos + 3; x = lcdNextPos + 3;
} }
else if (numWarnings == 7) {
lcdDrawText(x, y, "...", 0);
}
} }
} }
#endif #endif
} }
if (g_model.potsWarnMode) { 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++) { for (int i=0; i<NUM_POTS+NUM_SLIDERS; i++) {
if (!IS_POT_SLIDER_AVAILABLE(POT1+i)) { if (!IS_POT_SLIDER_AVAILABLE(POT1+i)) {
continue; continue;
} }
if (!(g_model.potsWarnEnabled & (1 << i))) { if (!(g_model.potsWarnEnabled & (1 << i))) {
if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) { if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) {
#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';
#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) { 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); lcdDrawText(x, y, s, ALARM_COLOR);
} x += 40;
else if (numWarnings == 6) {
lcdDrawText(x, y, "...", ALARM_COLOR);
}
x += 40;
#else #else
x = lcdNextPos + 3; 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);
x = lcdNextPos + 3;
#endif #endif
}
} }
} }
} }
} }
if (numWarnings >= 6) {
#if defined(COLORLCD)
lcdDrawText(x, y, "...", ALARM_COLOR);
#else
lcdDrawText(x, y, "...", 0);
#endif
}
last_bad_pots = bad_pots; last_bad_pots = bad_pots;
#else #else
if (last_bad_switches != switches_states) { if (last_bad_switches != switches_states) {
@ -747,7 +743,27 @@ void checkSwitches()
last_bad_switches = switches_states; 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(); doLoopCommonActions();

View file

@ -70,7 +70,7 @@ set(BOOTLOADER_SRC
../../../../../targets/${TARGET_DIR}/backlight_driver.cpp ../../../../../targets/${TARGET_DIR}/backlight_driver.cpp
../../../../../targets/${TARGET_DIR}/keys_driver.cpp ../../../../../targets/${TARGET_DIR}/keys_driver.cpp
../../../../../targets/${TARGET_DIR}/diskio.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}/pwr_driver.cpp
../../../../../targets/${TARGET_DIR}/bootloader/boot_menu.cpp ../../../../../targets/${TARGET_DIR}/bootloader/boot_menu.cpp
../usbd_usr.cpp ../usbd_usr.cpp

View file

@ -209,8 +209,8 @@ int main()
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph | RCC_APB2Periph_SYSCFG, ENABLE); RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph | RCC_APB2Periph_SYSCFG, ENABLE);
keysInit(); keysInit();
pwrInit();
boardPreInit(); pwrOff();
// wait for inputs to stabilize // wait for inputs to stabilize
for (uint32_t i = 0; i < 50000; i += 1) { for (uint32_t i = 0; i < 50000; i += 1) {
@ -227,7 +227,6 @@ int main()
rotaryEncoderInit(); rotaryEncoderInit();
#endif #endif
pwrInit();
pwrOn(); pwrOn();
delaysInit(); // needed for lcdInit() delaysInit(); // needed for lcdInit()
@ -489,12 +488,7 @@ int main()
if (state != ST_FLASHING && state != ST_USB) { if (state != ST_FLASHING && state != ST_USB) {
if (pwrOffPressed()) { if (pwrOffPressed()) {
lcdClear(); boardOff();
lcdOff(); // this drains LCD caps
pwrOff();
for (;;) {
// Wait for power to go off
}
} }
} }

View file

@ -108,10 +108,12 @@ set(GUI_SRC
${WIDGETS_SRC} ${WIDGETS_SRC}
rle.cpp rle.cpp
) )
if(DISK_CACHE) if(DISK_CACHE)
set(SRC ${SRC} disk_cache.cpp) set(SRC ${SRC} disk_cache.cpp)
add_definitions(-DDISK_CACHE) add_definitions(-DDISK_CACHE)
endif() endif()
if(INTERNAL_GPS) if(INTERNAL_GPS)
set(SRC ${SRC} gps.cpp) set(SRC ${SRC} gps.cpp)
add_definitions(-DINTERNAL_GPS) add_definitions(-DINTERNAL_GPS)
@ -128,6 +130,7 @@ set(TARGET_SRC
led_driver.cpp led_driver.cpp
extmodule_driver.cpp extmodule_driver.cpp
trainer_driver.cpp trainer_driver.cpp
../common/arm/stm32/heartbeat_driver.cpp
../common/arm/stm32/timers_driver.cpp ../common/arm/stm32/timers_driver.cpp
../common/arm/stm32/intmodule_serial_driver.cpp ../common/arm/stm32/intmodule_serial_driver.cpp
../common/arm/stm32/bluetooth_driver.cpp ../common/arm/stm32/bluetooth_driver.cpp

View file

@ -29,6 +29,10 @@ extern "C" {
} }
#endif #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; HardwareOptions hardwareOptions;
void watchdogInit(unsigned int duration) void watchdogInit(unsigned int duration)
@ -122,6 +126,7 @@ void boardInit()
ENABLE); ENABLE);
pwrInit(); pwrInit();
pwrOn();
delaysInit(); delaysInit();
#if defined(DEBUG) #if defined(DEBUG)
@ -184,52 +189,35 @@ void boardInit()
void boardOff() void boardOff()
{ {
BACKLIGHT_DISABLE(); backlightEnable(0);
while (pwrPressed()) { while (pwrPressed()) {
wdt_reset(); wdt_reset();
} }
SysTick->CTRL = 0; // turn off systick 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(); 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() uint16_t getBatteryVoltage()
{ {
int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose

View file

@ -108,7 +108,6 @@ extern uint16_t sessionTimer;
#endif #endif
// Board driver // Board driver
void boardPreInit(void);
void boardInit(void); void boardInit(void);
void boardOff(void); void boardOff(void);
@ -219,6 +218,9 @@ void init_pxx2(uint8_t module);
void disable_pxx2(uint8_t module); void disable_pxx2(uint8_t module);
void disable_serial(uint8_t module); void disable_serial(uint8_t module);
void init_intmodule_heartbeat();
void check_intmodule_heartbeat();
void intmoduleStop(); void intmoduleStop();
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable); void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable);
void intmodulePxxStart(); void intmodulePxxStart();
@ -507,6 +509,8 @@ extern "C" {
// Power driver // Power driver
#define SOFT_PWR_CTRL #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); void pwrInit(void);
uint32_t pwrCheck(void); uint32_t pwrCheck(void);
void pwrOn(void); void pwrOn(void);
@ -655,9 +659,6 @@ void bluetoothWriteWakeup(void);
uint8_t bluetoothIsWriting(void); uint8_t bluetoothIsWriting(void);
void bluetoothDisable(void); void bluetoothDisable(void);
extern uint8_t currentTrainerMode;
void checkTrainerSettings(void);
#if defined(__cplusplus) #if defined(__cplusplus)
#include "fifo.h" #include "fifo.h"
#include "dmafifo.h" #include "dmafifo.h"

View file

@ -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()
{
}

View file

@ -630,10 +630,16 @@
#endif #endif
// Heartbeat (not used) // Heartbeat (not used)
#define TRAINER_MODULE_RCC_AHB1Periph RCC_AHB1Periph_GPIOD #define INTMODULE_HEARTBEAT
#define INTMODULE_HEARTBEAT_GPIO GPIOD #define INTMODULE_HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
#define INTMODULE_HEARTBEAT_GPIO_PIN GPIO_Pin_12 // PD.12 #define INTMODULE_HEARTBEAT_GPIO GPIOD
#define INTMODULE_HEARTBEAT_TRIGGER EXTI_Trigger_Falling #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 // Trainer Port
#define TRAINER_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA1) #define TRAINER_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA1)

View file

@ -21,10 +21,6 @@
#include "pwr.h" #include "pwr.h"
#include "board.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() void pwrInit()
{ {
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
@ -86,23 +82,6 @@ void pwrOn()
void pwrOff() 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); GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
} }

View file

@ -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() uint16_t getBatteryVoltage()
{ {
int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose

View file

@ -34,7 +34,6 @@ extern uint16_t ResetReason;
#define FIRMWARE_ADDRESS 0x00400000 #define FIRMWARE_ADDRESS 0x00400000
// Board driver // Board driver
void boardPreInit(void);
void boardInit(void); void boardInit(void);
#define boardOff() pwrOff() #define boardOff() pwrOff()
@ -212,8 +211,8 @@ void calcConsumption();
// Trainer driver // Trainer driver
#define SLAVE_MODE() (pwrCheck() == e_power_trainer) #define SLAVE_MODE() (pwrCheck() == e_power_trainer)
#define TRAINER_CONNECTED() (PIOA->PIO_PDSR & PIO_PA8) #define TRAINER_CONNECTED() (PIOA->PIO_PDSR & PIO_PA8)
void checkTrainerSettings();
void init_trainer_capture(); void init_trainer_capture();
void stop_trainer_capture();
// Write Flash driver // Write Flash driver
#define FLASH_PAGESIZE 256 #define FLASH_PAGESIZE 256

View file

@ -82,14 +82,14 @@ extern "C" void TC3_IRQHandler() //capture ppm in at 2MHz
void init_trainer_capture() void init_trainer_capture()
{ {
PIOC->PIO_PER = PIO_PC22;
start_timer4() ; start_timer4() ;
start_timer3() ; start_timer3() ;
} }
#if 0
void stop_trainer_capture() void stop_trainer_capture()
{ {
PIOC->PIO_PDR = PIO_PC22;
TC1->TC_CHANNEL[0].TC_IDR = TC_IDR0_LDRAS ; TC1->TC_CHANNEL[0].TC_IDR = TC_IDR0_LDRAS ;
NVIC_DisableIRQ(TC3_IRQn) ; NVIC_DisableIRQ(TC3_IRQn) ;
} }
#endif

View file

@ -269,13 +269,13 @@ void boardInit()
void boardOff() void boardOff()
{ {
#if defined(STATUS_LEDS) #if defined(STATUS_LEDS) && !defined(BOOT)
ledOff(); ledOff();
#endif #endif
BACKLIGHT_DISABLE(); BACKLIGHT_DISABLE();
#if defined(TOPLCD_GPIO) #if defined(TOPLCD_GPIO) && !defined(BOOT)
toplcdOff(); toplcdOff();
#endif #endif
@ -288,64 +288,33 @@ void boardOff()
lcdOff(); lcdOff();
SysTick->CTRL = 0; // turn off systick SysTick->CTRL = 0; // turn off systick
pwrOff(); pwrOff();
}
uint8_t currentTrainerMode = 0xff; // disable interrupts
__disable_irq();
void checkTrainerSettings() while (1) {
{ wdt_reset();
uint8_t requiredTrainerMode = g_model.trainerData.mode; #if defined(SIMU)
if (requiredTrainerMode != currentTrainerMode) { return;
switch (currentTrainerMode) { #elif defined(PWR_BUTTON_PRESS)
case TRAINER_MODE_MASTER_TRAINER_JACK: // X9E/X7 needs watchdog reset because CPU is still running while
stop_trainer_capture(); // the power key is held pressed by the user.
break; // The power key should be released by now, but we must make sure
case TRAINER_MODE_SLAVE: if (!pwrPressed()) {
stop_trainer_ppm(); // Put the CPU into sleep to reduce the consumption,
break; // it might help with the RTC reset issue
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE: PWR->CR |= PWR_CR_CWUF;
stop_trainer_module_cppm(); /* Select STANDBY mode */
break; PWR->CR |= PWR_CR_PDDS;
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE: /* Set SLEEPDEEP bit of Cortex System Control Register */
stop_trainer_module_sbus(); SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
break; /* Request Wait For Event */
#if defined(TRAINER_BATTERY_COMPARTMENT) __WFE();
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 #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() uint16_t getBatteryVoltage()

View file

@ -120,7 +120,6 @@ void rotaryEncoderCheck(void);
extern uint16_t sessionTimer; extern uint16_t sessionTimer;
// Board driver // Board driver
void boardPreInit(void);
void boardInit(void); void boardInit(void);
void boardOff(void); void boardOff(void);
@ -249,10 +248,10 @@ void extmoduleSendNextFrame();
#define TRAINER_CONNECTED() (GPIO_ReadInputDataBit(TRAINER_DETECT_GPIO, TRAINER_DETECT_GPIO_PIN) == Bit_RESET) #define TRAINER_CONNECTED() (GPIO_ReadInputDataBit(TRAINER_DETECT_GPIO, TRAINER_DETECT_GPIO_PIN) == Bit_RESET)
#endif #endif
#if defined(TRAINER_GPIO) #if defined(TRAINER_GPIO)
void init_trainer_ppm(void); void init_trainer_ppm();
void stop_trainer_ppm(void); void stop_trainer_ppm();
void init_trainer_capture(void); void init_trainer_capture();
void stop_trainer_capture(void); void stop_trainer_capture();
#else #else
#define init_trainer_ppm() #define init_trainer_ppm()
#define stop_trainer_ppm() #define stop_trainer_ppm()
@ -260,15 +259,15 @@ void extmoduleSendNextFrame();
#define stop_trainer_capture() #define stop_trainer_capture()
#endif #endif
#if defined(TRAINER_MODULE_CPPM) #if defined(TRAINER_MODULE_CPPM)
void init_trainer_module_cppm(void); void init_trainer_module_cppm();
void stop_trainer_module_cppm(void); void stop_trainer_module_cppm();
#else #else
#define init_trainer_module_cppm() #define init_trainer_module_cppm()
#define stop_trainer_module_cppm() #define stop_trainer_module_cppm()
#endif #endif
#if defined(TRAINER_MODULE_SBUS) #if defined(TRAINER_MODULE_SBUS)
void init_trainer_module_sbus(void); void init_trainer_module_sbus();
void stop_trainer_module_sbus(void); void stop_trainer_module_sbus();
#else #else
#define init_trainer_module_sbus() #define init_trainer_module_sbus()
#define stop_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) #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) #if defined(__cplusplus)
#include "fifo.h" #include "fifo.h"
#include "dmafifo.h" #include "dmafifo.h"

View file

@ -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
}

View file

@ -28,16 +28,30 @@ void pwrInit()
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 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_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN; GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure); GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
// External module power
EXTERNAL_MODULE_PWR_OFF(); EXTERNAL_MODULE_PWR_OFF();
GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN; GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN;
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure); GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PWR_SWITCH_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
// PWR switch
GPIO_InitStructure.GPIO_Pin = PWR_SWITCH_GPIO_PIN;
GPIO_Init(PWR_SWITCH_GPIO, &GPIO_InitStructure); GPIO_Init(PWR_SWITCH_GPIO, &GPIO_InitStructure);
#if defined(TRAINER_DETECT_GPIO_PIN) #if defined(TRAINER_DETECT_GPIO_PIN)
@ -67,30 +81,6 @@ void pwrOn()
void pwrOff() void pwrOff()
{ {
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN); 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() uint32_t pwrPressed()

View file

@ -128,7 +128,7 @@ TASK_FUNCTION(mixerTask)
} }
#else #else
if (isForcePowerOffRequested()) { if (isForcePowerOffRequested()) {
pwrOff(); boardOff();
} }
#endif #endif

View file

@ -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_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.") 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
View 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

View file

@ -18,10 +18,10 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef _TRAINER_INPUT_H_ #ifndef _TRAINER_H_
#define _TRAINER_INPUT_H_ #define _TRAINER_H_
#include "opentx.h" #include "dataconstants.h"
// Trainer input channels // Trainer input channels
extern int16_t ppmInput[MAX_TRAINER_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 #define PPM_IN_VALID_TIMEOUT 100 // 1s
extern uint8_t ppmInputValidityTimer; extern uint8_t ppmInputValidityTimer;
extern uint8_t currentTrainerMode;
#define IS_TRAINER_INPUT_VALID() (ppmInputValidityTimer != 0) #define IS_TRAINER_INPUT_VALID() (ppmInputValidityTimer != 0)
void checkTrainerSignalWarning(); void checkTrainerSignalWarning();
void checkTrainerSettings();
// Needs to be inlined to avoid slow function calls in ISR routines // Needs to be inlined to avoid slow function calls in ISR routines
inline void captureTrainerPulses(uint16_t capture) inline void captureTrainerPulses(uint16_t capture)
@ -66,4 +68,4 @@ inline void captureTrainerPulses(uint16_t capture)
} }
} }
#endif // _TRAINER_INPUT_H_ #endif // _TRAINER_H_

View file

@ -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();
}
}