5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 #include "datastructs.h"
26 #define WARN_THR_BIT 0x01
27 #define WARN_BEP_BIT 0x80
28 #define WARN_SW_BIT 0x02
29 #define WARN_MEM_BIT 0x04
30 #define WARN_BVAL_BIT 0x38
32 #define WARN_THR (!(g_eeGeneral.warnOpts & WARN_THR_BIT))
33 #define WARN_BEP (!(g_eeGeneral.warnOpts & WARN_BEP_BIT))
34 #define WARN_SW (!(g_eeGeneral.warnOpts & WARN_SW_BIT))
35 #define WARN_MEM (!(g_eeGeneral.warnOpts & WARN_MEM_BIT))
36 #define BEEP_VAL ( (g_eeGeneral.warnOpts & WARN_BVAL_BIT) >>3 )
39 #define EEPROM_VER 218
40 #define FIRST_CONV_EEPROM_VER 216
41 #elif defined(CPUM2560) || defined(CPUM2561)
42 #define EEPROM_VER 217
43 #define FIRST_CONV_EEPROM_VER EEPROM_VER
44 #elif defined(CPUM128)
45 #define EEPROM_VER 217
47 #define EEPROM_VER 216
50 #define GET_PPM_POLARITY(idx) g_model.moduleData[idx].ppm.pulsePol
51 #define GET_SBUS_POLARITY(idx) g_model.moduleData[idx].sbus.noninverted
52 #define GET_PPM_DELAY(idx) (g_model.moduleData[idx].ppm.delay * 50 + 300)
53 #define SET_DEFAULT_PPM_FRAME_LENGTH(idx) g_model.moduleData[idx].ppm.frameLength = 4 * max((int8_t)0, g_model.moduleData[idx].channelsCount)
56 #define IS_TRAINER_EXTERNAL_MODULE() false
57 #define HAS_WIRELESS_TRAINER_HARDWARE() (g_eeGeneral.serial2Mode==UART_MODE_SBUS_TRAINER)
58 #elif defined(PCBTARANIS)
59 #define IS_TRAINER_EXTERNAL_MODULE() (g_model.trainerMode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || g_model.trainerMode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE)
60 #define HAS_WIRELESS_TRAINER_HARDWARE() (g_eeGeneral.serial2Mode==UART_MODE_SBUS_TRAINER)
62 #define IS_TRAINER_EXTERNAL_MODULE() false
66 #define IS_PLAY_FUNC(func) ((func) >= FUNC_PLAY_SOUND && func <= FUNC_PLAY_VALUE)
68 #define IS_PLAY_FUNC(func) ((func) == FUNC_PLAY_SOUND)
72 #define IS_PLAY_BOTH_FUNC(func) (0)
73 #define IS_VOLUME_FUNC(func) ((func) == FUNC_VOLUME)
75 #define IS_PLAY_BOTH_FUNC(func) ((func) == FUNC_PLAY_BOTH)
76 #define IS_VOLUME_FUNC(func) (0)
80 #define IS_ADJUST_GV_FUNC(func) ((func) == FUNC_ADJUST_GVAR)
82 #define IS_ADJUST_GV_FUNC(func) (0)
86 #define IS_HAPTIC_FUNC(func) ((func) == FUNC_HAPTIC)
88 #define IS_HAPTIC_FUNC(func) (0)
91 #define HAS_ENABLE_PARAM(func) ((func) < FUNC_FIRST_WITHOUT_ENABLE)
92 #define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func))
95 #define CFN_EMPTY(p) (!(p)->swtch)
96 #define CFN_SWITCH(p) ((p)->swtch)
97 #define CFN_FUNC(p) ((p)->func)
98 #define CFN_ACTIVE(p) ((p)->active)
99 #define CFN_CH_INDEX(p) ((p)->all.param)
100 #define CFN_GVAR_INDEX(p) ((p)->all.param)
101 #define CFN_TIMER_INDEX(p) ((p)->all.param)
102 #define CFN_PLAY_REPEAT(p) ((p)->active)
103 #define CFN_PLAY_REPEAT_MUL 1
104 #define CFN_PLAY_REPEAT_NOSTART 0xFF
105 #define CFN_GVAR_MODE(p) ((p)->all.mode)
106 #define CFN_PARAM(p) ((p)->all.val)
107 #define CFN_RESET(p) ((p)->active=0, (p)->clear.val1=0, (p)->clear.val2=0)
108 #define CFN_GVAR_CST_MIN -GVAR_MAX
109 #define CFN_GVAR_CST_MAX GVAR_MAX
110 #define MODEL_GVAR_MIN(idx) (CFN_GVAR_CST_MIN + g_model.gvars[idx].min)
111 #define MODEL_GVAR_MAX(idx) (CFN_GVAR_CST_MAX - g_model.gvars[idx].max)
112 #elif defined(CPUM2560)
113 #define CFN_SWITCH(p) ((p)->swtch)
114 #define CFN_FUNC(p) ((p)->func)
115 #define CFN_ACTIVE(p) ((p)->active)
116 #define CFN_CH_INDEX(p) ((p)->param)
117 #define CFN_TIMER_INDEX(p) ((p)->param)
118 #define CFN_GVAR_INDEX(p) ((p)->param)
119 #define CFN_PLAY_REPEAT(p) ((p)->param)
120 #define CFN_PLAY_REPEAT_MUL 10
121 #define CFN_GVAR_MODE(p) ((p)->mode)
122 #define CFN_PARAM(p) ((p)->value)
123 #define CFN_RESET(p) ((p)->active = 0, CFN_PARAM(p) = 0)
124 #define CFN_GVAR_CST_MAX 125
126 #define CFN_SWITCH(p) ((p)->all.swtch)
127 #define CFN_FUNC(p) ((p)->all.func)
128 #define CFN_ACTIVE(p) ((p)->all.active)
129 #define CFN_CH_INDEX(p) ((p)->all.param)
130 #define CFN_TIMER_INDEX(p) ((p)->all.param)
131 #define CFN_GVAR_INDEX(p) ((p)->gvar.param)
132 #define CFN_PLAY_REPEAT(p) ((p)->all.param)
133 #define CFN_PLAY_REPEAT_MUL 10
134 #define CFN_GVAR_MODE(p) ((p)->gvar.mode)
135 #define CFN_PARAM(p) ((p)->value)
136 #define CFN_RESET(p) ((p)->all.active = 0, CFN_PARAM(p) = 0)
137 #define CFN_GVAR_CST_MAX 125
140 #if defined(PCBTARANIS) || defined(PCBHORUS)
157 #define SWITCH_CONFIG(x) ((g_eeGeneral.switchConfig >> (2*(x))) & 0x03)
158 #define SWITCH_EXISTS(x) (SWITCH_CONFIG(x) != SWITCH_NONE)
159 #define IS_CONFIG_3POS(x) (SWITCH_CONFIG(x) == SWITCH_3POS)
160 #define IS_CONFIG_TOGGLE(x) (SWITCH_CONFIG(x) == SWITCH_TOGGLE)
161 #define SWITCH_WARNING_ALLOWED(x) (SWITCH_EXISTS(x) && !IS_CONFIG_TOGGLE(x))
163 #define IS_CONFIG_3POS(x) IS_3POS(x)
164 #define IS_CONFIG_TOGGLE(x) IS_TOGGLE(x)
165 #define switchInfo(x) ((x) >= 3 ? (x)-2 : 0)
166 #define SWITCH_EXISTS(x) true
169 #define ALTERNATE_VIEW 0x10
171 #if defined(PCBHORUS)
179 #define SWITCHES_DELAY() uint8_t(15+g_eeGeneral.switchesDelay)
180 #define SWITCHES_DELAY_NONE (-15)
181 #define HAPTIC_STRENGTH() (3+g_eeGeneral.hapticStrength)
191 #define MODE_DIFFERENTIAL 0
197 #define MIN_EXPO_WEIGHT -100
198 #define EXPO_VALID(ed) ((ed)->mode)
199 #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2)))
200 #elif defined(CPUM2560) || defined(CPUM2561)
201 #define MIN_EXPO_WEIGHT 0
202 #define EXPO_VALID(ed) ((ed)->mode)
203 #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2)))
205 #define MIN_EXPO_WEIGHT 0
206 #define EXPO_VALID(ed) ((ed)->mode)
207 #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2)))
211 #define limit_min_max_t int16_t
212 #define LIMIT_EXT_PERCENT 150
213 #define LIMIT_EXT_MAX (LIMIT_EXT_PERCENT*10)
214 #define PPM_CENTER_MAX 500
215 #define LIMIT_MAX(lim) (GV_IS_GV_VALUE(lim->max, -GV_RANGELARGE, GV_RANGELARGE) ? GET_GVAR_PREC1(lim->max, -LIMIT_EXT_MAX, LIMIT_EXT_MAX, mixerCurrentFlightMode) : lim->max+1000)
216 #define LIMIT_MIN(lim) (GV_IS_GV_VALUE(lim->min, -GV_RANGELARGE, GV_RANGELARGE) ? GET_GVAR_PREC1(lim->min, -LIMIT_EXT_MAX, LIMIT_EXT_MAX, mixerCurrentFlightMode) : lim->min-1000)
217 #define LIMIT_OFS(lim) (GV_IS_GV_VALUE(lim->offset, -1000, 1000) ? GET_GVAR_PREC1(lim->offset, -1000, 1000, mixerCurrentFlightMode) : lim->offset)
218 #define LIMIT_MAX_RESX(lim) calc1000toRESX(LIMIT_MAX(lim))
219 #define LIMIT_MIN_RESX(lim) calc1000toRESX(LIMIT_MIN(lim))
220 #define LIMIT_OFS_RESX(lim) calc1000toRESX(LIMIT_OFS(lim))
222 #define limit_min_max_t int8_t
223 #define LIMIT_EXT_PERCENT 125
224 #define LIMIT_EXT_MAX LIMIT_EXT_PERCENT
225 #define PPM_CENTER_MAX 125
226 #define LIMIT_MAX(lim) (lim->max+100)
227 #define LIMIT_MIN(lim) (lim->min-100)
228 #define LIMIT_OFS(lim) (lim->offset)
229 #define LIMIT_MAX_RESX(lim) calc100toRESX(LIMIT_MAX(lim))
230 #define LIMIT_MIN_RESX(lim) calc100toRESX(LIMIT_MIN(lim))
231 #define LIMIT_OFS_RESX(lim) calc1000toRESX(LIMIT_OFS(lim))
236 #define TRIM_RUD (-1)
237 #define TRIM_ELE (-2)
238 #define TRIM_THR (-3)
239 #define TRIM_AIL (-4)
240 #if defined(PCBHORUS)
243 #define TRIM_LAST TRIM_T6
245 #define TRIM_LAST TRIM_AIL
253 #define GV1_SMALL 128
254 #define GV1_LARGE 1024
255 #define GV_RANGE_WEIGHT 500
256 #define GV_RANGE_OFFSET 500
257 #define DELAY_STEP 10
259 #define DELAY_MAX (25*DELAY_STEP) /* 25 seconds */
260 #define SLOW_MAX (25*SLOW_STEP) /* 25 seconds */
262 #define MD_WEIGHT(md) (md->weight)
263 #define MD_WEIGHT_TO_UNION(md, var) var.word = md->weight
264 #define MD_UNION_TO_WEIGHT(var, md) md->weight = var.word
266 #define MD_OFFSET(md) (md->offset)
267 #define MD_OFFSET_TO_UNION(md, var) var.word = md->offset
268 #define MD_UNION_TO_OFFSET(var, md) md->offset = var.word
269 // #define MD_SETOFFSET(md, val) md->offset = val
273 // highest bit used for small values in mix 128 --> 8 bit is enough
274 #define GV1_SMALL 128
275 // highest bit used for large values in mix 256 --> 9 bits is used (8 bits + 1 extra bit from weightMode/offsetMode)
276 #define GV1_LARGE 256
280 #define DELAY_MAX 15 /* 7.5 seconds */
281 #define SLOW_MAX 15 /* 7.5 seconds */
283 PACK(union u_gvarint_t
{
290 u_gvarint_t(int8_t l
, uint8_t h
) {bytes_t
.lo
=l
; bytes_t
.hi
=h
?255:0;} // hi bit is negativ sign
293 // prevent unwanted constructors, also saves program
295 u_gvarint_t(const u_gvarint_t
&) {}
297 #define MD_WEIGHT(md) (u_gvarint_t(md->weight,md->weightMode).word)
299 #define MD_WEIGHT_TO_UNION(md, var) var.bytes_t.lo=md->weight; var.bytes_t.hi=md->weightMode?255:0
300 #define MD_UNION_TO_WEIGHT(var, md) md->weight=var.bytes_t.lo; if (var.word<0) md->weightMode=1; else md->weightMode=0
301 // #define MD_SETWEIGHT(md, val) md->weight=val; if (val<0) md->weightMode=1; else md->weightMode=0
303 #define MD_OFFSET(md) (u_gvarint_t(md->offset,md->offsetMode).word)
304 #define MD_OFFSET_TO_UNION(md, var) var.bytes_t.lo=md->offset; var.bytes_t.hi=md->offsetMode?255:0
305 #define MD_UNION_TO_OFFSET(var, md) md->offset=var.bytes_t.lo; if (var.word<0) md->offsetMode=1; else md->offsetMode=0 /* set negative sign */
306 // #define MD_SETOFFSET(md, val) md->offset=val; if (val<0) md->offsetMode=1; else md->offsetMode=0
310 enum LogicalSwitchesFunctions
{
313 LS_FUNC_VEQUAL
, // v==offset
315 LS_FUNC_VALMOSTEQUAL
, // v~=offset
316 LS_FUNC_VPOS
, // v>offset
317 LS_FUNC_VNEG
, // v<offset
321 LS_FUNC_APOS
, // |v|>offset
322 LS_FUNC_ANEG
, // |v|<offset
332 LS_FUNC_DIFFEGREATER
,
333 LS_FUNC_ADIFFEGREATER
,
337 LS_FUNC_MAX
= LS_FUNC_COUNT
-1
341 #define MAX_LS_DURATION 250 /*25s*/
342 #define MAX_LS_DELAY 250 /*25s*/
343 #define MAX_LS_ANDSW SWSRC_LAST
345 #define MAX_LS_ANDSW 15
349 //#define TELEM_FLAG_TIMEOUT 0x01
350 #define TELEM_FLAG_LOG 0x02
351 //#define TELEM_FLAG_PERSISTENT 0x04
352 //#define TELEM_FLAG_SCALE 0x08
353 #define TELEM_FLAG_AUTO_OFFSET 0x10
354 #define TELEM_FLAG_FILTER 0x20
355 #define TELEM_FLAG_LOSS_ALARM 0x40
357 enum TelemetrySensorType
360 TELEM_TYPE_CALCULATED
363 enum TelemetrySensorFormula
366 TELEM_FORMULA_AVERAGE
,
369 TELEM_FORMULA_MULTIPLY
,
370 TELEM_FORMULA_TOTALIZE
,
372 TELEM_FORMULA_CONSUMPTION
,
374 TELEM_FORMULA_LAST
= TELEM_FORMULA_DIST
379 #if !defined(TELEMETRY_FRSKY_SPORT)
381 VARIO_SOURCE_ALTI_PLUS
,
386 #if defined(TELEMETRY_FRSKY_SPORT)
390 VARIO_SOURCE_LAST
= VARIO_SOURCE_COUNT
-1
393 enum FrskyUsrProtocols
{
396 USR_PROTO_WS_HOW_HIGH
,
397 USR_PROTO_LAST
= USR_PROTO_WS_HOW_HIGH
,
400 enum FrskyCurrentSource
{
401 FRSKY_CURRENT_SOURCE_NONE
,
402 FRSKY_CURRENT_SOURCE_A1
,
403 FRSKY_CURRENT_SOURCE_A2
,
405 FRSKY_CURRENT_SOURCE_A3
,
406 FRSKY_CURRENT_SOURCE_A4
,
408 FRSKY_CURRENT_SOURCE_FAS
,
409 FRSKY_CURRENT_SOURCE_LAST
=FRSKY_CURRENT_SOURCE_FAS
412 enum FrskyVoltsSource
{
413 FRSKY_VOLTS_SOURCE_A1
,
414 FRSKY_VOLTS_SOURCE_A2
,
416 FRSKY_VOLTS_SOURCE_A3
,
417 FRSKY_VOLTS_SOURCE_A4
,
419 FRSKY_VOLTS_SOURCE_FAS
,
420 FRSKY_VOLTS_SOURCE_CELLS
,
421 FRSKY_VOLTS_SOURCE_LAST
=FRSKY_VOLTS_SOURCE_CELLS
432 SWASH_TYPE_MAX
= SWASH_TYPE_90
435 #define TRIM_EXTENDED_MAX 500
436 #define TRIM_EXTENDED_MIN (-TRIM_EXTENDED_MAX)
438 #define TRIM_MIN (-TRIM_MAX)
440 #define ROTARY_ENCODER_MAX 1024
443 #define TRIMS_ARRAY_SIZE 5
445 #define TRIMS_ARRAY_SIZE 8
447 #define TRIM_MODE_NONE 0x1F // 0b11111
452 #define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2)
453 #elif defined(CPUM2560)
454 #define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2)
456 #define IS_MANUAL_RESET_TIMER(idx) 0
459 #if defined(CPUARM) && !defined(PCBSKY9X)
460 #define TIMER_COUNTDOWN_START(x) (g_model.timers[x].countdownStart > 0 ? 5 : 10 - g_model.timers[x].countdownStart * 10)
462 #define TIMER_COUNTDOWN_START(x) 10
471 #if defined(PXX) || defined(DSM2) || defined(IRPROTOS)
474 #if defined(DSM2) || defined(IRPROTOS)
482 #if defined(IRPROTOS)
484 // we will need 4 bits for proto :(
498 enum XJTRFProtocols
{
503 RF_PROTO_LAST
= RF_PROTO_LR12
508 MODULE_SUBTYPE_R9M_FCC
,
509 MODULE_SUBTYPE_R9M_EU
,
510 MODULE_SUBTYPE_R9M_EUPLUS
,
511 MODULE_SUBTYPE_R9M_AUPLUS
,
512 MODULE_SUBTYPE_R9M_LAST
=MODULE_SUBTYPE_R9M_AUPLUS
515 enum MultiModuleRFProtocols
{
516 MM_RF_PROTO_CUSTOM
= -1,
517 MM_RF_PROTO_FIRST
= MM_RF_PROTO_CUSTOM
,
518 MM_RF_PROTO_FLYSKY
=0,
543 MM_RF_PROTO_FS_AFHDS2A
,
557 MM_RF_PROTO_BUGS_MINI
,
566 MM_RF_PROTO_POTENSIC
,
567 MM_RF_PROTO_LAST
= MM_RF_PROTO_POTENSIC
570 enum MMDSM2Subtypes
{
571 MM_RF_DSM2_SUBTYPE_DSM2_22
,
572 MM_RF_DSM2_SUBTYPE_DSM2_11
,
573 MM_RF_DSM2_SUBTYPE_DSMX_22
,
574 MM_RF_DSM2_SUBTYPE_DSMX_11
,
575 MM_RF_DSM2_SUBTYPE_AUTO
578 enum MMRFrskySubtypes
{
579 MM_RF_FRSKY_SUBTYPE_D16
,
580 MM_RF_FRSKY_SUBTYPE_D8
,
581 MM_RF_FRSKY_SUBTYPE_D16_8CH
,
582 MM_RF_FRSKY_SUBTYPE_V8
,
583 MM_RF_FRSKY_SUBTYPE_D16_LBT
,
584 MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH
587 #define HAS_RF_PROTOCOL_FAILSAFE(rf) ((rf) == RF_PROTO_X16)
588 #define HAS_RF_PROTOCOL_MODELINDEX(rf) (((rf) == RF_PROTO_X16) || ((rf) == RF_PROTO_LR12))
597 MODULE_TYPE_NONE
= 0,
601 MODULE_TYPE_CROSSFIRE
,
602 MODULE_TYPE_MULTIMODULE
,
609 XJT_INTERNAL_ANTENNA
,
619 FAILSAFE_LAST
= FAILSAFE_RECEIVER
622 enum ThrottleSources
{
624 THROTTLE_SOURCE_FIRST_POT
,
626 THROTTLE_SOURCE_F1
= THROTTLE_SOURCE_FIRST_POT
,
634 #elif defined(PCBTARANIS)
635 THROTTLE_SOURCE_S1
= THROTTLE_SOURCE_FIRST_POT
,
641 THROTTLE_SOURCE_P1
= THROTTLE_SOURCE_FIRST_POT
,
650 PROTOCOL_TELEMETRY_FIRST
,
651 PROTOCOL_FRSKY_SPORT
= PROTOCOL_TELEMETRY_FIRST
,
653 PROTOCOL_FRSKY_D_SECONDARY
,
654 PROTOCOL_PULSES_CROSSFIRE
,
656 PROTOCOL_FLYSKY_IBUS
,
657 PROTOCOL_MULTIMODULE
,
658 PROTOCOL_TELEMETRY_LAST
=PROTOCOL_MULTIMODULE
664 DISPLAY_TRIMS_CHANGE
,
668 #define TOTAL_EEPROM_USAGE (sizeof(ModelData)*MAX_MODELS + sizeof(RadioData))
670 extern RadioData g_eeGeneral
;
671 extern ModelData g_model
;
673 PACK(union u_int8int16_t
{
681 #endif // _MYEEPROM_H_