From d64989baac424bd6c52a58b8158bda8ea5472b31 Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 27 Nov 2014 23:09:14 +0100 Subject: [PATCH] All X9E switches now working --- radio/src/gui/menu_general.cpp | 35 ++- radio/src/gui/menu_model.cpp | 15 +- radio/src/gui/menus.cpp | 14 +- radio/src/gui/view_main.cpp | 10 + radio/src/keys.h | 39 +++ radio/src/lcd_common.cpp | 24 +- radio/src/mixer.cpp | 18 ++ radio/src/myeeprom.h | 87 ++++++- radio/src/opentx.h | 16 +- radio/src/switches.cpp | 27 ++ radio/src/targets/simu/simpgmspace.cpp | 13 +- radio/src/targets/simu/simpgmspace.h | 14 +- radio/src/targets/taranis/hal.h | 202 +++++++++------ radio/src/targets/taranis/keys_driver.cpp | 287 ++++++++++------------ radio/src/translations/en.h.txt | 14 +- 15 files changed, 520 insertions(+), 295 deletions(-) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index 7375b10d2..d96e15438 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1388,6 +1388,10 @@ enum menuGeneralHwItems { ITEM_SETUP_HW_SL, ITEM_SETUP_HW_SM, ITEM_SETUP_HW_SN, + CASE_REV9E(ITEM_SETUP_HW_SO) + CASE_REV9E(ITEM_SETUP_HW_SP) + CASE_REV9E(ITEM_SETUP_HW_SQ) + CASE_REV9E(ITEM_SETUP_HW_SR) ITEM_SETUP_HW_UART3_MODE, ITEM_SETUP_HW_MAX }; @@ -1400,11 +1404,16 @@ enum menuGeneralHwItems { #define POTS_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, 0, 0 #endif -#define SWITCH_ROWS(x) uint8_t(IS_2x2POS(x) ? 0 : HIDDEN_ROW) +#if defined(REV9E) + #define SWITCHES_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1 +#else + #define SWITCH_ROWS(x) uint8_t(IS_2x2POS(x) ? 0 : HIDDEN_ROW) + #define SWITCHES_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, SWITCH_ROWS(0), SWITCH_ROWS(1), SWITCH_ROWS(2), SWITCH_ROWS(3), SWITCH_ROWS(4), SWITCH_ROWS(6) +#endif void menuGeneralHardware(uint8_t event) { - MENU(STR_HARDWARE, menuTabGeneral, e_Hardware, ITEM_SETUP_HW_MAX+1, {0, LABEL(Sticks), 0, 0, 0, 0, LABEL(Pots), POTS_ROWS, LABEL(Switches), NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, SWITCH_ROWS(0), SWITCH_ROWS(1), SWITCH_ROWS(2), SWITCH_ROWS(3), SWITCH_ROWS(4), SWITCH_ROWS(6), 0}); + MENU(STR_HARDWARE, menuTabGeneral, e_Hardware, ITEM_SETUP_HW_MAX+1, {0, LABEL(Sticks), 0, 0, 0, 0, LABEL(Pots), POTS_ROWS, LABEL(Switches), SWITCHES_ROWS, 0}); uint8_t sub = m_posVert - 1; @@ -1480,23 +1489,39 @@ void menuGeneralHardware(uint8_t event) case ITEM_SETUP_HW_SL: case ITEM_SETUP_HW_SM: case ITEM_SETUP_HW_SN: +#if defined(REV9E) + case ITEM_SETUP_HW_SO: + case ITEM_SETUP_HW_SP: + case ITEM_SETUP_HW_SQ: + case ITEM_SETUP_HW_SR: +#endif { int index = k-ITEM_SETUP_HW_SA; char label[] = INDENT "S*"; label[2] = 'A' + index; - uint32_t config = SWITCH_CONFIG(index); + int config = SWITCH_CONFIG(index); lcd_putsAtt(0, y, label, m_posHorz < 0 ? attr : 0); if (ZEXIST(g_eeGeneral.switchNames[index]) || (attr && m_posHorz == 0)) editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.switchNames[index], LEN_SWITCH_NAME, event, m_posHorz == 0 ? attr : 0); else lcd_putsiAtt(HW_SETTINGS_COLUMN, y, STR_MMMINV, 0, 0); +#if defined(REV9E) + config = selectMenuItem(HW_SETTINGS_COLUMN+5*FW, y, "", "\007None\0 DefaultToggle\0""2POS\0 3POS\0", config, SWITCH_NONE, SWITCH_3POS, m_posHorz == 1 ? attr : 0, event); + if (attr && checkIncDec_Ret) { + uint32_t mask = 0x0f << (4*index); + TRACE("avant %x", g_eeGeneral.switchConfig); + g_eeGeneral.switchConfig = (g_eeGeneral.switchConfig & ~mask) | ((uint32_t(config)&0xf) << (4*index)); + TRACE("apres %x", g_eeGeneral.switchConfig); + } +#else if (k <= ITEM_SETUP_HW_SH) { - config = selectMenuItem(HW_SETTINGS_COLUMN+5*FW, y, "", "\007DefaultToggle\0""2POS\0 3POS\0 2x2POS\0", config, 0, 4, m_posHorz == 1 ? attr : 0, event); + config = selectMenuItem(HW_SETTINGS_COLUMN+5*FW, y, "", "\007DefaultToggle\0""2POS\0 3POS\0 2x2POS\0", config, SWITCH_NONE, SWITCH_2x2POS, m_posHorz == 1 ? attr : 0, event); if (attr && checkIncDec_Ret) { uint32_t mask = 0x0f << (4*index); - g_eeGeneral.switchConfig = (g_eeGeneral.switchConfig & ~mask) | (config << (4*index)); + g_eeGeneral.switchConfig = (g_eeGeneral.switchConfig & ~mask) | (((uint32_t)(config)&0xf) << (4*index)); } } +#endif break; } case ITEM_SETUP_HW_UART3_MODE: diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 16767f450..3f897e6d3 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -3056,7 +3056,7 @@ enum ExposFields { CASE_PCBTARANIS(EXPO_FIELD_OFFSET) CASE_9X(EXPO_FIELD_EXPO) CASE_CURVES(EXPO_FIELD_CURVE) - CASE_FLIGHT_MODES(EXPO_FIELD_FLIGHT_PHASE) + CASE_FLIGHT_MODES(EXPO_FIELD_FLIGHT_MODES) EXPO_FIELD_SWITCH, EXPO_FIELD_SIDE, CASE_PCBTARANIS(EXPO_FIELD_TRIM) @@ -3094,11 +3094,12 @@ void menuModelExpoOne(uint8_t event) coord_t y = MENU_TITLE_HEIGHT + 1; #if defined(PCBTARANIS) - for (uint8_t k=0; kflightModes = editFlightModes(EXPO_ONE_2ND_COLUMN-IF_9X(EXPO_ONE_FP_WIDTH), y, event, ed->flightModes, attr); break; #endif diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 92ca4f769..dfc108221 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -1484,9 +1484,13 @@ enum SwitchContext bool isSwitchAvailable(int swtch, SwitchContext context) { +#if defined(PCBTARANIS) + uint32_t index = switchInfo(abs(swtch)).quot; +#endif + if (swtch < 0) { #if defined(PCBTARANIS) - if (swtch == -SWSRC_SF0 || swtch == -SWSRC_SF2 || swtch == -SWSRC_SH0 || swtch == -SWSRC_SH2) + if (!IS_3POS(index)) return false; #endif if (swtch == -SWSRC_ON || swtch == -SWSRC_One) { @@ -1495,9 +1499,13 @@ bool isSwitchAvailable(int swtch, SwitchContext context) swtch = -swtch; } -#if defined(PCBTARANIS) +#if defined(PCBTARANIS) && defined(REV9E) + if (swtch >= SWSRC_SA1 && swtch <= SWSRC_SR1 && (swtch-SWSRC_SA1)%3 == 0) { + return IS_3POS(index); + } +#elif defined(PCBTARANIS) if (swtch == SWSRC_SA1 || swtch == SWSRC_SB1 || swtch == SWSRC_SC1 || swtch == SWSRC_SD1 || swtch == SWSRC_SE1 || swtch == SWSRC_SG1) { - return IS_3POS((swtch-SWSRC_SA0)/3); + return IS_3POS(index); } if (swtch >= SWSRC_SI0 && swtch <= SWSRC_SM2) { return IS_2x2POS((swtch-SWSRC_SI0)/2); diff --git a/radio/src/gui/view_main.cpp b/radio/src/gui/view_main.cpp index 144d40e2c..5ac8e94da 100644 --- a/radio/src/gui/view_main.cpp +++ b/radio/src/gui/view_main.cpp @@ -717,6 +717,15 @@ void menuMainView(uint8_t event) lcd_bmp(BITMAP_X, BITMAP_Y, modelBitmap); // Switches +#if defined(REV9E) + for (uint8_t i=0; i<8; i++) { + getvalue_t sw; + getvalue_t val; + val = getValue(MIXSRC_SA+i); + sw = ((val < 0) ? 3*i+1 : ((val == 0) ? 3*i+2 : 3*i+3)); + putsSwitches((g_eeGeneral.view == VIEW_INPUTS) ? (i<4 ? 8*FW+3 : 24*FW+1) : (i<4 ? 3*FW+2 : 8*FW-1), (i%4)*FH+3*FH, sw, 0); + } +#else for (uint8_t i=0; i<8; i++) { getvalue_t sw; getvalue_t val; @@ -741,6 +750,7 @@ void menuMainView(uint8_t event) } putsSwitches((g_eeGeneral.view == VIEW_INPUTS) ? (i<4 ? 8*FW+3 : 24*FW+1) : (i<4 ? 3*FW+2 : 8*FW-1), (i%4)*FH+3*FH, sw, 0); } +#endif if (g_eeGeneral.view == VIEW_TIMERS) { displayTimers(); diff --git a/radio/src/keys.h b/radio/src/keys.h index 11a87a29e..30318b9ba 100644 --- a/radio/src/keys.h +++ b/radio/src/keys.h @@ -89,12 +89,50 @@ enum EnumKeys { SW_SE1, SW_SE2, SW_SF0, +#if defined(REV9E) + SW_SF1, +#endif SW_SF2, SW_SG0, SW_SG1, SW_SG2, SW_SH0, +#if defined(REV9E) + SW_SH1, +#endif SW_SH2, +#if defined(REV9E) + SW_SI0, + SW_SI1, + SW_SI2, + SW_SJ0, + SW_SJ1, + SW_SJ2, + SW_SK0, + SW_SK1, + SW_SK2, + SW_SL0, + SW_SL1, + SW_SL2, + SW_SM0, + SW_SM1, + SW_SM2, + SW_SN0, + SW_SN1, + SW_SN2, + SW_SO0, + SW_SO1, + SW_SO2, + SW_SP0, + SW_SP1, + SW_SP2, + SW_SQ0, + SW_SQ1, + SW_SQ2, + SW_SR0, + SW_SR1, + SW_SR2, +#else SW_SI0, SW_SI2, SW_SJ0, @@ -107,6 +145,7 @@ enum EnumKeys { SW_SM2, SW_SN0, SW_SN2, +#endif #else SW_ID0=SW_BASE, SW_ID1, diff --git a/radio/src/lcd_common.cpp b/radio/src/lcd_common.cpp index d599175fc..19a85caea 100644 --- a/radio/src/lcd_common.cpp +++ b/radio/src/lcd_common.cpp @@ -808,28 +808,6 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att) } } -#if defined(PCBTARANIS) -div_t switchInfo(int switchPosition) -{ - if (switchPosition <= SWSRC_SE2) { - return div(switchPosition-SWSRC_SA0, 3); - } - else if (switchPosition <= SWSRC_SF2) { - div_t qr = { 5, switchPosition == SWSRC_SF2 ? 2 : 0 }; - return qr; - } - else if (switchPosition <= SWSRC_SG2) { - div_t qr = { 6, switchPosition-SWSRC_SG0 }; - return qr; - } - else { - div_t qr = div(2*7+switchPosition-SWSRC_SH0, 2); - qr.rem *= 2; - return qr; - } -} -#endif - void putsSwitches(coord_t x, coord_t y, int8_t idx, LcdFlags att) { if (idx == SWSRC_OFF) @@ -844,7 +822,7 @@ void putsSwitches(coord_t x, coord_t y, int8_t idx, LcdFlags att) } #endif #if defined(PCBTARANIS) - if (idx >= SWSRC_SA0 && idx <= SWSRC_SN2) { + if (idx >= SWSRC_FIRST_SWITCH && idx <= SWSRC_LAST_SWITCH) { div_t swinfo = switchInfo(idx); if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) { lcd_putsnAtt(x, y, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME, ZCHAR|att); diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index 06bb62ac7..cd81f54c1 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -307,8 +307,25 @@ getvalue_t getValue(mixsrc_t i) else if (i==MIXSRC_SC) return (switchState(SW_SC0) ? -1024 : (switchState(SW_SC1) ? 0 : 1024)); else if (i==MIXSRC_SD) return (switchState(SW_SD0) ? -1024 : (switchState(SW_SD1) ? 0 : 1024)); else if (i==MIXSRC_SE) return (switchState(SW_SE0) ? -1024 : (switchState(SW_SE1) ? 0 : 1024)); +#if defined(REV9E) + else if (i==MIXSRC_SF) return (switchState(SW_SF0) ? -1024 : (switchState(SW_SF1) ? 0 : 1024)); +#else else if (i==MIXSRC_SF) return (switchState(SW_SF0) ? -1024 : 1024); +#endif else if (i==MIXSRC_SG) return (switchState(SW_SG0) ? -1024 : (switchState(SW_SG1) ? 0 : 1024)); +#if defined(REV9E) + else if (i==MIXSRC_SH) return (switchState(SW_SH0) ? -1024 : (switchState(SW_SH1) ? 0 : 1024)); + else if (i==MIXSRC_SI) return (switchState(SW_SI0) ? -1024 : (switchState(SW_SI1) ? 0 : 1024)); + else if (i==MIXSRC_SJ) return (switchState(SW_SJ0) ? -1024 : (switchState(SW_SJ1) ? 0 : 1024)); + else if (i==MIXSRC_SK) return (switchState(SW_SK0) ? -1024 : (switchState(SW_SK1) ? 0 : 1024)); + else if (i==MIXSRC_SL) return (switchState(SW_SL0) ? -1024 : (switchState(SW_SL1) ? 0 : 1024)); + else if (i==MIXSRC_SM) return (switchState(SW_SM0) ? -1024 : (switchState(SW_SM1) ? 0 : 1024)); + else if (i==MIXSRC_SN) return (switchState(SW_SN0) ? -1024 : (switchState(SW_SN1) ? 0 : 1024)); + else if (i==MIXSRC_SO) return (switchState(SW_SO0) ? -1024 : (switchState(SW_SO1) ? 0 : 1024)); + else if (i==MIXSRC_SP) return (switchState(SW_SP0) ? -1024 : (switchState(SW_SP1) ? 0 : 1024)); + else if (i==MIXSRC_SQ) return (switchState(SW_SQ0) ? -1024 : (switchState(SW_SQ1) ? 0 : 1024)); + else if (i==MIXSRC_SR) return (switchState(SW_SR0) ? -1024 : (switchState(SW_SR1) ? 0 : 1024)); +#else else if (i==MIXSRC_SH) return (switchState(SW_SH0) ? -1024 : 1024); else if (i==MIXSRC_SI) return (switchState(SW_SI0) ? -1024 : 1024); else if (i==MIXSRC_SJ) return (switchState(SW_SJ0) ? -1024 : 1024); @@ -316,6 +333,7 @@ getvalue_t getValue(mixsrc_t i) else if (i==MIXSRC_SL) return (switchState(SW_SL0) ? -1024 : 1024); else if (i==MIXSRC_SM) return (switchState(SW_SM0) ? -1024 : 1024); else if (i==MIXSRC_SN) return (switchState(SW_SN0) ? -1024 : 1024); +#endif #else else if (i==MIXSRC_3POS) return (getSwitch(SW_ID0-SW_BASE+1) ? -1024 : (getSwitch(SW_ID1-SW_BASE+1) ? 0 : 1024)); // don't use switchState directly to give getSwitch possibility to hack values if needed for switch warning diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 9b3abed75..1947e109c 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -627,11 +627,14 @@ PACK(typedef struct { #endif enum SwitchConfig { + SWITCH_NONE = -1, SWITCH_DEFAULT, SWITCH_TOGGLE, SWITCH_2POS, SWITCH_3POS, +#if !defined(REV9E) SWITCH_2x2POS +#endif }; #define LEN_SWITCH_NAME 3 @@ -695,19 +698,37 @@ PACK(typedef struct t_EEGeneral { }) EEGeneral; -#define SWITCHES_DELAY() uint8_t(15+g_eeGeneral.switchesDelay) -#define SWITCHES_DELAY_NONE (-15) -#define HAPTIC_STRENGTH() (3+g_eeGeneral.hapticStrength) +#define SWITCHES_DELAY() uint8_t(15+g_eeGeneral.switchesDelay) +#define SWITCHES_DELAY_NONE (-15) +#define HAPTIC_STRENGTH() (3+g_eeGeneral.hapticStrength) #if defined(PCBTARANIS) -#define SWITCH_CONFIG(x) ((g_eeGeneral.switchConfig >> (4*(x))) & 0x0f) -#define SWITCH_DEFAULT_CONFIG(x) ((x)==5 ? SWITCH_2POS : ((x)==7 ? SWITCH_TOGGLE : SWITCH_3POS)) +PACK(union SwitchConfig4bits { + SwitchConfig4bits(uint8_t val): + word(val) + { + } + struct { + int8_t val:4; + int8_t spare:4; + }; + uint8_t word; +}); +#define SWITCH_CONFIG(x) SwitchConfig4bits((g_eeGeneral.switchConfig >> (4*(x))) & 0x0f).val int switchConfig(int idx); -#define IS_3POS(x) (switchConfig(x) == SWITCH_3POS) -#define IS_2x2POS(x) (switchConfig(x) == SWITCH_2x2POS) -#define ONE_2x2POS_DEFINED() (g_eeGeneral.switchConfig & 0x44444444) -#define IS_TOGGLE(x) (switchConfig(x) == SWITCH_TOGGLE) -#define SWITCH_WARNING_ALLOWED(x) (x<8 ? !IS_TOGGLE(x) : IS_2x2POS(x-8)) +#define IS_3POS(x) (switchConfig(x) == SWITCH_3POS) +#define IS_TOGGLE(x) (switchConfig(x) == SWITCH_TOGGLE) +#if defined(REV9E) + #define SWITCH_DEFAULT_CONFIG(x) (SWITCH_3POS) + #define IS_2x2POS(x) (false) + #define ONE_2x2POS_DEFINED() (false) + #define SWITCH_WARNING_ALLOWED(x) (!IS_TOGGLE(x)) +#else + #define SWITCH_DEFAULT_CONFIG(x) ((x)==5 ? SWITCH_2POS : ((x)==7 ? SWITCH_TOGGLE : SWITCH_3POS)) + #define IS_2x2POS(x) (switchConfig(x) == SWITCH_2x2POS) + #define ONE_2x2POS_DEFINED() (g_eeGeneral.switchConfig & 0x44444444) + #define SWITCH_WARNING_ALLOWED(x) (x<8 ? !IS_TOGGLE(x) : IS_2x2POS(x-8)) +#endif inline int getSwitchWarningsAllowed() { int count = 0; @@ -1563,13 +1584,52 @@ enum SwitchSources { SWSRC_SE1, SWSRC_SE2, SWSRC_SF0, +#if defined(REV9E) + SWSRC_SF1, +#endif SWSRC_SF2, SWSRC_SG0, SWSRC_SG1, SWSRC_SG2, SWSRC_SH0, +#if defined(REV9E) + SWSRC_SH1, +#endif 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_SI0, SWSRC_SI2, SWSRC_SJ0, @@ -1583,6 +1643,7 @@ enum SwitchSources { SWSRC_SN0, SWSRC_SN2, SWSRC_LAST_SWITCH = SWSRC_SN2, +#endif #else SWSRC_ID0 = SWSRC_FIRST_SWITCH, SWSRC_ID1, @@ -1741,6 +1802,12 @@ enum MixSources { MIXSRC_SL, LUA_EXPORT("sl", "Switch L") MIXSRC_SM, LUA_EXPORT("sm", "Switch M") MIXSRC_SN, LUA_EXPORT("sn", "Switch N") +#if defined(REV9E) + MIXSRC_SO, LUA_EXPORT("so", "Switch O") + MIXSRC_SP, LUA_EXPORT("sp", "Switch P") + MIXSRC_SQ, LUA_EXPORT("sq", "Switch Q") + MIXSRC_SR, LUA_EXPORT("sr", "Switch R") +#endif #else MIXSRC_3POS = MIXSRC_FIRST_SWITCH, MIXSRC_THR, diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 0154ce867..04f173368 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -222,6 +222,12 @@ #define CASE_REVPLUS(x) #endif +#if defined(PCBTARANIS) && defined(REV9E) + #define CASE_REV9E(x) x, +#else + #define CASE_REV9E(x) +#endif + #if ROTARY_ENCODERS > 0 #define ROTARY_ENCODER_NAVIGATION #endif @@ -316,7 +322,11 @@ extern void boardInit(); #endif #if defined(PCBTARANIS) - #define NUM_SWITCHES 14 // 8 physical switches + 6 possible from 3POS + #if defined(REV9E) + #define NUM_SWITCHES 18 // yes, it's a lot! + #else + #define NUM_SWITCHES 14 // 8 physical switches + 6 possible from 3POS + #endif #define NUM_SW_SRCRAW 8 #define SWSRC_THR SWSRC_SF2 #define SWSRC_GEA SWSRC_SG2 @@ -643,6 +653,10 @@ int zchar2str(char *dest, const char *src, int size); #include "keys.h" #include "pwr.h" +#if defined(PCBTARANIS) +div_t switchInfo(int switchPosition); +#endif + bool switchState(EnumKeys enuk); uint8_t trimDown(uint8_t idx); void readKeysAndTrims(); diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index c0750868a..44692a6fc 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -85,6 +85,33 @@ int switchConfig(int idx) return config; } +#if defined(REV9E) +div_t switchInfo(int switchPosition) +{ + return div(switchPosition-SWSRC_FIRST_SWITCH, 3); +} +#else +div_t switchInfo(int switchPosition) +{ + if (switchPosition <= SWSRC_SE2) { + return div(switchPosition-SWSRC_SA0, 3); + } + else if (switchPosition <= SWSRC_SF2) { + div_t qr = { 5, switchPosition == SWSRC_SF2 ? 2 : 0 }; + return qr; + } + else if (switchPosition <= SWSRC_SG2) { + div_t qr = { 6, switchPosition-SWSRC_SG0 }; + return qr; + } + else { + div_t qr = div(2*7+switchPosition-SWSRC_SH0, 2); + qr.rem *= 2; + return qr; + } +} +#endif + uint64_t check2PosSwitchPosition(EnumKeys sw) { uint64_t result; diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 3e717a866..cf066d600 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -55,7 +55,7 @@ FILE *fp = NULL; #if defined(PCBTARANIS) uint32_t Peri1_frequency, Peri2_frequency; -GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe; +GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog; TIM_TypeDef tim1, tim2, tim3, tim4, tim8, tim10; RCC_TypeDef rcc; DMA_Stream_TypeDef dma2_stream2, dma2_stream6; @@ -178,7 +178,16 @@ void simuSetSwitch(uint8_t swtch, int8_t state) { // printf("swtch=%d state=%d\n", swtch, state); fflush(stdout); switch (swtch) { -#if defined(PCBTARANIS) +#if defined(PCBTARANIS) && defined(REV9E) + SWITCH_3_CASE(0, GPIO_PIN_SW_A_L, GPIO_PIN_SW_A_H, PIN_SW_A_L, PIN_SW_A_H) + SWITCH_3_CASE(1, GPIO_PIN_SW_B_L, GPIO_PIN_SW_B_H, PIN_SW_B_L, PIN_SW_B_H) + SWITCH_3_CASE(2, GPIO_PIN_SW_C_L, GPIO_PIN_SW_C_H, PIN_SW_C_L, PIN_SW_C_H) + SWITCH_3_CASE(3, GPIO_PIN_SW_D_L, GPIO_PIN_SW_D_H, PIN_SW_D_L, PIN_SW_D_H) + SWITCH_3_CASE(4, GPIO_PIN_SW_E_H, GPIO_PIN_SW_E_L, PIN_SW_E_H, PIN_SW_E_L) + SWITCH_3_CASE(5, GPIO_PIN_SW_F_H, GPIO_PIN_SW_F_L, PIN_SW_F_H, PIN_SW_F_L) + SWITCH_3_CASE(6, GPIO_PIN_SW_G_L, GPIO_PIN_SW_G_H, PIN_SW_G_L, PIN_SW_G_H) + SWITCH_3_CASE(7, GPIO_PIN_SW_H_L, GPIO_PIN_SW_H_H, PIN_SW_H_H, PIN_SW_H_L) +#elif defined(PCBTARANIS) SWITCH_3_CASE(0, GPIO_PIN_SW_A_L, GPIO_PIN_SW_A_H, PIN_SW_A_L, PIN_SW_A_H) SWITCH_3_CASE(1, GPIO_PIN_SW_B_L, GPIO_PIN_SW_B_H, PIN_SW_B_L, PIN_SW_B_H) SWITCH_3_CASE(2, GPIO_PIN_SW_C_L, GPIO_PIN_SW_C_H, PIN_SW_C_L, PIN_SW_C_H) diff --git a/radio/src/targets/simu/simpgmspace.h b/radio/src/targets/simu/simpgmspace.h index 4325e92fd..1c7e00585 100644 --- a/radio/src/targets/simu/simpgmspace.h +++ b/radio/src/targets/simu/simpgmspace.h @@ -56,14 +56,14 @@ extern char * main_thread_error; #include inline void write_backtrace(char *output) { - void *buf[16]; char **s; - int n = backtrace(buf,16); + int n = backtrace(buf, 16); s = backtrace_symbols(buf, n); if (s) { - for(int i=0; iIDR #define GPIO_BUTTON_PLUS GPIOE->IDR #define GPIO_BUTTON_MINUS GPIOE->IDR #define GPIO_BUTTON_MENU GPIOD->IDR @@ -21,8 +20,10 @@ #define PIN_BUTTON_PLUS GPIO_Pin_10 // PE.10 #define PIN_BUTTON_MINUS GPIO_Pin_11 // PE.11 #if defined(REV9E) + #define GPIO_BUTTON_ENTER GPIOF->IDR #define PIN_BUTTON_ENTER GPIO_Pin_0 // PF.00 #else + #define GPIO_BUTTON_ENTER GPIOE->IDR #define PIN_BUTTON_ENTER GPIO_Pin_12 // PE.12 #endif #define PIN_BUTTON_MENU GPIO_Pin_7 // PD.07 @@ -30,35 +31,102 @@ #define PIN_BUTTON_EXIT GPIO_Pin_2 // PD.03 // Trims -#define GPIO_TRIM_LH_L GPIOE->IDR -#define GPIO_TRIM_LV_DN GPIOE->IDR -#define GPIO_TRIM_RV_UP GPIOC->IDR -#define GPIO_TRIM_RH_L GPIOC->IDR -#define GPIO_TRIM_LH_R GPIOE->IDR -#define GPIO_TRIM_LV_UP GPIOE->IDR #define GPIO_TRIM_RV_DN GPIOC->IDR -#define GPIO_TRIM_RH_R GPIOC->IDR #define PIN_TRIM_RV_DN GPIO_Pin_3 // PC.03 +#define GPIO_TRIM_RV_UP GPIOC->IDR #define PIN_TRIM_RV_UP GPIO_Pin_2 // PC.02 +#define GPIO_TRIM_RH_L GPIOC->IDR #define PIN_TRIM_RH_L GPIO_Pin_1 // PC.01 +#define GPIO_TRIM_RH_R GPIOC->IDR #define PIN_TRIM_RH_R GPIO_Pin_13 // PC.13 #if defined(REV3) - #define PIN_TRIM_LH_R GPIO_Pin_4 // PE.04 + #define GPIO_TRIM_LH_L GPIOE->IDR #define PIN_TRIM_LH_L GPIO_Pin_3 // PE.03 + #define GPIO_TRIM_LH_R GPIOE->IDR + #define PIN_TRIM_LH_R GPIO_Pin_4 // PE.04 #else + #define GPIO_TRIM_LH_L GPIOE->IDR #define PIN_TRIM_LH_L GPIO_Pin_4 // PE.04 + #define GPIO_TRIM_LH_R GPIOE->IDR #define PIN_TRIM_LH_R GPIO_Pin_3 // PE.03 #endif #if defined(REV9E) + #define GPIO_TRIM_LV_DN GPIOG->IDR #define PIN_TRIM_LV_DN GPIO_Pin_1 // PG.01 + #define GPIO_TRIM_LV_UP GPIOG->IDR #define PIN_TRIM_LV_UP GPIO_Pin_0 // PG.00 #else + #define GPIO_TRIM_LV_DN GPIOE->IDR #define PIN_TRIM_LV_DN GPIO_Pin_6 // PE.06 + #define GPIO_TRIM_LV_UP GPIOE->IDR #define PIN_TRIM_LV_UP GPIO_Pin_5 // PE.05 #endif // Switchs #if defined(REV3) + #define GPIO_PIN_SW_A_H (~GPIOB->IDR) + #define PIN_SW_A_H GPIO_Pin_7 // PB.07 + #define GPIO_PIN_SW_A_L (~GPIOE->IDR) + #define PIN_SW_A_L GPIO_Pin_2 // PE.02 +#else + #define GPIO_PIN_SW_A_H GPIOB->IDR + #define PIN_SW_A_H GPIO_Pin_5 // PB.05 + #define GPIO_PIN_SW_A_L GPIOE->IDR + #define PIN_SW_A_L GPIO_Pin_0 // PE.00 +#endif + +#if defined(REV3) + #define GPIO_PIN_SW_B_L GPIOB->IDR + #define PIN_SW_B_L GPIO_Pin_5 // PB.05 + #define GPIO_PIN_SW_B_H GPIOB->IDR + #define PIN_SW_B_H GPIO_Pin_6 // PB.06 +#else + #define GPIO_PIN_SW_B_H GPIOE->IDR + #define PIN_SW_B_H GPIO_Pin_1 // PE.01 + #define GPIO_PIN_SW_B_L GPIOE->IDR + #define PIN_SW_B_L GPIO_Pin_2 // PE.02 +#endif + +#if defined(REV3) + #define GPIO_PIN_SW_C_H (~GPIOB->IDR) + #define PIN_SW_C_H GPIO_Pin_1 // PB.01 + #define GPIO_PIN_SW_C_L (~GPIOE->IDR) + #define PIN_SW_C_L GPIO_Pin_7 // PE.07 +#else + #define GPIO_PIN_SW_C_H GPIOE->IDR + #define PIN_SW_C_H GPIO_Pin_15 // PE.15 + #define GPIO_PIN_SW_C_L GPIOA->IDR + #define PIN_SW_C_L GPIO_Pin_5 // PA.05 +#endif + +#if defined(REV3) + #define GPIO_PIN_SW_D_H (~GPIOE->IDR) + #define PIN_SW_D_H GPIO_Pin_9 // PE.09 + #define GPIO_PIN_SW_D_L (~GPIOE->IDR) + #define PIN_SW_D_L GPIO_Pin_8 // PE.08 +#elif defined(REVPLUS) + #define GPIO_PIN_SW_D_H (GPIOE->IDR) + #define PIN_SW_D_H GPIO_Pin_7 // PE.07 + #define GPIO_PIN_SW_D_L (GPIOE->IDR) + #define PIN_SW_D_L GPIO_Pin_13 // PE.13 +#else + #define GPIO_PIN_SW_D_H GPIOE->IDR + #define PIN_SW_D_H GPIO_Pin_7 // PE.07 + #define GPIO_PIN_SW_D_L GPIOB->IDR + #define PIN_SW_D_L GPIO_Pin_1 // PB.01 +#endif + +#define GPIO_PIN_SW_E_L GPIOB->IDR +#define PIN_SW_E_L GPIO_Pin_3 // PB.03 +#define GPIO_PIN_SW_E_H GPIOB->IDR +#define PIN_SW_E_H GPIO_Pin_4 // PB.04 + +#if defined(REV9E) + #define GPIO_PIN_SW_F_L GPIOF->IDR + #define PIN_SW_F_L GPIO_Pin_15 // PF.15 + #define GPIO_PIN_SW_F_H GPIOE->IDR + #define PIN_SW_F_H GPIO_Pin_14 // PE.14 +#elif defined(REV3) #define GPIO_PIN_SW_F (~GPIOE->IDR) #define PIN_SW_F GPIO_Pin_14 // PE.14 #else @@ -66,87 +134,77 @@ #define PIN_SW_F GPIO_Pin_14 // PE.14 #endif -#define GPIO_PIN_SW_E_L GPIOB->IDR -#define GPIO_PIN_SW_E_H GPIOB->IDR -#define PIN_SW_E_L GPIO_Pin_3 // PB.03 -#define PIN_SW_E_H GPIO_Pin_4 // PB.04 - -#if defined(REV3) - #define GPIO_PIN_SW_B_L GPIOB->IDR - #define GPIO_PIN_SW_B_H GPIOB->IDR - #define PIN_SW_B_L GPIO_Pin_5 // PB.05 - #define PIN_SW_B_H GPIO_Pin_6 // PB.06 -#else - #define GPIO_PIN_SW_B_H GPIOE->IDR - #define GPIO_PIN_SW_B_L GPIOE->IDR - #define PIN_SW_B_H GPIO_Pin_1 // PE.01 - #define PIN_SW_B_L GPIO_Pin_2 // PE.02 -#endif - -#if defined(REV3) - #define GPIO_PIN_SW_A_H (~GPIOB->IDR) - #define GPIO_PIN_SW_A_L (~GPIOE->IDR) - #define PIN_SW_A_H GPIO_Pin_7 // PB.07 - #define PIN_SW_A_L GPIO_Pin_2 // PE.02 -#else - #define GPIO_PIN_SW_A_H GPIOB->IDR - #define GPIO_PIN_SW_A_L GPIOE->IDR - #define PIN_SW_A_H GPIO_Pin_5 // PB.05 - #define PIN_SW_A_L GPIO_Pin_0 // PE.00 -#endif - #if defined(REV3) #define GPIO_PIN_SW_G_H (~GPIOA->IDR) - #define GPIO_PIN_SW_G_L (~GPIOB->IDR) #define PIN_SW_G_H GPIO_Pin_5 // PA.05 + #define GPIO_PIN_SW_G_L (~GPIOB->IDR) #define PIN_SW_G_L GPIO_Pin_0 // PB.00 #else #define GPIO_PIN_SW_G_H GPIOE->IDR - #define GPIO_PIN_SW_G_L GPIOE->IDR #define PIN_SW_G_H GPIO_Pin_9 // PE.09 + #define GPIO_PIN_SW_G_L GPIOE->IDR #define PIN_SW_G_L GPIO_Pin_8 // PE.08 #endif -#if defined(REV3) - #define GPIO_PIN_SW_C_H (~GPIOB->IDR) - #define GPIO_PIN_SW_C_L (~GPIOE->IDR) - #define PIN_SW_C_H GPIO_Pin_1 // PB.01 - #define PIN_SW_C_L GPIO_Pin_7 // PE.07 -#else - #define GPIO_PIN_SW_C_H GPIOE->IDR - #define GPIO_PIN_SW_C_L GPIOA->IDR - #define PIN_SW_C_H GPIO_Pin_15 // PE.15 - #define PIN_SW_C_L GPIO_Pin_5 // PA.05 -#endif - -#if defined(REV3) - #define GPIO_PIN_SW_D_H (~GPIOE->IDR) - #define GPIO_PIN_SW_D_L (~GPIOE->IDR) - #define PIN_SW_D_H GPIO_Pin_9 // PE.09 - #define PIN_SW_D_L GPIO_Pin_8 // PE.08 -#elif defined(REVPLUS) - #define GPIO_PIN_SW_D_H (GPIOE->IDR) - #define GPIO_PIN_SW_D_L (GPIOE->IDR) - #define PIN_SW_D_H GPIO_Pin_7 // PE.07 - #define PIN_SW_D_L GPIO_Pin_13 // PE.13 -#else - #define GPIO_PIN_SW_D_H GPIOE->IDR - #define GPIO_PIN_SW_D_L GPIOB->IDR - #define PIN_SW_D_H GPIO_Pin_7 // PE.07 - #define PIN_SW_D_L GPIO_Pin_1 // PB.01 -#endif - -#if defined(REV3) - #define GPIO_PIN_SW_H (~GPIOE->IDR) - #define PIN_SW_H GPIO_Pin_13 // PE.13 +#if defined(REV9E) + #define GPIO_PIN_SW_H_H GPIOD->IDR + #define PIN_SW_H_H GPIO_Pin_10 // PD.10 + #define GPIO_PIN_SW_H_L GPIOD->IDR + #define PIN_SW_H_L GPIO_Pin_14 // PD.14 #elif defined(REVPLUS) #define GPIO_PIN_SW_H GPIOD->IDR #define PIN_SW_H GPIO_Pin_14 // PD.14 +#elif defined(REV3) + #define GPIO_PIN_SW_H (~GPIOE->IDR) + #define PIN_SW_H GPIO_Pin_13 // PE.13 #else #define GPIO_PIN_SW_H GPIOE->IDR #define PIN_SW_H GPIO_Pin_13 // PE.13 #endif +#if defined(REV9E) + #define GPIO_PIN_SW_I_H GPIOF->IDR + #define PIN_SW_I_H GPIO_Pin_1 // PF.01 + #define GPIO_PIN_SW_I_L GPIOF->IDR + #define PIN_SW_I_L GPIO_Pin_2 // PF.02 + #define GPIO_PIN_SW_J_H GPIOF->IDR + #define PIN_SW_J_H GPIO_Pin_3 // PF.03 + #define GPIO_PIN_SW_J_L GPIOF->IDR + #define PIN_SW_J_L GPIO_Pin_4 // PF.04 + #define GPIO_PIN_SW_K_H GPIOF->IDR + #define PIN_SW_K_H GPIO_Pin_5 // PF.05 + #define GPIO_PIN_SW_K_L GPIOF->IDR + #define PIN_SW_K_L GPIO_Pin_6 // PF.06 + #define GPIO_PIN_SW_L_H GPIOF->IDR + #define PIN_SW_L_H GPIO_Pin_7 // PF.07 + #define GPIO_PIN_SW_L_L GPIOE->IDR + #define PIN_SW_L_L GPIO_Pin_10 // PE.10 + #define GPIO_PIN_SW_M_H GPIOF->IDR + #define PIN_SW_M_H GPIO_Pin_11 // PF.11 + #define GPIO_PIN_SW_M_L GPIOF->IDR + #define PIN_SW_M_L GPIO_Pin_12 // PF.12 + #define GPIO_PIN_SW_N_H GPIOF->IDR + #define PIN_SW_N_H GPIO_Pin_13 // PF.13 + #define GPIO_PIN_SW_N_L GPIOF->IDR + #define PIN_SW_N_L GPIO_Pin_14 // PF.14 + #define GPIO_PIN_SW_O_H GPIOG->IDR + #define PIN_SW_O_H GPIO_Pin_13 // PG.13 + #define GPIO_PIN_SW_O_L GPIOG->IDR + #define PIN_SW_O_L GPIO_Pin_12 // PG.12 + #define GPIO_PIN_SW_P_H GPIOG->IDR + #define PIN_SW_P_H GPIO_Pin_11 // PG.11 + #define GPIO_PIN_SW_P_L GPIOG->IDR + #define PIN_SW_P_L GPIO_Pin_10 // PG.10 + #define GPIO_PIN_SW_Q_H GPIOE->IDR + #define PIN_SW_Q_H GPIO_Pin_11 // PE.11 + #define GPIO_PIN_SW_Q_L GPIOE->IDR + #define PIN_SW_Q_L GPIO_Pin_12 // PE.12 + #define GPIO_PIN_SW_R_H GPIOG->IDR + #define PIN_SW_R_H GPIO_Pin_7 // PG.07 + #define GPIO_PIN_SW_R_L GPIOG->IDR + #define PIN_SW_R_L GPIO_Pin_8 // PG.08 +#endif + // ADC #define PIN_STK_J1 GPIO_Pin_0 // PA.00 #define PIN_STK_J2 GPIO_Pin_1 // PA.01 diff --git a/radio/src/targets/taranis/keys_driver.cpp b/radio/src/targets/taranis/keys_driver.cpp index 1134d3283..439573312 100644 --- a/radio/src/targets/taranis/keys_driver.cpp +++ b/radio/src/targets/taranis/keys_driver.cpp @@ -142,6 +142,90 @@ void readKeysAndTrims() } #if !defined(BOOT) + +#if defined(REV9E) +#define ADD_3POS_CASE(x, i) \ + case SW_S ## x ## 0: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H) && (~GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + break; \ + case SW_S ## x ## 1: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H) && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + break; \ + case SW_S ## x ## 2: \ + xxx = (~GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H) && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + break +#define ADD_3POS_INVERTED_CASE(x, i) ADD_3POS_CASE(x, i) +#define ADD_XTRA_2POS_CASE(...) +#else +#define ADD_2POS_CASE(x) \ + case SW_S ## x ## 0: \ + xxx = GPIO_PIN_SW_ ## x & PIN_SW_ ## x ; \ + break; \ + case SW_S ## x ## 2: \ + xxx = ~GPIO_PIN_SW_ ## x & PIN_SW_ ## x ; \ + break +#define ADD_3POS_CASE(x, i) \ + case SW_S ## x ## 0: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H); \ + if (IS_3POS(i)) { \ + xxx = xxx && (~GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + } \ + break; \ + case SW_S ## x ## 1: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H) && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + break; \ + case SW_S ## x ## 2: \ + xxx = (~GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H); \ + if (IS_3POS(i)) { \ + xxx = xxx && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + } \ + break +#define ADD_3POS_INVERTED_CASE(x, i) \ + case SW_S ## x ## 0: \ + xxx = (~GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H); \ + if (IS_3POS(i)) { \ + xxx = xxx && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + } \ + break; \ + case SW_S ## x ## 1: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H) && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + break; \ + case SW_S ## x ## 2: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H); \ + if (IS_3POS(i)) { \ + xxx = xxx && (~GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + } \ + break +#define ADD_XTRA_2POS_CASE(x, y) \ + case SW_S ## y ## 0: \ + xxx = GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L; \ + break; \ + case SW_S ## y ## 2: \ + xxx = ~GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L; \ + break +#endif + +#if defined(REV3) +#define ADD_3POS_INVERTED_REV3_CASE(x, i) \ + case SW_S ## x ## 0: \ + xxx = (GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H); \ + if (IS_3POS(i)) { \ + xxx = xxx && (~GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + } \ + break; \ + case SW_S ## x ## 1: \ + xxx = (~GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H) && (~GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + break; \ + case SW_S ## x ## 2: \ + xxx = (~GPIO_PIN_SW_ ## x ## _H & PIN_SW_ ## x ## _H); \ + if (IS_3POS(i)) { \ + xxx = xxx && (GPIO_PIN_SW_ ## x ## _L & PIN_SW_ ## x ## _L); \ + } \ + break +#else +#define ADD_3POS_INVERTED_REV3_CASE(x, i) ADD_3POS_CASE(x, i) +#endif + bool switchState(EnumKeys enuk) { register uint32_t xxx = 0; @@ -149,173 +233,48 @@ bool switchState(EnumKeys enuk) if (enuk < (int) DIM(keys)) return keys[enuk].state() ? 1 : 0; switch ((uint8_t) enuk) { - case SW_SA0: - xxx = (GPIO_PIN_SW_A_H & PIN_SW_A_H); - if (IS_3POS(0)) { - xxx = xxx && (~GPIO_PIN_SW_A_L & PIN_SW_A_L); - } - break; - case SW_SA1: -#if defined(REV3) - xxx = (~GPIO_PIN_SW_A_H & PIN_SW_A_H) && (~GPIO_PIN_SW_A_L & PIN_SW_A_L); + ADD_3POS_INVERTED_REV3_CASE(A, 0); + ADD_XTRA_2POS_CASE(A, I); + + ADD_3POS_CASE(B, 1); + ADD_XTRA_2POS_CASE(B, J); + + ADD_3POS_INVERTED_REV3_CASE(C, 2); + ADD_XTRA_2POS_CASE(C, K); + + ADD_3POS_INVERTED_REV3_CASE(D, 3); + ADD_XTRA_2POS_CASE(D, L); + + ADD_3POS_INVERTED_CASE(E, 4); + ADD_XTRA_2POS_CASE(E, M); + +#if defined(REV9E) + ADD_3POS_CASE(F, 5); #else - xxx = (GPIO_PIN_SW_A_H & PIN_SW_A_H) && (GPIO_PIN_SW_A_L & PIN_SW_A_L); + ADD_2POS_CASE(F); #endif - break; - case SW_SA2: - xxx = (~GPIO_PIN_SW_A_H & PIN_SW_A_H); - if (IS_3POS(0)) { - xxx = xxx && (GPIO_PIN_SW_A_L & PIN_SW_A_L); - } - break; - case SW_SI0: - xxx = GPIO_PIN_SW_A_L & PIN_SW_A_L; - break; - case SW_SI2: - xxx = ~GPIO_PIN_SW_A_L & PIN_SW_A_L; - break; + ADD_3POS_INVERTED_REV3_CASE(G, 6); + ADD_XTRA_2POS_CASE(G, N); - case SW_SB0: - xxx = (GPIO_PIN_SW_B_H & PIN_SW_B_H); - if (IS_3POS(1)) { - xxx = xxx && (~GPIO_PIN_SW_B_L & PIN_SW_B_L); - } - break; - case SW_SB1: - xxx = (GPIO_PIN_SW_B_H & PIN_SW_B_H) && (GPIO_PIN_SW_B_L & PIN_SW_B_L); - break; - case SW_SB2: - xxx = (~GPIO_PIN_SW_B_H & PIN_SW_B_H); - if (IS_3POS(1)) { - xxx = xxx && (GPIO_PIN_SW_B_L & PIN_SW_B_L); - } - break; - - case SW_SJ0: - xxx = GPIO_PIN_SW_B_L & PIN_SW_B_L; - break; - case SW_SJ2: - xxx = ~GPIO_PIN_SW_B_L & PIN_SW_B_L; - break; - - case SW_SC0: - xxx = (GPIO_PIN_SW_C_H & PIN_SW_C_H); - if (IS_3POS(2)) { - xxx = xxx && (~GPIO_PIN_SW_C_L & PIN_SW_C_L); - } - break; - case SW_SC1: -#if defined(REV3) - xxx = (~GPIO_PIN_SW_C_H & PIN_SW_C_H) && (~GPIO_PIN_SW_C_L & PIN_SW_C_L); +#if defined(REV9E) + ADD_3POS_CASE(H, 7); #else - xxx = (GPIO_PIN_SW_C_H & PIN_SW_C_H) && (GPIO_PIN_SW_C_L & PIN_SW_C_L); + ADD_2POS_CASE(H); #endif - break; - case SW_SC2: - xxx = (~GPIO_PIN_SW_C_H & PIN_SW_C_H); - if (IS_3POS(2)) { - xxx = xxx && (GPIO_PIN_SW_C_L & PIN_SW_C_L); - } - break; - case SW_SK0: - xxx = GPIO_PIN_SW_C_L & PIN_SW_C_L; - break; - case SW_SK2: - xxx = ~GPIO_PIN_SW_C_L & PIN_SW_C_L; - break; - - case SW_SD0: - xxx = (GPIO_PIN_SW_D_H & PIN_SW_D_H); - if (IS_3POS(3)) { - xxx = xxx && (~GPIO_PIN_SW_D_L & PIN_SW_D_L); - } - break; - case SW_SD1: -#if defined(REV3) - xxx = (~GPIO_PIN_SW_D_H & PIN_SW_D_H) && (~GPIO_PIN_SW_D_L & PIN_SW_D_L); -#else - xxx = (GPIO_PIN_SW_D_H & PIN_SW_D_H) && (GPIO_PIN_SW_D_L & PIN_SW_D_L); +#if defined(REV9E) + ADD_3POS_CASE(I, 8); + ADD_3POS_CASE(J, 9); + ADD_3POS_CASE(K, 10); + ADD_3POS_CASE(L, 11); + ADD_3POS_CASE(M, 12); + ADD_3POS_CASE(N, 13); + ADD_3POS_CASE(O, 14); + ADD_3POS_CASE(P, 15); + ADD_3POS_CASE(Q, 16); + ADD_3POS_CASE(R, 17); #endif - break; - case SW_SD2: - xxx = (~GPIO_PIN_SW_D_H & PIN_SW_D_H); - if (IS_3POS(3)) { - xxx = xxx && (GPIO_PIN_SW_D_L & PIN_SW_D_L); - } - break; - - case SW_SL0: - xxx = GPIO_PIN_SW_D_L & PIN_SW_D_L; - break; - case SW_SL2: - xxx = ~GPIO_PIN_SW_D_L & PIN_SW_D_L; - break; - - case SW_SE0: - xxx = (~GPIO_PIN_SW_E_H & PIN_SW_E_H); - if (IS_3POS(4)) { - xxx = xxx && (GPIO_PIN_SW_E_L & PIN_SW_E_L); - } - break; - case SW_SE1: - xxx = (GPIO_PIN_SW_E_H & PIN_SW_E_H) && (GPIO_PIN_SW_E_L & PIN_SW_E_L); - break; - case SW_SE2: - xxx = (GPIO_PIN_SW_E_H & PIN_SW_E_H); - if (IS_3POS(4)) { - xxx = xxx && (~GPIO_PIN_SW_E_L & PIN_SW_E_L); - } - break; - - case SW_SM0: - xxx = GPIO_PIN_SW_E_L & PIN_SW_E_L; - break; - case SW_SM2: - xxx = ~GPIO_PIN_SW_E_L & PIN_SW_E_L; - break; - - case SW_SF0: - xxx = GPIO_PIN_SW_F & PIN_SW_F; - break; - case SW_SF2: - xxx = ~GPIO_PIN_SW_F & PIN_SW_F; - break; - - case SW_SG0: - xxx = (GPIO_PIN_SW_G_H & PIN_SW_G_H); - if (IS_3POS(6)) { - xxx = xxx && (~GPIO_PIN_SW_G_L & PIN_SW_G_L); - } - break; - case SW_SG1: -#if defined(REV3) - xxx = (~GPIO_PIN_SW_G_H & PIN_SW_G_H) && (~GPIO_PIN_SW_G_L & PIN_SW_G_L); -#else - xxx = (GPIO_PIN_SW_G_H & PIN_SW_G_H) && (GPIO_PIN_SW_G_L & PIN_SW_G_L); -#endif - break; - case SW_SG2: - xxx = (~GPIO_PIN_SW_G_H & PIN_SW_G_H); - if (IS_3POS(6)) { - xxx = xxx && (GPIO_PIN_SW_G_L & PIN_SW_G_L); - } - break; - - case SW_SN0: - xxx = GPIO_PIN_SW_G_L & PIN_SW_G_L; - break; - case SW_SN2: - xxx = ~GPIO_PIN_SW_G_L & PIN_SW_G_L; - break; - - case SW_SH0: - xxx = GPIO_PIN_SW_H & PIN_SW_H; - break; - case SW_SH2: - xxx = ~GPIO_PIN_SW_H & PIN_SW_H; - break; default: break; @@ -338,7 +297,7 @@ void keysInit() | PIN_SW_A_L | PIN_SW_D_L | PIN_SW_F | PIN_SW_C_L | PIN_SW_D_H | PIN_SW_H; #elif defined(REV9E) GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_PLUS | PIN_BUTTON_MINUS | PIN_TRIM_LH_R | PIN_TRIM_LH_L - | PIN_SW_F | PIN_SW_A_L | PIN_SW_B_H | PIN_SW_B_L | PIN_SW_C_H | PIN_SW_D_H | PIN_SW_D_L | PIN_SW_G_H | PIN_SW_G_L; + | PIN_SW_F_H | PIN_SW_A_L | PIN_SW_B_H | PIN_SW_B_L | PIN_SW_C_H | PIN_SW_D_H | PIN_SW_D_L | PIN_SW_G_H | PIN_SW_G_L | PIN_SW_L_L | PIN_SW_Q_H | PIN_SW_Q_L; #elif defined(REVPLUS) GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_PLUS | PIN_BUTTON_ENTER | PIN_BUTTON_MINUS | PIN_TRIM_LH_R | PIN_TRIM_LH_L | PIN_TRIM_LV_DN | PIN_TRIM_LV_UP @@ -355,14 +314,16 @@ void keysInit() GPIO_Init(GPIOE, &GPIO_InitStructure); #if defined(REV9E) - GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_ENTER; + GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_ENTER | PIN_SW_F_L | PIN_SW_I_H | PIN_SW_I_L | PIN_SW_J_H | PIN_SW_J_L | PIN_SW_K_H | PIN_SW_K_L | PIN_SW_L_H | PIN_SW_M_H | PIN_SW_M_L | PIN_SW_N_H | PIN_SW_N_L; GPIO_Init(GPIOF, &GPIO_InitStructure); - GPIO_InitStructure.GPIO_Pin = PIN_TRIM_LV_DN | PIN_TRIM_LV_UP; + GPIO_InitStructure.GPIO_Pin = PIN_TRIM_LV_DN | PIN_TRIM_LV_UP | PIN_SW_O_H | PIN_SW_O_L | PIN_SW_P_H | PIN_SW_P_L | PIN_SW_R_H | PIN_SW_R_L; GPIO_Init(GPIOG, &GPIO_InitStructure); #endif -#if defined(REVPLUS) +#if defined(REV9E) + GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_MENU | PIN_BUTTON_EXIT | PIN_BUTTON_PAGE | PIN_SW_H_H | PIN_SW_H_L; +#elif defined(REVPLUS) GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_MENU | PIN_BUTTON_EXIT | PIN_BUTTON_PAGE | PIN_SW_H; #else GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_MENU | PIN_BUTTON_EXIT | PIN_BUTTON_PAGE; diff --git a/radio/src/translations/en.h.txt b/radio/src/translations/en.h.txt index 27a24f2a8..4f64dc4da 100644 --- a/radio/src/translations/en.h.txt +++ b/radio/src/translations/en.h.txt @@ -459,13 +459,19 @@ #define TR_ROTENC_SWITCHES #endif +#if defined(PCBTARANIS) && defined(REV9E) + #define TR_PHYS_SWITCHES "SA\300""SA-""SA\301""SB\300""SB-""SB\301""SC\300""SC-""SC\301""SD\300""SD-""SD\301""SE\300""SE-""SE\301""SF\300""SF-""SF\301""SG\300""SG-""SG\301""SH\300""SH-""SH\301""SI\300""SI-""SI\301""SJ\300""SJ-""SJ\301""SK\300""SK-""SK\301""SL\300""SL-""SL\301""SM\300""SM-""SM\301""SN\300""SN-""SN\301""SO\300""SO-""SO\301""SP\300""SP-""SP\301""SQ\300""SQ-""SQ\301""SR\300""SR-""SR\301" +#elif defined(PCBTARANIS) + #define TR_PHYS_SWITCHES "SA\300""SA-""SA\301""SB\300""SB-""SB\301""SC\300""SC-""SC\301""SD\300""SD-""SD\301""SE\300""SE-""SE\301""SF\300""SF\301""SG\300""SG-""SG\301""SH\300""SH\301""SI\300""SI\301""SJ\300""SJ\301""SK\300""SK\301""SL\300""SL\301""SM\300""SM\301""SN\300""SN\301" +#else + #define TR_PHYS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" +#endif + #if defined(PCBTARANIS) #define TR_6POS_POTS "S11""S12""S13""S14""S15""S16""S21""S22""S23""S24""S25""S26""S31""S32""S33""S34""S35""S36" - #define TR_VSWITCHES "---""SA\300""SA-""SA\301""SB\300""SB-""SB\301""SC\300""SC-""SC\301""SD\300""SD-""SD\301""SE\300""SE-""SE\301""SF\300""SF\301""SG\300""SG-""SG\301""SH\300""SH\301""SI\300""SI\301""SJ\300""SJ\301""SK\300""SK\301""SL\300""SL\301""SM\300""SM\301""SN\300""SN\301" TR_6POS_POTS TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" -#elif defined(CPUARM) - #define TR_VSWITCHES "---" TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" + #define TR_VSWITCHES "---" TR_PHYS_SWITCHES TR_6POS_POTS TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" #else - #define TR_VSWITCHES "---" TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" + #define TR_VSWITCHES "---" TR_9X_3POS_SWITCHES TR_PHYS_SWITCHES TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" #endif #if defined(HELI)