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.
27 if (~KEYS_GPIO_REG_ENTER
& KEYS_GPIO_PIN_ENTER
)
28 result
|= 1 << KEY_ENTER
;
30 #if defined(KEYS_GPIO_PIN_MENU)
31 if (~KEYS_GPIO_REG_MENU
& KEYS_GPIO_PIN_MENU
)
32 result
|= 1 << KEY_MENU
;
35 #if defined(KEYS_GPIO_PIN_PAGE)
36 if (~KEYS_GPIO_REG_PAGE
& KEYS_GPIO_PIN_PAGE
)
37 result
|= 1 << KEY_PAGE
;
40 if (~KEYS_GPIO_REG_EXIT
& KEYS_GPIO_PIN_EXIT
)
41 result
|= 1 << KEY_EXIT
;
43 #if defined(KEYS_GPIO_PIN_PLUS)
44 if (~KEYS_GPIO_REG_PLUS
& KEYS_GPIO_PIN_PLUS
)
45 result
|= 1 << KEY_PLUS
;
46 if (~KEYS_GPIO_REG_MINUS
& KEYS_GPIO_PIN_MINUS
)
47 result
|= 1 << KEY_MINUS
;
50 #if defined(KEYS_GPIO_PIN_LEFT)
51 if (~KEYS_GPIO_REG_LEFT
& KEYS_GPIO_PIN_LEFT
)
52 result
|= 1 << KEY_LEFT
;
53 if (~KEYS_GPIO_REG_RIGHT
& KEYS_GPIO_PIN_RIGHT
)
54 result
|= 1 << KEY_RIGHT
;
55 if (~KEYS_GPIO_REG_UP
& KEYS_GPIO_PIN_UP
)
56 result
|= 1 << KEY_UP
;
57 if (~KEYS_GPIO_REG_DOWN
& KEYS_GPIO_PIN_DOWN
)
58 result
|= 1 << KEY_DOWN
;
61 #if defined(KEYS_GPIO_PIN_SHIFT)
62 if (~KEYS_GPIO_REG_SHIFT
& KEYS_GPIO_PIN_SHIFT
)
63 result
|= 1 << KEY_SHIFT
;
66 // if (result != 0) TRACE("readKeys(): result=0x%02x", result);
75 if (~TRIMS_GPIO_REG_LHL
& TRIMS_GPIO_PIN_LHL
)
77 if (~TRIMS_GPIO_REG_LHR
& TRIMS_GPIO_PIN_LHR
)
79 if (~TRIMS_GPIO_REG_LVD
& TRIMS_GPIO_PIN_LVD
)
81 if (~TRIMS_GPIO_REG_LVU
& TRIMS_GPIO_PIN_LVU
)
85 if (IS_SHIFT_PRESSED())
86 result
= ((result
& 0x03) << 6) | ((result
& 0x0c) << 2);
88 if (~TRIMS_GPIO_REG_RVD
& TRIMS_GPIO_PIN_RVD
)
90 if (~TRIMS_GPIO_REG_RVU
& TRIMS_GPIO_PIN_RVU
)
92 if (~TRIMS_GPIO_REG_RHL
& TRIMS_GPIO_PIN_RHL
)
94 if (~TRIMS_GPIO_REG_RHR
& TRIMS_GPIO_PIN_RHR
)
98 // TRACE("readTrims(): result=0x%02x", result);
103 bool trimDown(uint8_t idx
)
105 return readTrims() & (1 << idx
);
110 return readKeys() || readTrims();
113 /* TODO common to ARM */
114 void readKeysAndTrims()
117 uint32_t keys_input
= readKeys();
118 for (uint8_t i
= 1; i
!= uint8_t(1 << TRM_BASE
); i
<<= 1) {
119 keys
[index
++].input(keys_input
& i
);
122 uint32_t trims_input
= readTrims();
123 for (uint8_t i
= 1; i
!= uint8_t(1 << 8); i
<<= 1) {
124 keys
[index
++].input(trims_input
& i
);
127 #if defined(PWR_BUTTON_PRESS)
128 if ((keys_input
|| trims_input
|| pwrPressed()) && (g_eeGeneral
.backlightMode
& e_backlight_mode_keys
)) {
130 if ((keys_input
|| trims_input
) && (g_eeGeneral
.backlightMode
& e_backlight_mode_keys
)) {
132 // on keypress turn the light on
138 #define ADD_2POS_CASE(x) \
139 case SW_S ## x ## 2: \
140 xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
142 case SW_S ## x ## 0: \
143 xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
146 #define ADD_2POS_CASE(x) \
147 case SW_S ## x ## 0: \
148 xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
150 case SW_S ## x ## 2: \
151 xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
155 #define ADD_3POS_CASE(x, i) \
156 case SW_S ## x ## 0: \
157 xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
158 if (IS_CONFIG_3POS(i)) { \
159 xxx = xxx && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
162 case SW_S ## x ## 1: \
163 xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
165 case SW_S ## x ## 2: \
166 xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
167 if (IS_CONFIG_3POS(i)) { \
168 xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
173 uint32_t switchState(uint8_t index
)
182 #if defined(PCBX9LITES)
187 #elif defined(PCBX9LITE)
190 #elif defined(PCBXLITES)
194 // no SWG and SWH on XLITES
195 #elif defined(PCBXLITE)
197 // no SWE, SWF, SWG and SWH on XLITE
212 #if defined(PCBX9DP) && PCBREV >= 2019
219 ADD_3POS_CASE(K
, 10);
220 ADD_3POS_CASE(L
, 11);
221 ADD_3POS_CASE(M
, 12);
222 ADD_3POS_CASE(N
, 13);
223 ADD_3POS_CASE(O
, 14);
224 ADD_3POS_CASE(P
, 15);
225 ADD_3POS_CASE(Q
, 16);
226 ADD_3POS_CASE(R
, 17);
233 // TRACE("switch %d => %d", index, xxx);
240 GPIO_InitTypeDef GPIO_InitStructure
;
241 GPIO_InitStructure
.GPIO_Speed
= GPIO_Speed_2MHz
;
242 GPIO_InitStructure
.GPIO_OType
= GPIO_OType_PP
;
243 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_UP
;
244 GPIO_InitStructure
.GPIO_Mode
= GPIO_Mode_IN
;
246 #if defined(KEYS_GPIOA_PINS)
247 INIT_KEYS_PINS(GPIOA
);
250 #if defined(KEYS_GPIOB_PINS)
251 INIT_KEYS_PINS(GPIOB
);
254 #if defined(KEYS_GPIOC_PINS)
255 INIT_KEYS_PINS(GPIOC
);
258 #if defined(KEYS_GPIOD_PINS)
259 INIT_KEYS_PINS(GPIOD
);
262 #if defined(KEYS_GPIOE_PINS)
263 INIT_KEYS_PINS(GPIOE
);
266 #if defined(KEYS_GPIOF_PINS)
267 INIT_KEYS_PINS(GPIOF
);
270 #if defined(KEYS_GPIOG_PINS)
271 INIT_KEYS_PINS(GPIOG
);