Skip to content

Commit 2484f6e

Browse files
committed
Re-work pl18u keys trims mapping with KL and KR
1 parent 67116e1 commit 2484f6e

File tree

4 files changed

+293
-101
lines changed

4 files changed

+293
-101
lines changed

radio/src/targets/pl18/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ add_definitions(-DSTM32_SUPPORT_32BIT_TIMERS)
4444

4545
if(PCBREV STREQUAL PL18U)
4646
set(FLAVOUR pl18u)
47-
add_definitions(-DRADIO_PL18U -DUSE_HATS_AS_KEYS)
47+
add_definitions(-DRADIO_PL18U)
4848
set(DISK_CACHE ON)
4949
set(WIRELESS_CHARGER YES)
5050
set(FLYSKY_GIMBAL ON)
5151
set(LED_STRIP ON)
5252
set(USE_VS1053B ON)
53-
set(KEY_DRIVER key_driver.cpp)
53+
set(KEY_DRIVER pl18u_key_driver.cpp)
5454

5555
# Defines internal module for PL18U
5656
set(INTERNAL_MODULES AFHDS3;CRSF CACHE STRING "Internal modules")

radio/src/targets/pl18/hal.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@
235235

236236
#else // !defined(RADIO_NB4P) && !defined(RADIO_NV14_FAMILY)
237237

238+
// Keys
239+
#if defined(RADIO_PL18U)
240+
#define KEYS_GPIO_PIN_ENTER
241+
#define KEYS_GPIO_REG_ENTER
242+
#define KEYS_GPIO_PIN_EXIT
243+
#define KEYS_GPIO_REG_EXIT
244+
#endif
245+
238246
// Trims
239247
#define TRIMS_GPIO_REG_LHL
240248
#define TRIMS_GPIO_PIN_LHL
@@ -272,19 +280,19 @@
272280
#define TRIMS_GPIO_REG_RSU
273281
#define TRIMS_GPIO_PIN_RSU
274282

275-
#define TRIMS_GPIO_REG_T7L
276-
#define TRIMS_GPIO_PIN_T7L
283+
#if !defined(RADIO_PL18U)
284+
#define TRIMS_GPIO_REG_T7L
285+
#define TRIMS_GPIO_PIN_T7L
277286

278-
#define TRIMS_GPIO_REG_T7R
279-
#define TRIMS_GPIO_PIN_T7R
287+
#define TRIMS_GPIO_REG_T7R
288+
#define TRIMS_GPIO_PIN_T7R
280289

281-
#define TRIMS_GPIO_REG_T8D
282-
#define TRIMS_GPIO_PIN_T8D
290+
#define TRIMS_GPIO_REG_T8D
291+
#define TRIMS_GPIO_PIN_T8D
283292

284-
#define TRIMS_GPIO_REG_T8U
285-
#define TRIMS_GPIO_PIN_T8U
293+
#define TRIMS_GPIO_REG_T8U
294+
#define TRIMS_GPIO_PIN_T8U
286295

287-
#if !defined(RADIO_PL18U)
288296
#define TRIMS_GPIO_REG_TR1U GPIOH->IDR
289297
#define TRIMS_GPIO_PIN_TR1U LL_GPIO_PIN_8 // PH.08
290298
#define TRIMS_GPIO_REG_TR1D GPIOH->IDR

radio/src/targets/pl18/key_driver.cpp

Lines changed: 26 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -28,56 +28,36 @@
2828
#include "delays_driver.h"
2929
#include "keys.h"
3030

31-
32-
3331
/* The output bit-order has to be (D = L, U = R):
34-
PL18 PL18U
35-
0 LHL TR7D(L) TR5D(L)
36-
1 LHR TR7U(R) TR5U(R)
37-
2 LVD TR5D TR3D
38-
3 LVU TR5U TR3U
39-
4 RVD TR6D TR4D
40-
5 RVU TR6U TR4U
41-
6 RHL TR8D(L) TR6D(L)
42-
7 RHR TR8U(R) TR6U(R)
43-
8 LSD TR1D TR1D
44-
9 LSU TR1U TR1U
45-
10 RSD TR2D TR2D
46-
11 RSU TR2U TR2U
47-
12 EX1D TR3D TR7D
48-
13 EX1U TR3U TR7U
49-
14 EX2D TR4D TR8D
50-
15 EX2U TR4U TR8U
32+
PL18/PL18EV
33+
0 LHL TR7L
34+
1 LHR TR7R
35+
2 LVD TR5D
36+
3 LVU TR5U
37+
4 RVD TR6D
38+
5 RVU TR6U
39+
6 RHL TR8L
40+
7 RHR TR8R
41+
8 LSD TR1D
42+
9 LSU TR1U
43+
10 RSD TR2D
44+
11 RSU TR2U
45+
12 EX1D TR3D
46+
13 EX1U TR3U
47+
14 EX2D TR4D
48+
15 EX2U TR4U
5149
*/
5250

5351
enum PhysicalTrims
5452
{
55-
#if defined(RADIO_PL18U)
56-
TR5D = 0,
57-
TR5U,
58-
TR3D = 2,
59-
TR3U,
60-
TR4D = 4,
61-
TR4U,
62-
TR6D = 6,
63-
TR6U,
64-
TR1D = 8,
65-
TR1U,
66-
TR2D = 10,
67-
TR2U,
68-
TR7D = 12,
69-
TR7U,
70-
TR8D = 14,
71-
TR8U,
72-
#else
73-
TR7D = 0,
74-
TR7U,
53+
TR7L = 0,
54+
TR7R,
7555
TR5D = 2,
7656
TR5U,
7757
TR6D = 4,
7858
TR6U,
79-
TR8D = 6,
80-
TR8U,
59+
TR8L = 6,
60+
TR8R,
8161
TR1D = 8,
8262
TR1U,
8363
TR2D = 10,
@@ -86,7 +66,6 @@ enum PhysicalTrims
8666
TR3U,
8767
TR4D = 14,
8868
TR4U,
89-
#endif
9069
};
9170

9271
void keysInit()
@@ -96,9 +75,6 @@ void keysInit()
9675
stm32_gpio_enable_clock(GPIOD);
9776
stm32_gpio_enable_clock(GPIOG);
9877
stm32_gpio_enable_clock(GPIOH);
99-
#if defined(RADIO_PL18U)
100-
stm32_gpio_enable_clock(GPIOI);
101-
#endif
10278
stm32_gpio_enable_clock(GPIOJ);
10379

10480
LL_GPIO_InitTypeDef pinInit;
@@ -115,10 +91,8 @@ void keysInit()
11591
pinInit.Pin = KEYS_GPIOD_PINS;
11692
LL_GPIO_Init(GPIOD, &pinInit);
11793

118-
#if defined(KEYS_GPIOH_PINS)
11994
pinInit.Pin = KEYS_GPIOH_PINS;
12095
LL_GPIO_Init(GPIOH, &pinInit);
121-
#endif
12296

12397
pinInit.Pin = KEYS_GPIOJ_PINS;
12498
LL_GPIO_Init(GPIOJ, &pinInit);
@@ -130,15 +104,8 @@ void keysInit()
130104
pinInit.Pin = KEYS_OUT_GPIOG_PINS;
131105
LL_GPIO_Init(GPIOG, &pinInit);
132106

133-
#if defined(KEYS_OUT_GPIOH_PINS)
134107
pinInit.Pin = KEYS_OUT_GPIOH_PINS;
135108
LL_GPIO_Init(GPIOH, &pinInit);
136-
#endif
137-
138-
#if defined(KEYS_OUT_GPIOI_PINS)
139-
pinInit.Pin = KEYS_OUT_GPIOI_PINS;
140-
LL_GPIO_Init(GPIOI, &pinInit);
141-
#endif
142109
}
143110

144111
static uint32_t _readKeyMatrix()
@@ -165,16 +132,11 @@ static uint32_t _readKeyMatrix()
165132
LL_GPIO_ResetOutputPin(TRIMS_GPIO_OUT1, TRIMS_GPIO_OUT1_PIN);
166133
LL_GPIO_SetOutputPin(TRIMS_GPIO_OUT2, TRIMS_GPIO_OUT2_PIN);
167134
LL_GPIO_SetOutputPin(TRIMS_GPIO_OUT3, TRIMS_GPIO_OUT3_PIN);
168-
169-
#if defined(TRIMS_GPIO_OUT4)
170-
LL_GPIO_SetOutputPin(TRIMS_GPIO_OUT4, TRIMS_GPIO_OUT4_PIN);
171-
#endif
172-
173135
delay_us(10);
174136
if (~TRIMS_GPIO_REG_IN1 & TRIMS_GPIO_PIN_IN1)
175-
result |= 1 << TR7D;
137+
result |= 1 << TR7L;
176138
if (~TRIMS_GPIO_REG_IN2 & TRIMS_GPIO_PIN_IN2)
177-
result |= 1 << TR7U;
139+
result |= 1 << TR7R;
178140
if (~TRIMS_GPIO_REG_IN3 & TRIMS_GPIO_PIN_IN3)
179141
result |= 1 << TR5D;
180142
if (~TRIMS_GPIO_REG_IN4 & TRIMS_GPIO_PIN_IN4)
@@ -200,26 +162,12 @@ static uint32_t _readKeyMatrix()
200162
if (~TRIMS_GPIO_REG_IN2 & TRIMS_GPIO_PIN_IN2)
201163
result |= 1 << TR6D;
202164
if (~TRIMS_GPIO_REG_IN3 & TRIMS_GPIO_PIN_IN3)
203-
result |= 1 << TR8D;
165+
result |= 1 << TR8L;
204166
if (~TRIMS_GPIO_REG_IN4 & TRIMS_GPIO_PIN_IN4)
205-
result |= 1 << TR8U;
167+
result |= 1 << TR8R;
206168

207169
LL_GPIO_SetOutputPin(TRIMS_GPIO_OUT3, TRIMS_GPIO_OUT3_PIN);
208170

209-
#if defined(TRIMS_GPIO_OUT4)
210-
LL_GPIO_ResetOutputPin(TRIMS_GPIO_OUT4, TRIMS_GPIO_OUT4_PIN);
211-
delay_us(10);
212-
if (~TRIMS_GPIO_REG_IN1 & TRIMS_GPIO_PIN_IN1)
213-
result |= 1 << TR1U;
214-
if (~TRIMS_GPIO_REG_IN2 & TRIMS_GPIO_PIN_IN2)
215-
result |= 1 << TR1D;
216-
if (~TRIMS_GPIO_REG_IN3 & TRIMS_GPIO_PIN_IN3)
217-
result |= 1 << TR2D;
218-
if (~TRIMS_GPIO_REG_IN4 & TRIMS_GPIO_PIN_IN4)
219-
result |= 1 << TR2U;
220-
LL_GPIO_SetOutputPin(TRIMS_GPIO_OUT4, TRIMS_GPIO_OUT4_PIN);
221-
#endif
222-
223171
syncelem.oldResult = result;
224172
syncelem.ui8ReadInProgress = 0;
225173

@@ -232,13 +180,8 @@ uint32_t readKeys()
232180

233181
if (getHatsAsKeys()) {
234182
uint32_t mkeys = _readKeyMatrix();
235-
#if defined(RADIO_PL18U)
236-
if (mkeys & (1 << TR2D)) result |= 1 << KEY_ENTER;
237-
if (mkeys & (1 << TR2U)) result |= 1 << KEY_EXIT;
238-
#else
239183
if (mkeys & (1 << TR4D)) result |= 1 << KEY_ENTER;
240184
if (mkeys & (1 << TR4U)) result |= 1 << KEY_EXIT;
241-
#endif
242185
}
243186

244187
return result;
@@ -250,22 +193,15 @@ uint32_t readTrims()
250193

251194
result |= _readKeyMatrix();
252195

253-
#if defined(TRIMS_GPIO_REG_TR1U)
254196
if (~TRIMS_GPIO_REG_TR1U & TRIMS_GPIO_PIN_TR1U)
255197
result |= 1 << (TR1U);
256-
#endif
257-
#if defined(TRIMS_GPIO_REG_TR1D)
258198
if (~TRIMS_GPIO_REG_TR1D & TRIMS_GPIO_PIN_TR1D)
259199
result |= 1 << (TR1D);
260-
#endif
261-
#if defined(TRIMS_GPIO_REG_TR2U)
200+
262201
if (~TRIMS_GPIO_REG_TR2U & TRIMS_GPIO_PIN_TR2U)
263202
result |= 1 << (TR2U);
264-
#endif
265-
#if defined(TRIMS_GPIO_REG_TR2D)
266203
if (~TRIMS_GPIO_REG_TR2D & TRIMS_GPIO_PIN_TR2D)
267204
result |= 1 << (TR2D);
268-
#endif
269205

270206
return result;
271207
}

0 commit comments

Comments
 (0)