Better manage additional switches declared as toggle or 2pos (#4793)

This commit is contained in:
3djc
2017-04-16 21:13:51 +02:00
committed by Bertrand Songis
parent 1d6f2acbc2
commit 95bc595f50
+6 -16
View File
@@ -2,7 +2,7 @@
* Copyright (C) OpenTX * Copyright (C) OpenTX
* *
* Based on code named * 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 * er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x * gruvin9x - http://code.google.com/p/gruvin9x
* *
@@ -123,17 +123,7 @@ void readKeysAndTrims()
break; \ break; \
case SW_S ## x ## 0: \ case SW_S ## x ## 0: \
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \ xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break break;
#define ADD_3POS_CASE(x, i) \
case SW_S ## x ## 0: \
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
break; \
case SW_S ## x ## 1: \
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
break; \
case SW_S ## x ## 2: \
xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
break
#else #else
#define ADD_2POS_CASE(x) \ #define ADD_2POS_CASE(x) \
case SW_S ## x ## 0: \ case SW_S ## x ## 0: \
@@ -141,7 +131,8 @@ void readKeysAndTrims()
break; \ break; \
case SW_S ## x ## 2: \ case SW_S ## x ## 2: \
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \ xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break break;
#endif
#define ADD_3POS_CASE(x, i) \ #define ADD_3POS_CASE(x, i) \
case SW_S ## x ## 0: \ case SW_S ## x ## 0: \
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \ xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
@@ -158,7 +149,6 @@ void readKeysAndTrims()
xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \ xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
} \ } \
break break
#endif
uint8_t keyState(uint8_t index) uint8_t keyState(uint8_t index)
{ {
@@ -169,7 +159,7 @@ uint8_t keyState(uint8_t index)
uint32_t switchState(uint8_t index) uint32_t switchState(uint8_t index)
{ {
uint32_t xxx = 0; uint32_t xxx = 0;
switch (index) { switch (index) {
ADD_3POS_CASE(A, 0); ADD_3POS_CASE(A, 0);
ADD_3POS_CASE(B, 1); ADD_3POS_CASE(B, 1);
@@ -248,7 +238,7 @@ void keysInit()
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS; GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure);
#endif #endif
#if defined(ROTARY_ENCODER_NAVIGATION) #if defined(ROTARY_ENCODER_NAVIGATION)
rotencPosition = ROTARY_ENCODER_POSITION(); rotencPosition = ROTARY_ENCODER_POSITION();
#endif #endif