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_PPM_DELAY(idx) (g_model.moduleData[idx].ppm.delay * 50 + 300)
52 #define SET_DEFAULT_PPM_FRAME_LENGTH(idx) g_model.moduleData[idx].ppm.frameLength = 4 * max((int8_t)0, g_model.moduleData[idx].channelsCount)
55 #define IS_TRAINER_EXTERNAL_MODULE() false
56 #define HAS_WIRELESS_TRAINER_HARDWARE() (g_eeGeneral.serial2Mode==UART_MODE_SBUS_TRAINER)
57 #elif defined(PCBTARANIS)
58 #define IS_TRAINER_EXTERNAL_MODULE() (g_model.trainerMode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || g_model.trainerMode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE)
59 #define HAS_WIRELESS_TRAINER_HARDWARE() (g_eeGeneral.serial2Mode==UART_MODE_SBUS_TRAINER)
61 #define IS_TRAINER_EXTERNAL_MODULE() false
65 #define IS_PLAY_FUNC(func) ((func) >= FUNC_PLAY_SOUND && func <= FUNC_PLAY_VALUE)
67 #define IS_PLAY_FUNC(func) ((func) == FUNC_PLAY_SOUND)
71 #define IS_PLAY_BOTH_FUNC(func) (0)
72 #define IS_VOLUME_FUNC(func) ((func) == FUNC_VOLUME)
74 #define IS_PLAY_BOTH_FUNC(func) ((func) == FUNC_PLAY_BOTH)
75 #define IS_VOLUME_FUNC(func) (0)
79 #define IS_ADJUST_GV_FUNC(func) ((func) == FUNC_ADJUST_GVAR)
81 #define IS_ADJUST_GV_FUNC(func) (0)
85 #define IS_HAPTIC_FUNC(func) ((func) == FUNC_HAPTIC)
87 #define IS_HAPTIC_FUNC(func) (0)
90 #define HAS_ENABLE_PARAM(func) ((func) < FUNC_FIRST_WITHOUT_ENABLE)
91 #define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func))
94 #define CFN_EMPTY(p) (!(p)->swtch)
95 #define CFN_SWITCH(p) ((p)->swtch)
96 #define CFN_FUNC(p) ((p)->func)
97 #define CFN_ACTIVE(p) ((p)->active)
98 #define CFN_CH_INDEX(p) ((p)->all.param)
99 #define CFN_GVAR_INDEX(p) ((p)->all.param)
100 #define CFN_TIMER_INDEX(p) ((p)->all.param)
101 #define CFN_PLAY_REPEAT(p) ((p)->active)
102 #define CFN_PLAY_REPEAT_MUL 1
103 #define CFN_PLAY_REPEAT_NOSTART 0xFF
104 #define CFN_GVAR_MODE(p) ((p)->all.mode)
105 #define CFN_PARAM(p) ((p)->all.val)
106 #define CFN_RESET(p) ((p)->active=0, (p)->clear.val1=0, (p)->clear.val2=0)
107 #define CFN_GVAR_CST_MIN -GVAR_MAX
108 #define CFN_GVAR_CST_MAX GVAR_MAX
109 #elif defined(CPUM2560)
110 #define CFN_SWITCH(p) ((p)->swtch)
111 #define CFN_FUNC(p) ((p)->func)
112 #define CFN_ACTIVE(p) ((p)->active)
113 #define CFN_CH_INDEX(p) ((p)->param)
114 #define CFN_TIMER_INDEX(p) ((p)->param)
115 #define CFN_GVAR_INDEX(p) ((p)->param)
116 #define CFN_PLAY_REPEAT(p) ((p)->param)
117 #define CFN_PLAY_REPEAT_MUL 10
118 #define CFN_GVAR_MODE(p) ((p)->mode)
119 #define CFN_PARAM(p) ((p)->value)
120 #define CFN_RESET(p) ((p)->active = 0, CFN_PARAM(p) = 0)
121 #define CFN_GVAR_CST_MAX 125
123 #define CFN_SWITCH(p) ((p)->all.swtch)
124 #define CFN_FUNC(p) ((p)->all.func)
125 #define CFN_ACTIVE(p) ((p)->all.active)
126 #define CFN_CH_INDEX(p) ((p)->all.param)
127 #define CFN_TIMER_INDEX(p) ((p)->all.param)
128 #define CFN_GVAR_INDEX(p) ((p)->gvar.param)
129 #define CFN_PLAY_REPEAT(p) ((p)->all.param)
130 #define CFN_PLAY_REPEAT_MUL 10
131 #define CFN_GVAR_MODE(p) ((p)->gvar.mode)
132 #define CFN_PARAM(p) ((p)->value)
133 #define CFN_RESET(p) ((p)->all.active = 0, CFN_PARAM(p) = 0)
134 #define CFN_GVAR_CST_MAX 125
137 #if defined(PCBTARANIS) || defined(PCBHORUS) || defined(PCBFLAMENCO)
154 #define SWITCH_CONFIG(x) ((g_eeGeneral.switchConfig >> (2*(x))) & 0x03)
155 #define SWITCH_EXISTS(x) (SWITCH_CONFIG(x) != SWITCH_NONE)
156 #define IS_CONFIG_3POS(x) (SWITCH_CONFIG(x) == SWITCH_3POS)
157 #define IS_CONFIG_TOGGLE(x) (SWITCH_CONFIG(x) == SWITCH_TOGGLE)
158 #define SWITCH_WARNING_ALLOWED(x) (SWITCH_EXISTS(x) && !IS_CONFIG_TOGGLE(x))
160 #define IS_CONFIG_3POS(x) IS_3POS(x)
161 #define IS_CONFIG_TOGGLE(x) IS_TOGGLE(x)
162 #define switchInfo(x) ((x) >= 3 ? (x)-2 : 0)
163 #define SWITCH_EXISTS(x) true
166 #define ALTERNATE_VIEW 0x10
168 #if defined(PCBHORUS)
176 #define SWITCHES_DELAY() uint8_t(15+g_eeGeneral.switchesDelay)
177 #define SWITCHES_DELAY_NONE (-15)
178 #define HAPTIC_STRENGTH() (3+g_eeGeneral.hapticStrength)
188 #define MODE_DIFFERENTIAL 0
194 #define MIN_EXPO_WEIGHT -100
195 #define EXPO_VALID(ed) ((ed)->mode)
196 #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2)))
197 #elif defined(CPUM2560) || defined(CPUM2561)
198 #define MIN_EXPO_WEIGHT 0
199 #define EXPO_VALID(ed) ((ed)->mode)
200 #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2)))
202 #define MIN_EXPO_WEIGHT 0
203 #define EXPO_VALID(ed) ((ed)->mode)
204 #define EXPO_MODE_ENABLE(ed, v) (((v)<0 && ((ed)->mode&1)) || ((v)>=0 && ((ed)->mode&2)))
208 #define limit_min_max_t int16_t
209 #define LIMIT_EXT_PERCENT 150
210 #define LIMIT_EXT_MAX (LIMIT_EXT_PERCENT*10)
211 #define PPM_CENTER_MAX 500
212 #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)
213 #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)
214 #define LIMIT_OFS(lim) (GV_IS_GV_VALUE(lim->offset, -1000, 1000) ? GET_GVAR_PREC1(lim->offset, -1000, 1000, mixerCurrentFlightMode) : lim->offset)
215 #define LIMIT_MAX_RESX(lim) calc1000toRESX(LIMIT_MAX(lim))
216 #define LIMIT_MIN_RESX(lim) calc1000toRESX(LIMIT_MIN(lim))
217 #define LIMIT_OFS_RESX(lim) calc1000toRESX(LIMIT_OFS(lim))
219 #define limit_min_max_t int8_t
220 #define LIMIT_EXT_PERCENT 125
221 #define LIMIT_EXT_MAX LIMIT_EXT_PERCENT
222 #define PPM_CENTER_MAX 125
223 #define LIMIT_MAX(lim) (lim->max+100)
224 #define LIMIT_MIN(lim) (lim->min-100)
225 #define LIMIT_OFS(lim) (lim->offset)
226 #define LIMIT_MAX_RESX(lim) calc100toRESX(LIMIT_MAX(lim))
227 #define LIMIT_MIN_RESX(lim) calc100toRESX(LIMIT_MIN(lim))
228 #define LIMIT_OFS_RESX(lim) calc1000toRESX(LIMIT_OFS(lim))
233 #define TRIM_RUD (-1)
234 #define TRIM_ELE (-2)
235 #define TRIM_THR (-3)
236 #define TRIM_AIL (-4)
237 #if defined(PCBHORUS)
240 #define TRIM_LAST TRIM_T6
242 #define TRIM_LAST TRIM_AIL
250 #define GV1_SMALL 128
251 #define GV1_LARGE 1024
252 #define GV_RANGE_WEIGHT 500
253 #define GV_RANGE_OFFSET 500
254 #define DELAY_STEP 10
256 #define DELAY_MAX (25*DELAY_STEP) /* 25 seconds */
257 #define SLOW_MAX (25*SLOW_STEP) /* 25 seconds */
259 #define MD_WEIGHT(md) (md->weight)
260 #define MD_WEIGHT_TO_UNION(md, var) var.word = md->weight
261 #define MD_UNION_TO_WEIGHT(var, md) md->weight = var.word
263 #define MD_OFFSET(md) (md->offset)
264 #define MD_OFFSET_TO_UNION(md, var) var.word = md->offset
265 #define MD_UNION_TO_OFFSET(var, md) md->offset = var.word
266 // #define MD_SETOFFSET(md, val) md->offset = val
270 // highest bit used for small values in mix 128 --> 8 bit is enough
271 #define GV1_SMALL 128
272 // highest bit used for large values in mix 256 --> 9 bits is used (8 bits + 1 extra bit from weightMode/offsetMode)
273 #define GV1_LARGE 256
277 #define DELAY_MAX 15 /* 7.5 seconds */
278 #define SLOW_MAX 15 /* 7.5 seconds */
280 PACK(union u_gvarint_t
{
287 u_gvarint_t(int8_t l
, uint8_t h
) {bytes_t
.lo
=l
; bytes_t
.hi
=h
?255:0;} // hi bit is negativ sign
290 // prevent unwanted constructors, also saves program
292 u_gvarint_t(const u_gvarint_t
&) {}
294 #define MD_WEIGHT(md) (u_gvarint_t(md->weight,md->weightMode).word)
296 #define MD_WEIGHT_TO_UNION(md, var) var.bytes_t.lo=md->weight; var.bytes_t.hi=md->weightMode?255:0
297 #define MD_UNION_TO_WEIGHT(var, md) md->weight=var.bytes_t.lo; if (var.word<0) md->weightMode=1; else md->weightMode=0
298 // #define MD_SETWEIGHT(md, val) md->weight=val; if (val<0) md->weightMode=1; else md->weightMode=0
300 #define MD_OFFSET(md) (u_gvarint_t(md->offset,md->offsetMode).word)
301 #define MD_OFFSET_TO_UNION(md, var) var.bytes_t.lo=md->offset; var.bytes_t.hi=md->offsetMode?255:0
302 #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 */
303 // #define MD_SETOFFSET(md, val) md->offset=val; if (val<0) md->offsetMode=1; else md->offsetMode=0
307 enum LogicalSwitchesFunctions
{
310 LS_FUNC_VEQUAL
, // v==offset
312 LS_FUNC_VALMOSTEQUAL
, // v~=offset
313 LS_FUNC_VPOS
, // v>offset
314 LS_FUNC_VNEG
, // v<offset
318 LS_FUNC_APOS
, // |v|>offset
319 LS_FUNC_ANEG
, // |v|<offset
329 LS_FUNC_DIFFEGREATER
,
330 LS_FUNC_ADIFFEGREATER
,
334 LS_FUNC_MAX
= LS_FUNC_COUNT
-1
338 #define MAX_LS_DURATION 250 /*25s*/
339 #define MAX_LS_DELAY 250 /*25s*/
340 #define MAX_LS_ANDSW SWSRC_LAST
342 #define MAX_LS_ANDSW 15
346 //#define TELEM_FLAG_TIMEOUT 0x01
347 #define TELEM_FLAG_LOG 0x02
348 //#define TELEM_FLAG_PERSISTENT 0x04
349 //#define TELEM_FLAG_SCALE 0x08
350 #define TELEM_FLAG_AUTO_OFFSET 0x10
351 #define TELEM_FLAG_FILTER 0x20
352 #define TELEM_FLAG_LOSS_ALARM 0x40
354 enum TelemetrySensorType
357 TELEM_TYPE_CALCULATED
360 enum TelemetrySensorFormula
363 TELEM_FORMULA_AVERAGE
,
366 TELEM_FORMULA_MULTIPLY
,
367 TELEM_FORMULA_TOTALIZE
,
369 TELEM_FORMULA_CONSUMPTION
,
371 TELEM_FORMULA_LAST
= TELEM_FORMULA_DIST
376 #if !defined(TELEMETRY_FRSKY_SPORT)
378 VARIO_SOURCE_ALTI_PLUS
,
383 #if defined(TELEMETRY_FRSKY_SPORT)
387 VARIO_SOURCE_LAST
= VARIO_SOURCE_COUNT
-1
390 enum FrskyUsrProtocols
{
393 USR_PROTO_WS_HOW_HIGH
,
394 USR_PROTO_LAST
= USR_PROTO_WS_HOW_HIGH
,
397 enum FrskyCurrentSource
{
398 FRSKY_CURRENT_SOURCE_NONE
,
399 FRSKY_CURRENT_SOURCE_A1
,
400 FRSKY_CURRENT_SOURCE_A2
,
402 FRSKY_CURRENT_SOURCE_A3
,
403 FRSKY_CURRENT_SOURCE_A4
,
405 FRSKY_CURRENT_SOURCE_FAS
,
406 FRSKY_CURRENT_SOURCE_LAST
=FRSKY_CURRENT_SOURCE_FAS
409 enum FrskyVoltsSource
{
410 FRSKY_VOLTS_SOURCE_A1
,
411 FRSKY_VOLTS_SOURCE_A2
,
413 FRSKY_VOLTS_SOURCE_A3
,
414 FRSKY_VOLTS_SOURCE_A4
,
416 FRSKY_VOLTS_SOURCE_FAS
,
417 FRSKY_VOLTS_SOURCE_CELLS
,
418 FRSKY_VOLTS_SOURCE_LAST
=FRSKY_VOLTS_SOURCE_CELLS
429 SWASH_TYPE_MAX
= SWASH_TYPE_90
432 #define TRIM_EXTENDED_MAX 500
433 #define TRIM_EXTENDED_MIN (-TRIM_EXTENDED_MAX)
435 #define TRIM_MIN (-TRIM_MAX)
437 #define ROTARY_ENCODER_MAX 1024
440 #define TRIMS_ARRAY_SIZE 5
442 #define TRIMS_ARRAY_SIZE 8
444 #define TRIM_MODE_NONE 0x1F // 0b11111
449 #define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2)
450 #elif defined(CPUM2560)
451 #define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2)
453 #define IS_MANUAL_RESET_TIMER(idx) 0
456 #if defined(CPUARM) && !defined(PCBSKY9X)
457 #define TIMER_COUNTDOWN_START(x) (g_model.timers[x].countdownStart > 0 ? 5 : 10 - g_model.timers[x].countdownStart * 10)
459 #define TIMER_COUNTDOWN_START(x) 10
468 #if defined(PXX) || defined(DSM2) || defined(IRPROTOS)
471 #if defined(DSM2) || defined(IRPROTOS)
476 #if defined(CROSSFIRE) || defined(MULTIMODULE)
479 #if defined(IRPROTOS)
481 // we will need 4 bits for proto :(
487 #if defined(MULTIMODULE)
494 enum XJTRFProtocols
{
499 RF_PROTO_LAST
= RF_PROTO_LR12
502 enum MultiModuleRFProtocols
{
503 MM_RF_PROTO_CUSTOM
= -1,
504 MM_RF_PROTO_FIRST
= MM_RF_PROTO_CUSTOM
,
505 MM_RF_PROTO_FLYSKY
=0,
530 MM_RF_PROTO_FS_AFHDS2A
,
536 MM_RF_PROTO_LAST
= MM_RF_PROTO_DM002
539 enum MMDSM2Subtypes
{
540 MM_RF_DSM2_SUBTYPE_DSM2_22
,
541 MM_RF_DSM2_SUBTYPE_DSM2_11
,
542 MM_RF_DSM2_SUBTYPE_DSMX_22
,
543 MM_RF_DSM2_SUBTYPE_DSMX_11
,
544 MM_RF_DSM2_SUBTYPE_AUTO
547 enum MMRFrskySubtypes
{
548 MM_RF_FRSKY_SUBTYPE_D16
,
549 MM_RF_FRSKY_SUBTYPE_D8
,
550 MM_RF_FRSKY_SUBTYPE_D16_8CH
,
551 MM_RF_FRSKY_SUBTYPE_V8
,
552 MM_RF_FRSKY_SUBTYPE_D16_LBT
,
553 MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH
556 #define HAS_RF_PROTOCOL_FAILSAFE(rf) ((rf) == RF_PROTO_X16)
557 #define HAS_RF_PROTOCOL_MODELINDEX(rf) (((rf) == RF_PROTO_X16) || ((rf) == RF_PROTO_LR12))
566 MODULE_TYPE_NONE
= 0,
570 MODULE_TYPE_CROSSFIRE
,
571 MODULE_TYPE_MULTIMODULE
,
577 XJT_INTERNAL_ANTENNA
,
587 FAILSAFE_LAST
= FAILSAFE_RECEIVER
590 enum ThrottleSources
{
592 THROTTLE_SOURCE_FIRST_POT
,
593 #if defined(PCBFLAMENCO)
597 #elif defined(PCBX9E)
598 THROTTLE_SOURCE_F1
= THROTTLE_SOURCE_FIRST_POT
,
606 #elif defined(PCBTARANIS)
607 THROTTLE_SOURCE_S1
= THROTTLE_SOURCE_FIRST_POT
,
613 THROTTLE_SOURCE_P1
= THROTTLE_SOURCE_FIRST_POT
,
622 PROTOCOL_TELEMETRY_FIRST
,
623 PROTOCOL_FRSKY_SPORT
= PROTOCOL_TELEMETRY_FIRST
,
625 PROTOCOL_FRSKY_D_SECONDARY
,
626 PROTOCOL_PULSES_CROSSFIRE
,
628 PROTOCOL_FLYSKY_IBUS
,
629 PROTOCOL_MULTIMODULE
,
630 PROTOCOL_TELEMETRY_LAST
=PROTOCOL_MULTIMODULE
636 DISPLAY_TRIMS_CHANGE
,
640 #define TOTAL_EEPROM_USAGE (sizeof(ModelData)*MAX_MODELS + sizeof(RadioData))
642 extern RadioData g_eeGeneral
;
643 extern ModelData g_model
;
645 PACK(union u_int8int16_t
{
653 #endif // _MYEEPROM_H_