From 55f71f053bc7996acffc7e2325072fe85d08a877 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 4 Mar 2016 23:54:19 +0100 Subject: [PATCH] myeeprom.h splitted into dataconstants.h and datastructs.h --- radio/src/CMakeLists.txt | 21 +- radio/src/dataconstants.h | 988 ++++++++++ radio/src/datastructs.h | 1005 ++++++++++ radio/src/dump.cpp | 4 +- radio/src/gui/9x/lcd.h | 2 + radio/src/gui/9x/view_mavlink.cpp | 4 +- radio/src/gui/9x/view_mavlink.h | 3 +- radio/src/gui/horus/bitmapbuffer.h | 2 +- radio/src/gui/horus/theme.h | 2 +- radio/src/gui/horus/widgets_container.h | 1 + radio/src/lua/interface.cpp | 15 +- radio/src/myeeprom.h | 1798 +----------------- radio/src/opentx.cpp | 18 +- radio/src/opentx.h | 17 +- radio/src/storage/eeprom_conversions.cpp | 18 +- radio/src/storage/eeprom_rlc.cpp | 12 +- radio/src/storage/rambackup.cpp | 43 + radio/src/storage/storage.h | 7 +- radio/src/targets/common_avr/serial_driver.h | 2 + radio/src/targets/gruvin9x/diskio.cpp | 40 +- radio/src/targets/sky9x/MEDSdcard.c | 42 +- radio/src/targets/sky9x/diskio.cpp | 46 +- radio/src/telemetry/mavlink.cpp | 9 +- radio/src/telemetry/mavlink.h | 5 +- radio/util/commit-tests.sh | 32 +- radio/util/generate_datacopy.py | 33 + 26 files changed, 2252 insertions(+), 1917 deletions(-) create mode 100644 radio/src/dataconstants.h create mode 100644 radio/src/datastructs.h create mode 100644 radio/src/storage/rambackup.cpp create mode 100644 radio/util/generate_datacopy.py diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index ae478c885..d138e30aa 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -63,10 +63,11 @@ if(PCB STREQUAL HORUS) set(GUI_DIR horus) set(TARGET_DIR horus) set(LINKER_SCRIPT targets/horus/stm32f4_flash.ld) - set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} horus_bitmaps) + set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} horus_bitmaps datacopy) set(LUA_EXPORT lua_export_horus) set(FLAVOUR horus) set(VIRTUAL_INPUTS YES) + set(RAMBACKUP YES) add_definitions(-DPCBHORUS -DCOLORLCD -DSTM32F429_439xx -DPPM_PIN_HW_SERIAL) add_definitions(-DEEPROM_VARIANT=0 -DAUDIO -DVOICE -DRTCLOCK) add_definitions(-DLUAINPUTS -DXCURVES -DVARIO) @@ -113,6 +114,12 @@ if(PCB STREQUAL HORUS) STM32F4xx_StdPeriph_Driver/src/stm32f4xx_tim.c STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma2d.c ) + add_custom_command( + OUTPUT datacopy.cpp + COMMAND python ${RADIO_DIRECTORY}/util/generate_datacopy.py ${RADIO_DIRECTORY}/src/datastructs.h -DPCBHORUS -DCPUARM -DCOLORLCD -DBACKUP > datacopy.cpp + DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py + ) + add_custom_target(datacopy DEPENDS datacopy.cpp) elseif(PCB STREQUAL TARANIS) option(PCBREV "PCB Revision" REVPLUS) option(SHUTDOWN_CONFIRMATION "Shutdown confirmation" OFF) @@ -694,6 +701,11 @@ set(GUI_SRC view_statistics.cpp ) +if(RAMBACKUP) + add_definitions(-DRAMBACKUP) + set(SRC ${SRC} storage/rambackup.cpp) +endif() + if(VIRTUAL_INPUTS) add_definitions(-DVIRTUALINPUTS) set(TEMPLATES OFF) @@ -745,10 +757,6 @@ if(GVARS) math(EXPR EEPROM_VARIANT ${EEPROM_VARIANT}+${GVARS_VARIANT}) endif() -if(SDCARD) - set(FIRMWARE_SRC ${FIRMWARE_SRC} ${FATFS_SRC}) -endif() - if(FAI STREQUAL YES) add_definitions(-DFAI) elseif(FAI STREQUAL CHOICE) @@ -771,11 +779,12 @@ if(JITTER_FILTER) add_definitions(-DJITTER_FILTER) endif() -if(SDCARD STREQUAL YES) +if(SDCARD) add_definitions(-DSDCARD) include_directories(${FATFS_DIR} ${FATFS_DIR}/option) set(SRC ${SRC} sdcard.cpp rtc.cpp logs.cpp) set(GUI_SRC ${GUI_SRC} menu_general_sdmanager.cpp) + set(FIRMWARE_SRC ${FIRMWARE_SRC} ${FATFS_SRC}) endif() if(SHUTDOWN_CONFIRMATION) diff --git a/radio/src/dataconstants.h b/radio/src/dataconstants.h new file mode 100644 index 000000000..35b93eee2 --- /dev/null +++ b/radio/src/dataconstants.h @@ -0,0 +1,988 @@ +/* + * 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. + */ + +#ifndef _DATACONSTANTS_H_ +#define _DATACONSTANTS_H_ + +#if defined(EXPORT) + #define LUA_EXPORT(...) LEXP(__VA_ARGS__) + #define LUA_EXPORT_MULTIPLE(...) LEXP_MULTIPLE(__VA_ARGS__) + #define LUA_EXPORT_EXTRA(...) LEXP_EXTRA(__VA_ARGS__) +#else + #define LUA_EXPORT(...) + #define LUA_EXPORT_MULTIPLE(...) + #define LUA_EXPORT_EXTRA(...) +#endif + +#define NUM_STICKS 4 + +#if defined(PCBHORUS) + #define MAX_MODELS 60 + #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 + #define MAX_FLIGHT_MODES 9 + #define MAX_MIXERS 64 + #define MAX_EXPOS 64 + #define NUM_LOGICAL_SWITCH 64 // number of custom switches + #define NUM_CFN 64 // number of functions assigned to switches + #define MAX_SCRIPTS 9 + #define MAX_INPUTS 32 + #define NUM_TRAINER 16 + #define NUM_POTS 7 + #define NUM_XPOTS 3 + #define MAX_SENSORS 32 + #define MAX_CUSTOM_SCREENS 5 +#elif defined(PCBFLAMENCO) + #define MAX_MODELS 60 + #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 + #define MAX_FLIGHT_MODES 9 + #define MAX_MIXERS 64 + #define MAX_EXPOS 64 + #define NUM_LOGICAL_SWITCH 32 // number of custom switches + #define NUM_CFN 64 // number of functions assigned to switches + #define MAX_SCRIPTS 7 + #define MAX_INPUTS 32 + #define NUM_TRAINER 16 + #define NUM_POTS 3 + #define NUM_XPOTS 0 + #define MAX_SENSORS 32 +#elif defined(PCBTARANIS) + #define MAX_MODELS 60 + #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 + #define MAX_FLIGHT_MODES 9 + #define MAX_MIXERS 64 + #define MAX_EXPOS 64 + #define NUM_LOGICAL_SWITCH 64 // number of logical switches + #define NUM_CFN 64 // number of functions assigned to switches + #define MAX_SCRIPTS 7 + #define MAX_INPUTS 32 + #define NUM_TRAINER 16 + #if defined(REV9E) + #define NUM_POTS 8 + #define NUM_XPOTS 4 + #else + #define NUM_POTS 5 + #define NUM_XPOTS 3 + #endif + #define MAX_SENSORS 32 +#elif defined(PCBSKY9X) + #define MAX_MODELS 60 + #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 + #define MAX_FLIGHT_MODES 9 + #define MAX_MIXERS 64 + #define MAX_EXPOS 32 + #define NUM_LOGICAL_SWITCH 64 // number of custom switches + #define NUM_CFN 64 // number of functions assigned to switches + #define NUM_TRAINER 16 + #define NUM_POTS 3 + #define NUM_XPOTS 0 + #define MAX_SENSORS 32 +#elif defined(CPUM2560) || defined(CPUM2561) + #define MAX_MODELS 30 + #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 + #define MAX_FLIGHT_MODES 6 + #define MAX_MIXERS 32 + #define MAX_EXPOS 16 + #define NUM_LOGICAL_SWITCH 12 // number of custom switches + #define NUM_CFN 24 // number of functions assigned to switches + #define NUM_TRAINER 8 + #define NUM_POTS 3 + #define NUM_XPOTS 0 + #define MAX_SENSORS 0 +#elif defined(CPUM128) + #define MAX_MODELS 30 + #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 + #define MAX_FLIGHT_MODES 5 + #define MAX_MIXERS 32 + #define MAX_EXPOS 14 + #define NUM_LOGICAL_SWITCH 12 // number of custom switches + #define NUM_CFN 24 // number of functions assigned to switches + #define NUM_TRAINER 8 + #define NUM_POTS 3 + #define NUM_XPOTS 0 + #define MAX_SENSORS 0 +#else + #define MAX_MODELS 16 + #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 + #define MAX_FLIGHT_MODES 5 + #define MAX_MIXERS 32 + #define MAX_EXPOS 14 + #define NUM_LOGICAL_SWITCH 12 // number of custom switches + #define NUM_CFN 16 // number of functions assigned to switches + #define NUM_TRAINER 8 + #define NUM_POTS 3 + #define NUM_XPOTS 0 + #define MAX_SENSORS 0 +#endif + +#if defined(CPUARM) + #define MAX_TIMERS 3 +#else + #define MAX_TIMERS 2 +#endif + +#define NUM_CYC 3 +#define NUM_CAL_PPM 4 + +enum CurveType { + CURVE_TYPE_STANDARD, + CURVE_TYPE_CUSTOM, + CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM +}; + +#define MIN_POINTS 3 +#define MAX_POINTS 17 + +#if defined(PCBHORUS) + #define LEN_MODEL_NAME 15 + #define LEN_TIMER_NAME 8 + #define LEN_FLIGHT_MODE_NAME 10 + #define LEN_BITMAP_NAME 10 + #define LEN_EXPOMIX_NAME 6 + #define LEN_CHANNEL_NAME 6 + #define LEN_INPUT_NAME 4 + #define LEN_CURVE_NAME 3 + #define MAX_CURVES 32 + #define NUM_POINTS 512 +#elif defined(PCBFLAMENCO) + #define LEN_MODEL_NAME 12 + #define LEN_TIMER_NAME 8 + #define LEN_FLIGHT_MODE_NAME 10 + #define LEN_EXPOMIX_NAME 6 + #define LEN_CHANNEL_NAME 6 + #define LEN_INPUT_NAME 4 + #define LEN_CURVE_NAME 3 + #define MAX_CURVES 32 + #define NUM_POINTS 512 +#elif defined(PCBTARANIS) + #define LEN_MODEL_NAME 12 + #define LEN_TIMER_NAME 8 + #define LEN_FLIGHT_MODE_NAME 10 + #define LEN_BITMAP_NAME 10 + #define LEN_EXPOMIX_NAME 8 + #define LEN_CHANNEL_NAME 6 + #define LEN_INPUT_NAME 4 + #define LEN_CURVE_NAME 3 + #define MAX_CURVES 32 + #define NUM_POINTS 512 +#elif defined(CPUARM) + #define LEN_MODEL_NAME 10 + #define LEN_TIMER_NAME 3 + #define LEN_FLIGHT_MODE_NAME 6 + #define LEN_EXPOMIX_NAME 6 + #define MAX_CURVES 16 + #define NUM_POINTS 512 +#else + #define LEN_MODEL_NAME 10 + #define LEN_FLIGHT_MODE_NAME 6 + #define MAX_CURVES 8 + #define NUM_POINTS (112-MAX_CURVES) +#endif + +#if defined(PCBTARANIS) || defined(PCBSKY9X) || defined(PCBHORUS) + #define NUM_MODULES 2 +#else + #define NUM_MODULES 1 +#endif + +#if defined(PCBFLAMENCO) + #define NUM_SWITCHES 5 +#elif defined(PCBTARANIS) && defined(REV9E) + #define NUM_SWITCHES 18 // yes, it's a lot! +#elif defined(PCBTARANIS) || defined(PCBHORUS) + #define NUM_SWITCHES 8 +#else + #define NUM_SWITCHES 7 +#endif + +#define XPOTS_MULTIPOS_COUNT 6 + +#if defined(PCBTARANIS) + #define MAX_ROTARY_ENCODERS 0 + #define NUM_ROTARY_ENCODERS 0 +#elif defined(REVX) + #define MAX_ROTARY_ENCODERS 1 + #define NUM_ROTARY_ENCODERS 0 +#elif defined(PCBSKY9X) + #define MAX_ROTARY_ENCODERS 1 + #define NUM_ROTARY_ENCODERS 1 +#elif defined(CPUM2560) + #define MAX_ROTARY_ENCODERS 2 + #define NUM_ROTARY_ENCODERS 2 +#else + #define MAX_ROTARY_ENCODERS 0 + #define NUM_ROTARY_ENCODERS 0 +#endif + +#if defined(COLORLCD) +enum MainViews { + VIEW_BLANK, + VIEW_TIMERS_ALTITUDE, + VIEW_CHANNELS, + VIEW_TELEM1, + VIEW_TELEM2, + VIEW_TELEM3, + VIEW_TELEM4, + VIEW_COUNT +}; +#elif defined(PCBTARANIS) +enum MainViews { + VIEW_TIMERS, + VIEW_INPUTS, + VIEW_SWITCHES, + VIEW_COUNT +}; +#else +enum MainViews { + VIEW_OUTPUTS_VALUES, + VIEW_OUTPUTS_BARS, + VIEW_INPUTS, + VIEW_TIMER2, + VIEW_COUNT +}; +#endif + +enum BeeperMode { + e_mode_quiet = -2, + e_mode_alarms, + e_mode_nokeys, + e_mode_all +}; + +enum UartModes { +#if defined(CLI) || defined(DEBUG) + UART_MODE_DEBUG, +#else + UART_MODE_NONE, +#endif + UART_MODE_TELEMETRY_MIRROR, + UART_MODE_TELEMETRY, + UART_MODE_SBUS_TRAINER, + // UART_MODE_CPPM_TRAINER, + UART_MODE_COUNT, + UART_MODE_MAX = UART_MODE_COUNT-1 +}; + +#if defined(PCBHORUS) + #define LEN_SWITCH_NAME 3 + #define LEN_ANA_NAME 3 + #define LEN_MODEL_FILENAME 16 + #define LEN_BLUETOOTH_NAME 10 +#elif defined(PCBFLAMENCO) + #define LEN_SWITCH_NAME 3 + #define LEN_ANA_NAME 3 +#elif defined(PCBTARANIS) + #define LEN_SWITCH_NAME 3 + #define LEN_ANA_NAME 3 + #define LEN_BLUETOOTH_NAME 10 +#endif + +#if defined(CPUARM) +#define TELEM_LABEL_LEN 4 +enum TelemetryUnit { + UNIT_RAW, + UNIT_VOLTS, + UNIT_AMPS, + UNIT_MILLIAMPS, + UNIT_KTS, + UNIT_METERS_PER_SECOND, + UNIT_FEET_PER_SECOND, + UNIT_KMH, + UNIT_MPH, + UNIT_METERS, + UNIT_FEET, + UNIT_CELSIUS, + UNIT_FAHRENHEIT, + UNIT_PERCENT, + UNIT_MAH, + UNIT_WATTS, + UNIT_DB, + UNIT_RPMS, + UNIT_G, + UNIT_DEGREE, + UNIT_MILLILITERS, + UNIT_FLOZ, + UNIT_HOURS, + UNIT_MINUTES, + UNIT_SECONDS, + // FrSky format used for these fields, could be another format in the future + UNIT_FIRST_VIRTUAL, + UNIT_CELLS = UNIT_FIRST_VIRTUAL, + UNIT_DATETIME, + UNIT_GPS, + UNIT_GPS_LONGITUDE, + UNIT_GPS_LATITUDE, + UNIT_GPS_LONGITUDE_EW, + UNIT_GPS_LATITUDE_NS, + UNIT_DATETIME_YEAR, + UNIT_DATETIME_DAY_MONTH, + UNIT_DATETIME_HOUR_MIN, + UNIT_DATETIME_SEC +}; +#define UNIT_MAX UNIT_FLOZ +#define UNIT_DIST UNIT_METERS +#define UNIT_TEMPERATURE UNIT_CELSIUS +#define UNIT_SPEED UNIT_KMH +#else +#if !defined(CPUARM) +enum TelemetrySource { + TELEM_NONE, + TELEM_TX_VOLTAGE, + TELEM_TIMER1, + TELEM_TIMER2, + TELEM_TIMER_MAX=TELEM_TIMER2, + TELEM_RSSI_TX, + TELEM_RSSI_RX, + TELEM_A_FIRST, + TELEM_A1=TELEM_A_FIRST, + TELEM_A2, + TELEM_A_LAST=TELEM_A2, + TELEM_ALT, + TELEM_RPM, + TELEM_FUEL, + TELEM_T1, + TELEM_T2, + TELEM_SPEED, + TELEM_DIST, + TELEM_GPSALT, + TELEM_CELL, + TELEM_CELLS_SUM, + TELEM_VFAS, + TELEM_CURRENT, + TELEM_CONSUMPTION, + TELEM_POWER, + TELEM_ACCx, + TELEM_ACCy, + TELEM_ACCz, + TELEM_HDG, + TELEM_VSPEED, + TELEM_ASPEED, + TELEM_DTE, + TELEM_MIN_A_FIRST, + TELEM_MIN_A1=TELEM_MIN_A_FIRST, + TELEM_MIN_A2, + TELEM_MIN_A_LAST=TELEM_MIN_A2, + TELEM_MIN_ALT, + TELEM_MAX_ALT, + TELEM_MAX_RPM, + TELEM_MAX_T1, + TELEM_MAX_T2, + TELEM_MAX_SPEED, + TELEM_MAX_DIST, + TELEM_MAX_ASPEED, + TELEM_MIN_CELL, + TELEM_MIN_CELLS_SUM, + TELEM_MIN_VFAS, + TELEM_MAX_CURRENT, + TELEM_MAX_POWER, + TELEM_ACC, + TELEM_GPS_TIME, + TELEM_CSW_MAX = TELEM_MAX_POWER, + TELEM_NOUSR_MAX = TELEM_A2, +#if defined(FRSKY) + TELEM_DISPLAY_MAX = TELEM_MAX_POWER, +#else + TELEM_DISPLAY_MAX = TELEM_TIMER2, // because used also in PlayValue +#endif + TELEM_STATUS_MAX = TELEM_GPS_TIME, + TELEM_FIRST_STREAMED_VALUE = TELEM_RSSI_TX, +}; + +#if defined(FRSKY_HUB) + #define NUM_TELEMETRY TELEM_CSW_MAX +#elif defined(WS_HOW_HIGH) + #define NUM_TELEMETRY TELEM_ALT +#elif defined(FRSKY) + #define NUM_TELEMETRY TELEM_A2 +#elif defined(MAVLINK) + #define NUM_TELEMETRY 4 +#else + #define NUM_TELEMETRY TELEM_TIMER2 +#endif + +#endif + +enum TelemetryUnit { + UNIT_VOLTS, + UNIT_AMPS, + UNIT_METERS_PER_SECOND, + UNIT_RAW, + UNIT_SPEED, + UNIT_DIST, + UNIT_TEMPERATURE, + UNIT_PERCENT, + UNIT_MILLIAMPS, + UNIT_A1A2_MAX = UNIT_MILLIAMPS, + UNIT_MAH, + UNIT_WATTS, + UNIT_DB, + UNIT_FEET, + UNIT_KTS, + UNIT_HOURS, + UNIT_MINUTES, + UNIT_SECONDS, + UNIT_RPMS, + UNIT_G, + UNIT_HDG, +}; +#endif + +#if defined(PCBTARANIS) + #define NUM_LINE_ITEMS 3 +#else + #define NUM_LINE_ITEMS 2 +#endif + +#if defined(PCBTARANIS) +#define MAX_TELEM_SCRIPT_INPUTS 8 +#endif + +#if defined(CPUARM) +enum TelemetryScreenType { + TELEMETRY_SCREEN_TYPE_NONE, + TELEMETRY_SCREEN_TYPE_VALUES, + TELEMETRY_SCREEN_TYPE_GAUGES, +#if defined(LUA) + TELEMETRY_SCREEN_TYPE_SCRIPT, + TELEMETRY_SCREEN_TYPE_MAX = TELEMETRY_SCREEN_TYPE_SCRIPT +#else + TELEMETRY_SCREEN_TYPE_MAX = TELEMETRY_SCREEN_TYPE_GAUGES +#endif +}; +#define MAX_TELEMETRY_SCREENS 4 +#define TELEMETRY_SCREEN_TYPE(screenIndex) TelemetryScreenType((g_model.frsky.screensType >> (2*(screenIndex))) & 0x03) +#define IS_BARS_SCREEN(screenIndex) (TELEMETRY_SCREEN_TYPE(screenIndex) == TELEMETRY_SCREEN_TYPE_GAUGES) +#define MIN_BLADES -1 // 1 blade +#define MAX_BLADES 126 // 128 blades +#else +#define MAX_FRSKY_A_CHANNELS 2 +#define MAX_TELEMETRY_SCREENS 2 +#define IS_BARS_SCREEN(screenIndex) (g_model.frsky.screensType & (1<<(screenIndex))) +#define MIN_BLADES 0 // 2 blades +#define MAX_BLADES 3 // 5 blades +#endif + +#define FAILSAFE_CHANNEL_HOLD 2000 +#define FAILSAFE_CHANNEL_NOPULSE 2001 + +#define LEN_SCRIPT_FILENAME 8 +#define LEN_SCRIPT_NAME 8 +#define MAX_SCRIPT_INPUTS 8 +#define MAX_SCRIPT_OUTPUTS 6 + +enum PotsWarnMode { + POTS_WARN_OFF, + POTS_WARN_MANUAL, + POTS_WARN_AUTO +}; + +#if !defined(PCBSTD) + #define LEN_GVAR_NAME 3 + #define GVAR_MAX 1024 + #define GVAR_MIN -GVAR_MAX +#endif + +#define RESERVE_RANGE_FOR_GVARS 10 +// even we do not spend space in EEPROM for 10 GVARS, we reserve the space inside the range of values, like offset, weight, etc. + +#if defined(PCBSTD) && defined(GVARS) + #define MAX_GVARS 5 +#elif defined(PCBSTD) + #define MAX_GVARS 0 +#else + #if defined(CPUARM) + #define MAX_GVARS 9 + #else + #define MAX_GVARS 5 + #endif +#endif + +#if defined(PCBTARANIS) + #define LEN_CFN_NAME 8 +#elif defined(CPUARM) + #define LEN_CFN_NAME 6 +#endif + +enum SwitchSources { + SWSRC_NONE = 0, + + SWSRC_FIRST_SWITCH, + +#if defined(PCBFLAMENCO) + SWSRC_SA0 = SWSRC_FIRST_SWITCH, + SWSRC_SA1, + SWSRC_SA2, + SWSRC_SB0, + SWSRC_SB2, + SWSRC_SC0, + SWSRC_SC1, + SWSRC_SC2, + SWSRC_SC3, + SWSRC_SC4, + SWSRC_SC5, + SWSRC_SE0, + SWSRC_SE2, + SWSRC_SF0, + SWSRC_SF1, + SWSRC_SF2, + SWSRC_LAST_SWITCH = SWSRC_SF2, +#elif defined(PCBTARANIS) || defined(PCBHORUS) + SWSRC_SA0 = SWSRC_FIRST_SWITCH, + SWSRC_SA1, + SWSRC_SA2, + SWSRC_SB0, + SWSRC_SB1, + SWSRC_SB2, + SWSRC_SC0, + SWSRC_SC1, + SWSRC_SC2, + SWSRC_SD0, + SWSRC_SD1, + SWSRC_SD2, + SWSRC_SE0, + SWSRC_SE1, + SWSRC_SE2, + SWSRC_SF0, + SWSRC_SF1, + SWSRC_SF2, + SWSRC_SG0, + SWSRC_SG1, + SWSRC_SG2, + SWSRC_SH0, + SWSRC_SH1, + SWSRC_SH2, + SWSRC_TRAINER = SWSRC_SH2, +#if defined(REV9E) + SWSRC_SI0, + SWSRC_SI1, + SWSRC_SI2, + SWSRC_SJ0, + SWSRC_SJ1, + SWSRC_SJ2, + SWSRC_SK0, + SWSRC_SK1, + SWSRC_SK2, + SWSRC_SL0, + SWSRC_SL1, + SWSRC_SL2, + SWSRC_SM0, + SWSRC_SM1, + SWSRC_SM2, + SWSRC_SN0, + SWSRC_SN1, + SWSRC_SN2, + SWSRC_SO0, + SWSRC_SO1, + SWSRC_SO2, + SWSRC_SP0, + SWSRC_SP1, + SWSRC_SP2, + SWSRC_SQ0, + SWSRC_SQ1, + SWSRC_SQ2, + SWSRC_SR0, + SWSRC_SR1, + SWSRC_SR2, + SWSRC_LAST_SWITCH = SWSRC_SR2, +#else + SWSRC_LAST_SWITCH = SWSRC_SH2, +#endif +#else + SWSRC_ID0 = SWSRC_FIRST_SWITCH, + SWSRC_ID1, + SWSRC_ID2, + SWSRC_THR, + SWSRC_RUD, + SWSRC_ELE, + SWSRC_AIL, + SWSRC_GEA, + SWSRC_TRN, + SWSRC_TRAINER = SWSRC_TRN, + SWSRC_LAST_SWITCH = SWSRC_TRN, +#endif + +#if NUM_XPOTS > 0 + SWSRC_FIRST_MULTIPOS_SWITCH, + SWSRC_LAST_MULTIPOS_SWITCH = SWSRC_FIRST_MULTIPOS_SWITCH + (NUM_XPOTS*XPOTS_MULTIPOS_COUNT) - 1, +#endif + + SWSRC_FIRST_TRIM, + SWSRC_TrimRudLeft = SWSRC_FIRST_TRIM, + SWSRC_TrimRudRight, + SWSRC_TrimEleDown, + SWSRC_TrimEleUp, + SWSRC_TrimThrDown, + SWSRC_TrimThrUp, + SWSRC_TrimAilLeft, + SWSRC_TrimAilRight, + SWSRC_LAST_TRIM = SWSRC_TrimAilRight, + +#if defined(PCBSKY9X) + SWSRC_REa, +#elif defined(CPUM2560) + SWSRC_REa, + SWSRC_REb, +#endif + + SWSRC_FIRST_LOGICAL_SWITCH, + SWSRC_SW1 = SWSRC_FIRST_LOGICAL_SWITCH, + SWSRC_SW2, + SWSRC_SW3, + SWSRC_SW4, + SWSRC_SW5, + SWSRC_SW6, + SWSRC_SW7, + SWSRC_SW8, + SWSRC_SW9, + SWSRC_SWA, + SWSRC_SWB, + SWSRC_SWC, + SWSRC_LAST_LOGICAL_SWITCH = SWSRC_FIRST_LOGICAL_SWITCH+NUM_LOGICAL_SWITCH-1, + + SWSRC_ON, + SWSRC_ONE, + +#if defined(CPUARM) + SWSRC_FIRST_FLIGHT_MODE, + SWSRC_LAST_FLIGHT_MODE = SWSRC_FIRST_FLIGHT_MODE+MAX_FLIGHT_MODES-1, + + SWSRC_TELEMETRY_STREAMING, + SWSRC_FIRST_SENSOR, + SWSRC_LAST_SENSOR = SWSRC_FIRST_SENSOR+MAX_SENSORS-1, +#endif + + SWSRC_COUNT, + + SWSRC_OFF = -SWSRC_ON, + + SWSRC_LAST = SWSRC_COUNT-1, + SWSRC_FIRST = -SWSRC_LAST, + +#if defined(CPUARM) + SWSRC_LAST_IN_LOGICAL_SWITCHES = SWSRC_COUNT-1, + SWSRC_LAST_IN_MIXES = SWSRC_COUNT-1, +#else + SWSRC_LAST_IN_LOGICAL_SWITCHES = SWSRC_LAST_LOGICAL_SWITCH, + SWSRC_LAST_IN_MIXES = SWSRC_LAST_LOGICAL_SWITCH, +#endif + + SWSRC_FIRST_IN_LOGICAL_SWITCHES = -SWSRC_LAST_IN_LOGICAL_SWITCHES, + SWSRC_FIRST_IN_MIXES = -SWSRC_LAST_IN_MIXES, + +#if defined(CPUARM) + SWSRC_INVERT = SWSRC_COUNT+1, +#endif +}; + +enum MixSources { + MIXSRC_NONE, + +#if defined(VIRTUALINPUTS) + MIXSRC_FIRST_INPUT, LUA_EXPORT_MULTIPLE("input", "Input [I%d]", MAX_INPUTS) + MIXSRC_LAST_INPUT = MIXSRC_FIRST_INPUT+MAX_INPUTS-1, + + MIXSRC_FIRST_LUA, + MIXSRC_LAST_LUA = MIXSRC_FIRST_LUA+(MAX_SCRIPTS*MAX_SCRIPT_OUTPUTS)-1, +#endif + + MIXSRC_FIRST_STICK, + MIXSRC_Rud = MIXSRC_FIRST_STICK, LUA_EXPORT("rud", "Rudder") + MIXSRC_Ele, LUA_EXPORT("ele", "Elevator") + MIXSRC_Thr, LUA_EXPORT("thr", "Throttle") + MIXSRC_Ail, LUA_EXPORT("ail", "Aileron") + + MIXSRC_FIRST_POT, +#if defined(PCBHORUS) + MIXSRC_S1 = MIXSRC_FIRST_POT, LUA_EXPORT("s1", "Potentiometer S1") + MIXSRC_6POS, LUA_EXPORT("6pos", "Multipos Switch") + MIXSRC_S2, LUA_EXPORT("s2", "Potentiometer S2") + MIXSRC_FIRST_SLIDER, + MIXSRC_S3 = MIXSRC_FIRST_SLIDER, LUA_EXPORT("s3", "Slider S3") + MIXSRC_S4, LUA_EXPORT("s4", "Slider S4") + MIXSRC_LS, LUA_EXPORT("ls", "Left rear slider") + MIXSRC_RS, LUA_EXPORT("rs", "Right rear slider") + MIXSRC_LAST_POT = MIXSRC_RS, +#elif defined(PCBFLAMENCO) + MIXSRC_POT1 = MIXSRC_FIRST_POT, LUA_EXPORT("sd", "Potentiometer D") + MIXSRC_SLIDER1, LUA_EXPORT("ls", "Left slider") + MIXSRC_SLIDER2, LUA_EXPORT("rs", "Right slider") + MIXSRC_LAST_POT = MIXSRC_SLIDER2, +#elif defined(PCBTARANIS) + MIXSRC_POT1 = MIXSRC_FIRST_POT, LUA_EXPORT("s1", "Potentiometer 1") + MIXSRC_POT2, LUA_EXPORT("s2", "Potentiometer 2") + MIXSRC_POT3, LUA_EXPORT("s3", "Potentiometer 3") + #if defined(REV9E) + MIXSRC_POT4, LUA_EXPORT("s4", "Potentiometer 4 (X9E only)") + #endif + MIXSRC_FIRST_SLIDER, + MIXSRC_SLIDER1 = MIXSRC_FIRST_SLIDER, LUA_EXPORT("ls", "Left slider") + MIXSRC_SLIDER2, LUA_EXPORT("rs", "Right slider") + #if defined(REV9E) + MIXSRC_SLIDER3, LUA_EXPORT("lcs", "Left center slider (X9E only)") + MIXSRC_SLIDER4, LUA_EXPORT("rcs", "Right center slider (X9E only)") + MIXSRC_LAST_POT = MIXSRC_SLIDER4, + #else + MIXSRC_LAST_POT = MIXSRC_SLIDER2, + #endif +#else + MIXSRC_P1 = MIXSRC_FIRST_POT, + MIXSRC_P2, + MIXSRC_P3, + MIXSRC_LAST_POT = MIXSRC_P3, +#endif + +#if defined(PCBSKY9X) + MIXSRC_REa, + MIXSRC_LAST_ROTARY_ENCODER = MIXSRC_REa, +#elif defined(CPUM2560) + MIXSRC_REa, + MIXSRC_REb, + #if ROTARY_ENCODERS > 2 + MIXSRC_REc, + MIXSRC_REd, + MIXSRC_LAST_ROTARY_ENCODER = MIXSRC_REd, + #else + MIXSRC_LAST_ROTARY_ENCODER = MIXSRC_REb, + #endif +#endif + + MIXSRC_MAX, + + MIXSRC_FIRST_HELI, + MIXSRC_CYC1 = MIXSRC_FIRST_HELI, LUA_EXPORT("cyc1", "Cyclic 1") + MIXSRC_CYC2, LUA_EXPORT("cyc2", "Cyclic 2") + MIXSRC_CYC3, LUA_EXPORT("cyc3", "Cyclic 3") + + MIXSRC_FIRST_TRIM, + MIXSRC_TrimRud = MIXSRC_FIRST_TRIM, LUA_EXPORT("trim-rud", "Rudder trim") + MIXSRC_TrimEle, LUA_EXPORT("trim-ele", "Elevator trim") + MIXSRC_TrimThr, LUA_EXPORT("trim-thr", "Throttle trim") + MIXSRC_TrimAil, LUA_EXPORT("trim-ail", "Aileron trim") + MIXSRC_LAST_TRIM = MIXSRC_TrimAil, + + MIXSRC_FIRST_SWITCH, + +#if defined(PCBFLAMENCO) + MIXSRC_SA = MIXSRC_FIRST_SWITCH, LUA_EXPORT("sa", "Switch A") + MIXSRC_SB, LUA_EXPORT("sb", "Switch B") + MIXSRC_SC, LUA_EXPORT("sc", "Switch C") + MIXSRC_SE, LUA_EXPORT("se", "Switch E") + MIXSRC_SF, LUA_EXPORT("sf", "Switch F") + MIXSRC_LAST_SWITCH = MIXSRC_SF, +#elif defined(PCBTARANIS) || defined(PCBHORUS) + MIXSRC_SA = MIXSRC_FIRST_SWITCH, LUA_EXPORT("sa", "Switch A") + MIXSRC_SB, LUA_EXPORT("sb", "Switch B") + MIXSRC_SC, LUA_EXPORT("sc", "Switch C") + MIXSRC_SD, LUA_EXPORT("sd", "Switch D") + MIXSRC_SE, LUA_EXPORT("se", "Switch E") + MIXSRC_SF, LUA_EXPORT("sf", "Switch F") + MIXSRC_SG, LUA_EXPORT("sg", "Switch G") + MIXSRC_SH, LUA_EXPORT("sh", "Switch H") +#if defined(REV9E) + MIXSRC_SI, LUA_EXPORT("si", "Switch I (X9E only)") + MIXSRC_SJ, LUA_EXPORT("sj", "Switch J (X9E only)") + MIXSRC_SK, LUA_EXPORT("sk", "Switch K (X9E only)") + MIXSRC_SL, LUA_EXPORT("sl", "Switch L (X9E only)") + MIXSRC_SM, LUA_EXPORT("sm", "Switch M (X9E only)") + MIXSRC_SN, LUA_EXPORT("sn", "Switch N (X9E only)") + MIXSRC_SO, LUA_EXPORT("so", "Switch O (X9E only)") + MIXSRC_SP, LUA_EXPORT("sp", "Switch P (X9E only)") + MIXSRC_SQ, LUA_EXPORT("sq", "Switch Q (X9E only)") + MIXSRC_SR, LUA_EXPORT("sr", "Switch R (X9E only)") + MIXSRC_LAST_SWITCH = MIXSRC_SR, +#else + MIXSRC_LAST_SWITCH = MIXSRC_SH, +#endif +#else + MIXSRC_3POS = MIXSRC_FIRST_SWITCH, + MIXSRC_THR, + MIXSRC_RUD, + MIXSRC_ELE, + MIXSRC_AIL, + MIXSRC_GEA, + MIXSRC_TRN, + MIXSRC_LAST_SWITCH = MIXSRC_TRN, +#endif + MIXSRC_FIRST_LOGICAL_SWITCH, + MIXSRC_SW1 = MIXSRC_FIRST_LOGICAL_SWITCH, LUA_EXPORT_MULTIPLE("ls", "Logical switch L%d", NUM_LOGICAL_SWITCH) + MIXSRC_SW9 = MIXSRC_SW1 + 8, + MIXSRC_SWA, + MIXSRC_SWB, + MIXSRC_SWC, + MIXSRC_LAST_LOGICAL_SWITCH = MIXSRC_FIRST_LOGICAL_SWITCH+NUM_LOGICAL_SWITCH-1, + + MIXSRC_FIRST_TRAINER, LUA_EXPORT_MULTIPLE("trn", "Trainer input %d", NUM_TRAINER) + MIXSRC_LAST_TRAINER = MIXSRC_FIRST_TRAINER+NUM_TRAINER-1, + + MIXSRC_FIRST_CH, + MIXSRC_CH1 = MIXSRC_FIRST_CH, LUA_EXPORT_MULTIPLE("ch", "Channel CH%d", NUM_CHNOUT) + MIXSRC_CH2, + MIXSRC_CH3, + MIXSRC_CH4, + MIXSRC_CH5, + MIXSRC_CH6, + MIXSRC_CH7, + MIXSRC_CH8, + MIXSRC_CH9, + MIXSRC_CH10, + MIXSRC_CH11, + MIXSRC_CH12, + MIXSRC_CH13, + MIXSRC_CH14, + MIXSRC_CH15, + MIXSRC_CH16, + MIXSRC_LAST_CH = MIXSRC_CH1+NUM_CHNOUT-1, + + MIXSRC_FIRST_GVAR, + MIXSRC_GVAR1 = MIXSRC_FIRST_GVAR, LUA_EXPORT_MULTIPLE("gvar", "Global variable %d", MAX_GVARS) + MIXSRC_LAST_GVAR = MIXSRC_FIRST_GVAR+MAX_GVARS-1, + +#if defined(CPUARM) + MIXSRC_TX_VOLTAGE, LUA_EXPORT("tx-voltage", "Transmitter battery voltage [volts]") + MIXSRC_TX_TIME, LUA_EXPORT("clock", "RTC clock [minutes from midnight]") + MIXSRC_RESERVE1, + MIXSRC_RESERVE2, + MIXSRC_RESERVE3, + MIXSRC_RESERVE4, + MIXSRC_RESERVE5, + MIXSRC_FIRST_TIMER, + MIXSRC_TIMER1 = MIXSRC_FIRST_TIMER, LUA_EXPORT("timer1", "Timer 1 value [seconds]") + MIXSRC_TIMER2, LUA_EXPORT("timer2", "Timer 2 value [seconds]") + MIXSRC_TIMER3, LUA_EXPORT("timer3", "Timer 3 value [seconds]") + MIXSRC_LAST_TIMER = MIXSRC_TIMER3, +#endif + + MIXSRC_FIRST_TELEM, +#if defined(CPUARM) + MIXSRC_LAST_TELEM = MIXSRC_FIRST_TELEM+3*MAX_SENSORS-1 +#else + MIXSRC_LAST_TELEM = MIXSRC_FIRST_TELEM+NUM_TELEMETRY-1 +#endif +}; + +#define MIXSRC_FIRST (MIXSRC_NONE+1) +#define MIXSRC_LAST MIXSRC_LAST_CH +#define INPUTSRC_FIRST MIXSRC_Rud +#define INPUTSRC_LAST MIXSRC_LAST_TELEM + +enum BacklightMode { + e_backlight_mode_off = 0, + e_backlight_mode_keys = 1, + e_backlight_mode_sticks = 2, + e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks, + e_backlight_mode_on +}; + +enum Functions { + // first the functions which need a checkbox + FUNC_OVERRIDE_CHANNEL, + FUNC_TRAINER, + FUNC_INSTANT_TRIM, + FUNC_RESET, +#if defined(CPUARM) + FUNC_SET_TIMER, +#endif + FUNC_ADJUST_GVAR, +#if defined(CPUARM) + FUNC_VOLUME, + FUNC_SET_FAILSAFE, + FUNC_RANGECHECK, + FUNC_BIND, +#endif + // then the other functions + FUNC_FIRST_WITHOUT_ENABLE, + FUNC_PLAY_SOUND = FUNC_FIRST_WITHOUT_ENABLE, + FUNC_PLAY_TRACK, +#if !defined(CPUARM) + FUNC_PLAY_BOTH, +#endif + FUNC_PLAY_VALUE, +#if defined(CPUARM) + FUNC_RESERVE4, + FUNC_PLAY_SCRIPT, + FUNC_RESERVE5, + FUNC_BACKGND_MUSIC, + FUNC_BACKGND_MUSIC_PAUSE, +#endif + FUNC_VARIO, + FUNC_HAPTIC, +#if !defined(PCBSTD) + FUNC_LOGS, +#endif + FUNC_BACKLIGHT, +#if defined(PCBTARANIS) + FUNC_SCREENSHOT, +#endif +#if defined(DEBUG) + FUNC_TEST, // should remain the last before MAX as not added in companion9x +#endif + FUNC_MAX +}; + +enum TimerModes { + TMRMODE_NONE, + TMRMODE_ABS, + TMRMODE_THR, + TMRMODE_THR_REL, + TMRMODE_THR_TRG, + TMRMODE_COUNT +}; + +enum CountDownModes { + COUNTDOWN_SILENT, + COUNTDOWN_BEEPS, + COUNTDOWN_VOICE, +#if defined(CPUARM) && defined(HAPTIC) + COUNTDOWN_HAPTIC, +#endif + COUNTDOWN_COUNT +}; + +enum ResetFunctionParam { + FUNC_RESET_TIMER1, + FUNC_RESET_TIMER2, +#if defined(CPUARM) + FUNC_RESET_TIMER3, +#endif + FUNC_RESET_FLIGHT, +#if defined(FRSKY) + FUNC_RESET_TELEMETRY, +#endif +#if ROTARY_ENCODERS > 0 + FUNC_RESET_ROTENC1, +#endif +#if ROTARY_ENCODERS > 1 + FUNC_RESET_ROTENC2, +#endif +#if defined(CPUARM) + FUNC_RESET_PARAM_FIRST_TELEM, + FUNC_RESET_PARAM_LAST_TELEM = FUNC_RESET_PARAM_FIRST_TELEM + MAX_SENSORS, +#endif + FUNC_RESET_PARAMS_COUNT, + FUNC_RESET_PARAM_LAST = FUNC_RESET_PARAMS_COUNT-1, +}; + +enum AdjustGvarFunctionParam { + FUNC_ADJUST_GVAR_CONSTANT, + FUNC_ADJUST_GVAR_SOURCE, + FUNC_ADJUST_GVAR_GVAR, + FUNC_ADJUST_GVAR_INCDEC, +}; + +#endif // _DATACONSTANTS_H_ diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h new file mode 100644 index 000000000..d30806d8b --- /dev/null +++ b/radio/src/datastructs.h @@ -0,0 +1,1005 @@ +/* + * 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. + */ + +// No include guards here, this file may be included many times in different namespaces +// i.e. BACKUP RAM Backup/Restore functions + +#include +#include "dataconstants.h" + +#if defined(CPUARM) + #define ARM_FIELD(x) x; + #define AVR_FIELD(x) +#else + #define ARM_FIELD(x) + #define AVR_FIELD(x) x; +#endif + +#if defined(PCBSTD) + #define N_PCBSTD_FIELD(x) +#else + #define N_PCBSTD_FIELD(x) x; +#endif + +#if defined(PCBTARANIS) + #define N_TARANIS_FIELD(x) + #define TARANIS_FIELD(x) x; +#else + #define N_TARANIS_FIELD(x) x; + #define TARANIS_FIELD(x) +#endif + +#if defined(PCBTARANIS) && defined(REV9E) + #define TARANIS_REV9E_FIELD(x) x; +#else + #define TARANIS_REV9E_FIELD(x) +#endif + +#if defined(BACKUP) + #define NOBACKUP(...) +#else + #define NOBACKUP(...) __VA_ARGS__ +#endif + +#if __GNUC__ + #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) +#else + #define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) ) +#endif + +#if defined(PCBTARANIS) || defined(PCBHORUS) +typedef uint16_t source_t; +#else +typedef uint8_t source_t; +#endif + +/* + * Mixer structure + */ + +#if defined(VIRTUALINPUTS) +PACK(struct CurveRef { + uint8_t type; + int8_t value; +}); + +PACK(struct MixData { + int16_t weight:11; // GV1=-1024, -GV1=1023 + uint16_t destCh:5; + uint16_t srcRaw:10; // srcRaw=0 means not used + uint16_t carryTrim:1; + uint16_t mixWarn:2; // mixer warning + uint16_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := + uint16_t spare:1; + int32_t offset:14; + int32_t swtch:9; + uint32_t flightModes:9; + CurveRef curve; + uint8_t delayUp; + uint8_t delayDown; + uint8_t speedUp; + uint8_t speedDown; + NOBACKUP(char name[LEN_EXPOMIX_NAME]); +}); +#elif defined(CPUARM) +PACK(struct MixData { + uint8_t destCh:5; + uint8_t mixWarn:3; // mixer warning + uint16_t flightModes:9; + uint16_t curveMode:1; + uint16_t noExpo:1; + int16_t carryTrim:3; + uint16_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := + int16_t weight; + int8_t swtch; + int8_t curveParam; + uint8_t delayUp; + uint8_t delayDown; + uint8_t speedUp; + uint8_t speedDown; + uint8_t srcRaw; + int16_t offset; + NOBACKUP(char name[LEN_EXPOMIX_NAME]); +}); +#elif defined(CPUM2560) || defined(CPUM2561) +PACK(struct MixData { + uint8_t destCh:4; // 0, 1..NUM_CHNOUT + uint8_t curveMode:1; // O=curve, 1=differential + uint8_t noExpo:1; + uint8_t weightMode:1; + uint8_t offsetMode:1; + uint8_t srcRaw; + int8_t weight; + int8_t swtch; + uint8_t flightModes; + uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := + int8_t carryTrim:3; + uint8_t mixWarn:2; // mixer warning + uint8_t spare:1; + uint8_t delayUp:4; + uint8_t delayDown:4; + uint8_t speedUp:4; + uint8_t speedDown:4; + int8_t curveParam; + int8_t offset; +}); +#else +PACK(struct MixData { + uint8_t destCh:4; // 0, 1..NUM_CHNOUT + uint8_t curveMode:1; // O=curve, 1=differential + uint8_t noExpo:1; + uint8_t weightMode:1; + uint8_t offsetMode:1; + int8_t weight; + int8_t swtch:6; + uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := + uint8_t flightModes:5; + int8_t carryTrim:3; + uint8_t srcRaw:6; + uint8_t mixWarn:2; // mixer warning + uint8_t delayUp:4; + uint8_t delayDown:4; + uint8_t speedUp:4; + uint8_t speedDown:4; + int8_t curveParam; + int8_t offset; +}); +#endif + +/* + * Expo/Input structure + */ + +#if defined(VIRTUALINPUTS) +PACK(struct ExpoData { + uint16_t mode:2; + uint16_t scale:14; + uint16_t srcRaw:10; + int16_t carryTrim:6; + uint32_t chn:5; + int32_t swtch:9; + uint32_t flightModes:9; + int32_t weight:8; + int32_t spare:1; + NOBACKUP(char name[LEN_EXPOMIX_NAME]); + int8_t offset; + CurveRef curve; +}); +#elif defined(CPUARM) +PACK(struct ExpoData { + uint16_t mode:2; // 0=end, 1=pos, 2=neg, 3=both + uint16_t chn:3; + uint16_t curveMode:2; + uint16_t flightModes:9; + int8_t swtch; + int8_t weight; + NOBACKUP(char name[LEN_EXPOMIX_NAME]); + int8_t curveParam; +}); +#elif defined(CPUM2560) || defined(CPUM2561) +PACK(struct ExpoData { + uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both + uint8_t chn:2; + uint8_t curveMode:1; + uint8_t spare:3; + uint8_t flightModes; + int8_t swtch; + uint8_t weight; + int8_t curveParam; +}); +#else +PACK(struct ExpoData { + uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both + int8_t swtch:6; + uint8_t chn:2; + uint8_t flightModes:5; + uint8_t curveMode:1; + uint8_t weight; // One spare bit here (used for GVARS) + int8_t curveParam; +}); +#endif + +/* + * Limit structure + */ + +#if defined(VIRTUALINPUTS) +PACK(struct LimitData { + int32_t min:11; + int32_t max:11; + int32_t ppmCenter:10; + int16_t offset:11; + uint16_t symetrical:1; + uint16_t revert:1; + uint16_t spare:3; + int8_t curve; + NOBACKUP(char name[LEN_CHANNEL_NAME]); +}); +#else +PACK(struct LimitData { + int8_t min; + int8_t max; + int8_t ppmCenter; + int16_t offset:14; + uint16_t symetrical:1; + uint16_t revert:1; +}); +#endif + +/* + * LogicalSwitch structure + */ + +#if defined(CPUARM) +PACK(struct LogicalSwitchData { + uint8_t func; + int32_t v1:10; + int32_t v3:10; + int32_t andsw:9; // TODO rename to xswtch + uint32_t andswtype:1; // TODO rename to xswtchType (AND / OR) + uint32_t spare:2; // anything else needed? + int16_t v2; + uint8_t delay; + uint8_t duration; +}); +#else +PACK(struct LogicalSwitchData { + int8_t v1; //input + int8_t v2; //offset + uint8_t func:4; + uint8_t andsw:4; +}); +#endif + +/* + * SpecialFunction structure + */ + +#if defined(CPUARM) + +#if defined(PCBTARANIS) + #define CFN_SPARE_TYPE int32_t +#else + #define CFN_SPARE_TYPE int16_t +#endif + +PACK(struct CustomFunctionData { + int16_t swtch:9; + uint16_t func:7; + PACK(union { + NOBACKUP(PACK(struct { + char name[LEN_CFN_NAME]; + }) play); + + PACK(struct { + int16_t val; + uint8_t mode; + uint8_t param; + NOBACKUP(CFN_SPARE_TYPE spare); + }) all; + + PACK(struct { + int32_t val1; + NOBACKUP(CFN_SPARE_TYPE val2); + }) clear; + }); + uint8_t active; +}); +#elif defined(CPUM2560) +PACK(struct CustomFunctionData { + int8_t swtch; + uint8_t func; + uint8_t mode:2; + uint8_t param:4; + uint8_t active:1; + uint8_t spare:1; + uint8_t value; +}); +#else +PACK(struct CustomFunctionData { + PACK(union { + PACK(struct { + int16_t swtch:6; + uint16_t func:4; + uint16_t mode:2; + uint16_t param:3; + uint16_t active:1; + }) gvar; + + PACK(struct { + int16_t swtch:6; + uint16_t func:4; + uint16_t param:4; + uint16_t spare:1; + uint16_t active:1; + }) all; + }); + uint8_t value; +}); +#endif + +/* + * FlightMode structure + */ + + #if defined(VIRTUALINPUTS) + PACK(struct trim_t { + int16_t value:11; + uint16_t mode:5; + }); + #else + typedef int16_t trim_t; + #endif + +typedef int16_t gvar_t; + +#if defined(CPUARM) +PACK(struct FlightModeData { + trim_t trim[4]; + NOBACKUP(char name[LEN_FLIGHT_MODE_NAME]); + int16_t swtch:9; // swtch of phase[0] is not used + int16_t spare:7; + uint8_t fadeIn; + uint8_t fadeOut; + int16_t rotaryEncoders[MAX_ROTARY_ENCODERS]; + gvar_t gvars[MAX_GVARS]; +}); +#elif !defined(PCBSTD) +PACK(struct FlightModeData { + trim_t trim[4]; + int8_t swtch; // swtch of phase[0] is not used + NOBACKUP(char name[LEN_FLIGHT_MODE_NAME]); + uint8_t fadeIn:4; + uint8_t fadeOut:4; + int16_t rotaryEncoders[MAX_ROTARY_ENCODERS]; + gvar_t gvars[MAX_GVARS]; +}); +#else +PACK(struct FlightModeData { + int8_t trim[4]; + int8_t trim_ext; // 2 extra bits per trim (10bits) + int8_t swtch; // swtch of phase[0] is not used + NOBACKUP(char name[LEN_FLIGHT_MODE_NAME]); + uint8_t fadeIn:4; + uint8_t fadeOut:4; +}); +#endif + +/* + * Curve structure + */ + +#if defined(XCURVES) +PACK(struct CurveData { + uint8_t type:1; + uint8_t smooth:1; + int8_t points:6; // TODO conversion + NOBACKUP(char name[LEN_CURVE_NAME]); +}); +#elif defined(CPUARM) +typedef int16_t CurveData; +#else +typedef int8_t CurveData; +#endif + +/* + * GVar structure + */ + +#if !defined(PCBSTD) +PACK(struct GVarData { + NOBACKUP(char name[LEN_GVAR_NAME]); + uint32_t min:12; + uint32_t max:12; + uint32_t popup:1; + uint32_t prec:1; + uint32_t unit:2; + uint32_t spare:4; +}); +#endif + +/* + * Timer structure + */ + +#if defined(CPUARM) +PACK(struct TimerData { + int32_t mode:9; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw + uint32_t start:23; + int32_t value:24; + uint32_t countdownBeep:2; + uint32_t minuteBeep:1; + uint32_t persistent:2; + uint32_t spare:3; + NOBACKUP(char name[LEN_TIMER_NAME]); +}); +#elif defined(CPUM2560) +PACK(struct TimerData { + int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw + uint16_t start; + uint8_t countdownBeep:2; + uint8_t minuteBeep:1; + uint8_t persistent:2; + uint8_t spare:3; + uint16_t value; +}); +#else +PACK(struct TimerData { + int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw + uint16_t start:12; + uint16_t countdownBeep:1; + uint16_t minuteBeep:1; + uint16_t spare:2; +}); +#endif + +/* + * Swash Ring structure + */ + +#if defined(VIRTUALINPUTS) +PACK(struct SwashRingData { + uint8_t type; + uint8_t value; + uint8_t collectiveSource; + uint8_t aileronSource; + uint8_t elevatorSource; + int8_t collectiveWeight; + int8_t aileronWeight; + int8_t elevatorWeight; +}); +#else +PACK(struct SwashRingData { + uint8_t invertELE:1; + uint8_t invertAIL:1; + uint8_t invertCOL:1; + uint8_t type:5; + uint8_t collectiveSource; + uint8_t value; +}); +#endif + +#if MAX_SCRIPTS > 0 +PACK(struct ScriptData { + char file[LEN_SCRIPT_FILENAME]; + char name[LEN_SCRIPT_NAME]; + int8_t inputs[MAX_SCRIPT_INPUTS]; +}); +#endif + +/* + * Frsky Telemetry structure + */ + +PACK(struct FrSkyRSSIAlarm { + int8_t level:2; + int8_t value:6; +}); + +#if defined(CPUARM) +typedef int16_t ls_telemetry_value_t; +#else +typedef uint8_t ls_telemetry_value_t; +#endif + +#if !defined(COLORLCD) +PACK(struct FrSkyBarData { + source_t source; + ls_telemetry_value_t barMin; // minimum for bar display + ls_telemetry_value_t barMax; // ditto for max display (would usually = ratio) +}); + +PACK(struct FrSkyLineData { + source_t sources[NUM_LINE_ITEMS]; +}); + +#if defined(PCBTARANIS) +PACK(struct TelemetryScriptData { + char file[LEN_SCRIPT_FILENAME]; + int16_t inputs[MAX_TELEM_SCRIPT_INPUTS]; +}); +#endif + +union FrSkyScreenData { + FrSkyBarData bars[4]; + FrSkyLineData lines[4]; +#if defined(PCBTARANIS) + TelemetryScriptData script; +#endif +}; +#endif + +#if defined(COLORLCD) +PACK(struct FrSkyTelemetryData { + uint8_t varioSource:7; + uint8_t varioCenterSilent:1; + int8_t varioCenterMax; + int8_t varioCenterMin; + int8_t varioMin; + int8_t varioMax; + FrSkyRSSIAlarm rssiAlarms[2]; +}); +#elif defined(CPUARM) +PACK(struct FrSkyChannelData { + uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. + int16_t offset:12; + uint16_t type:4; // channel unit (0=volts, ...) + uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. + uint8_t alarms_level:4; + uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) + uint8_t spare:2; + uint8_t multiplier; // 0=no multiplier, 1=*2 multiplier +}); + +PACK(struct FrSkyTelemetryData { + uint8_t voltsSource; + uint8_t altitudeSource; + uint8_t screensType; // 2bits per screen (None/Gauges/Numbers/Script) + FrSkyScreenData screens[MAX_TELEMETRY_SCREENS]; + uint8_t varioSource:7; + uint8_t varioCenterSilent:1; + int8_t varioCenterMax; + int8_t varioCenterMin; + int8_t varioMin; + int8_t varioMax; + FrSkyRSSIAlarm rssiAlarms[2]; +}); +#else +PACK(struct FrSkyChannelData { + uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. + int16_t offset:12; + uint16_t type:4; // channel unit (0=volts, ...) + uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. + uint8_t alarms_level:4; + uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) + uint8_t multiplier:2; // 0=no multiplier, 1=*2 multiplier +}); + +PACK(struct FrSkyTelemetryData { + FrSkyChannelData channels[MAX_FRSKY_A_CHANNELS]; + uint8_t usrProto:2; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh, 3=Halcyon + uint8_t blades:2; // How many blades for RPMs, 0=2 blades + uint8_t screensType:2; + uint8_t voltsSource:2; + int8_t varioMin:4; + int8_t varioMax:4; + FrSkyRSSIAlarm rssiAlarms[2]; + FrSkyScreenData screens[MAX_TELEMETRY_SCREENS]; + uint8_t varioSource:3; + int8_t varioCenterMin:5; + uint8_t currentSource:3; + int8_t varioCenterMax:5; + int8_t fasOffset; +}); +#endif + +/* + * MAVLINK Telemetry structure + */ + +#if defined(MAVLINK) +PACK(struct MavlinkTelemetryData { + uint8_t rc_rssi_scale:4; + uint8_t pc_rssi_en:1; + uint8_t spare1:3; + uint8_t spare2[3]; +}); +#endif + +/* + * Telemetry Sensor structure + */ + +#if defined(CPUARM) +// TODO struct as others +PACK(class TelemetrySensor { + public: + union { + uint16_t id; // data identifier, for FrSky we can reuse existing ones. Source unit is derived from type. + uint16_t persistentValue; + }; + union { + uint8_t instance; // instance ID to allow handling multiple instances of same value type, for FrSky can be the physical ID of the sensor + uint8_t formula; + }; + char label[TELEM_LABEL_LEN]; // user defined label + uint8_t type:1; // 0=custom / 1=calculated + uint8_t unit:5; // user can choose what unit to display each value in + uint8_t prec:2; + uint8_t autoOffset:1; + uint8_t filter:1; + uint8_t logs:1; + uint8_t persistent:1; + uint8_t onlyPositive:1; + uint8_t subId:3; + union { + PACK(struct { + uint16_t ratio; + int16_t offset; + }) custom; + PACK(struct { + uint8_t source; + uint8_t index; + uint16_t spare; + }) cell; + PACK(struct { + int8_t sources[4]; + }) calc; + PACK(struct { + uint8_t source; + uint8_t spare[3]; + }) consumption; + PACK(struct { + uint8_t gps; + uint8_t alt; + uint16_t spare; + }) dist; + uint32_t param; + }; + NOBACKUP( + void init(const char *label, uint8_t unit=UNIT_RAW, uint8_t prec=0); + void init(uint16_t id); + bool isAvailable() const; + int32_t getValue(int32_t value, uint8_t unit, uint8_t prec) const; + bool isConfigurable() const; + bool isPrecConfigurable() const; + int32_t getPrecMultiplier() const; + int32_t getPrecDivisor() const); +}); +#endif + +/* + * Module structure + */ + +PACK(struct ModuleData { + uint8_t type:4; + int8_t rfProtocol:4; + uint8_t channelsStart; + int8_t channelsCount; // 0=8 channels + uint8_t failsafeMode:7; + uint8_t invertedSerial:1; // telemetry serial inverted from standard + int16_t failsafeChannels[NUM_CHNOUT]; + int8_t ppmDelay:6; + uint8_t ppmPulsePol:1; + uint8_t ppmOutputType:1; // false = open drain, true = push pull + int8_t ppmFrameLength; +}); + +/* + * Model structure + */ + +#if defined(CPUARM) || defined(CPUM2560) +typedef uint16_t BeepANACenter; +#else +typedef uint8_t BeepANACenter; +#endif + +PACK(struct ModelHeader { + char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName + uint8_t modelId[NUM_MODULES]; +#if LEN_BITMAP_NAME > 0 + NOBACKUP(char bitmap[LEN_BITMAP_NAME]); +#endif +}); + +#if defined(COLORLCD) +typedef uint16_t swconfig_t; +typedef uint32_t swarnstate_t; +#elif defined(PCBTARANIS) && defined(REV9E) +typedef uint64_t swconfig_t; +typedef uint64_t swarnstate_t; +typedef uint32_t swarnenable_t; +#elif defined(PCBTARANIS) +typedef uint16_t swconfig_t; +typedef uint16_t swarnstate_t; +typedef uint8_t swarnenable_t; +#else +typedef uint8_t swarnstate_t; +typedef uint8_t swarnenable_t; +#endif + +#if defined(COLORLCD) + #define SWITCHES_WARNING_DATA \ + NOBACKUP(swarnstate_t switchWarningState); +#else + #define SWITCHES_WARNING_DATA \ + swarnstate_t switchWarningState; \ + swarnenable_t switchWarningEnable; +#endif + +#if defined(PCBSTD) && defined(GVARS) + #define MODEL_GVARS_DATA gvar_t gvars[MAX_GVARS]; +#elif defined(PCBSTD) + #define MODEL_GVARS_DATA +#else + #define MODEL_GVARS_DATA GVarData gvars[MAX_GVARS]; +#endif + +#if defined(MAVLINK) + #define TELEMETRY_DATA MavlinkTelemetryData mavlink; +#elif defined(FRSKY) || !defined(PCBSTD) + #define TELEMETRY_DATA NOBACKUP(FrSkyTelemetryData frsky); +#else + #define TELEMETRY_DATA +#endif + +#if defined(PCBHORUS) +#include "layout.h" +#include "topbar.h" +PACK(struct CustomScreenData { + char layoutName[10]; + Layout::PersistentData layoutData; +}); +#define CUSTOM_SCREENS_DATA \ + NOBACKUP(CustomScreenData screenData[MAX_CUSTOM_SCREENS]); \ + NOBACKUP(Topbar::PersistentData topbarData); +#else +#define CUSTOM_SCREENS_DATA +// TODO other boards could have their custom screens here as well +#endif + +#if defined(PCBHORUS) + #define MODELDATA_EXTRA NOBACKUP(uint8_t spare:3); NOBACKUP(uint8_t trainerMode:3); NOBACKUP(uint8_t potsWarnMode:2); ModuleData moduleData[NUM_MODULES+1]; NOBACKUP(ScriptData scriptsData[MAX_SCRIPTS]); NOBACKUP(char inputNames[MAX_INPUTS][LEN_INPUT_NAME]); NOBACKUP(uint8_t potsWarnEnabled); NOBACKUP(int8_t potsWarnPosition[NUM_POTS]); +#elif defined(PCBFLAMENCO) + #define MODELDATA_EXTRA uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; +#elif defined(PCBTARANIS) + #define MODELDATA_EXTRA uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; +#elif defined(PCBSKY9X) + #define MODELDATA_EXTRA uint8_t spare:6; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; uint8_t rxBattAlarms[2]; +#else + #define MODELDATA_EXTRA +#endif + +PACK(struct ModelData { + ModelHeader header; + TimerData timers[MAX_TIMERS]; + AVR_FIELD(uint8_t protocol:3) + ARM_FIELD(uint8_t telemetryProtocol:3) + uint8_t thrTrim:1; // Enable Throttle Trim + AVR_FIELD(int8_t ppmNCH:4) + ARM_FIELD(uint8_t noGlobalFunctions:1) + ARM_FIELD(uint8_t displayTrims:2) + ARM_FIELD(uint8_t ignoreSensorIds:1) + int8_t trimInc:3; // Trim Increments + uint8_t disableThrottleWarning:1; + ARM_FIELD(uint8_t displayChecklist:1) + AVR_FIELD(uint8_t pulsePol:1) + uint8_t extendedLimits:1; + uint8_t extendedTrims:1; + uint8_t throttleReversed:1; + AVR_FIELD(int8_t ppmDelay) + BeepANACenter beepANACenter; + MixData mixData[MAX_MIXERS]; + LimitData limitData[NUM_CHNOUT]; + ExpoData expoData[MAX_EXPOS]; + + CurveData curves[MAX_CURVES]; + int8_t points[NUM_POINTS]; + + LogicalSwitchData logicalSw[NUM_LOGICAL_SWITCH]; + CustomFunctionData customFn[NUM_CFN]; + SwashRingData swashR; + FlightModeData flightModeData[MAX_FLIGHT_MODES]; + + AVR_FIELD(int8_t ppmFrameLength) // 0=22.5ms (10ms-30ms) 0.5ms increments + + NOBACKUP(uint8_t thrTraceSrc); + + SWITCHES_WARNING_DATA + + MODEL_GVARS_DATA + + TELEMETRY_DATA + + MODELDATA_EXTRA + + ARM_FIELD(NOBACKUP(TelemetrySensor telemetrySensors[MAX_SENSORS])) + + TARANIS_REV9E_FIELD(uint8_t toplcdTimer) + + CUSTOM_SCREENS_DATA + +}); + +/* + * Radio structure + */ + +#if XPOTS_MULTIPOS_COUNT > 0 +PACK(struct StepsCalibData { + uint8_t count; + uint8_t steps[XPOTS_MULTIPOS_COUNT-1]; +}); +#endif + +PACK(struct CalibData { + int16_t mid; + int16_t spanNeg; + int16_t spanPos; +}); + +PACK(struct TrainerMix { + uint8_t srcChn:6; // 0-7 = ch1-8 + uint8_t mode:2; // off,add-mode,subst-mode + int8_t studWeight; +}); + +PACK(struct TrainerData { + int16_t calib[4]; + NOBACKUP(TrainerMix mix[4]); +}); + +#if defined(PCBHORUS) + #define SPLASH_MODE +#elif defined(FSPLASH) + #define SPLASH_MODE uint8_t splashMode:3 +#elif defined(PCBTARANIS) + #define SPLASH_MODE int8_t splashMode:3 +#else + #define SPLASH_MODE uint8_t splashMode:1; uint8_t splashSpare:2 +#endif + +#if defined(CPUARM) + #define EXTRA_GENERAL_FIELDS_ARM \ + NOBACKUP(uint8_t backlightBright); \ + /* TODO remove */ NOBACKUP(int8_t txCurrentCalibration); \ + /* TODO remove */ NOBACKUP(int8_t temperatureWarn); \ + /* TODO remove */ NOBACKUP(uint8_t mAhWarn); \ + /* TODO remove */ NOBACKUP(uint16_t mAhUsed); \ + NOBACKUP(uint32_t globalTimer); \ + /* TODO remove */ NOBACKUP(int8_t temperatureCalib); \ + NOBACKUP(uint8_t btBaudrate); \ + /* TODO remove */ NOBACKUP(uint8_t optrexDisplay); \ + /* TODO remove */ uint8_t sticksGain; \ + /* TODO remove */ NOBACKUP(uint8_t rotarySteps); \ + NOBACKUP(uint8_t countryCode); \ + NOBACKUP(uint8_t imperial); \ + NOBACKUP(char ttsLanguage[2]); \ + NOBACKUP(int8_t beepVolume:4); \ + NOBACKUP(int8_t wavVolume:4); \ + NOBACKUP(int8_t varioVolume:4); \ + NOBACKUP(int8_t backgroundVolume:4); \ + NOBACKUP(int8_t varioPitch); \ + NOBACKUP(int8_t varioRange); \ + NOBACKUP(int8_t varioRepeat); +#endif + +#if defined(PCBHORUS) + #define EXTRA_GENERAL_FIELDS \ + EXTRA_GENERAL_FIELDS_ARM \ + NOBACKUP(uint8_t serial2Mode:6); \ + uint8_t slidersConfig:2; \ + CustomFunctionData customFn[NUM_CFN]; \ + uint32_t switchConfig; \ + uint8_t potsConfig; /* two bits per pot */ \ + NOBACKUP(char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]); \ + NOBACKUP(char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]); \ + NOBACKUP(char currModelFilename[LEN_MODEL_FILENAME+1]); \ + NOBACKUP(uint8_t bluetoothEnable); \ + NOBACKUP(char bluetoothName[LEN_BLUETOOTH_NAME]); +#elif defined(PCBFLAMENCO) + #define EXTRA_GENERAL_FIELDS \ + EXTRA_GENERAL_FIELDS_ARM \ + uint8_t serial2Mode:6; \ + uint8_t spare:2; \ + CustomFunctionData customFn[NUM_CFN]; \ + uint32_t switchConfig; \ + uint8_t potsType; /*two bits for every pot*/\ + char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ + char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; +#elif defined(PCBTARANIS) + #if defined(REV9E) + #define BLUETOOTH_FIELDS \ + uint8_t bluetoothEnable; \ + char bluetoothName[LEN_BLUETOOTH_NAME]; + #else + #define BLUETOOTH_FIELDS + #endif + #define EXTRA_GENERAL_FIELDS \ + EXTRA_GENERAL_FIELDS_ARM \ + uint8_t serial2Mode:6; \ + uint8_t slidersConfig:2; \ + uint8_t potsConfig; /* two bits per pot */\ + uint8_t backlightColor; \ + swarnstate_t switchUnlockStates; \ + CustomFunctionData customFn[NUM_CFN]; \ + swconfig_t switchConfig; \ + char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ + char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; \ + BLUETOOTH_FIELDS +#elif defined(CPUARM) + #define EXTRA_GENERAL_FIELDS \ + EXTRA_GENERAL_FIELDS_ARM \ + CustomFunctionData customFn[NUM_CFN]; +#elif defined(PXX) + #define EXTRA_GENERAL_FIELDS uint8_t countryCode; +#else + #define EXTRA_GENERAL_FIELDS +#endif + +#if defined(COLORLCD) + #include "theme.h" + #define THEME_DATA \ + NOBACKUP(char themeName[8]); \ + NOBACKUP(Theme::PersistentData themeData); +#else + #define THEME_DATA +#endif + +PACK(struct RadioData { + NOBACKUP(uint8_t version); + NOBACKUP(uint16_t variant); + CalibData calib[NUM_STICKS+NUM_POTS]; + NOBACKUP(uint16_t chkSum); + /* TODO not horus */ NOBACKUP(int8_t currModel); + NOBACKUP(uint8_t contrast); + NOBACKUP(uint8_t vBatWarn); + NOBACKUP(int8_t txVoltageCalibration); + NOBACKUP(int8_t backlightMode); + NOBACKUP(TrainerData trainer); + NOBACKUP(uint8_t view); // index of view in main screen + NOBACKUP(int8_t buzzerMode:2); // -2=quiet, -1=only alarms, 0=no keys, 1=all + NOBACKUP(uint8_t fai:1); + NOBACKUP(int8_t beepMode:2); // -2=quiet, -1=only alarms, 0=no keys, 1=all + NOBACKUP(uint8_t alarmsFlash:1); + NOBACKUP(uint8_t disableMemoryWarning:1); + NOBACKUP(uint8_t disableAlarmWarning:1); + uint8_t stickMode:2; + NOBACKUP(int8_t timezone:5); + NOBACKUP(uint8_t adjustRTC:1); + NOBACKUP(uint8_t inactivityTimer); + NOBACKUP(uint8_t mavbaud:3); + SPLASH_MODE; /* 3bits */ + NOBACKUP(int8_t hapticMode:2); // -2=quiet, -1=only alarms, 0=no keys, 1=all + AVR_FIELD(uint8_t blOffBright:4) + AVR_FIELD(uint8_t blOnBright:4) + ARM_FIELD(int8_t switchesDelay) + NOBACKUP(uint8_t lightAutoOff); + NOBACKUP(uint8_t templateSetup); // RETA order for receiver channels + NOBACKUP(int8_t PPM_Multiplier); + NOBACKUP(int8_t hapticLength); + /* TODO remove */ N_PCBSTD_FIELD(uint8_t reNavigation) + /* TODO not on horus */ N_TARANIS_FIELD(uint8_t stickReverse) + NOBACKUP(int8_t beepLength:3); + NOBACKUP(int8_t hapticStrength:3); + NOBACKUP(uint8_t gpsFormat:1); + NOBACKUP(uint8_t unexpectedShutdown:1); + NOBACKUP(uint8_t speakerPitch); + NOBACKUP(int8_t speakerVolume); + NOBACKUP(int8_t vBatMin); + NOBACKUP(int8_t vBatMax); + + EXTRA_GENERAL_FIELDS + + THEME_DATA + +}); + +#undef SWITCHES_WARNING_DATA +#undef MODEL_GVARS_DATA +#undef TELEMETRY_DATA +#undef MODELDATA_EXTRA +#undef CUSTOM_SCREENS_DATA +#undef SPLASH_MODE +#undef EXTRA_GENERAL_FIELDS +#undef THEME_DATA +#undef NOBACKUP diff --git a/radio/src/dump.cpp b/radio/src/dump.cpp index 90c54b495..c189444db 100644 --- a/radio/src/dump.cpp +++ b/radio/src/dump.cpp @@ -50,9 +50,11 @@ void dumpEnd() dumpPrintf("\r\n"); } -void dump(const uint8_t *data, unsigned int size) +#if defined(DEBUG) || defined(CLI) +void dump(const uint8_t * data, unsigned int size) { dumpStart(size); dumpBody(data, size); dumpEnd(); } +#endif diff --git a/radio/src/gui/9x/lcd.h b/radio/src/gui/9x/lcd.h index fbb973f3e..bc485c94f 100644 --- a/radio/src/gui/9x/lcd.h +++ b/radio/src/gui/9x/lcd.h @@ -21,6 +21,8 @@ #ifndef _LCD_H_ #define _LCD_H_ +#include + #define LCD_W 128 #define LCD_H 64 #define BOX_WIDTH 23 diff --git a/radio/src/gui/9x/view_mavlink.cpp b/radio/src/gui/9x/view_mavlink.cpp index 21261b747..7a5af41d1 100644 --- a/radio/src/gui/9x/view_mavlink.cpp +++ b/radio/src/gui/9x/view_mavlink.cpp @@ -26,7 +26,9 @@ #include "view_mavlink.h" #define VIEW_MAVLINK_2ND_COLUMN (LCD_W-6*FW-3-MENUS_SCROLLBAR_WIDTH) - + +uint8_t MAVLINK_menu = MENU_INFO; + /*! \brief Top Mavlink Menu definition * \details Registers button events and handles that info. Buttons select menus, * these are launched from the MAVLINK_menu switch statement. Setup menu is diff --git a/radio/src/gui/9x/view_mavlink.h b/radio/src/gui/9x/view_mavlink.h index ff4e511ca..19d15bb69 100644 --- a/radio/src/gui/9x/view_mavlink.h +++ b/radio/src/gui/9x/view_mavlink.h @@ -25,7 +25,6 @@ #ifndef _VIEW_MAVLINK_H_ #define _VIEW_MAVLINK_H_ -#include "menus.h" #include "opentx.h" #include "telemetry/mavlink.h" #include "targets/common_avr/serial_driver.h" @@ -76,6 +75,6 @@ enum menuMavlinkSetupItems { }; //! \brief Menu index varible, initialized on info menu. -uint8_t MAVLINK_menu = MENU_INFO; +extern uint8_t MAVLINK_menu; #endif // _VIEW_MAVLINK_H_ diff --git a/radio/src/gui/horus/bitmapbuffer.h b/radio/src/gui/horus/bitmapbuffer.h index a24d839a7..430e44b72 100644 --- a/radio/src/gui/horus/bitmapbuffer.h +++ b/radio/src/gui/horus/bitmapbuffer.h @@ -178,7 +178,7 @@ class BitmapBuffer: public BitmapBufferBase void drawFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags); - void drawSizedText(coord_t x, coord_t y, const pm_char * s, uint8_t len, LcdFlags flags); + void drawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags flags); template void drawBitmap(coord_t x, coord_t y, const T * bmp, coord_t srcx=0, coord_t srcy=0, coord_t w=0, coord_t h=0, float scale=0) diff --git a/radio/src/gui/horus/theme.h b/radio/src/gui/horus/theme.h index 78e82c763..04251836c 100644 --- a/radio/src/gui/horus/theme.h +++ b/radio/src/gui/horus/theme.h @@ -21,7 +21,7 @@ #ifndef _THEME_H_ #define _THEME_H_ -#include "bitmapbuffer.h" +class BitmapBuffer; #define MAX_THEME_OPTIONS 5 diff --git a/radio/src/gui/horus/widgets_container.h b/radio/src/gui/horus/widgets_container.h index 837cb303f..ca274df94 100644 --- a/radio/src/gui/horus/widgets_container.h +++ b/radio/src/gui/horus/widgets_container.h @@ -21,6 +21,7 @@ #ifndef _WIDGETS_CONTAINER_H_ #define _WIDGETS_CONTAINER_H_ +#include #include "widget.h" class WidgetsContainerInterface diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index d4bf4aa5b..237dce88e 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -364,6 +364,7 @@ bool luaLoadFunctionScript(uint8_t index) return true; } +#if defined(PCBTARANIS) bool luaLoadTelemetryScript(uint8_t index) { TelemetryScreenType screenType = TELEMETRY_SCREEN_TYPE(index); @@ -391,6 +392,7 @@ bool luaLoadTelemetryScript(uint8_t index) } return true; } +#endif uint8_t isTelemetryScriptAvailable(uint8_t index) { @@ -423,12 +425,14 @@ void luaLoadPermanentScripts() } } +#if defined(PCBTARANIS) // Load custom telemetry scripts for (int i=0; ioutputsCount : 0, 0) == 0) { diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index ec1cb8431..64c150879 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -21,17 +21,7 @@ #ifndef _MYEEPROM_H_ #define _MYEEPROM_H_ -#include - -#if defined(EXPORT) - #define LUA_EXPORT(...) LEXP(__VA_ARGS__) - #define LUA_EXPORT_MULTIPLE(...) LEXP_MULTIPLE(__VA_ARGS__) - #define LUA_EXPORT_EXTRA(...) LEXP_EXTRA(__VA_ARGS__) -#else - #define LUA_EXPORT(...) - #define LUA_EXPORT_MULTIPLE(...) - #define LUA_EXPORT_EXTRA(...) -#endif +#include "datastructs.h" #define WARN_THR_BIT 0x01 #define WARN_BEP_BIT 0x80 @@ -57,470 +47,14 @@ #define EEPROM_VER 216 #endif -#ifndef PACK -#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) -#endif - -#if defined(CPUARM) - #define ARM_FIELD(x) x; - #define AVR_FIELD(x) -#else - #define ARM_FIELD(x) - #define AVR_FIELD(x) x; -#endif - #if defined(PCBSTD) - #define N_PCBSTD_FIELD(x) -#else - #define N_PCBSTD_FIELD(x) x; -#endif - -#if defined(PCBTARANIS) - #define N_TARANIS_FIELD(x) - #define TARANIS_FIELD(x) x; -#else - #define N_TARANIS_FIELD(x) x; - #define TARANIS_FIELD(x) -#endif - -#if defined(PCBTARANIS) && defined(REV9E) - #define TARANIS_REV9E_FIELD(x) x; -#else - #define TARANIS_REV9E_FIELD(x) -#endif - -#define NUM_STICKS 4 - -#if defined(PCBHORUS) - #define MAX_MODELS 60 - #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 - #define MAX_FLIGHT_MODES 9 - #define MAX_MIXERS 64 - #define MAX_EXPOS 64 - #define NUM_LOGICAL_SWITCH 64 // number of custom switches - #define NUM_CFN 64 // number of functions assigned to switches - #define MAX_SCRIPTS 9 - #define MAX_INPUTS 32 - #define NUM_TRAINER 16 - #define NUM_POTS 7 - #define NUM_XPOTS 3 - #define MAX_SENSORS 32 - #define MAX_CUSTOM_SCREENS 5 -#elif defined(PCBFLAMENCO) - #define MAX_MODELS 60 - #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 - #define MAX_FLIGHT_MODES 9 - #define MAX_MIXERS 64 - #define MAX_EXPOS 64 - #define NUM_LOGICAL_SWITCH 32 // number of custom switches - #define NUM_CFN 64 // number of functions assigned to switches - #define MAX_SCRIPTS 7 - #define MAX_INPUTS 32 - #define NUM_TRAINER 16 - #define NUM_POTS 3 - #define NUM_XPOTS 0 - #define MAX_SENSORS 32 -#elif defined(PCBTARANIS) - #define MAX_MODELS 60 - #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 - #define MAX_FLIGHT_MODES 9 - #define MAX_MIXERS 64 - #define MAX_EXPOS 64 - #define NUM_LOGICAL_SWITCH 64 // number of logical switches - #define NUM_CFN 64 // number of functions assigned to switches - #define MAX_SCRIPTS 7 - #define MAX_INPUTS 32 - #define NUM_TRAINER 16 - #if defined(REV9E) - #define NUM_POTS 8 - #define NUM_XPOTS 4 - #else - #define NUM_POTS 5 - #define NUM_XPOTS 3 - #endif - #define MAX_SENSORS 32 -#elif defined(PCBSKY9X) - #define MAX_MODELS 60 - #define NUM_CHNOUT 32 // number of real output channels CH1-CH32 - #define MAX_FLIGHT_MODES 9 - #define MAX_MIXERS 64 - #define MAX_EXPOS 32 - #define NUM_LOGICAL_SWITCH 64 // number of custom switches - #define NUM_CFN 64 // number of functions assigned to switches - #define NUM_TRAINER 16 - #define NUM_POTS 3 - #define NUM_XPOTS 0 - #define MAX_SENSORS 32 -#elif defined(CPUM2560) || defined(CPUM2561) - #define MAX_MODELS 30 - #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 - #define MAX_FLIGHT_MODES 6 - #define MAX_MIXERS 32 - #define MAX_EXPOS 16 - #define NUM_LOGICAL_SWITCH 12 // number of custom switches - #define NUM_CFN 24 // number of functions assigned to switches - #define NUM_TRAINER 8 - #define NUM_POTS 3 - #define NUM_XPOTS 0 - #define MAX_SENSORS 0 -#elif defined(CPUM128) - #define MAX_MODELS 30 - #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 - #define MAX_FLIGHT_MODES 5 - #define MAX_MIXERS 32 - #define MAX_EXPOS 14 - #define NUM_LOGICAL_SWITCH 12 // number of custom switches - #define NUM_CFN 24 // number of functions assigned to switches - #define NUM_TRAINER 8 - #define NUM_POTS 3 - #define NUM_XPOTS 0 - #define MAX_SENSORS 0 -#else - #define MAX_MODELS 16 - #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 - #define MAX_FLIGHT_MODES 5 - #define MAX_MIXERS 32 - #define MAX_EXPOS 14 - #define NUM_LOGICAL_SWITCH 12 // number of custom switches - #define NUM_CFN 16 // number of functions assigned to switches - #define NUM_TRAINER 8 - #define NUM_POTS 3 - #define NUM_XPOTS 0 - #define MAX_SENSORS 0 -#endif - -#if defined(CPUARM) - #define MAX_TIMERS 3 -#else - #define MAX_TIMERS 2 -#endif - -#define NUM_CYC 3 -#define NUM_CAL_PPM 4 - -enum CurveType { - CURVE_TYPE_STANDARD, - CURVE_TYPE_CUSTOM, - CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM -}; - -#if defined(PCBHORUS) - #define LEN_MODEL_NAME 15 - #define LEN_TIMER_NAME 8 - #define LEN_FLIGHT_MODE_NAME 10 - #define LEN_BITMAP_NAME 10 - #define LEN_EXPOMIX_NAME 6 - #define LEN_CHANNEL_NAME 6 - #define LEN_INPUT_NAME 4 - #define LEN_CURVE_NAME 3 - #define MAX_CURVES 32 - #define NUM_POINTS 512 -#elif defined(PCBFLAMENCO) - #define LEN_MODEL_NAME 12 - #define LEN_TIMER_NAME 8 - #define LEN_FLIGHT_MODE_NAME 10 - #define LEN_EXPOMIX_NAME 6 - #define LEN_CHANNEL_NAME 6 - #define LEN_INPUT_NAME 4 - #define LEN_CURVE_NAME 3 - #define MAX_CURVES 32 - #define NUM_POINTS 512 -#elif defined(PCBTARANIS) - #define LEN_MODEL_NAME 12 - #define LEN_TIMER_NAME 8 - #define LEN_FLIGHT_MODE_NAME 10 - #define LEN_BITMAP_NAME 10 - #define LEN_EXPOMIX_NAME 8 - #define LEN_CHANNEL_NAME 6 - #define LEN_INPUT_NAME 4 - #define LEN_CURVE_NAME 3 - #define MAX_CURVES 32 - #define NUM_POINTS 512 -#elif defined(CPUARM) - #define LEN_MODEL_NAME 10 - #define LEN_TIMER_NAME 3 - #define LEN_FLIGHT_MODE_NAME 6 - #define LEN_EXPOMIX_NAME 6 - #define MAX_CURVES 16 - #define NUM_POINTS 512 -#else - #define LEN_MODEL_NAME 10 - #define LEN_FLIGHT_MODE_NAME 6 - #define MAX_CURVES 8 - #define NUM_POINTS (112-MAX_CURVES) -#endif - -#if defined(PCBTARANIS) || defined(PCBSKY9X) || defined(PCBHORUS) - #define NUM_MODULES 2 -#else - #define NUM_MODULES 1 -#endif - -#if defined(XCURVES) -PACK(typedef struct { - uint8_t type:3; - uint8_t smooth:1; - uint8_t spare:4; - int8_t points; - char name[LEN_CURVE_NAME]; -}) CurveData; -#elif defined(CPUARM) -typedef int16_t CurveData; -#else -typedef int8_t CurveData; -#endif - -typedef int16_t gvar_t; - -#if defined(PCBTARANIS) - typedef uint16_t source_t; -#else - typedef uint8_t source_t; -#endif - -#if !defined(PCBSTD) - #define LEN_GVAR_NAME 3 - #define GVAR_MAX 1024 - #define GVAR_MIN -GVAR_MAX - PACK(typedef struct { - char name[LEN_GVAR_NAME]; - uint32_t min:12; - uint32_t max:12; - uint32_t popup:1; - uint32_t prec:1; - uint32_t unit:2; - uint32_t spare:4; - }) GVarData; -#endif - -#define RESERVE_RANGE_FOR_GVARS 10 -// even we do not spend space in EEPROM for 10 GVARS, we reserve the space inside the range of values, like offset, weight, etc. - -#if defined(PCBSTD) && defined(GVARS) - #define MAX_GVARS 5 - #define MODEL_GVARS_DATA gvar_t gvars[MAX_GVARS]; - #define PHASE_GVARS_DATA #define GVAR_VALUE(x, p) g_model.gvars[x] -#elif defined(PCBSTD) - #define MAX_GVARS 0 - #define MODEL_GVARS_DATA - #define PHASE_GVARS_DATA #else - #if defined(CPUARM) - #define MAX_GVARS 9 - #else - #define MAX_GVARS 5 - #endif - #define MODEL_GVARS_DATA GVarData gvars[MAX_GVARS]; - #define PHASE_GVARS_DATA gvar_t gvars[MAX_GVARS] #define GVAR_VALUE(gv, fm) g_model.flightModeData[fm].gvars[gv] #endif -PACK(typedef struct { - uint8_t srcChn:6; // 0-7 = ch1-8 - uint8_t mode:2; // off,add-mode,subst-mode - int8_t studWeight; -}) TrainerMix; - -PACK(typedef struct { - int16_t calib[4]; - TrainerMix mix[4]; -}) TrainerData; - -PACK(typedef struct { - int8_t level:2; - int8_t value:6; -}) FrSkyRSSIAlarm; - -#if defined(PCBFLAMENCO) || defined(PCBHORUS) -enum MainViews { - VIEW_BLANK, - VIEW_TIMERS_ALTITUDE, - VIEW_CHANNELS, - VIEW_TELEM1, - VIEW_TELEM2, - VIEW_TELEM3, - VIEW_TELEM4, - VIEW_COUNT -}; -#elif defined(PCBTARANIS) -enum MainViews { - VIEW_TIMERS, - VIEW_INPUTS, - VIEW_SWITCHES, - VIEW_COUNT -}; -#else -enum MainViews { - VIEW_OUTPUTS_VALUES, - VIEW_OUTPUTS_BARS, - VIEW_INPUTS, - VIEW_TIMER2, - VIEW_COUNT -}; -#endif - -enum BeeperMode { - e_mode_quiet = -2, - e_mode_alarms, - e_mode_nokeys, - e_mode_all -}; - -#if defined(CPUARM) - #define EXTRA_GENERAL_FIELDS_ARM \ - uint8_t backlightBright; \ - int8_t txCurrentCalibration; \ - int8_t temperatureWarn; \ - uint8_t mAhWarn; \ - uint16_t mAhUsed; \ - uint32_t globalTimer; \ - int8_t temperatureCalib; \ - uint8_t btBaudrate; \ - uint8_t optrexDisplay; \ - uint8_t sticksGain; \ - uint8_t rotarySteps; \ - uint8_t countryCode; \ - uint8_t imperial; \ - char ttsLanguage[2]; \ - int8_t beepVolume:4; \ - int8_t wavVolume:4; \ - int8_t varioVolume:4; \ - int8_t backgroundVolume:4; \ - int8_t varioPitch; \ - int8_t varioRange; \ - int8_t varioRepeat; -#endif - -#if defined(PCBHORUS) || defined(PCBFLAMENCO) - #define swconfig_t uint16_t - #define swarnstate_t uint32_t -#elif defined(PCBTARANIS) - #if defined(REV9E) - #define swconfig_t uint64_t - #define swarnstate_t uint64_t - #define swarnenable_t uint32_t - #else - #define swconfig_t uint16_t - #define swarnstate_t uint16_t - #define swarnenable_t uint8_t - #endif -#else - #define swarnstate_t uint8_t - #define swarnenable_t uint8_t -#endif - -enum UartModes { -#if defined(CLI) || defined(DEBUG) - UART_MODE_DEBUG, -#else - UART_MODE_NONE, -#endif - UART_MODE_TELEMETRY_MIRROR, - UART_MODE_TELEMETRY, - UART_MODE_SBUS_TRAINER, - // UART_MODE_CPPM_TRAINER, - UART_MODE_COUNT, - UART_MODE_MAX = UART_MODE_COUNT-1 -}; - -#if defined(PCBHORUS) - #define LEN_SWITCH_NAME 3 - #define LEN_ANA_NAME 3 - #define LEN_MODEL_FILENAME 16 - #define LEN_BLUETOOTH_NAME 10 - #define EXTRA_GENERAL_FIELDS \ - EXTRA_GENERAL_FIELDS_ARM \ - uint8_t serial2Mode:6; \ - uint8_t slidersConfig:2; \ - CustomFunctionData customFn[NUM_CFN]; \ - uint32_t switchConfig; \ - uint8_t potsConfig; /* two bits per pot */ \ - char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ - char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; \ - char currModelFilename[LEN_MODEL_FILENAME+1]; \ - uint8_t bluetoothEnable; \ - char bluetoothName[LEN_BLUETOOTH_NAME]; -#elif defined(PCBFLAMENCO) - #define LEN_SWITCH_NAME 3 - #define LEN_ANA_NAME 3 - #define EXTRA_GENERAL_FIELDS \ - EXTRA_GENERAL_FIELDS_ARM \ - uint8_t serial2Mode:6; \ - uint8_t spare:2; \ - CustomFunctionData customFn[NUM_CFN]; \ - uint32_t switchConfig; \ - uint8_t potsType; /*two bits for every pot*/\ - char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ - char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; -#elif defined(PCBTARANIS) - #define LEN_SWITCH_NAME 3 - #define LEN_ANA_NAME 3 - #define LEN_BLUETOOTH_NAME 10 - #if defined(REV9E) - #define BLUETOOTH_FIELDS \ - uint8_t bluetoothEnable; \ - char bluetoothName[LEN_BLUETOOTH_NAME]; - #else - #define BLUETOOTH_FIELDS - #endif - #define EXTRA_GENERAL_FIELDS \ - EXTRA_GENERAL_FIELDS_ARM \ - uint8_t serial2Mode:6; \ - uint8_t slidersConfig:2; \ - uint8_t potsConfig; /* two bits per pot */\ - uint8_t backlightColor; \ - swarnstate_t switchUnlockStates; \ - CustomFunctionData customFn[NUM_CFN]; \ - swconfig_t switchConfig; \ - char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ - char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]; \ - BLUETOOTH_FIELDS -#elif defined(CPUARM) - #define EXTRA_GENERAL_FIELDS \ - EXTRA_GENERAL_FIELDS_ARM \ - CustomFunctionData customFn[NUM_CFN]; -#elif defined(PXX) - #define EXTRA_GENERAL_FIELDS uint8_t countryCode; -#else - #define EXTRA_GENERAL_FIELDS -#endif - -#define FAILSAFE_CHANNEL_HOLD 2000 -#define FAILSAFE_CHANNEL_NOPULSE 2001 - -PACK(typedef struct { - uint8_t type:4; - int8_t rfProtocol:4; - uint8_t channelsStart; - int8_t channelsCount; // 0=8 channels - uint8_t failsafeMode:7; - uint8_t invertedSerial:1; // telemetry serial inverted from standard - int16_t failsafeChannels[NUM_CHNOUT]; - int8_t ppmDelay:6; - uint8_t ppmPulsePol:1; - uint8_t ppmOutputType:1; // false = open drain, true = push pull - int8_t ppmFrameLength; -}) ModuleData; - #define SET_DEFAULT_PPM_FRAME_LENGTH(idx) g_model.moduleData[idx].ppmFrameLength = 4 * max((int8_t)0, g_model.moduleData[idx].channelsCount) -#define LEN_SCRIPT_FILENAME 8 -#define LEN_SCRIPT_NAME 8 -#define MAX_SCRIPT_INPUTS 8 -#define MAX_SCRIPT_OUTPUTS 6 -PACK(typedef struct { - char file[LEN_SCRIPT_FILENAME]; - char name[LEN_SCRIPT_NAME]; - int8_t inputs[MAX_SCRIPT_INPUTS]; -}) ScriptData; - -enum PotsWarnMode { - POTS_WARN_OFF, - POTS_WARN_MANUAL, - POTS_WARN_AUTO -}; - #if defined(PCBFLAMENCO) enum ModuleIndex { EXTERNAL_MODULE, @@ -553,100 +87,6 @@ enum PotsWarnMode { }; #endif -#if defined(PCBHORUS) - #define MODELDATA_BITMAP char bitmap[LEN_BITMAP_NAME]; - #define MODELDATA_EXTRA uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; -#elif defined(PCBFLAMENCO) - #define MODELDATA_BITMAP uint8_t bitmap; - #define MODELDATA_EXTRA uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; -#elif defined(PCBTARANIS) - #define MODELDATA_BITMAP char bitmap[LEN_BITMAP_NAME]; - #define MODELDATA_EXTRA uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; -#elif defined(PCBSKY9X) - #define MODELDATA_BITMAP - #define MODELDATA_EXTRA uint8_t spare:6; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS]; uint8_t rxBattAlarms[2]; -#else - #define MODELDATA_BITMAP - #define MODELDATA_EXTRA -#endif - -enum BacklightMode { - e_backlight_mode_off = 0, - e_backlight_mode_keys = 1, - e_backlight_mode_sticks = 2, - e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks, - e_backlight_mode_on -}; - -#if defined(FSPLASH) - #define SPLASH_MODE uint8_t splashMode:3 -#elif defined(PCBTARANIS) - #define SPLASH_MODE int8_t splashMode:3 -#else - #define SPLASH_MODE uint8_t splashMode:1; uint8_t splashSpare:2 -#endif - -#define XPOTS_MULTIPOS_COUNT 6 - -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) -PACK(typedef struct { - uint8_t count; - uint8_t steps[XPOTS_MULTIPOS_COUNT-1]; -}) StepsCalibData; -#endif - -PACK(typedef struct { - int16_t mid; - int16_t spanNeg; - int16_t spanPos; -}) CalibData; - - -enum Functions { - // first the functions which need a checkbox - FUNC_OVERRIDE_CHANNEL, - FUNC_TRAINER, - FUNC_INSTANT_TRIM, - FUNC_RESET, -#if defined(CPUARM) - FUNC_SET_TIMER, -#endif - FUNC_ADJUST_GVAR, -#if defined(CPUARM) - FUNC_VOLUME, - FUNC_SET_FAILSAFE, - FUNC_RANGECHECK, - FUNC_BIND, -#endif - // then the other functions - FUNC_FIRST_WITHOUT_ENABLE, - FUNC_PLAY_SOUND = FUNC_FIRST_WITHOUT_ENABLE, - FUNC_PLAY_TRACK, -#if !defined(CPUARM) - FUNC_PLAY_BOTH, -#endif - FUNC_PLAY_VALUE, -#if defined(CPUARM) - FUNC_RESERVE4, - FUNC_PLAY_SCRIPT, - FUNC_RESERVE5, - FUNC_BACKGND_MUSIC, - FUNC_BACKGND_MUSIC_PAUSE, -#endif - FUNC_VARIO, - FUNC_HAPTIC, -#if !defined(PCBSTD) - FUNC_LOGS, -#endif - FUNC_BACKLIGHT, -#if defined(PCBTARANIS) - FUNC_SCREENSHOT, -#endif -#if defined(DEBUG) - FUNC_TEST, // should remain the last before MAX as not added in companion9x -#endif - FUNC_MAX -}; #if defined(VOICE) #define IS_PLAY_FUNC(func) ((func) >= FUNC_PLAY_SOUND && func <= FUNC_PLAY_VALUE) @@ -677,67 +117,7 @@ enum Functions { #define HAS_ENABLE_PARAM(func) ((func) < FUNC_FIRST_WITHOUT_ENABLE && !IS_ADJUST_GV_FUNC(func)) #define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func) || IS_ADJUST_GV_FUNC(func)) -enum ResetFunctionParam { - FUNC_RESET_TIMER1, - FUNC_RESET_TIMER2, #if defined(CPUARM) - FUNC_RESET_TIMER3, -#endif - FUNC_RESET_FLIGHT, -#if defined(FRSKY) - FUNC_RESET_TELEMETRY, -#endif -#if ROTARY_ENCODERS > 0 - FUNC_RESET_ROTENC1, -#endif -#if ROTARY_ENCODERS > 1 - FUNC_RESET_ROTENC2, -#endif -#if defined(CPUARM) - FUNC_RESET_PARAM_FIRST_TELEM, - FUNC_RESET_PARAM_LAST_TELEM = FUNC_RESET_PARAM_FIRST_TELEM + MAX_SENSORS, -#endif - FUNC_RESET_PARAMS_COUNT, - FUNC_RESET_PARAM_LAST = FUNC_RESET_PARAMS_COUNT-1, -}; - -enum AdjustGvarFunctionParam { - FUNC_ADJUST_GVAR_CONSTANT, - FUNC_ADJUST_GVAR_SOURCE, - FUNC_ADJUST_GVAR_GVAR, - FUNC_ADJUST_GVAR_INCDEC, -}; - -#if defined(CPUARM) -#if defined(PCBTARANIS) - #define LEN_CFN_NAME 8 - #define CFN_SPARE_TYPE int32_t -#else - #define LEN_CFN_NAME 6 - #define CFN_SPARE_TYPE int16_t -#endif -PACK(typedef struct { - int16_t swtch:9; - uint16_t func:7; - PACK(union { - PACK(struct { - char name[LEN_CFN_NAME]; - }) play; - - PACK(struct { - int16_t val; - uint8_t mode; - uint8_t param; - CFN_SPARE_TYPE spare; - }) all; - - PACK(struct { - int32_t val1; - CFN_SPARE_TYPE val2; - }) clear; - }); - uint8_t active; -}) CustomFunctionData; #define CFN_EMPTY(p) (!(p)->swtch) #define CFN_SWITCH(p) ((p)->swtch) #define CFN_FUNC(p) ((p)->func) @@ -754,15 +134,6 @@ PACK(typedef struct { #define CFN_GVAR_CST_MIN -GVAR_MAX #define CFN_GVAR_CST_MAX GVAR_MAX #elif defined(CPUM2560) -PACK(typedef struct { - int8_t swtch; - uint8_t func; - uint8_t mode:2; - uint8_t param:4; - uint8_t active:1; - uint8_t spare:1; - uint8_t value; -}) CustomFunctionData; #define CFN_SWITCH(p) ((p)->swtch) #define CFN_FUNC(p) ((p)->func) #define CFN_ACTIVE(p) ((p)->active) @@ -776,26 +147,6 @@ PACK(typedef struct { #define CFN_RESET(p) ((p)->active = 0, CFN_PARAM(p) = 0) #define CFN_GVAR_CST_MAX 125 #else -PACK(typedef struct { - PACK(union { - PACK(struct { - int16_t swtch:6; - uint16_t func:4; - uint16_t mode:2; - uint16_t param:3; - uint16_t active:1; - }) gvar; - - PACK(struct { - int16_t swtch:6; - uint16_t func:4; - uint16_t param:4; - uint16_t spare:1; - uint16_t active:1; - }) all; - }); - uint8_t value; -}) CustomFunctionData; #define CFN_SWITCH(p) ((p)->all.swtch) #define CFN_FUNC(p) ((p)->all.func) #define CFN_ACTIVE(p) ((p)->all.active) @@ -810,7 +161,7 @@ PACK(typedef struct { #define CFN_GVAR_CST_MAX 125 #endif -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) +#if defined(VIRTUALINPUTS) enum SwitchConfig { SWITCH_NONE, SWITCH_TOGGLE, @@ -844,75 +195,10 @@ PACK(typedef struct { #include "layout.h" #include "theme.h" #include "topbar.h" - #define SWITCHES_WARNING_DATA \ - swarnstate_t switchWarningState; - PACK(typedef struct { - char layoutName[10]; - Layout::PersistentData layoutData; - }) CustomScreenData; - #define CUSTOM_SCREENS_DATA \ - CustomScreenData screenData[MAX_CUSTOM_SCREENS]; \ - Topbar::PersistentData topbarData; - #define THEME_DATA \ - char themeName[8]; \ - Theme::PersistentData themeData; #else - #define SWITCHES_WARNING_DATA \ - swarnstate_t switchWarningState; \ - swarnenable_t switchWarningEnable; - #define CUSTOM_SCREENS_DATA #define THEME_DATA #endif -PACK(typedef struct { - uint8_t version; - uint16_t variant; - CalibData calib[NUM_STICKS+NUM_POTS]; - uint16_t chkSum; - int8_t currModel; - uint8_t contrast; - uint8_t vBatWarn; - int8_t txVoltageCalibration; - int8_t backlightMode; - TrainerData trainer; - uint8_t view; // index of view in main screen - int8_t buzzerMode:2; // -2=quiet, -1=only alarms, 0=no keys, 1=all - uint8_t fai:1; - int8_t beepMode:2; // -2=quiet, -1=only alarms, 0=no keys, 1=all - uint8_t alarmsFlash:1; - uint8_t disableMemoryWarning:1; - uint8_t disableAlarmWarning:1; - uint8_t stickMode:2; - int8_t timezone:5; - uint8_t adjustRTC:1; - uint8_t inactivityTimer; - uint8_t mavbaud:3; - SPLASH_MODE; /* 3bits */ - int8_t hapticMode:2; // -2=quiet, -1=only alarms, 0=no keys, 1=all - AVR_FIELD(uint8_t blOffBright:4) - AVR_FIELD(uint8_t blOnBright:4) - ARM_FIELD(int8_t switchesDelay) - uint8_t lightAutoOff; - uint8_t templateSetup; // RETA order for receiver channels - int8_t PPM_Multiplier; - int8_t hapticLength; - N_PCBSTD_FIELD( uint8_t reNavigation) - N_TARANIS_FIELD(uint8_t stickReverse) - int8_t beepLength:3; - int8_t hapticStrength:3; - uint8_t gpsFormat:1; - uint8_t unexpectedShutdown:1; - uint8_t speakerPitch; - int8_t speakerVolume; - int8_t vBatMin; - int8_t vBatMax; - - EXTRA_GENERAL_FIELDS - - THEME_DATA - -}) EEGeneral; - #define SWITCHES_DELAY() uint8_t(15+g_eeGeneral.switchesDelay) #define SWITCHES_DELAY_NONE (-15) #define HAPTIC_STRENGTH() (3+g_eeGeneral.hapticStrength) @@ -924,79 +210,31 @@ enum CurveRefType { CURVE_REF_CUSTOM }; -PACK(typedef struct { - uint8_t type; - int8_t value; -}) CurveRef; - #if !defined(XCURVES) #define MODE_DIFFERENTIAL 0 #define MODE_EXPO 0 #define MODE_CURVE 1 #endif -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) -PACK(typedef struct { - uint16_t mode:2; - uint16_t scale:14; - uint16_t srcRaw:10; - int16_t carryTrim:6; - uint32_t chn:5; - int32_t swtch:9; - uint32_t flightModes:9; - int32_t weight:8; - int32_t spare:1; - char name[LEN_EXPOMIX_NAME]; - int8_t offset; - CurveRef curve; -}) ExpoData; +#if defined(VIRTUALINPUTS) #define MIN_EXPO_WEIGHT -100 #define EXPO_VALID(ed) ((ed)->mode) #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2))) #elif defined(CPUARM) -PACK(typedef struct { - uint16_t mode:2; // 0=end, 1=pos, 2=neg, 3=both - uint16_t chn:3; - uint16_t curveMode:2; - uint16_t flightModes:9; - int8_t swtch; - int8_t weight; - char name[LEN_EXPOMIX_NAME]; - int8_t curveParam; -}) ExpoData; #define MIN_EXPO_WEIGHT 0 #define EXPO_VALID(ed) ((ed)->mode) #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2))) #elif defined(CPUM2560) || defined(CPUM2561) -PACK(typedef struct { - uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both - uint8_t chn:2; - uint8_t curveMode:1; - uint8_t spare:3; - uint8_t flightModes; - int8_t swtch; - uint8_t weight; - int8_t curveParam; -}) ExpoData; #define MIN_EXPO_WEIGHT 0 #define EXPO_VALID(ed) ((ed)->mode) #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2))) #else -PACK(typedef struct { - uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both - int8_t swtch:6; - uint8_t chn:2; - uint8_t flightModes:5; - uint8_t curveMode:1; - uint8_t weight; // One spare bit here (used for GVARS) - int8_t curveParam; -}) ExpoData; #define MIN_EXPO_WEIGHT 0 #define EXPO_VALID(ed) ((ed)->mode) #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2))) #endif -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) +#if defined(VIRTUALINPUTS) #define limit_min_max_t int16_t #define LIMIT_EXT_PERCENT 150 #define LIMIT_EXT_MAX (LIMIT_EXT_PERCENT*10) @@ -1020,29 +258,6 @@ PACK(typedef struct { #define LIMIT_OFS_RESX(lim) calc1000toRESX(LIMIT_OFS(lim)) #endif -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) -PACK(typedef struct { - int32_t min:11; - int32_t max:11; - int32_t ppmCenter:10; - int16_t offset:11; - uint16_t symetrical:1; - uint16_t revert:1; - uint16_t spare:3; - int8_t curve; - char name[LEN_CHANNEL_NAME]; -}) LimitData; -#else -PACK(typedef struct { - int8_t min; - int8_t max; - int8_t ppmCenter; - int16_t offset:14; - uint16_t symetrical:1; - uint16_t revert:1; -}) LimitData; -#endif - #define TRIM_OFF (1) #define TRIM_ON (0) #define TRIM_RUD (-1) @@ -1063,58 +278,11 @@ PACK(typedef struct { #define SLOW_STEP 10 #define DELAY_MAX (25*DELAY_STEP) /* 25 seconds */ #define SLOW_MAX (25*SLOW_STEP) /* 25 seconds */ -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) -PACK(typedef struct { - int16_t weight:11; // GV1=-1024, -GV1=1023 - uint16_t destCh:5; - uint16_t srcRaw:10; // srcRaw=0 means not used - uint16_t carryTrim:1; - uint16_t mixWarn:2; // mixer warning - uint16_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - uint16_t spare:1; - int32_t offset:14; - int32_t swtch:9; - uint32_t flightModes:9; - CurveRef curve; - uint8_t delayUp; - uint8_t delayDown; - uint8_t speedUp; - uint8_t speedDown; - char name[LEN_EXPOMIX_NAME]; -}) MixData; -#else -PACK(typedef struct { - uint8_t destCh:5; - uint8_t mixWarn:3; // mixer warning - uint16_t flightModes:9; - uint16_t curveMode:1; - uint16_t noExpo:1; - int16_t carryTrim:3; - uint16_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int16_t weight; - int8_t swtch; - int8_t curveParam; - uint8_t delayUp; - uint8_t delayDown; - uint8_t speedUp; - uint8_t speedDown; - uint8_t srcRaw; - int16_t offset; - char name[LEN_EXPOMIX_NAME]; -}) MixData; -#endif + #define MD_WEIGHT(md) (md->weight) #define MD_WEIGHT_TO_UNION(md, var) var.word = md->weight #define MD_UNION_TO_WEIGHT(var, md) md->weight = var.word -PACK( union u_int8int16_t { - struct { - int8_t lo; - uint8_t hi; - } bytes_t; - int16_t word; -}); - #define MD_OFFSET(md) (md->offset) #define MD_OFFSET_TO_UNION(md, var) var.word = md->offset #define MD_UNION_TO_OFFSET(var, md) md->offset = var.word @@ -1132,50 +300,6 @@ PACK( union u_int8int16_t { #define DELAY_MAX 15 /* 7.5 seconds */ #define SLOW_MAX 15 /* 7.5 seconds */ -#if defined(CPUM2560) || defined(CPUM2561) -PACK(typedef struct { - uint8_t destCh:4; // 0, 1..NUM_CHNOUT - uint8_t curveMode:1; // O=curve, 1=differential - uint8_t noExpo:1; - uint8_t weightMode:1; - uint8_t offsetMode:1; - uint8_t srcRaw; - int8_t weight; - int8_t swtch; - uint8_t flightModes; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t carryTrim:3; - uint8_t mixWarn:2; // mixer warning - uint8_t spare:1; - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; - uint8_t speedDown:4; - int8_t curveParam; - int8_t offset; -}) MixData; -#else -PACK(typedef struct { - uint8_t destCh:4; // 0, 1..NUM_CHNOUT - uint8_t curveMode:1; // O=curve, 1=differential - uint8_t noExpo:1; - uint8_t weightMode:1; - uint8_t offsetMode:1; - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - uint8_t flightModes:5; - int8_t carryTrim:3; - uint8_t srcRaw:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; - uint8_t speedDown:4; - int8_t curveParam; - int8_t offset; -}) MixData; -#endif PACK(union u_gvarint_t { struct { int8_t lo; @@ -1192,14 +316,6 @@ private: }); #define MD_WEIGHT(md) (u_gvarint_t(md->weight,md->weightMode).word) -PACK(union u_int8int16_t { - struct { - int8_t lo; - uint8_t hi; - } bytes_t; - int16_t word; -}); - #define MD_WEIGHT_TO_UNION(md, var) var.bytes_t.lo=md->weight; var.bytes_t.hi=md->weightMode?255:0 #define MD_UNION_TO_WEIGHT(var, md) md->weight=var.bytes_t.lo; if (var.word<0) md->weightMode=1; else md->weightMode=0 // #define MD_SETWEIGHT(md, val) md->weight=val; if (val<0) md->weightMode=1; else md->weightMode=0 @@ -1245,125 +361,11 @@ enum LogicalSwitchesFunctions { #define MAX_LS_DURATION 250 /*25s*/ #define MAX_LS_DELAY 250 /*25s*/ #define MAX_LS_ANDSW SWSRC_LAST -typedef int16_t ls_telemetry_value_t; -PACK(typedef struct { // Logical Switches data - uint8_t func; - int32_t v1:10; - int32_t v3:10; - int32_t andsw:9; // TODO rename to xswtch - uint32_t andswtype:1; // TODO rename to xswtchType (AND / OR) - uint32_t spare:2; // anything else needed? - int16_t v2; - uint8_t delay; - uint8_t duration; -}) LogicalSwitchData; #else -typedef uint8_t ls_telemetry_value_t; #define MAX_LS_ANDSW 15 -PACK(typedef struct { // Logical Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func:4; - uint8_t andsw:4; -}) LogicalSwitchData; #endif #if defined(CPUARM) -enum TelemetryUnit { - UNIT_RAW, - UNIT_VOLTS, - UNIT_AMPS, - UNIT_MILLIAMPS, - UNIT_KTS, - UNIT_METERS_PER_SECOND, - UNIT_FEET_PER_SECOND, - UNIT_KMH, - UNIT_MPH, - UNIT_METERS, - UNIT_FEET, - UNIT_CELSIUS, - UNIT_FAHRENHEIT, - UNIT_PERCENT, - UNIT_MAH, - UNIT_WATTS, - UNIT_DB, - UNIT_RPMS, - UNIT_G, - UNIT_DEGREE, - UNIT_MILLILITERS, - UNIT_FLOZ, - UNIT_HOURS, - UNIT_MINUTES, - UNIT_SECONDS, - // FrSky format used for these fields, could be another format in the future - UNIT_FIRST_VIRTUAL, - UNIT_CELLS = UNIT_FIRST_VIRTUAL, - UNIT_DATETIME, - UNIT_GPS, - UNIT_GPS_LONGITUDE, - UNIT_GPS_LATITUDE, - UNIT_GPS_LONGITUDE_EW, - UNIT_GPS_LATITUDE_NS, - UNIT_DATETIME_YEAR, - UNIT_DATETIME_DAY_MONTH, - UNIT_DATETIME_HOUR_MIN, - UNIT_DATETIME_SEC -}; -#define UNIT_MAX UNIT_FLOZ -#define UNIT_DIST UNIT_METERS -#define UNIT_TEMPERATURE UNIT_CELSIUS -#define UNIT_SPEED UNIT_KMH -#else -enum TelemetryUnit { - UNIT_VOLTS, - UNIT_AMPS, - UNIT_METERS_PER_SECOND, - UNIT_RAW, - UNIT_SPEED, - UNIT_DIST, - UNIT_TEMPERATURE, - UNIT_PERCENT, - UNIT_MILLIAMPS, - UNIT_A1A2_MAX = UNIT_MILLIAMPS, - UNIT_MAH, - UNIT_WATTS, - UNIT_DB, - UNIT_FEET, - UNIT_KTS, - UNIT_HOURS, - UNIT_MINUTES, - UNIT_SECONDS, - UNIT_RPMS, - UNIT_G, - UNIT_HDG, -}; -#endif - -#if defined(CPUARM) -PACK(typedef struct { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - int16_t offset:12; - uint16_t type:4; // channel unit (0=volts, ...) - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t spare:2; - uint8_t multiplier; // 0=no multiplier, 1=*2 multiplier -}) FrSkyChannelData; -#else -PACK(typedef struct { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - int16_t offset:12; - uint16_t type:4; // channel unit (0=volts, ...) - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t multiplier:2; // 0=no multiplier, 1=*2 multiplier -}) FrSkyChannelData; -#endif - -#if defined(CPUARM) -#define TELEM_LABEL_LEN 4 //#define TELEM_FLAG_TIMEOUT 0x01 #define TELEM_FLAG_LOG 0x02 //#define TELEM_FLAG_PERSISTENT 0x04 @@ -1391,125 +393,6 @@ enum TelemetrySensorFormula TELEM_FORMULA_DIST, TELEM_FORMULA_LAST = TELEM_FORMULA_DIST }; - -PACK(class TelemetrySensor { - public: - union { - uint16_t id; // data identifier, for FrSky we can reuse existing ones. Source unit is derived from type. - uint16_t persistentValue; - }; - union { - uint8_t instance; // instance ID to allow handling multiple instances of same value type, for FrSky can be the physical ID of the sensor - uint8_t formula; - }; - char label[TELEM_LABEL_LEN]; // user defined label - uint8_t type:1; // 0=custom / 1=calculated - uint8_t unit:5; // user can choose what unit to display each value in - uint8_t prec:2; - uint8_t autoOffset:1; - uint8_t filter:1; - uint8_t logs:1; - uint8_t persistent:1; - uint8_t onlyPositive:1; - uint8_t subId:3; - union { - PACK(struct { - uint16_t ratio; - int16_t offset; - }) custom; - PACK(struct { - uint8_t source; - uint8_t index; - uint16_t spare; - }) cell; - PACK(struct { - int8_t sources[4]; - }) calc; - PACK(struct { - uint8_t source; - uint8_t spare[3]; - }) consumption; - PACK(struct { - uint8_t gps; - uint8_t alt; - uint16_t spare; - }) dist; - uint32_t param; - }; - void init(const char *label, uint8_t unit=UNIT_RAW, uint8_t prec=0); - void init(uint16_t id); - bool isAvailable() const; - int32_t getValue(int32_t value, uint8_t unit, uint8_t prec) const; - bool isConfigurable() const; - bool isPrecConfigurable() const; - int32_t getPrecMultiplier() const; - int32_t getPrecDivisor() const; -}) ; -#endif - -#if !defined(CPUARM) -enum TelemetrySource { - TELEM_NONE, - TELEM_TX_VOLTAGE, - TELEM_TIMER1, - TELEM_TIMER2, - TELEM_TIMER_MAX=TELEM_TIMER2, - TELEM_RSSI_TX, - TELEM_RSSI_RX, - TELEM_A_FIRST, - TELEM_A1=TELEM_A_FIRST, - TELEM_A2, - TELEM_A_LAST=TELEM_A2, - TELEM_ALT, - TELEM_RPM, - TELEM_FUEL, - TELEM_T1, - TELEM_T2, - TELEM_SPEED, - TELEM_DIST, - TELEM_GPSALT, - TELEM_CELL, - TELEM_CELLS_SUM, - TELEM_VFAS, - TELEM_CURRENT, - TELEM_CONSUMPTION, - TELEM_POWER, - TELEM_ACCx, - TELEM_ACCy, - TELEM_ACCz, - TELEM_HDG, - TELEM_VSPEED, - TELEM_ASPEED, - TELEM_DTE, - TELEM_MIN_A_FIRST, - TELEM_MIN_A1=TELEM_MIN_A_FIRST, - TELEM_MIN_A2, - TELEM_MIN_A_LAST=TELEM_MIN_A2, - TELEM_MIN_ALT, - TELEM_MAX_ALT, - TELEM_MAX_RPM, - TELEM_MAX_T1, - TELEM_MAX_T2, - TELEM_MAX_SPEED, - TELEM_MAX_DIST, - TELEM_MAX_ASPEED, - TELEM_MIN_CELL, - TELEM_MIN_CELLS_SUM, - TELEM_MIN_VFAS, - TELEM_MAX_CURRENT, - TELEM_MAX_POWER, - TELEM_ACC, - TELEM_GPS_TIME, - TELEM_CSW_MAX = TELEM_MAX_POWER, - TELEM_NOUSR_MAX = TELEM_A2, -#if defined(FRSKY) - TELEM_DISPLAY_MAX = TELEM_MAX_POWER, -#else - TELEM_DISPLAY_MAX = TELEM_TIMER2, // because used also in PlayValue -#endif - TELEM_STATUS_MAX = TELEM_GPS_TIME, - TELEM_FIRST_STREAMED_VALUE = TELEM_RSSI_TX, -}; #endif enum VarioSource { @@ -1527,50 +410,6 @@ enum VarioSource { VARIO_SOURCE_LAST = VARIO_SOURCE_COUNT-1 }; -#if defined(FRSKY_HUB) - #define NUM_TELEMETRY TELEM_CSW_MAX -#elif defined(WS_HOW_HIGH) - #define NUM_TELEMETRY TELEM_ALT -#elif defined(FRSKY) - #define NUM_TELEMETRY TELEM_A2 -#elif defined(MAVLINK) - #define NUM_TELEMETRY 4 -#else - #define NUM_TELEMETRY TELEM_TIMER2 -#endif - -PACK(typedef struct { - source_t source; - ls_telemetry_value_t barMin; // minimum for bar display - ls_telemetry_value_t barMax; // ditto for max display (would usually = ratio) -}) FrSkyBarData; - -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) - #define NUM_LINE_ITEMS 3 -#else - #define NUM_LINE_ITEMS 2 -#endif - -PACK(typedef struct { - source_t sources[NUM_LINE_ITEMS]; -}) FrSkyLineData; - -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) -#define MAX_TELEM_SCRIPT_INPUTS 8 -PACK(typedef struct { - char file[LEN_SCRIPT_FILENAME]; - int16_t inputs[MAX_TELEM_SCRIPT_INPUTS]; -}) TelemetryScriptData; -#endif - -typedef union { - FrSkyBarData bars[4]; - FrSkyLineData lines[4]; -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) - TelemetryScriptData script; -#endif -} FrSkyScreenData; - enum FrskyUsrProtocols { USR_PROTO_NONE, USR_PROTO_FRSKY, @@ -1602,68 +441,7 @@ enum FrskyVoltsSource { FRSKY_VOLTS_SOURCE_LAST=FRSKY_VOLTS_SOURCE_CELLS }; -#if defined(CPUARM) -enum TelemetryScreenType { - TELEMETRY_SCREEN_TYPE_NONE, - TELEMETRY_SCREEN_TYPE_VALUES, - TELEMETRY_SCREEN_TYPE_GAUGES, -#if defined(LUA) - TELEMETRY_SCREEN_TYPE_SCRIPT, - TELEMETRY_SCREEN_TYPE_MAX = TELEMETRY_SCREEN_TYPE_SCRIPT -#else - TELEMETRY_SCREEN_TYPE_MAX = TELEMETRY_SCREEN_TYPE_GAUGES -#endif -}; -#define MAX_TELEMETRY_SCREENS 4 -#define TELEMETRY_SCREEN_TYPE(screenIndex) TelemetryScreenType((g_model.frsky.screensType >> (2*(screenIndex))) & 0x03) -#define IS_BARS_SCREEN(screenIndex) (TELEMETRY_SCREEN_TYPE(screenIndex) == TELEMETRY_SCREEN_TYPE_GAUGES) -PACK(typedef struct { - uint8_t voltsSource; - uint8_t altitudeSource; - uint8_t screensType; // 2bits per screen (None/Gauges/Numbers/Script) - FrSkyScreenData screens[MAX_TELEMETRY_SCREENS]; - uint8_t varioSource:7; - uint8_t varioCenterSilent:1; - int8_t varioCenterMax; - int8_t varioCenterMin; - int8_t varioMin; - int8_t varioMax; - FrSkyRSSIAlarm rssiAlarms[2]; -}) FrSkyData; -#define MIN_BLADES -1 // 1 blade -#define MAX_BLADES 126 // 128 blades -#else -#define MAX_FRSKY_A_CHANNELS 2 -#define MAX_TELEMETRY_SCREENS 2 -#define IS_BARS_SCREEN(screenIndex) (g_model.frsky.screensType & (1<<(screenIndex))) -PACK(typedef struct { - FrSkyChannelData channels[MAX_FRSKY_A_CHANNELS]; - uint8_t usrProto:2; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh, 3=Halcyon - uint8_t blades:2; // How many blades for RPMs, 0=2 blades - uint8_t screensType:2; - uint8_t voltsSource:2; - int8_t varioMin:4; - int8_t varioMax:4; - FrSkyRSSIAlarm rssiAlarms[2]; - FrSkyScreenData screens[MAX_TELEMETRY_SCREENS]; - uint8_t varioSource:3; - int8_t varioCenterMin:5; - uint8_t currentSource:3; - int8_t varioCenterMax:5; - int8_t fasOffset; -}) FrSkyData; -#define MIN_BLADES 0 // 2 blades -#define MAX_BLADES 3 // 5 blades -#endif -#if defined(MAVLINK) -PACK(typedef struct t_MavlinkData { - uint8_t rc_rssi_scale:4; - uint8_t pc_rssi_en:1; - uint8_t spare1:3; - uint8_t spare2[3]; -}) MavlinkData; -#endif enum SwashType { SWASH_TYPE_NONE, @@ -1674,28 +452,6 @@ enum SwashType { SWASH_TYPE_MAX = SWASH_TYPE_90 }; -#if defined(VIRTUALINPUTS) -PACK(typedef struct { - uint8_t type; - uint8_t value; - uint8_t collectiveSource; - uint8_t aileronSource; - uint8_t elevatorSource; - int8_t collectiveWeight; - int8_t aileronWeight; - int8_t elevatorWeight; -}) SwashRingData; -#else -PACK(typedef struct { - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; -}) SwashRingData; -#endif - #define TRIM_EXTENDED_MAX 500 #define TRIM_EXTENDED_MIN (-TRIM_EXTENDED_MAX) #define TRIM_MAX 125 @@ -1703,479 +459,20 @@ PACK(typedef struct { #define ROTARY_ENCODER_MAX 1024 -#if defined(PCBTARANIS) - #define NUM_ROTARY_ENCODERS 0 - #define ROTARY_ENCODER_ARRAY -#elif defined(REVX) - #define NUM_ROTARY_ENCODERS 0 - #define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[1]; -#elif defined(PCBSKY9X) - #define NUM_ROTARY_ENCODERS 1 - #define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[1]; -#elif defined(CPUM2560) - #define NUM_ROTARY_ENCODERS 2 - #define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[2]; -#else - #define NUM_ROTARY_ENCODERS 0 - #define ROTARY_ENCODER_ARRAY -#endif - #if defined(PCBSTD) - #define TRIMS_ARRAY int8_t trim[4]; int8_t trim_ext:8 #define TRIMS_ARRAY_SIZE 5 - #define trim_t int16_t #else - #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) - PACK(typedef struct { - int16_t value:11; - uint16_t mode:5; - }) trim_t; - #define TRIM_MODE_NONE 0x1F // 0b11111 - #else - #define trim_t int16_t - #endif - #define TRIMS_ARRAY trim_t trim[4] #define TRIMS_ARRAY_SIZE 8 -#endif - -#if defined(CPUARM) -PACK(typedef struct { - TRIMS_ARRAY; - char name[LEN_FLIGHT_MODE_NAME]; - int16_t swtch:9; // swtch of phase[0] is not used - int16_t spare:7; - uint8_t fadeIn; - uint8_t fadeOut; - ROTARY_ENCODER_ARRAY; - PHASE_GVARS_DATA; -}) FlightModeData; -#else -PACK(typedef struct { - TRIMS_ARRAY; - int8_t swtch; // swtch of phase[0] is not used - char name[LEN_FLIGHT_MODE_NAME]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - ROTARY_ENCODER_ARRAY; - PHASE_GVARS_DATA; -}) FlightModeData; -#endif - -enum SwitchSources { - SWSRC_NONE = 0, - - SWSRC_FIRST_SWITCH, - -#if defined(PCBFLAMENCO) - SWSRC_SA0 = SWSRC_FIRST_SWITCH, - SWSRC_SA1, - SWSRC_SA2, - SWSRC_SB0, - SWSRC_SB2, - SWSRC_SC0, - SWSRC_SC1, - SWSRC_SC2, - SWSRC_SC3, - SWSRC_SC4, - SWSRC_SC5, - SWSRC_SE0, - SWSRC_SE2, - SWSRC_SF0, - SWSRC_SF1, - SWSRC_SF2, - SWSRC_LAST_SWITCH = SWSRC_SF2, -#elif defined(PCBTARANIS) || defined(PCBHORUS) - SWSRC_SA0 = SWSRC_FIRST_SWITCH, - SWSRC_SA1, - SWSRC_SA2, - SWSRC_SB0, - SWSRC_SB1, - SWSRC_SB2, - SWSRC_SC0, - SWSRC_SC1, - SWSRC_SC2, - SWSRC_SD0, - SWSRC_SD1, - SWSRC_SD2, - SWSRC_SE0, - SWSRC_SE1, - SWSRC_SE2, - SWSRC_SF0, - SWSRC_SF1, - SWSRC_SF2, - SWSRC_SG0, - SWSRC_SG1, - SWSRC_SG2, - SWSRC_SH0, - SWSRC_SH1, - SWSRC_SH2, - SWSRC_TRAINER = SWSRC_SH2, -#if defined(REV9E) - SWSRC_SI0, - SWSRC_SI1, - SWSRC_SI2, - SWSRC_SJ0, - SWSRC_SJ1, - SWSRC_SJ2, - SWSRC_SK0, - SWSRC_SK1, - SWSRC_SK2, - SWSRC_SL0, - SWSRC_SL1, - SWSRC_SL2, - SWSRC_SM0, - SWSRC_SM1, - SWSRC_SM2, - SWSRC_SN0, - SWSRC_SN1, - SWSRC_SN2, - SWSRC_SO0, - SWSRC_SO1, - SWSRC_SO2, - SWSRC_SP0, - SWSRC_SP1, - SWSRC_SP2, - SWSRC_SQ0, - SWSRC_SQ1, - SWSRC_SQ2, - SWSRC_SR0, - SWSRC_SR1, - SWSRC_SR2, - SWSRC_LAST_SWITCH = SWSRC_SR2, -#else - SWSRC_LAST_SWITCH = SWSRC_SH2, -#endif -#else - SWSRC_ID0 = SWSRC_FIRST_SWITCH, - SWSRC_ID1, - SWSRC_ID2, - SWSRC_THR, - SWSRC_RUD, - SWSRC_ELE, - SWSRC_AIL, - SWSRC_GEA, - SWSRC_TRN, - SWSRC_TRAINER = SWSRC_TRN, - SWSRC_LAST_SWITCH = SWSRC_TRN, -#endif - -#if NUM_XPOTS > 0 - SWSRC_FIRST_MULTIPOS_SWITCH, - SWSRC_LAST_MULTIPOS_SWITCH = SWSRC_FIRST_MULTIPOS_SWITCH + (NUM_XPOTS*XPOTS_MULTIPOS_COUNT) - 1, -#endif - - SWSRC_FIRST_TRIM, - SWSRC_TrimRudLeft = SWSRC_FIRST_TRIM, - SWSRC_TrimRudRight, - SWSRC_TrimEleDown, - SWSRC_TrimEleUp, - SWSRC_TrimThrDown, - SWSRC_TrimThrUp, - SWSRC_TrimAilLeft, - SWSRC_TrimAilRight, - SWSRC_LAST_TRIM = SWSRC_TrimAilRight, - -#if defined(PCBSKY9X) - SWSRC_REa, -#elif defined(CPUM2560) - SWSRC_REa, - SWSRC_REb, -#endif - - SWSRC_FIRST_LOGICAL_SWITCH, - SWSRC_SW1 = SWSRC_FIRST_LOGICAL_SWITCH, - SWSRC_SW2, - SWSRC_SW3, - SWSRC_SW4, - SWSRC_SW5, - SWSRC_SW6, - SWSRC_SW7, - SWSRC_SW8, - SWSRC_SW9, - SWSRC_SWA, - SWSRC_SWB, - SWSRC_SWC, - SWSRC_LAST_LOGICAL_SWITCH = SWSRC_FIRST_LOGICAL_SWITCH+NUM_LOGICAL_SWITCH-1, - - SWSRC_ON, - SWSRC_ONE, - -#if defined(CPUARM) - SWSRC_FIRST_FLIGHT_MODE, - SWSRC_LAST_FLIGHT_MODE = SWSRC_FIRST_FLIGHT_MODE+MAX_FLIGHT_MODES-1, - - SWSRC_TELEMETRY_STREAMING, - SWSRC_FIRST_SENSOR, - SWSRC_LAST_SENSOR = SWSRC_FIRST_SENSOR+MAX_SENSORS-1, -#endif - - SWSRC_COUNT, - - SWSRC_OFF = -SWSRC_ON, - - SWSRC_LAST = SWSRC_COUNT-1, - SWSRC_FIRST = -SWSRC_LAST, - -#if defined(CPUARM) - SWSRC_LAST_IN_LOGICAL_SWITCHES = SWSRC_COUNT-1, - SWSRC_LAST_IN_MIXES = SWSRC_COUNT-1, -#else - SWSRC_LAST_IN_LOGICAL_SWITCHES = SWSRC_LAST_LOGICAL_SWITCH, - SWSRC_LAST_IN_MIXES = SWSRC_LAST_LOGICAL_SWITCH, -#endif - - SWSRC_FIRST_IN_LOGICAL_SWITCHES = -SWSRC_LAST_IN_LOGICAL_SWITCHES, - SWSRC_FIRST_IN_MIXES = -SWSRC_LAST_IN_MIXES, - -#if defined(CPUARM) - SWSRC_INVERT = SWSRC_COUNT+1, -#endif -}; - -enum MixSources { - MIXSRC_NONE, - -#if defined(VIRTUALINPUTS) - MIXSRC_FIRST_INPUT, LUA_EXPORT_MULTIPLE("input", "Input [I%d]", MAX_INPUTS) - MIXSRC_LAST_INPUT = MIXSRC_FIRST_INPUT+MAX_INPUTS-1, - - MIXSRC_FIRST_LUA, - MIXSRC_LAST_LUA = MIXSRC_FIRST_LUA+(MAX_SCRIPTS*MAX_SCRIPT_OUTPUTS)-1, -#endif - - MIXSRC_FIRST_STICK, - MIXSRC_Rud = MIXSRC_FIRST_STICK, LUA_EXPORT("rud", "Rudder") - MIXSRC_Ele, LUA_EXPORT("ele", "Elevator") - MIXSRC_Thr, LUA_EXPORT("thr", "Throttle") - MIXSRC_Ail, LUA_EXPORT("ail", "Aileron") - - MIXSRC_FIRST_POT, -#if defined(PCBHORUS) - MIXSRC_S1 = MIXSRC_FIRST_POT, LUA_EXPORT("s1", "Potentiometer S1") - MIXSRC_6POS, LUA_EXPORT("6pos", "Multipos Switch") - MIXSRC_S2, LUA_EXPORT("s2", "Potentiometer S2") - MIXSRC_FIRST_SLIDER, - MIXSRC_S3 = MIXSRC_FIRST_SLIDER, LUA_EXPORT("s3", "Slider S3") - MIXSRC_S4, LUA_EXPORT("s4", "Slider S4") - MIXSRC_LS, LUA_EXPORT("ls", "Left rear slider") - MIXSRC_RS, LUA_EXPORT("rs", "Right rear slider") - MIXSRC_LAST_POT = MIXSRC_RS, -#elif defined(PCBFLAMENCO) - MIXSRC_POT1 = MIXSRC_FIRST_POT, LUA_EXPORT("sd", "Potentiometer D") - MIXSRC_SLIDER1, LUA_EXPORT("ls", "Left slider") - MIXSRC_SLIDER2, LUA_EXPORT("rs", "Right slider") - MIXSRC_LAST_POT = MIXSRC_SLIDER2, -#elif defined(PCBTARANIS) - MIXSRC_POT1 = MIXSRC_FIRST_POT, LUA_EXPORT("s1", "Potentiometer 1") - MIXSRC_POT2, LUA_EXPORT("s2", "Potentiometer 2") - MIXSRC_POT3, LUA_EXPORT("s3", "Potentiometer 3") - #if defined(REV9E) - MIXSRC_POT4, LUA_EXPORT("s4", "Potentiometer 4 (X9E only)") - #endif - MIXSRC_FIRST_SLIDER, - MIXSRC_SLIDER1 = MIXSRC_FIRST_SLIDER, LUA_EXPORT("ls", "Left slider") - MIXSRC_SLIDER2, LUA_EXPORT("rs", "Right slider") - #if defined(REV9E) - MIXSRC_SLIDER3, LUA_EXPORT("lcs", "Left center slider (X9E only)") - MIXSRC_SLIDER4, LUA_EXPORT("rcs", "Right center slider (X9E only)") - MIXSRC_LAST_POT = MIXSRC_SLIDER4, - #else - MIXSRC_LAST_POT = MIXSRC_SLIDER2, - #endif -#else - MIXSRC_P1 = MIXSRC_FIRST_POT, - MIXSRC_P2, - MIXSRC_P3, - MIXSRC_LAST_POT = MIXSRC_P3, -#endif - -#if defined(PCBSKY9X) - MIXSRC_REa, - MIXSRC_LAST_ROTARY_ENCODER = MIXSRC_REa, -#elif defined(CPUM2560) - MIXSRC_REa, - MIXSRC_REb, - #if ROTARY_ENCODERS > 2 - MIXSRC_REc, - MIXSRC_REd, - MIXSRC_LAST_ROTARY_ENCODER = MIXSRC_REd, - #else - MIXSRC_LAST_ROTARY_ENCODER = MIXSRC_REb, + #if defined(VIRTUALINPUTS) + #define TRIM_MODE_NONE 0x1F // 0b11111 #endif #endif - MIXSRC_MAX, - - MIXSRC_FIRST_HELI, - MIXSRC_CYC1 = MIXSRC_FIRST_HELI, LUA_EXPORT("cyc1", "Cyclic 1") - MIXSRC_CYC2, LUA_EXPORT("cyc2", "Cyclic 2") - MIXSRC_CYC3, LUA_EXPORT("cyc3", "Cyclic 3") - - MIXSRC_FIRST_TRIM, - MIXSRC_TrimRud = MIXSRC_FIRST_TRIM, LUA_EXPORT("trim-rud", "Rudder trim") - MIXSRC_TrimEle, LUA_EXPORT("trim-ele", "Elevator trim") - MIXSRC_TrimThr, LUA_EXPORT("trim-thr", "Throttle trim") - MIXSRC_TrimAil, LUA_EXPORT("trim-ail", "Aileron trim") - MIXSRC_LAST_TRIM = MIXSRC_TrimAil, - - MIXSRC_FIRST_SWITCH, - -#if defined(PCBFLAMENCO) - MIXSRC_SA = MIXSRC_FIRST_SWITCH, LUA_EXPORT("sa", "Switch A") - MIXSRC_SB, LUA_EXPORT("sb", "Switch B") - MIXSRC_SC, LUA_EXPORT("sc", "Switch C") - MIXSRC_SE, LUA_EXPORT("se", "Switch E") - MIXSRC_SF, LUA_EXPORT("sf", "Switch F") - MIXSRC_LAST_SWITCH = MIXSRC_SF, -#elif defined(PCBTARANIS) || defined(PCBHORUS) - MIXSRC_SA = MIXSRC_FIRST_SWITCH, LUA_EXPORT("sa", "Switch A") - MIXSRC_SB, LUA_EXPORT("sb", "Switch B") - MIXSRC_SC, LUA_EXPORT("sc", "Switch C") - MIXSRC_SD, LUA_EXPORT("sd", "Switch D") - MIXSRC_SE, LUA_EXPORT("se", "Switch E") - MIXSRC_SF, LUA_EXPORT("sf", "Switch F") - MIXSRC_SG, LUA_EXPORT("sg", "Switch G") - MIXSRC_SH, LUA_EXPORT("sh", "Switch H") -#if defined(REV9E) - MIXSRC_SI, LUA_EXPORT("si", "Switch I (X9E only)") - MIXSRC_SJ, LUA_EXPORT("sj", "Switch J (X9E only)") - MIXSRC_SK, LUA_EXPORT("sk", "Switch K (X9E only)") - MIXSRC_SL, LUA_EXPORT("sl", "Switch L (X9E only)") - MIXSRC_SM, LUA_EXPORT("sm", "Switch M (X9E only)") - MIXSRC_SN, LUA_EXPORT("sn", "Switch N (X9E only)") - MIXSRC_SO, LUA_EXPORT("so", "Switch O (X9E only)") - MIXSRC_SP, LUA_EXPORT("sp", "Switch P (X9E only)") - MIXSRC_SQ, LUA_EXPORT("sq", "Switch Q (X9E only)") - MIXSRC_SR, LUA_EXPORT("sr", "Switch R (X9E only)") - MIXSRC_LAST_SWITCH = MIXSRC_SR, -#else - MIXSRC_LAST_SWITCH = MIXSRC_SH, -#endif -#else - MIXSRC_3POS = MIXSRC_FIRST_SWITCH, - MIXSRC_THR, - MIXSRC_RUD, - MIXSRC_ELE, - MIXSRC_AIL, - MIXSRC_GEA, - MIXSRC_TRN, - MIXSRC_LAST_SWITCH = MIXSRC_TRN, -#endif - MIXSRC_FIRST_LOGICAL_SWITCH, - MIXSRC_SW1 = MIXSRC_FIRST_LOGICAL_SWITCH, LUA_EXPORT_MULTIPLE("ls", "Logical switch L%d", NUM_LOGICAL_SWITCH) - MIXSRC_SW9 = MIXSRC_SW1 + 8, - MIXSRC_SWA, - MIXSRC_SWB, - MIXSRC_SWC, - MIXSRC_LAST_LOGICAL_SWITCH = MIXSRC_FIRST_LOGICAL_SWITCH+NUM_LOGICAL_SWITCH-1, - - MIXSRC_FIRST_TRAINER, LUA_EXPORT_MULTIPLE("trn", "Trainer input %d", NUM_TRAINER) - MIXSRC_LAST_TRAINER = MIXSRC_FIRST_TRAINER+NUM_TRAINER-1, - - MIXSRC_FIRST_CH, - MIXSRC_CH1 = MIXSRC_FIRST_CH, LUA_EXPORT_MULTIPLE("ch", "Channel CH%d", NUM_CHNOUT) - MIXSRC_CH2, - MIXSRC_CH3, - MIXSRC_CH4, - MIXSRC_CH5, - MIXSRC_CH6, - MIXSRC_CH7, - MIXSRC_CH8, - MIXSRC_CH9, - MIXSRC_CH10, - MIXSRC_CH11, - MIXSRC_CH12, - MIXSRC_CH13, - MIXSRC_CH14, - MIXSRC_CH15, - MIXSRC_CH16, - MIXSRC_LAST_CH = MIXSRC_CH1+NUM_CHNOUT-1, - - MIXSRC_FIRST_GVAR, - MIXSRC_GVAR1 = MIXSRC_FIRST_GVAR, LUA_EXPORT_MULTIPLE("gvar", "Global variable %d", MAX_GVARS) - MIXSRC_LAST_GVAR = MIXSRC_FIRST_GVAR+MAX_GVARS-1, - #if defined(CPUARM) - MIXSRC_TX_VOLTAGE, LUA_EXPORT("tx-voltage", "Transmitter battery voltage [volts]") - MIXSRC_TX_TIME, LUA_EXPORT("clock", "RTC clock [minutes from midnight]") - MIXSRC_RESERVE1, - MIXSRC_RESERVE2, - MIXSRC_RESERVE3, - MIXSRC_RESERVE4, - MIXSRC_RESERVE5, - MIXSRC_FIRST_TIMER, - MIXSRC_TIMER1 = MIXSRC_FIRST_TIMER, LUA_EXPORT("timer1", "Timer 1 value [seconds]") - MIXSRC_TIMER2, LUA_EXPORT("timer2", "Timer 2 value [seconds]") - MIXSRC_TIMER3, LUA_EXPORT("timer3", "Timer 3 value [seconds]") - MIXSRC_LAST_TIMER = MIXSRC_TIMER3, -#endif - - MIXSRC_FIRST_TELEM, -#if defined(CPUARM) - MIXSRC_LAST_TELEM = MIXSRC_FIRST_TELEM+3*MAX_SENSORS-1 -#else - MIXSRC_LAST_TELEM = MIXSRC_FIRST_TELEM+NUM_TELEMETRY-1 -#endif -}; - -#define MIXSRC_FIRST (MIXSRC_NONE+1) -#define MIXSRC_LAST MIXSRC_LAST_CH -#define INPUTSRC_FIRST MIXSRC_Rud -#define INPUTSRC_LAST MIXSRC_LAST_TELEM - -#define MIN_POINTS 3 -#define MAX_POINTS 17 - -enum TimerModes { - TMRMODE_NONE, - TMRMODE_ABS, - TMRMODE_THR, - TMRMODE_THR_REL, - TMRMODE_THR_TRG, - TMRMODE_COUNT -}; - -enum CountDownModes { - COUNTDOWN_SILENT, - COUNTDOWN_BEEPS, - COUNTDOWN_VOICE, -#if defined(CPUARM) && defined(HAPTIC) - COUNTDOWN_HAPTIC, -#endif - COUNTDOWN_COUNT -}; - -#if defined(CPUARM) -PACK(typedef struct { - int32_t mode:9; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint32_t start:23; - int32_t value:24; - uint32_t countdownBeep:2; - uint32_t minuteBeep:1; - uint32_t persistent:2; - uint32_t spare:3; - char name[LEN_TIMER_NAME]; -}) TimerData; #define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2) #elif defined(CPUM2560) -PACK(typedef struct { - int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint16_t start; - uint8_t countdownBeep:2; - uint8_t minuteBeep:1; - uint8_t persistent:2; - uint8_t spare:3; - uint16_t value; -}) TimerData; #define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2) #else -PACK(typedef struct { - int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint16_t start:12; - uint16_t countdownBeep:1; - uint16_t minuteBeep:1; - uint16_t spare:2; -}) TimerData; #define IS_MANUAL_RESET_TIMER(idx) 0 #endif @@ -2248,26 +545,6 @@ enum FailsafeModes { FAILSAFE_LAST = FAILSAFE_RECEIVER }; -#if defined(MAVLINK) - #define TELEMETRY_DATA MavlinkData mavlink; -#elif defined(FRSKY) || !defined(PCBSTD) - #define TELEMETRY_DATA FrSkyData frsky; -#else - #define TELEMETRY_DATA -#endif - -#if defined(CPUARM) || defined(CPUM2560) - #define BeepANACenter uint16_t -#else - #define BeepANACenter uint8_t -#endif - -PACK(typedef struct { - char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName - uint8_t modelId[NUM_MODULES]; - MODELDATA_BITMAP -}) ModelHeader; - enum ThrottleSources { THROTTLE_SOURCE_THR, THROTTLE_SOURCE_FIRST_POT, @@ -2314,60 +591,17 @@ enum DisplayTrims DISPLAY_TRIMS_ALWAYS }; -PACK(typedef struct { - ModelHeader header; - TimerData timers[MAX_TIMERS]; - AVR_FIELD(uint8_t protocol:3) - ARM_FIELD(uint8_t telemetryProtocol:3) - uint8_t thrTrim:1; // Enable Throttle Trim - AVR_FIELD(int8_t ppmNCH:4) - ARM_FIELD(uint8_t noGlobalFunctions:1) - ARM_FIELD(uint8_t displayTrims:2) - ARM_FIELD(uint8_t ignoreSensorIds:1) - int8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - ARM_FIELD(uint8_t displayChecklist:1) - AVR_FIELD(uint8_t pulsePol:1) - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t throttleReversed:1; - AVR_FIELD(int8_t ppmDelay) - BeepANACenter beepANACenter; - MixData mixData[MAX_MIXERS]; - LimitData limitData[NUM_CHNOUT]; - ExpoData expoData[MAX_EXPOS]; +#define TOTAL_EEPROM_USAGE (sizeof(ModelData)*MAX_MODELS + sizeof(RadioData)) - CurveData curves[MAX_CURVES]; - int8_t points[NUM_POINTS]; - - LogicalSwitchData logicalSw[NUM_LOGICAL_SWITCH]; - CustomFunctionData customFn[NUM_CFN]; - SwashRingData swashR; - FlightModeData flightModeData[MAX_FLIGHT_MODES]; - - AVR_FIELD(int8_t ppmFrameLength) // 0=22.5ms (10ms-30ms) 0.5ms increments - - uint8_t thrTraceSrc; - - SWITCHES_WARNING_DATA - - MODEL_GVARS_DATA - - TELEMETRY_DATA - - MODELDATA_EXTRA - - ARM_FIELD(TelemetrySensor telemetrySensors[MAX_SENSORS]) - - TARANIS_REV9E_FIELD(uint8_t toplcdTimer) - - CUSTOM_SCREENS_DATA - -}) ModelData; - -extern EEGeneral g_eeGeneral; +extern RadioData g_eeGeneral; extern ModelData g_model; -#define TOTAL_EEPROM_USAGE (sizeof(ModelData)*MAX_MODELS + sizeof(EEGeneral)) +PACK(union u_int8int16_t { + struct { + int8_t lo; + uint8_t hi; + } bytes_t; + int16_t word; +}); #endif // _MYEEPROM_H_ diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index cc91b0de7..ac394c3b4 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -21,7 +21,7 @@ #include "opentx.h" #include "timers.h" -EEGeneral g_eeGeneral; +RadioData g_eeGeneral; ModelData g_model; #if defined(SDCARD) @@ -1591,26 +1591,26 @@ void getADC() uint16_t v = temp[x] >> (3 - ANALOG_SCALE); #if defined(VIRTUALINPUTS) && defined(JITTER_FILTER) - // Jitter filter: + // Jitter filter: // * pass trough any big change directly // * for small change use Modified moving average (MMA) filter // // Explanation: // - // Normal MMA filter has this formula: + // Normal MMA filter has this formula: // = ((ALPHA-1)* + )/ALPHA // // If calculation is done this way with integer arithmetics, then any small change in // input signal is lost. One way to combat that, is to rearrange the formula somewhat, - // to store a more precise (larger) number between iterations. The basic idea is to - // store undivided value between iterations. Therefore an new variable is + // to store a more precise (larger) number between iterations. The basic idea is to + // store undivided value between iterations. Therefore an new variable is // used. The new formula becomes: // = - /ALPHA + // = /ALPHA (use only when out is needed) // - // The above formula with a maximum allowed ALPHA value (we are limited by + // The above formula with a maximum allowed ALPHA value (we are limited by // the 16 bit s_anaFilt[]) was tested on the radio. The resulting signal still had - // some jitter (a value of 1 was observed). The jitter might be bigger on other + // some jitter (a value of 1 was observed). The jitter might be bigger on other // radios. // // So another idea is to use larger input values for filtering. So instead of using @@ -1975,6 +1975,10 @@ uint8_t calcStickScroll( uint8_t index ) void opentxStart() { +#if defined(RAMBACKUP) + RamBackupWrite(); +#endif + doSplash(); #if defined(DEBUG_TRACE_BUFFER) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 538920ae9..28b65a6d1 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -222,7 +222,7 @@ #else #define __SDRAM __DMA #endif - + #if defined(SIMU) || defined(CPUARM) || GCC_VERSION < 472 typedef int32_t int24_t; #else @@ -334,20 +334,13 @@ #include "debug.h" #if defined(PCBFLAMENCO) - #define NUM_SWITCHES 5 #elif defined(PCBTARANIS) || defined(PCBHORUS) - #if defined(REV9E) - #define NUM_SWITCHES 18 // yes, it's a lot! - #else - #define NUM_SWITCHES 8 - #endif #define SWSRC_THR SWSRC_SF2 #define SWSRC_GEA SWSRC_SG2 #define SWSRC_ID0 SWSRC_SA0 #define SWSRC_ID1 SWSRC_SA1 #define SWSRC_ID2 SWSRC_SA2 #else - #define NUM_SWITCHES 7 #define IS_3POS(sw) ((sw) == 0) #define IS_MOMENTARY(sw) (sw == SWSRC_TRN) #define SW_DSM2_BIND SW_TRN @@ -597,9 +590,11 @@ enum BaseCurves { #define SPLASH_NEEDED() (!IS_DSM2_PROTOCOL(g_model.protocol) && !g_eeGeneral.splashMode) #endif -#if defined(FSPLASH) +#if defined(PCBHORUS) + #define SPLASH_TIMEOUT 300 /* 3s */ +#elif defined(FSPLASH) #define SPLASH_TIMEOUT (g_eeGeneral.splashMode == 0 ? 60000/*infinite=10mn*/ : ((4*100) * (g_eeGeneral.splashMode & 0x03))) -#elif defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) +#elif defined(PCBTARANIS) || defined(PCBFLAMENCO) #define SPLASH_TIMEOUT (g_eeGeneral.splashMode==-4 ? 1500 : (g_eeGeneral.splashMode<=0 ? (400-g_eeGeneral.splashMode*200) : (400-g_eeGeneral.splashMode*100))) #else #define SPLASH_TIMEOUT (4*100) // 4 seconds diff --git a/radio/src/storage/eeprom_conversions.cpp b/radio/src/storage/eeprom_conversions.cpp index 1892e98c7..205cae70e 100644 --- a/radio/src/storage/eeprom_conversions.cpp +++ b/radio/src/storage/eeprom_conversions.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -516,7 +516,13 @@ PACK(typedef struct { uint8_t potsWarnEnabled; \ int8_t potsWarnPosition[NUM_POTS]; #else -#define MODELDATA_EXTRA_217 MODELDATA_EXTRA +#define MODELDATA_EXTRA_217 \ + uint8_t spare:6; \ + uint8_t potsWarnMode:2; \ + ModuleData moduleData[NUM_MODULES+1]; \ + uint8_t potsWarnEnabled; \ + int8_t potsWarnPosition[NUM_POTS]; \ + uint8_t rxBattAlarms[2]; #endif #if defined(PCBTARANIS) @@ -606,9 +612,9 @@ PACK(typedef struct { swarnstate_t switchWarningState; swarnenable_t switchWarningEnable; - MODEL_GVARS_DATA + GVarData gvars[MAX_GVARS]; - TELEMETRY_DATA + FrSkyTelemetryData frsky; MODELDATA_EXTRA_217 @@ -683,7 +689,7 @@ int ConvertGVar_216_to_217(int value) return value; } -void ConvertGeneralSettings_216_to_217(EEGeneral & settings) +void ConvertGeneralSettings_216_to_217(RadioData & settings) { settings.version = 217; #if defined(PCBTARANIS) @@ -692,7 +698,7 @@ void ConvertGeneralSettings_216_to_217(EEGeneral & settings) #endif } -void ConvertGeneralSettings_217_to_218(EEGeneral & settings) +void ConvertGeneralSettings_217_to_218(RadioData & settings) { settings.version = 218; for (int i=0; i= BS-sizeof(blkid_t)) { m_ofs = 0; @@ -565,7 +565,7 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc) if (buf[i]) buf[i] = idx2char(buf[i]); else - buf[i] = '_'; + buf[i] = '_'; } i--; } @@ -881,7 +881,7 @@ bool eeLoadGeneral() theFile.openRlc(FILE_GENERAL); if (theFile.readRlc((uint8_t*)&g_eeGeneral, 3) == 3 && g_eeGeneral.version == EEPROM_VER) { theFile.openRlc(FILE_GENERAL); - if (theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)) <= sizeof(EEGeneral) && g_eeGeneral.variant == EEPROM_VARIANT) { + if (theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)) <= sizeof(g_eeGeneral) && g_eeGeneral.variant == EEPROM_VARIANT) { return true; } } @@ -927,7 +927,7 @@ void storageCheck(bool immediately) if (storageDirtyMsk & EE_GENERAL) { TRACE("eeprom write general"); storageDirtyMsk -= EE_GENERAL; - theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(EEGeneral), immediately); + theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral), immediately); if (!immediately) return; } diff --git a/radio/src/storage/rambackup.cpp b/radio/src/storage/rambackup.cpp new file mode 100644 index 000000000..9940dd3aa --- /dev/null +++ b/radio/src/storage/rambackup.cpp @@ -0,0 +1,43 @@ +/* + * 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" + +namespace Backup { +#define BACKUP +#include "datastructs.h" +PACK(struct RamBackup { + ModelData model; + RadioData radio; +}) ramBackup; +#undef BACKUP +}; + +#include "datacopy.cpp" + +void RamBackupWrite() +{ + TRACE("RamBackup size=%d vs %d", sizeof(Backup::RamBackup), sizeof(ModelData)+sizeof(RadioData)); +} + +void RamBackupRead() +{ + +} diff --git a/radio/src/storage/storage.h b/radio/src/storage/storage.h index 49a746ac9..c3fe87ca7 100644 --- a/radio/src/storage/storage.h +++ b/radio/src/storage/storage.h @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -57,4 +57,9 @@ void postModelLoad(bool newModel); #include "sdcard_raw.h" #endif +#if defined(RAMBACKUP) +void RamBackupWrite(); +void RamBackupRead(); +#endif + #endif // _STORAGE_H_ diff --git a/radio/src/targets/common_avr/serial_driver.h b/radio/src/targets/common_avr/serial_driver.h index e5ba5a935..649e78fd6 100644 --- a/radio/src/targets/common_avr/serial_driver.h +++ b/radio/src/targets/common_avr/serial_driver.h @@ -21,6 +21,8 @@ #ifndef _SERIAL_DRIVER_H_ #define _SERIAL_DRIVER_H_ +#include + typedef enum serial_tx_state_ { TX_STATE_EMPTY = 0, // TX_STATE_READY, // diff --git a/radio/src/targets/gruvin9x/diskio.cpp b/radio/src/targets/gruvin9x/diskio.cpp index ba72baf1d..9ad7eb28d 100644 --- a/radio/src/targets/gruvin9x/diskio.cpp +++ b/radio/src/targets/gruvin9x/diskio.cpp @@ -1,23 +1,23 @@ -/* - * 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. - */ - +/* + * 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. + */ + /*-----------------------------------------------------------------------*/ /* MMCv3/SDv1/SDv2 (in SPI mode) control module (C)ChaN, 2010 */ /*-----------------------------------------------------------------------*/ diff --git a/radio/src/targets/sky9x/MEDSdcard.c b/radio/src/targets/sky9x/MEDSdcard.c index 9dfe18e6c..bbbfd8c4a 100644 --- a/radio/src/targets/sky9x/MEDSdcard.c +++ b/radio/src/targets/sky9x/MEDSdcard.c @@ -1,30 +1,30 @@ -/* - * 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. - */ - +/* + * 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. + */ + //------------------------------------------------------------------------------ // Headers //------------------------------------------------------------------------------ #include #include "debug.h" -#include "../FatFs/diskio.h" +#include "diskio.h" #include "board.h" #include "Media.h" diff --git a/radio/src/targets/sky9x/diskio.cpp b/radio/src/targets/sky9x/diskio.cpp index 5bb017d6a..0a590eaad 100644 --- a/radio/src/targets/sky9x/diskio.cpp +++ b/radio/src/targets/sky9x/diskio.cpp @@ -1,32 +1,32 @@ -/* - * 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. - */ - +/* + * 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. + */ + /*-----------------------------------------------------------------------*/ /* MMCv3/SDv1/SDv2 (in SPI mode) control module (C)ChaN, 2010 */ /*-----------------------------------------------------------------------*/ /* Only rcvr_spi(), xmit_spi(), sdPoll10ms() and some macros */ /* are platform dependent. */ /*-----------------------------------------------------------------------*/ - -#include "../../opentx.h" -#include "../FatFs/diskio.h" + +#include "../../opentx.h" +#include "diskio.h" #define CARD_TYPE_bmHC (1 << 0) /**< Bit for High-Capacity(Density) */ #define CARD_TYPE_bmSDMMC (0x3 << 1) /**< Bits mask for SD/MMC */ diff --git a/radio/src/telemetry/mavlink.cpp b/radio/src/telemetry/mavlink.cpp index c13ed2087..c67dd54bc 100644 --- a/radio/src/telemetry/mavlink.cpp +++ b/radio/src/telemetry/mavlink.cpp @@ -39,11 +39,10 @@ mavlink_system_t mavlink_system = { 7, MAV_COMP_ID_MISSIONPLANNER, 0, 0, 0, 0 }; // Mavlink message decoded Status Text #define PARAM_NB_REPEAT 10 -#define LEN_STATUSTEXT 20 -static char mav_statustext[LEN_STATUSTEXT]; -static int8_t mav_heartbeat = 0; -static int8_t mav_heartbeat_recv = 0; -static uint8_t data_stream_start_stop = 0; +char mav_statustext[LEN_STATUSTEXT]; +int8_t mav_heartbeat = 0; +int8_t mav_heartbeat_recv = 0; +uint8_t data_stream_start_stop = 0; // Telemetry data hold diff --git a/radio/src/telemetry/mavlink.h b/radio/src/telemetry/mavlink.h index 08a8523e1..8c80b3bf7 100644 --- a/radio/src/telemetry/mavlink.h +++ b/radio/src/telemetry/mavlink.h @@ -32,8 +32,11 @@ #include "targets/common_avr/serial_driver.h" #include "opentx.h" +extern int8_t mav_heartbeat; extern mavlink_system_t mavlink_system; - +#define LEN_STATUSTEXT 20 +extern char mav_statustext[LEN_STATUSTEXT]; + extern void SERIAL_start_uart_send(); extern void SERIAL_end_uart_send(); extern void SERIAL_send_uart_bytes(const uint8_t * buf, uint16_t len); diff --git a/radio/util/commit-tests.sh b/radio/util/commit-tests.sh index 41a189d55..8e6018268 100755 --- a/radio/util/commit-tests.sh +++ b/radio/util/commit-tests.sh @@ -4,7 +4,7 @@ set -e set -x -mkdir build +mkdir build || true cd build # Companion @@ -25,25 +25,25 @@ cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=9X -DHELI=YES -DEXT=MAVLINK .. make -j2 firmware # OpenTX on Mega2560 -# rm -rf * -#cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=MEGA2560 -DHELI=YES .. -#make -j2 firmware -#make -j2 simu -#make -j2 gtests ; ./gtests +rm -rf * +cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=MEGA2560 -DHELI=YES .. +make -j2 firmware +make -j2 simu +make -j2 gtests ; ./gtests # OpenTX on Mega2560 with Mavlink telemetry -# rm -rf * -#cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=MEGA2560 -DEXT=MAVLINK -DHELI=YES .. -#make -j2 firmware -#make -j2 simu -#make -j2 gtests ; ./gtests +rm -rf * +cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=MEGA2560 -DEXT=MAVLINK -DHELI=YES .. +make -j2 firmware +make -j2 simu +make -j2 gtests ; ./gtests # OpenTX on gruvin9x board -# rm -rf * -#cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=GRUVIN9X -DHELI=YES .. -#make -j2 firmware -#make -j2 simu -#make -j2 gtests ; ./gtests +rm -rf * +cmake -DCMAKE_BUILD_TYPE=Debug -DPCB=GRUVIN9X -DHELI=YES .. +make -j2 firmware +make -j2 simu +make -j2 gtests ; ./gtests # OpenTX on Sky9x rm -rf * diff --git a/radio/util/generate_datacopy.py b/radio/util/generate_datacopy.py new file mode 100644 index 000000000..8e8ca3d8b --- /dev/null +++ b/radio/util/generate_datacopy.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import sys +import clang.cindex + +structs = [] + +def build_struct(cursor): + structs.append(cursor.spelling) + print "template \nvoid copy%s(A * dest, B * src)\n{" % cursor.spelling + for c in cursor.get_children(): + if c.kind == clang.cindex.CursorKind.FIELD_DECL: + if c.type.get_array_size() > 0: + if c.type.get_array_element_type().spelling in structs: + print " for (int i=0; i<%d; i++) {" % c.type.get_array_size() + print " copy%s(dest->%s[i], src->%s[i]);" % (c.type.get_array_element_type().spelling, c.spelling, c.spelling) + print " }" + else: + print " memcpy(&dest->%s, &src->%s, sizeof(dest->%s));" % (c.spelling, c.spelling, c.spelling) + else: + print " dest->%s = src->%s;" % (c.spelling, c.spelling) + print "}\n" + +def build(cursor): + result = [] + for c in cursor.get_children(): + if c.kind == clang.cindex.CursorKind.STRUCT_DECL: + build_struct(c) + return result + +index = clang.cindex.Index.create() +translation_unit = index.parse(sys.argv[1], ['-x', 'c++', '-std=c++11'] + sys.argv[2:]) +build(translation_unit.cursor)