mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 16:25:16 +03:00
perMain() moved into main_avr.cpp and main_arm.cpp
This commit is contained in:
parent
e55b7504c3
commit
afedd86fae
11 changed files with 340 additions and 261 deletions
|
@ -63,6 +63,7 @@ namespace Open9xGruvin9x {
|
|||
#include "radio/src/eeprom_common.cpp"
|
||||
#include "radio/src/eeprom_rlc.cpp"
|
||||
#include "radio/src/opentx.cpp"
|
||||
#include "radio/src/main_avr.cpp"
|
||||
#include "radio/src/strhelpers.cpp"
|
||||
#include "radio/src/switches.cpp"
|
||||
#include "radio/src/functions.cpp"
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace OpenTxM128 {
|
|||
#include "radio/src/eeprom_common.cpp"
|
||||
#include "radio/src/eeprom_rlc.cpp"
|
||||
#include "radio/src/opentx.cpp"
|
||||
#include "radio/src/main_avr.cpp"
|
||||
#include "radio/src/strhelpers.cpp"
|
||||
#include "radio/src/switches.cpp"
|
||||
#include "radio/src/functions.cpp"
|
||||
|
|
|
@ -69,6 +69,7 @@ namespace OpenTxM64 {
|
|||
#include "radio/src/eeprom_common.cpp"
|
||||
#include "radio/src/eeprom_rlc.cpp"
|
||||
#include "radio/src/opentx.cpp"
|
||||
#include "radio/src/main_avr.cpp"
|
||||
#include "radio/src/strhelpers.cpp"
|
||||
#include "radio/src/switches.cpp"
|
||||
#include "radio/src/functions.cpp"
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace Open9xSky9x {
|
|||
#include "radio/src/eeprom_raw.cpp"
|
||||
#include "radio/src/eeprom_conversions.cpp"
|
||||
#include "radio/src/opentx.cpp"
|
||||
#include "radio/src/main_arm.cpp"
|
||||
#include "radio/src/strhelpers.cpp"
|
||||
#include "radio/src/switches.cpp"
|
||||
#include "radio/src/functions.cpp"
|
||||
|
|
|
@ -79,6 +79,7 @@ inline int geteepromsize() {
|
|||
#include "radio/src/eeprom_conversions.cpp"
|
||||
#include "radio/src/eeprom_rlc.cpp"
|
||||
#include "radio/src/opentx.cpp"
|
||||
#include "radio/src/main_arm.cpp"
|
||||
#include "radio/src/strhelpers.cpp"
|
||||
#include "radio/src/switches.cpp"
|
||||
#include "radio/src/functions.cpp"
|
||||
|
|
|
@ -80,6 +80,7 @@ inline int geteepromsize() {
|
|||
#include "radio/src/eeprom_conversions.cpp"
|
||||
#include "radio/src/eeprom_rlc.cpp"
|
||||
#include "radio/src/opentx.cpp"
|
||||
#include "radio/src/main_arm.cpp"
|
||||
#include "radio/src/strhelpers.cpp"
|
||||
#include "radio/src/switches.cpp"
|
||||
#include "radio/src/functions.cpp"
|
||||
|
|
|
@ -362,7 +362,7 @@ ifeq ($(PCB), $(filter $(PCB), STD 9X 9XR))
|
|||
THR_TRACE = NO
|
||||
INCDIRS += targets/stock
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL -DPCBSTD -DCPUM64 -DEEPROM_VARIANT=$(shell echo ${EEPROM_VARIANT} | bc)
|
||||
BOARDSRC = targets/stock/board_stock.cpp
|
||||
BOARDSRC = main_avr.cpp targets/stock/board_stock.cpp
|
||||
EXTRABOARDSRC = targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
LCDSRC = lcd_common.cpp lcd_default.cpp
|
||||
|
@ -426,7 +426,7 @@ ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128))
|
|||
EEPROM_VARIANT += ${M128_VARIANT}
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL -DPCBSTD -DCPUM128 -DEEPROM_VARIANT=$(shell echo ${EEPROM_VARIANT} | bc)
|
||||
INCDIRS += targets/stock
|
||||
BOARDSRC = targets/stock/board_stock.cpp
|
||||
BOARDSRC = main_avr.cpp targets/stock/board_stock.cpp
|
||||
EXTRABOARDSRC = targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
LCDSRC = lcd_common.cpp lcd_default.cpp
|
||||
|
@ -486,7 +486,7 @@ ifeq ($(PCB), $(filter $(PCB), 9X2561))
|
|||
EEPROM_VARIANT += ${M2561_VARIANT}
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL -DPCBSTD -DCPUM2561 -DEEPROM_VARIANT=$(shell echo ${EEPROM_VARIANT} | bc)
|
||||
INCDIRS += targets/stock
|
||||
BOARDSRC = targets/stock/board_stock.cpp
|
||||
BOARDSRC = main_avr.cpp targets/stock/board_stock.cpp
|
||||
EXTRABOARDSRC = targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
LCDSRC = lcd_common.cpp lcd_default.cpp
|
||||
|
@ -547,7 +547,7 @@ ifeq ($(PCB), GRUVIN9X)
|
|||
BUZZER = NO
|
||||
THR_TRACE = YES
|
||||
INCDIRS += targets/gruvin9x targets/stock FatFs FatFs/option
|
||||
BOARDSRC = targets/gruvin9x/board_gruvin9x.cpp
|
||||
BOARDSRC = main_avr.cpp targets/gruvin9x/board_gruvin9x.cpp
|
||||
EXTRABOARDSRC = targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
LCDSRC = lcd_common.cpp lcd_default.cpp
|
||||
|
@ -586,7 +586,7 @@ ifeq ($(PCB), MEGA2560)
|
|||
SDCARD = YES
|
||||
THR_TRACE = YES
|
||||
INCDIRS += targets/mega2560 targets/stock FatFs FatFs/option
|
||||
BOARDSRC = targets/mega2560/board_mega2560.cpp
|
||||
BOARDSRC = main_avr.cpp targets/mega2560/board_mega2560.cpp
|
||||
EXTRABOARDSRC = targets/mega2560/lcd_driver_ST7565R.cpp targets/common_avr/telemetry_driver.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
LCDSRC = lcd_common.cpp lcd_default.cpp
|
||||
|
@ -640,7 +640,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO))
|
|||
CPPDEFS += -DSPORT_FILE_LOG
|
||||
endif
|
||||
INCDIRS += targets/sky9x CoOS/kernel CoOS/portable
|
||||
BOARDSRC = targets/sky9x/board_sky9x.cpp
|
||||
BOARDSRC = main_arm.cpp targets/sky9x/board_sky9x.cpp
|
||||
EXTRABOARDSRC = targets/sky9x/lcd_driver.cpp
|
||||
SRC += targets/sky9x/core_cm3.c targets/sky9x/board_lowlevel.c targets/sky9x/crt.c targets/sky9x/vectors_sam3s.c
|
||||
SRC += CoOS/kernel/core.c CoOS/kernel/hook.c CoOS/kernel/task.c CoOS/kernel/event.c CoOS/kernel/time.c CoOS/kernel/timer.c CoOS/kernel/flag.c CoOS/kernel/mutex.c CoOS/kernel/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c
|
||||
|
@ -744,7 +744,7 @@ ifeq ($(PCB), TARANIS)
|
|||
EXTRAINCDIRS += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/include
|
||||
EXTRAINCDIRS += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc
|
||||
EXTRAINCDIRS += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc
|
||||
BOARDSRC = targets/taranis/board_taranis.cpp
|
||||
BOARDSRC = main_arm.cpp targets/taranis/board_taranis.cpp
|
||||
EXTRABOARDSRC += targets/taranis/configure_pins.cpp targets/taranis/lcd_driver.cpp targets/taranis/flash_driver.cpp targets/taranis/aspi.c targets/taranis/i2c.c targets/taranis/delays.c
|
||||
SRC += CoOS/kernel/core.c CoOS/kernel/hook.c CoOS/kernel/task.c CoOS/kernel/event.c CoOS/kernel/time.c CoOS/kernel/timer.c CoOS/kernel/flag.c CoOS/kernel/mutex.c CoOS/kernel/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c
|
||||
SRC += targets/taranis/pwr_driver.c targets/taranis/usb_driver.c
|
||||
|
|
162
radio/src/main_arm.cpp
Normal file
162
radio/src/main_arm.cpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
static uint8_t currentSpeakerVolume = 255;
|
||||
uint8_t requiredSpeakerVolume = 255;
|
||||
|
||||
extern void checkBattery();
|
||||
|
||||
void handleUsbConnection()
|
||||
{
|
||||
#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
static bool usbStarted = false;
|
||||
if (!usbStarted && usbPlugged()) {
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
opentxClose();
|
||||
#endif
|
||||
usbStart();
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
usbPluggedIn();
|
||||
#endif
|
||||
usbStarted = true;
|
||||
}
|
||||
|
||||
#if defined(USB_JOYSTICK)
|
||||
if (usbStarted) {
|
||||
if (!usbPlugged()) {
|
||||
//disable USB
|
||||
usbStop();
|
||||
usbStarted = false;
|
||||
}
|
||||
else {
|
||||
usbJoystickUpdate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif //#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
}
|
||||
|
||||
void checkSpeakerVolume()
|
||||
{
|
||||
if (currentSpeakerVolume != requiredSpeakerVolume) {
|
||||
currentSpeakerVolume = requiredSpeakerVolume;
|
||||
setVolume(currentSpeakerVolume);
|
||||
}
|
||||
}
|
||||
|
||||
void checkEeprom()
|
||||
{
|
||||
if (!usbPlugged()) {
|
||||
// TODO merge these 2 branches
|
||||
#if defined(PCBSKY9X)
|
||||
if (Eeprom32_process_state != E32_IDLE)
|
||||
ee32_process();
|
||||
else if (TIME_TO_WRITE())
|
||||
eeCheck(false);
|
||||
#else
|
||||
if (theFile.isWriting())
|
||||
theFile.nextWriteStep();
|
||||
else if (TIME_TO_WRITE())
|
||||
eeCheck(false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void perMainArm()
|
||||
{
|
||||
#if defined(PCBSKY9X) && !defined(REVA)
|
||||
calcConsumption();
|
||||
#endif
|
||||
checkSpeakerVolume();
|
||||
checkEeprom();
|
||||
sdMountPoll();
|
||||
writeLogs();
|
||||
handleUsbConnection();
|
||||
checkTrainerSettings();
|
||||
checkBattery();
|
||||
|
||||
uint8_t evt = getEvent(false);
|
||||
if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on
|
||||
checkBacklight();
|
||||
#if defined(NAVIGATION_STICKS)
|
||||
uint8_t sticks_evt = getSticksNavigationEvent();
|
||||
if (sticks_evt) evt = sticks_evt;
|
||||
#endif
|
||||
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
if (usbPlugged()) {
|
||||
// disable access to menus
|
||||
lcd_clear();
|
||||
menuMainView(0);
|
||||
lcdRefresh();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running)
|
||||
luaRunNonGuiScripts();
|
||||
|
||||
// draw LCD from menus or from Lua script
|
||||
if (luaRunGuiScripts(evt)) { // either stand-alone or telemetry scripts
|
||||
// let Lua manage LCD fully
|
||||
}
|
||||
else {
|
||||
// normal GUI from menus
|
||||
const char *warn = s_warning;
|
||||
uint8_t menu = s_menu_count;
|
||||
lcd_clear();
|
||||
if (menuEvent) {
|
||||
m_posVert = menuEvent == EVT_ENTRY_UP ? g_menuPos[g_menuStackPtr] : 0;
|
||||
m_posHorz = 0;
|
||||
evt = menuEvent;
|
||||
menuEvent = 0;
|
||||
AUDIO_MENUS();
|
||||
}
|
||||
g_menuStack[g_menuStackPtr]((warn || menu) ? 0 : evt);
|
||||
if (warn) DISPLAY_WARNING(evt);
|
||||
if (menu) {
|
||||
const char * result = displayMenu(evt);
|
||||
if (result) {
|
||||
menuHandler(result);
|
||||
putEvent(EVT_MENU_UP);
|
||||
}
|
||||
}
|
||||
drawStatusLine();
|
||||
}
|
||||
lcdRefresh();
|
||||
}
|
165
radio/src/main_avr.cpp
Normal file
165
radio/src/main_avr.cpp
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
extern void checkBattery();
|
||||
extern uint8_t checkTrim(uint8_t event);
|
||||
|
||||
void perMain()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
doMixerCalculations();
|
||||
#endif
|
||||
uint16_t t0 = getTmr16KHz();
|
||||
int16_t delta = (nextMixerEndTime - lastMixerDuration) - t0;
|
||||
if (delta > 0 && delta < MAX_MIXER_DELTA) {
|
||||
#if defined(PCBSTD) && defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotencPoll();
|
||||
#endif
|
||||
|
||||
// @@@ open.20.fsguruh
|
||||
// SLEEP(); // wouldn't that make sense? should save a lot of battery power!!!
|
||||
/* for future use; currently very very beta... */
|
||||
#if defined(POWER_SAVE)
|
||||
ADCSRA&=0x7F; // disable ADC for power saving
|
||||
ACSR&=0xF7; // disable ACIE Interrupts
|
||||
ACSR|=0x80; // disable Analog Comparator
|
||||
// maybe we disable here a lot more hardware components in future to save even more power
|
||||
|
||||
|
||||
|
||||
MCUCR|=0x20; // enable Sleep (bit5)
|
||||
// MCUCR|=0x28; // enable Sleep (bit5) enable ADC Noise Reduction (bit3)
|
||||
// first tests showed: simple sleep would reduce cpu current from 40.5mA to 32.0mA
|
||||
// noise reduction sleep would reduce it down to 28.5mA; However this would break pulses in theory
|
||||
// however with standard module, it will need about 95mA. Therefore the drop to 88mA is not much noticable
|
||||
do {
|
||||
asm volatile(" sleep \n\t"); // if _SLEEP() is not defined use this
|
||||
t0=getTmr16KHz();
|
||||
delta= (nextMixerEndTime - lastMixerDuration) - t0;
|
||||
} while ((delta>0) && (delta<MAX_MIXER_DELTA));
|
||||
|
||||
// reenabling of the hardware components needed here
|
||||
MCUCR&=0x00; // disable sleep
|
||||
ADCSRA|=0x80; // enable ADC
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
nextMixerEndTime = t0 + MAX_MIXER_DELTA;
|
||||
// this is a very tricky implementation; lastMixerEndTime is just like a default value not to stop mixcalculations totally;
|
||||
// the real value for lastMixerEndTime is calculated inside pulses_XXX.cpp which aligns the timestamp to the pulses generated
|
||||
// nextMixerEndTime is actually defined inside pulses_XXX.h
|
||||
|
||||
doMixerCalculations();
|
||||
|
||||
t0 = getTmr16KHz() - t0;
|
||||
lastMixerDuration = t0;
|
||||
if (t0 > maxMixerDuration) maxMixerDuration = t0;
|
||||
|
||||
#if defined(MODULE_ALWAYS_SEND_PULSES)
|
||||
if (startupWarningState < STARTUP_WARNING_DONE) {
|
||||
// don't do menu's until throttle and switch warnings are handled
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!eeprom_buffer_size) {
|
||||
if (theFile.isWriting())
|
||||
theFile.nextWriteStep();
|
||||
else if (TIME_TO_WRITE())
|
||||
eeCheck(false);
|
||||
}
|
||||
|
||||
#if defined(SDCARD)
|
||||
sdMountPoll();
|
||||
writeLogs();
|
||||
#endif
|
||||
|
||||
uint8_t evt = getEvent();
|
||||
evt = checkTrim(evt);
|
||||
|
||||
if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on
|
||||
checkBacklight();
|
||||
|
||||
#if (defined(FRSKY) || defined(MAVLINK))
|
||||
telemetryWakeup();
|
||||
#endif
|
||||
|
||||
#if defined(NAVIGATION_STICKS)
|
||||
uint8_t sticks_evt = getSticksNavigationEvent();
|
||||
if (sticks_evt) evt = sticks_evt;
|
||||
#endif
|
||||
|
||||
const char *warn = s_warning;
|
||||
uint8_t menu = s_menu_count;
|
||||
|
||||
lcd_clear();
|
||||
if (menuEvent) {
|
||||
m_posVert = menuEvent == EVT_ENTRY_UP ? g_menuPos[g_menuStackPtr] : 0;
|
||||
m_posHorz = 0;
|
||||
evt = menuEvent;
|
||||
menuEvent = 0;
|
||||
AUDIO_MENUS();
|
||||
}
|
||||
g_menuStack[g_menuStackPtr]((warn || menu) ? 0 : evt);
|
||||
|
||||
|
||||
if (warn) DISPLAY_WARNING(evt);
|
||||
#if defined(NAVIGATION_MENUS)
|
||||
if (menu) {
|
||||
const char * result = displayMenu(evt);
|
||||
if (result) {
|
||||
menuHandler(result);
|
||||
putEvent(EVT_MENU_UP);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
drawStatusLine();
|
||||
|
||||
lcdRefresh();
|
||||
|
||||
if (SLAVE_MODE()) {
|
||||
JACK_PPM_OUT();
|
||||
}
|
||||
else {
|
||||
JACK_PPM_IN();
|
||||
}
|
||||
|
||||
checkBattery();
|
||||
}
|
|
@ -2204,135 +2204,6 @@ void checkBattery()
|
|||
|
||||
}
|
||||
|
||||
#if !defined(CPUARM)
|
||||
void perMain()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
doMixerCalculations();
|
||||
#endif
|
||||
uint16_t t0 = getTmr16KHz();
|
||||
int16_t delta = (nextMixerEndTime - lastMixerDuration) - t0;
|
||||
if (delta > 0 && delta < MAX_MIXER_DELTA) {
|
||||
#if defined(PCBSTD) && defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotencPoll();
|
||||
#endif
|
||||
|
||||
// @@@ open.20.fsguruh
|
||||
// SLEEP(); // wouldn't that make sense? should save a lot of battery power!!!
|
||||
/* for future use; currently very very beta... */
|
||||
#if defined(POWER_SAVE)
|
||||
ADCSRA&=0x7F; // disable ADC for power saving
|
||||
ACSR&=0xF7; // disable ACIE Interrupts
|
||||
ACSR|=0x80; // disable Analog Comparator
|
||||
// maybe we disable here a lot more hardware components in future to save even more power
|
||||
|
||||
|
||||
|
||||
MCUCR|=0x20; // enable Sleep (bit5)
|
||||
// MCUCR|=0x28; // enable Sleep (bit5) enable ADC Noise Reduction (bit3)
|
||||
// first tests showed: simple sleep would reduce cpu current from 40.5mA to 32.0mA
|
||||
// noise reduction sleep would reduce it down to 28.5mA; However this would break pulses in theory
|
||||
// however with standard module, it will need about 95mA. Therefore the drop to 88mA is not much noticable
|
||||
do {
|
||||
asm volatile(" sleep \n\t"); // if _SLEEP() is not defined use this
|
||||
t0=getTmr16KHz();
|
||||
delta= (nextMixerEndTime - lastMixerDuration) - t0;
|
||||
} while ((delta>0) && (delta<MAX_MIXER_DELTA));
|
||||
|
||||
// reenabling of the hardware components needed here
|
||||
MCUCR&=0x00; // disable sleep
|
||||
ADCSRA|=0x80; // enable ADC
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
nextMixerEndTime = t0 + MAX_MIXER_DELTA;
|
||||
// this is a very tricky implementation; lastMixerEndTime is just like a default value not to stop mixcalculations totally;
|
||||
// the real value for lastMixerEndTime is calculated inside pulses_XXX.cpp which aligns the timestamp to the pulses generated
|
||||
// nextMixerEndTime is actually defined inside pulses_XXX.h
|
||||
|
||||
doMixerCalculations();
|
||||
|
||||
t0 = getTmr16KHz() - t0;
|
||||
lastMixerDuration = t0;
|
||||
if (t0 > maxMixerDuration) maxMixerDuration = t0;
|
||||
|
||||
#if defined(MODULE_ALWAYS_SEND_PULSES)
|
||||
if (startupWarningState < STARTUP_WARNING_DONE) {
|
||||
// don't do menu's until throttle and switch warnings are handled
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!eeprom_buffer_size) {
|
||||
if (theFile.isWriting())
|
||||
theFile.nextWriteStep();
|
||||
else if (TIME_TO_WRITE())
|
||||
eeCheck(false);
|
||||
}
|
||||
|
||||
#if defined(SDCARD)
|
||||
sdMountPoll();
|
||||
writeLogs();
|
||||
#endif
|
||||
|
||||
uint8_t evt = getEvent();
|
||||
evt = checkTrim(evt);
|
||||
|
||||
if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on
|
||||
checkBacklight();
|
||||
|
||||
#if (defined(FRSKY) || defined(MAVLINK))
|
||||
telemetryWakeup();
|
||||
#endif
|
||||
|
||||
#if defined(NAVIGATION_STICKS)
|
||||
uint8_t sticks_evt = getSticksNavigationEvent();
|
||||
if (sticks_evt) evt = sticks_evt;
|
||||
#endif
|
||||
|
||||
const char *warn = s_warning;
|
||||
uint8_t menu = s_menu_count;
|
||||
|
||||
lcd_clear();
|
||||
if (menuEvent) {
|
||||
m_posVert = menuEvent == EVT_ENTRY_UP ? g_menuPos[g_menuStackPtr] : 0;
|
||||
m_posHorz = 0;
|
||||
evt = menuEvent;
|
||||
menuEvent = 0;
|
||||
AUDIO_MENUS();
|
||||
}
|
||||
g_menuStack[g_menuStackPtr]((warn || menu) ? 0 : evt);
|
||||
|
||||
|
||||
if (warn) DISPLAY_WARNING(evt);
|
||||
#if defined(NAVIGATION_MENUS)
|
||||
if (menu) {
|
||||
const char * result = displayMenu(evt);
|
||||
if (result) {
|
||||
menuHandler(result);
|
||||
putEvent(EVT_MENU_UP);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
drawStatusLine();
|
||||
|
||||
lcdRefresh();
|
||||
|
||||
if (SLAVE_MODE()) {
|
||||
JACK_PPM_OUT();
|
||||
}
|
||||
else {
|
||||
JACK_PPM_IN();
|
||||
}
|
||||
|
||||
checkBattery();
|
||||
}
|
||||
#endif // #if !defined(CPUARM)
|
||||
|
||||
|
||||
|
||||
int16_t g_ppmIns[NUM_TRAINER];
|
||||
uint8_t ppmInState = 0; // 0=unsync 1..8= wait for value i-1
|
||||
uint8_t ppmInValid = 0;
|
||||
|
|
|
@ -36,131 +36,6 @@
|
|||
|
||||
#include "opentx.h"
|
||||
|
||||
static uint8_t currentSpeakerVolume = 255;
|
||||
uint8_t requiredSpeakerVolume = 255;
|
||||
|
||||
extern void checkBattery();
|
||||
|
||||
void handleUsbConnection()
|
||||
{
|
||||
#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
static bool usbStarted = false;
|
||||
if (!usbStarted && usbPlugged()) {
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
opentxClose();
|
||||
#endif
|
||||
usbStart();
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
usbPluggedIn();
|
||||
#endif
|
||||
usbStarted = true;
|
||||
}
|
||||
|
||||
#if defined(USB_JOYSTICK)
|
||||
if (usbStarted) {
|
||||
if (!usbPlugged()) {
|
||||
//disable USB
|
||||
usbStop();
|
||||
usbStarted = false;
|
||||
}
|
||||
else {
|
||||
usbJoystickUpdate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif //#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
}
|
||||
|
||||
void checkSpeakerVolume()
|
||||
{
|
||||
if (currentSpeakerVolume != requiredSpeakerVolume) {
|
||||
currentSpeakerVolume = requiredSpeakerVolume;
|
||||
setVolume(currentSpeakerVolume);
|
||||
}
|
||||
}
|
||||
|
||||
void checkEeprom()
|
||||
{
|
||||
if (!usbPlugged()) {
|
||||
// TODO merge these 2 branches
|
||||
#if defined(PCBSKY9X)
|
||||
if (Eeprom32_process_state != E32_IDLE)
|
||||
ee32_process();
|
||||
else if (TIME_TO_WRITE())
|
||||
eeCheck(false);
|
||||
#else
|
||||
if (theFile.isWriting())
|
||||
theFile.nextWriteStep();
|
||||
else if (TIME_TO_WRITE())
|
||||
eeCheck(false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void perMainArm()
|
||||
{
|
||||
#if defined(PCBSKY9X) && !defined(REVA)
|
||||
calcConsumption();
|
||||
#endif
|
||||
checkSpeakerVolume();
|
||||
checkEeprom();
|
||||
sdMountPoll();
|
||||
writeLogs();
|
||||
handleUsbConnection();
|
||||
checkTrainerSettings();
|
||||
checkBattery();
|
||||
|
||||
uint8_t evt = getEvent(false);
|
||||
if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on
|
||||
checkBacklight();
|
||||
#if defined(NAVIGATION_STICKS)
|
||||
uint8_t sticks_evt = getSticksNavigationEvent();
|
||||
if (sticks_evt) evt = sticks_evt;
|
||||
#endif
|
||||
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
if (usbPlugged()) {
|
||||
// disable access to menus
|
||||
lcd_clear();
|
||||
menuMainView(0);
|
||||
lcdRefresh();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running)
|
||||
luaRunNonGuiScripts();
|
||||
|
||||
// draw LCD from menus or from Lua script
|
||||
if (luaRunGuiScripts(evt)) { // either stand-alone or telemetry scripts
|
||||
// let Lua manage LCD fully
|
||||
}
|
||||
else {
|
||||
// normal GUI from menus
|
||||
const char *warn = s_warning;
|
||||
uint8_t menu = s_menu_count;
|
||||
lcd_clear();
|
||||
if (menuEvent) {
|
||||
m_posVert = menuEvent == EVT_ENTRY_UP ? g_menuPos[g_menuStackPtr] : 0;
|
||||
m_posHorz = 0;
|
||||
evt = menuEvent;
|
||||
menuEvent = 0;
|
||||
AUDIO_MENUS();
|
||||
}
|
||||
g_menuStack[g_menuStackPtr]((warn || menu) ? 0 : evt);
|
||||
if (warn) DISPLAY_WARNING(evt);
|
||||
if (menu) {
|
||||
const char * result = displayMenu(evt);
|
||||
if (result) {
|
||||
menuHandler(result);
|
||||
putEvent(EVT_MENU_UP);
|
||||
}
|
||||
}
|
||||
drawStatusLine();
|
||||
}
|
||||
lcdRefresh();
|
||||
}
|
||||
|
||||
#define MENUS_STACK_SIZE 2000
|
||||
#define MIXER_STACK_SIZE 500
|
||||
#define AUDIO_STACK_SIZE 500
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue