[Taranis X9E] Last minute changes taken into account. It remains a bug

in SWF and SWP definitions (they share the same pins in the spec)
This commit is contained in:
bsongis
2015-06-11 19:21:30 +02:00
parent 08f97e08c6
commit 95de75ba41
11 changed files with 306 additions and 262 deletions
+71 -122
View File
@@ -36,80 +36,53 @@
#include "../../opentx.h"
// TODO FrSky code included PIN_BIND and PIN_POWER
uint32_t readKeys()
{
register uint32_t result = 0;
register uint32_t d = ~GPIOD->IDR;
uint32_t result = 0;
if (~KEYS_GPIO_REG_ENTER & KEYS_GPIO_PIN_ENTER)
result |= 1 << KEY_ENTER;
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
result |= 1 << KEY_MENU;
if (~KEYS_GPIO_REG_PAGE & KEYS_GPIO_PIN_PAGE)
result |= 1 << KEY_PAGE;
if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
result |= 1 << KEY_EXIT;
#if !defined(REV9E) || defined(SIMU)
register uint32_t e = ~GPIOE->IDR;
(void)e;
if (~KEYS_GPIO_REG_PLUS & KEYS_GPIO_PIN_PLUS)
result |= 1 << KEY_PLUS;
if (~KEYS_GPIO_REG_MINUS & KEYS_GPIO_PIN_MINUS)
result |= 1 << KEY_MINUS;
#endif
#if defined(REV9E)
if (!(GPIOF->IDR & KEYS_GPIO_PIN_ENTER))
#else
if (e & KEYS_GPIO_PIN_ENTER)
#endif
result |= 0x02 << KEY_ENTER;
#if !defined(REV9E) || defined(SIMU)
if (e & KEYS_GPIO_PIN_PLUS)
result |= 0x02 << KEY_PLUS;
if (e & KEYS_GPIO_PIN_MINUS)
result |= 0x02 << KEY_MINUS;
#endif
if (d & KEYS_GPIO_PIN_MENU)
result |= 0x02 << KEY_MENU;
if (d & KEYS_GPIO_PIN_PAGE)
result |= 0x02 << KEY_PAGE;
if (d & KEYS_GPIO_PIN_EXIT)
result |= 0x02 << KEY_EXIT;
// TRACE("readKeys(): %x %x => %x", d, e, result);
// TRACE("readKeys(): result=0x%02x", result);
return result;
}
uint32_t readTrims()
{
register uint32_t c = GPIOC->IDR;
register uint32_t e = GPIOE->IDR;
#if defined(REV9E)
register uint32_t g = GPIOG->IDR;
#endif
register uint32_t result = 0;
uint32_t result = 0;
if (~e & TRIMS_GPIO_PIN_LHL)
result |= 0x01; // LH_L
if (~e & TRIMS_GPIO_PIN_LHR)
result |= 0x02; // LH_R
if (~TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
result |= 0x01;
if (~TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
result |= 0x02;
if (~TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
result |= 0x04;
if (~TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
result |= 0x08;
if (~TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
result |= 0x10;
if (~TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
result |= 0x20;
if (~TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
result |= 0x40;
if (~TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
result |= 0x80;
#if defined(REV9E)
if (~g & TRIMS_GPIO_PIN_LVD)
result |= 0x04; // LV_DN
if (~g & TRIMS_GPIO_PIN_LVU)
result |= 0x08; // LV_UP
#else
if (~e & TRIMS_GPIO_PIN_LVD)
result |= 0x04; // LV_DN
if (~e & TRIMS_GPIO_PIN_LVU)
result |= 0x08; // LV_UP
#endif
if (~c & TRIMS_GPIO_PIN_RVD)
result |= 0x10; // RV_DN
if (~c & TRIMS_GPIO_PIN_RVU)
result |= 0x20; // RV_UP
if (~c & TRIMS_GPIO_PIN_RHL)
result |= 0x40; // RH_L
if (~c & TRIMS_GPIO_PIN_RHR)
result |= 0x80; // RH_R
// TRACE("readTrims(): %x %x => %x", c, e, result);
// TRACE("readTrims(): result=0x%02x", result);
return result;
}
@@ -131,13 +104,10 @@ extern rotenc_t x9de_rotenc;
/* TODO common to ARM */
void readKeysAndTrims()
{
register uint32_t i;
uint8_t enuk = KEY_MENU;
uint8_t enuk = 0;
uint32_t in = readKeys();
for (i = 1; i <= TRM_BASE; i++) {
keys[enuk].input(in & (1 << i));
++enuk;
for (uint8_t i = 1; i != uint8_t(1 << TRM_BASE); i <<= 1) {
keys[enuk++].input(in & i);
}
#if defined(REV9E) && !defined(SIMU)
@@ -156,15 +126,21 @@ void readKeysAndTrims()
#endif
in = readTrims();
for (i = 1; i < 256; i <<= 1) {
keys[enuk].input(in & i);
++enuk;
for (uint8_t i = 1; i != uint8_t(1 << 8); i <<= 1) {
keys[enuk++].input(in & i);
}
}
#if !defined(BOOT)
#define ADD_2POS_CASE(x) \
case SW_S ## x ## 0: \
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break; \
case SW_S ## x ## 2: \
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break
#if defined(REV9E)
#define ADD_3POS_CASE(x, i) \
case SW_S ## x ## 0: \
@@ -178,13 +154,6 @@ void readKeysAndTrims()
break
#define ADD_3POS_INVERTED_CASE(x, i) ADD_3POS_CASE(x, i)
#else
#define ADD_2POS_CASE(x) \
case SW_S ## x ## 0: \
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break; \
case SW_S ## x ## 2: \
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
break
#define ADD_3POS_CASE(x, i) \
case SW_S ## x ## 0: \
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
@@ -229,7 +198,11 @@ bool switchState(EnumKeys enuk)
ADD_3POS_CASE(A, 0);
ADD_3POS_CASE(B, 1);
ADD_3POS_CASE(C, 2);
#if defined(REV9E)
ADD_2POS_CASE(D);
#else
ADD_3POS_CASE(D, 3);
#endif
ADD_3POS_INVERTED_CASE(E, 4);
#if defined(REV9E)
ADD_3POS_CASE(F, 5);
@@ -237,12 +210,7 @@ bool switchState(EnumKeys enuk)
ADD_2POS_CASE(F);
#endif
ADD_3POS_CASE(G, 6);
#if defined(REV9E)
ADD_3POS_CASE(H, 7);
#else
ADD_2POS_CASE(H);
#endif
#if defined(REV9E)
ADD_3POS_CASE(I, 8);
ADD_3POS_CASE(J, 9);
@@ -272,52 +240,33 @@ void keysInit()
RCC_AHB1PeriphClockCmd(KEYS_RCC_AHB1Periph_GPIO, ENABLE);
#if defined(REV9E)
GPIO_InitStructure.GPIO_Pin = TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_LHL
| SWITCHES_GPIO_PIN_F_H | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_L_L | SWITCHES_GPIO_PIN_Q_H | SWITCHES_GPIO_PIN_Q_L;
#elif defined(REVPLUS)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIO_PIN_PLUS | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_MINUS | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_LHL
| TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU
| SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L;
#else
GPIO_InitStructure.GPIO_Pin = KEYS_GPIO_PIN_PLUS | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_MINUS | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_LHL
| TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU
| SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H;
#endif
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOA_PINS;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
#if defined(REV9E)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIO_PIN_ENTER | SWITCHES_GPIO_PIN_F_L | SWITCHES_GPIO_PIN_I_H | SWITCHES_GPIO_PIN_I_L | SWITCHES_GPIO_PIN_J_H | SWITCHES_GPIO_PIN_J_L | SWITCHES_GPIO_PIN_K_H | SWITCHES_GPIO_PIN_K_L | SWITCHES_GPIO_PIN_L_H | SWITCHES_GPIO_PIN_M_H | SWITCHES_GPIO_PIN_M_L | SWITCHES_GPIO_PIN_N_H | SWITCHES_GPIO_PIN_N_L;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | SWITCHES_GPIO_PIN_O_H | SWITCHES_GPIO_PIN_O_L | SWITCHES_GPIO_PIN_P_H | SWITCHES_GPIO_PIN_P_L | SWITCHES_GPIO_PIN_R_H | SWITCHES_GPIO_PIN_R_L;
GPIO_Init(GPIOG, &GPIO_InitStructure);
#endif
#if defined(REV9E)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_H_H | SWITCHES_GPIO_PIN_H_L;
#elif defined(REVPLUS)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_H;
#else
GPIO_InitStructure.GPIO_Pin = KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE;
#endif
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR;
GPIO_Init(GPIOC, &GPIO_InitStructure);
#if defined(REVPLUS)
GPIO_InitStructure.GPIO_Pin = SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_A_H;
#else
GPIO_InitStructure.GPIO_Pin = SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_D_L;
#endif
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SWITCHES_GPIO_PIN_C_L;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOC_PINS;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOE_PINS;
GPIO_Init(GPIOE, &GPIO_InitStructure);
#if defined(KEYS_GPIOF_PINS)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOF_PINS;
GPIO_Init(GPIOF, &GPIO_InitStructure);
#endif
#if defined(KEYS_GPIOG_PINS)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
GPIO_Init(GPIOG, &GPIO_InitStructure);
#endif
}
#endif