Fix doc path
[opentx.git] / radio / src / targets / taranis / hal.h
blob716bae3689faada6734d85819d5327a815d1882d
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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.
21 #ifndef _HAL_H_
22 #define _HAL_H_
24 // Keys
25 #if defined(PCBX9E)
26 #define KEYS_GPIO_REG_MENU GPIOD->IDR
27 #define KEYS_GPIO_PIN_MENU GPIO_Pin_7 // PD.07
28 #define KEYS_GPIO_REG_EXIT GPIOD->IDR
29 #define KEYS_GPIO_PIN_EXIT GPIO_Pin_2 // PD.02
30 #define KEYS_GPIO_REG_PAGE GPIOD->IDR
31 #define KEYS_GPIO_PIN_PAGE GPIO_Pin_3 // PD.03
32 #define KEYS_GPIO_REG_ENTER GPIOF->IDR
33 #define KEYS_GPIO_PIN_ENTER GPIO_Pin_0 // PF.00
34 #elif defined(PCBXLITE)
35 #define KEYS_GPIO_REG_SHIFT GPIOE->IDR
36 #define KEYS_GPIO_PIN_SHIFT GPIO_Pin_8 // PE.08
37 #define KEYS_GPIO_REG_EXIT GPIOE->IDR
38 #define KEYS_GPIO_PIN_EXIT GPIO_Pin_7 // PE.07
39 #define KEYS_GPIO_REG_ENTER GPIOE->IDR
40 #define KEYS_GPIO_PIN_ENTER GPIO_Pin_11 // PE.11
41 #define KEYS_GPIO_REG_UP GPIOE->IDR
42 #define KEYS_GPIO_PIN_UP GPIO_Pin_10 // PE.10
43 #define KEYS_GPIO_REG_DOWN GPIOE->IDR
44 #define KEYS_GPIO_PIN_DOWN GPIO_Pin_14 // PE.14
45 #define KEYS_GPIO_REG_LEFT GPIOE->IDR
46 #define KEYS_GPIO_PIN_LEFT GPIO_Pin_12 // PE.12
47 #define KEYS_GPIO_REG_RIGHT GPIOE->IDR
48 #define KEYS_GPIO_PIN_RIGHT GPIO_Pin_13 // PE.13
49 #elif defined(PCBX7)
50 #define KEYS_GPIO_REG_PAGE GPIOD->IDR
51 #define KEYS_GPIO_PIN_PAGE GPIO_Pin_3 // PD.03
52 #define KEYS_GPIO_REG_MENU GPIOD->IDR
53 #define KEYS_GPIO_PIN_MENU GPIO_Pin_7 // PD.07
54 #define KEYS_GPIO_REG_EXIT GPIOD->IDR
55 #define KEYS_GPIO_PIN_EXIT GPIO_Pin_2 // PD.02
56 #define KEYS_GPIO_REG_ENTER GPIOE->IDR
57 #define KEYS_GPIO_PIN_ENTER GPIO_Pin_10 // PE.10
58 #else
59 #define KEYS_GPIO_REG_MENU GPIOD->IDR
60 #define KEYS_GPIO_PIN_MENU GPIO_Pin_7 // PD.07
61 #define KEYS_GPIO_REG_EXIT GPIOD->IDR
62 #define KEYS_GPIO_PIN_EXIT GPIO_Pin_2 // PD.02
63 #define KEYS_GPIO_REG_PAGE GPIOD->IDR
64 #define KEYS_GPIO_PIN_PAGE GPIO_Pin_3 // PD.03
65 #define KEYS_GPIO_REG_PLUS GPIOE->IDR
66 #define KEYS_GPIO_PIN_PLUS GPIO_Pin_10 // PE.10
67 #define KEYS_GPIO_REG_MINUS GPIOE->IDR
68 #define KEYS_GPIO_PIN_MINUS GPIO_Pin_11 // PE.11
69 #define KEYS_GPIO_REG_ENTER GPIOE->IDR
70 #define KEYS_GPIO_PIN_ENTER GPIO_Pin_12 // PE.12
71 #endif
73 // Rotary Encoder
74 #if defined(PCBX9E)
75 #define ENC_GPIO GPIOD
76 #define ENC_GPIO_PIN_A GPIO_Pin_12 // PD.12
77 #define ENC_GPIO_PIN_B GPIO_Pin_13 // PD.13
78 #define ROTARY_ENCODER_POSITION() (ENC_GPIO->IDR >> 12) & 0x03
79 #elif defined(PCBX7)
80 #define ENC_GPIO GPIOE
81 #define ENC_GPIO_PIN_A GPIO_Pin_9 // PE.09
82 #define ENC_GPIO_PIN_B GPIO_Pin_11 // PE.11
83 #define ROTARY_ENCODER_POSITION() (((ENC_GPIO->IDR >> 10) & 0x02) + ((ENC_GPIO->IDR >> 9) & 0x01))
84 #endif
86 // This is for SIMU: reuse rotary encoder pins to map UP and DOWN keyboard keys
87 #if defined(SIMU) && (defined(PCBX9E) || defined(PCBX7))
88 #define KEYS_GPIO_REG_PLUS ENC_GPIO->IDR
89 #define KEYS_GPIO_PIN_PLUS ENC_GPIO_PIN_A
90 #define KEYS_GPIO_REG_MINUS ENC_GPIO->IDR
91 #define KEYS_GPIO_PIN_MINUS ENC_GPIO_PIN_B
92 #endif
94 // Trims
95 #if defined(PCBX9E)
96 #define TRIMS_GPIO_REG_LHL GPIOG->IDR
97 #define TRIMS_GPIO_PIN_LHL GPIO_Pin_1 // PG.01
98 #define TRIMS_GPIO_REG_LHR GPIOG->IDR
99 #define TRIMS_GPIO_PIN_LHR GPIO_Pin_0 // PG.00
100 #define TRIMS_GPIO_REG_LVD GPIOE->IDR
101 #define TRIMS_GPIO_PIN_LVD GPIO_Pin_4 // PE.04
102 #define TRIMS_GPIO_REG_LVU GPIOE->IDR
103 #define TRIMS_GPIO_PIN_LVU GPIO_Pin_3 // PE.03
104 #define TRIMS_GPIO_REG_RVD GPIOC->IDR
105 #define TRIMS_GPIO_PIN_RVD GPIO_Pin_3 // PC.03
106 #define TRIMS_GPIO_REG_RHL GPIOC->IDR
107 #define TRIMS_GPIO_PIN_RHL GPIO_Pin_1 // PC.01
108 #define TRIMS_GPIO_REG_RVU GPIOC->IDR
109 #define TRIMS_GPIO_PIN_RVU GPIO_Pin_2 // PC.02
110 #define TRIMS_GPIO_REG_RHR GPIOC->IDR
111 #define TRIMS_GPIO_PIN_RHR GPIO_Pin_13 // PC.13
112 #elif defined(PCBXLITE)
113 #define TRIMS_GPIO_REG_LHL GPIOC->IDR
114 #define TRIMS_GPIO_PIN_LHL GPIO_Pin_4 // PC.04
115 #define TRIMS_GPIO_REG_LHR GPIOC->IDR
116 #define TRIMS_GPIO_PIN_LHR GPIO_Pin_5 // PC.05
117 #define TRIMS_GPIO_REG_LVU GPIOB->IDR
118 #define TRIMS_GPIO_PIN_LVU GPIO_Pin_0 // PB.00
119 #define TRIMS_GPIO_REG_LVD GPIOB->IDR
120 #define TRIMS_GPIO_PIN_LVD GPIO_Pin_1 // PB.01
121 #elif defined(PCBX7)
122 #define TRIMS_GPIO_REG_LHL GPIOD->IDR
123 #define TRIMS_GPIO_PIN_LHL GPIO_Pin_15 // PD.15
124 #define TRIMS_GPIO_REG_LHR GPIOC->IDR
125 #define TRIMS_GPIO_PIN_LHR GPIO_Pin_1 // PC.01
126 #define TRIMS_GPIO_REG_LVD GPIOE->IDR
127 #define TRIMS_GPIO_PIN_LVD GPIO_Pin_6 // PE.06
128 #define TRIMS_GPIO_REG_LVU GPIOE->IDR
129 #define TRIMS_GPIO_PIN_LVU GPIO_Pin_5 // PE.05
130 #define TRIMS_GPIO_REG_RVD GPIOC->IDR
131 #define TRIMS_GPIO_PIN_RVD GPIO_Pin_3 // PC.03
132 #define TRIMS_GPIO_REG_RHL GPIOE->IDR
133 #define TRIMS_GPIO_PIN_RHL GPIO_Pin_3 // PE.03
134 #define TRIMS_GPIO_REG_RVU GPIOC->IDR
135 #define TRIMS_GPIO_PIN_RVU GPIO_Pin_2 // PC.02
136 #define TRIMS_GPIO_REG_RHR GPIOE->IDR
137 #define TRIMS_GPIO_PIN_RHR GPIO_Pin_4 // PE.04
138 #else
139 #define TRIMS_GPIO_REG_LHL GPIOE->IDR
140 #define TRIMS_GPIO_PIN_LHL GPIO_Pin_4 // PE.04
141 #define TRIMS_GPIO_REG_LHR GPIOE->IDR
142 #define TRIMS_GPIO_PIN_LHR GPIO_Pin_3 // PE.03
143 #define TRIMS_GPIO_REG_LVD GPIOE->IDR
144 #define TRIMS_GPIO_PIN_LVD GPIO_Pin_6 // PE.06
145 #define TRIMS_GPIO_REG_LVU GPIOE->IDR
146 #define TRIMS_GPIO_PIN_LVU GPIO_Pin_5 // PE.05
147 #define TRIMS_GPIO_REG_RVD GPIOC->IDR
148 #define TRIMS_GPIO_PIN_RVD GPIO_Pin_3 // PC.03
149 #define TRIMS_GPIO_REG_RHL GPIOC->IDR
150 #define TRIMS_GPIO_PIN_RHL GPIO_Pin_1 // PC.01
151 #define TRIMS_GPIO_REG_RVU GPIOC->IDR
152 #define TRIMS_GPIO_PIN_RVU GPIO_Pin_2 // PC.02
153 #define TRIMS_GPIO_REG_RHR GPIOC->IDR
154 #define TRIMS_GPIO_PIN_RHR GPIO_Pin_13 // PC.13
155 #endif
157 // Switches
158 #if defined(PCBX9E)
159 #define SWITCHES_GPIO_REG_A_H GPIOD->IDR
160 #define SWITCHES_GPIO_PIN_A_H GPIO_Pin_10 // PD.10
161 #define SWITCHES_GPIO_REG_A_L GPIOD->IDR
162 #define SWITCHES_GPIO_PIN_A_L GPIO_Pin_14 // PD.14
163 #elif defined(PCBXLITE)
164 #define SWITCHES_GPIO_REG_A_H GPIOE->IDR
165 #define SWITCHES_GPIO_PIN_A_H GPIO_Pin_1 // PE.01
166 #define SWITCHES_GPIO_REG_A_L GPIOE->IDR
167 #define SWITCHES_GPIO_PIN_A_L GPIO_Pin_0 // PE.00
168 #elif defined(PCBX7)
169 #define SWITCHES_GPIO_REG_A_L GPIOE->IDR
170 #define SWITCHES_GPIO_PIN_A_L GPIO_Pin_7 // PE.07
171 #define SWITCHES_GPIO_REG_A_H GPIOE->IDR
172 #define SWITCHES_GPIO_PIN_A_H GPIO_Pin_13 // PE.13
173 #else
174 #define SWITCHES_GPIO_REG_A_H GPIOB->IDR
175 #define SWITCHES_GPIO_PIN_A_H GPIO_Pin_5 // PB.05
176 #define SWITCHES_GPIO_REG_A_L GPIOE->IDR
177 #define SWITCHES_GPIO_PIN_A_L GPIO_Pin_0 // PE.00
178 #endif
180 #if defined(PCBX9E)
181 #define SWITCHES_GPIO_REG_B_H GPIOG->IDR
182 #define SWITCHES_GPIO_PIN_B_H GPIO_Pin_11 // PG.11
183 #define SWITCHES_GPIO_REG_B_L GPIOG->IDR
184 #define SWITCHES_GPIO_PIN_B_L GPIO_Pin_10 // PG.10
185 #elif defined(PCBXLITE)
186 #define SWITCHES_GPIO_REG_B_L GPIOA->IDR
187 #define SWITCHES_GPIO_PIN_B_L GPIO_Pin_6 // PA.06
188 #define SWITCHES_GPIO_REG_B_H GPIOA->IDR
189 #define SWITCHES_GPIO_PIN_B_H GPIO_Pin_5 // PA.05
190 #elif defined(PCBX7)
191 #define SWITCHES_GPIO_REG_B_L GPIOE->IDR
192 #define SWITCHES_GPIO_PIN_B_L GPIO_Pin_15 // PE.15
193 #define SWITCHES_GPIO_REG_B_H GPIOA->IDR
194 #define SWITCHES_GPIO_PIN_B_H GPIO_Pin_5 // PA.05
195 #else
196 #define SWITCHES_GPIO_REG_B_H GPIOE->IDR
197 #define SWITCHES_GPIO_PIN_B_H GPIO_Pin_1 // PE.01
198 #define SWITCHES_GPIO_REG_B_L GPIOE->IDR
199 #define SWITCHES_GPIO_PIN_B_L GPIO_Pin_2 // PE.02
200 #endif
202 #if defined(PCBX9E)
203 #define SWITCHES_GPIO_REG_C_H GPIOF->IDR
204 #define SWITCHES_GPIO_PIN_C_H GPIO_Pin_13 // PF.13
205 #define SWITCHES_GPIO_REG_C_L GPIOF->IDR
206 #define SWITCHES_GPIO_PIN_C_L GPIO_Pin_14 // PF.14
207 #elif defined(PCBXLITE)
208 #define SWITCHES_GPIO_REG_C_L GPIOE->IDR
209 #define SWITCHES_GPIO_PIN_C_L GPIO_Pin_2 // PE.02
210 #define SWITCHES_GPIO_REG_C_H GPIOE->IDR
211 #define SWITCHES_GPIO_PIN_C_H GPIO_Pin_3 // PE.03
212 #elif defined(PCBX7)
213 #define SWITCHES_GPIO_REG_C_L GPIOD->IDR
214 #define SWITCHES_GPIO_PIN_C_L GPIO_Pin_11 // PD.11
215 #define SWITCHES_GPIO_REG_C_H GPIOE->IDR
216 #define SWITCHES_GPIO_PIN_C_H GPIO_Pin_0 // PE.00
217 #else
218 #define SWITCHES_GPIO_REG_C_H GPIOE->IDR
219 #define SWITCHES_GPIO_PIN_C_H GPIO_Pin_15 // PE.15
220 #define SWITCHES_GPIO_REG_C_L GPIOA->IDR
221 #define SWITCHES_GPIO_PIN_C_L GPIO_Pin_5 // PA.05
222 #endif
224 #if defined(PCBX9E)
225 #define SWITCHES_GPIO_REG_D_H GPIOE->IDR
226 #define SWITCHES_GPIO_PIN_D_H GPIO_Pin_1 // PE.01
227 #define SWITCHES_GPIO_REG_D_L GPIOE->IDR
228 #define SWITCHES_GPIO_PIN_D_L GPIO_Pin_2 // PE.02
229 #elif defined(PCBX9DP)
230 #define SWITCHES_GPIO_REG_D_H GPIOE->IDR
231 #define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PE.07
232 #define SWITCHES_GPIO_REG_D_L GPIOE->IDR
233 #define SWITCHES_GPIO_PIN_D_L GPIO_Pin_13 // PE.13
234 #elif defined(PCBXLITE)
235 #define SWITCHES_GPIO_REG_D_L GPIOB->IDR
236 #define SWITCHES_GPIO_PIN_D_L GPIO_Pin_4 // PB.04
237 #define SWITCHES_GPIO_REG_D_H GPIOB->IDR
238 #define SWITCHES_GPIO_PIN_D_H GPIO_Pin_5 // PB.05
239 #elif defined(PCBX7)
240 #define SWITCHES_GPIO_REG_D_L GPIOE->IDR
241 #define SWITCHES_GPIO_PIN_D_L GPIO_Pin_1 // PE.01
242 #define SWITCHES_GPIO_REG_D_H GPIOE->IDR
243 #define SWITCHES_GPIO_PIN_D_H GPIO_Pin_2 // PE.02
244 #else
245 #define SWITCHES_GPIO_REG_D_H GPIOE->IDR
246 #define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PE.07
247 #define SWITCHES_GPIO_REG_D_L GPIOB->IDR
248 #define SWITCHES_GPIO_PIN_D_L GPIO_Pin_1 // PB.01
249 #endif
251 #if defined(PCBX9E)
252 #define SWITCHES_GPIO_REG_E_H GPIOE->IDR
253 #define SWITCHES_GPIO_PIN_E_H GPIO_Pin_7 // PE.07
254 #define SWITCHES_GPIO_REG_E_L GPIOE->IDR
255 #define SWITCHES_GPIO_PIN_E_L GPIO_Pin_13 // PE.13
256 #elif defined(PCBX7) || defined(PCBXLITE)
257 // no SWE
258 #else
259 #define SWITCHES_GPIO_REG_E_H GPIOB->IDR
260 #define SWITCHES_GPIO_PIN_E_H GPIO_Pin_3 // PB.03
261 #define SWITCHES_GPIO_REG_E_L GPIOB->IDR
262 #define SWITCHES_GPIO_PIN_E_L GPIO_Pin_4 // PB.04
263 #endif
265 #if defined(PCBX9E)
266 #define SWITCHES_GPIO_REG_F GPIOE->IDR
267 #define SWITCHES_GPIO_PIN_F GPIO_Pin_11 // PE.11
268 #elif defined(PCBXLITE)
269 // no SWF
270 #elif defined(PCBX7)
271 #define SWITCHES_GPIO_REG_F GPIOE->IDR
272 #define SWITCHES_GPIO_PIN_F GPIO_Pin_14 // PE.14
273 #else
274 #define SWITCHES_GPIO_REG_F GPIOE->IDR
275 #define SWITCHES_GPIO_PIN_F GPIO_Pin_14 // PE.14
276 #endif
278 #if defined(PCBX9E)
279 #define SWITCHES_GPIO_REG_G_H GPIOF->IDR
280 #define SWITCHES_GPIO_PIN_G_H GPIO_Pin_3 // PF.03
281 #define SWITCHES_GPIO_REG_G_L GPIOF->IDR
282 #define SWITCHES_GPIO_PIN_G_L GPIO_Pin_4 // PF.04
283 #elif defined(PCBX7) || defined(PCBXLITE)
284 // no SWG
285 #else
286 #define SWITCHES_GPIO_REG_G_H GPIOE->IDR
287 #define SWITCHES_GPIO_PIN_G_H GPIO_Pin_9 // PE.09
288 #define SWITCHES_GPIO_REG_G_L GPIOE->IDR
289 #define SWITCHES_GPIO_PIN_G_L GPIO_Pin_8 // PE.08
290 #endif
292 #if defined(PCBX9E)
293 #define SWITCHES_GPIO_REG_H GPIOF->IDR
294 #define SWITCHES_GPIO_PIN_H GPIO_Pin_1 // PF.01
295 #elif defined(PCBX9DP)
296 #define SWITCHES_GPIO_REG_H GPIOD->IDR
297 #define SWITCHES_GPIO_PIN_H GPIO_Pin_14 // PD.14
298 #elif defined(PCBXLITE)
299 // no SWH
300 #elif defined(PCBX7)
301 #define SWITCHES_GPIO_REG_H GPIOD->IDR
302 #define SWITCHES_GPIO_PIN_H GPIO_Pin_14 // PD.14
303 #else
304 #define SWITCHES_GPIO_REG_H GPIOE->IDR
305 #define SWITCHES_GPIO_PIN_H GPIO_Pin_13 // PE.13
306 #endif
308 #if defined(PCBX9E)
309 #define SWITCHES_GPIO_REG_I_H GPIOF->IDR
310 #define SWITCHES_GPIO_PIN_I_H GPIO_Pin_15 // PF.15
311 #define SWITCHES_GPIO_REG_I_L GPIOE->IDR
312 #define SWITCHES_GPIO_PIN_I_L GPIO_Pin_14 // PE.14
313 #define SWITCHES_GPIO_REG_J_H GPIOG->IDR
314 #define SWITCHES_GPIO_PIN_J_H GPIO_Pin_7 // PG.07
315 #define SWITCHES_GPIO_REG_J_L GPIOG->IDR
316 #define SWITCHES_GPIO_PIN_J_L GPIO_Pin_8 // PG.08
317 #define SWITCHES_GPIO_REG_K_H GPIOG->IDR
318 #define SWITCHES_GPIO_PIN_K_H GPIO_Pin_13 // PG.13
319 #define SWITCHES_GPIO_REG_K_L GPIOG->IDR
320 #define SWITCHES_GPIO_PIN_K_L GPIO_Pin_12 // PG.12
321 #define SWITCHES_GPIO_REG_L_H GPIOE->IDR
322 #define SWITCHES_GPIO_PIN_L_H GPIO_Pin_9 // PE.09
323 #define SWITCHES_GPIO_REG_L_L GPIOE->IDR
324 #define SWITCHES_GPIO_PIN_L_L GPIO_Pin_8 // PE.08
325 #define SWITCHES_GPIO_REG_M_H GPIOE->IDR
326 #define SWITCHES_GPIO_PIN_M_H GPIO_Pin_15 // PE.15
327 #define SWITCHES_GPIO_REG_M_L GPIOA->IDR
328 #define SWITCHES_GPIO_PIN_M_L GPIO_Pin_5 // PA.05
329 #define SWITCHES_GPIO_REG_N_H GPIOB->IDR
330 #define SWITCHES_GPIO_PIN_N_H GPIO_Pin_3 // PB.03
331 #define SWITCHES_GPIO_REG_N_L GPIOB->IDR
332 #define SWITCHES_GPIO_PIN_N_L GPIO_Pin_4 // PB.04
333 #define SWITCHES_GPIO_REG_O_H GPIOF->IDR
334 #define SWITCHES_GPIO_PIN_O_H GPIO_Pin_7 // PF.07
335 #define SWITCHES_GPIO_REG_O_L GPIOE->IDR
336 #define SWITCHES_GPIO_PIN_O_L GPIO_Pin_10 // PE.10
337 #define SWITCHES_GPIO_REG_P_H GPIOF->IDR
338 #define SWITCHES_GPIO_PIN_P_H GPIO_Pin_11 // PF.11
339 #define SWITCHES_GPIO_REG_P_L GPIOF->IDR
340 #define SWITCHES_GPIO_PIN_P_L GPIO_Pin_12 // PF.12
341 #define SWITCHES_GPIO_REG_Q_H GPIOF->IDR
342 #define SWITCHES_GPIO_PIN_Q_H GPIO_Pin_5 // PF.05
343 #define SWITCHES_GPIO_REG_Q_L GPIOF->IDR
344 #define SWITCHES_GPIO_PIN_Q_L GPIO_Pin_6 // PF.06
345 #define SWITCHES_GPIO_REG_R_H GPIOB->IDR
346 #define SWITCHES_GPIO_PIN_R_H GPIO_Pin_5 // PB.05
347 #define SWITCHES_GPIO_REG_R_L GPIOE->IDR
348 #define SWITCHES_GPIO_PIN_R_L GPIO_Pin_0 // PE.00
349 #endif
351 #if defined(PCBX9E)
352 #define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG)
353 #define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_M_L)
354 #define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_N_H | SWITCHES_GPIO_PIN_N_L | SWITCHES_GPIO_PIN_R_H)
355 #define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
356 #define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_A_L | ENC_GPIO_PIN_A | ENC_GPIO_PIN_B)
357 #define KEYS_GPIOE_PINS (TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_LVD | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_D_L| SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_I_L | SWITCHES_GPIO_PIN_L_H | SWITCHES_GPIO_PIN_L_L | SWITCHES_GPIO_PIN_M_H | SWITCHES_GPIO_PIN_O_L | SWITCHES_GPIO_PIN_R_L)
358 #define KEYS_GPIOF_PINS (KEYS_GPIO_PIN_ENTER | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_C_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | SWITCHES_GPIO_PIN_I_H | SWITCHES_GPIO_PIN_O_H | SWITCHES_GPIO_PIN_P_H | SWITCHES_GPIO_PIN_P_L | SWITCHES_GPIO_PIN_Q_H | SWITCHES_GPIO_PIN_Q_L)
359 #define KEYS_GPIOG_PINS (TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LHR| SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_J_H | SWITCHES_GPIO_PIN_J_L | SWITCHES_GPIO_PIN_K_H | SWITCHES_GPIO_PIN_K_L)
360 #elif defined(PCBX9DP)
361 #define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
362 #define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_C_L)
363 #define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_A_H)
364 #define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
365 #define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_H)
366 #define KEYS_GPIOE_PINS (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)
367 #elif defined(PCBXLITE)
368 #define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE)
369 #define KEYS_GPIOA_PINS (GPIO_Pin_5 | GPIO_Pin_6)
370 #define KEYS_GPIOB_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5)
371 #define KEYS_GPIOC_PINS (GPIO_Pin_4 | GPIO_Pin_5)
372 #define KEYS_GPIOE_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14)
373 #elif defined(PCBX7)
374 #define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
375 #define KEYS_GPIOA_PINS SWITCHES_GPIO_PIN_B_H
376 #define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU)
377 #define KEYS_GPIOD_PINS (TRIMS_GPIO_PIN_LHL | KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_C_L | SWITCHES_GPIO_PIN_H)
378 #define KEYS_GPIOE_PINS (ENC_GPIO_PIN_A | ENC_GPIO_PIN_B | KEYS_GPIO_PIN_ENTER | TRIMS_GPIO_PIN_RHR | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_F)
379 #else
380 #define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
381 #define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_C_L)
382 #define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_D_L)
383 #define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
384 #define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE)
385 #define KEYS_GPIOE_PINS (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)
386 #endif
388 // ADC
389 #define ADC_MAIN ADC1
390 #define ADC_DMA DMA2
391 #define ADC_DMA_SxCR_CHSEL 0
392 #define ADC_DMA_Stream DMA2_Stream4
393 #define ADC_SET_DMA_FLAGS() ADC_DMA->HIFCR = (DMA_HIFCR_CTCIF4 | DMA_HIFCR_CHTIF4 | DMA_HIFCR_CTEIF4 | DMA_HIFCR_CDMEIF4 | DMA_HIFCR_CFEIF4)
394 #define ADC_TRANSFER_COMPLETE() (ADC_DMA->HISR & DMA_HISR_TCIF4)
395 #define ADC_SAMPTIME 2 // sample time = 28 cycles
396 #if defined(PCBX9E)
397 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
398 #define ADC_RCC_APB1Periph 0
399 #define ADC_RCC_APB2Periph (RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
400 #define ADC_GPIO_PIN_STICK_RV GPIO_Pin_0 // PA.00
401 #define ADC_GPIO_PIN_STICK_RH GPIO_Pin_1 // PA.01
402 #define ADC_GPIO_PIN_STICK_LH GPIO_Pin_2 // PA.02
403 #define ADC_GPIO_PIN_STICK_LV GPIO_Pin_3 // PA.03
404 #define ADC_CHANNEL_STICK_RV ADC_Channel_0 // ADC1_IN0
405 #define ADC_CHANNEL_STICK_RH ADC_Channel_1 // ADC1_IN1
406 #define ADC_CHANNEL_STICK_LH ADC_Channel_2 // ADC1_IN2
407 #define ADC_CHANNEL_STICK_LV ADC_Channel_3 // ADC1_IN3
408 #define ADC_GPIO_PIN_POT1 GPIO_Pin_8 // PF.08
409 #define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
410 #define ADC_GPIO_PIN_POT3 GPIO_Pin_5 // PC.05
411 #define ADC_GPIO_PIN_POT4 GPIO_Pin_4 // PC.04
412 #define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_10 // PF.10
413 #define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_9 // PF.09
414 #define ADC_GPIO_PIN_SLIDER3 GPIO_Pin_6 // PA.06
415 #define ADC_GPIO_PIN_SLIDER4 GPIO_Pin_1 // PB.01
416 #define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
417 #define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_SLIDER3)
418 #define ADC_GPIOB_PINS (ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_SLIDER4)
419 #define ADC_GPIOC_PINS (ADC_GPIO_PIN_POT3 | ADC_GPIO_PIN_POT4 | ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2 | ADC_GPIO_PIN_BATT)
420 #define ADC_GPIOF_PINS (ADC_GPIO_PIN_POT1 | ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2)
421 #define ADC_CHANNEL_POT1 ADC_Channel_6 // ADC3_IN6
422 #define ADC_CHANNEL_POT2 ADC_Channel_8 // ADC1_IN8
423 #define ADC_CHANNEL_POT3 ADC_Channel_15 // ADC1_IN15
424 #define ADC_CHANNEL_POT4 ADC_Channel_14 // ADC1_IN14
425 #define ADC_CHANNEL_SLIDER1 ADC_Channel_8 // ADC3_IN8
426 #define ADC_CHANNEL_SLIDER2 ADC_Channel_7 // ADC3_IN7
427 #define ADC_CHANNEL_SLIDER3 ADC_Channel_6 // ADC1_IN6
428 #define ADC_CHANNEL_SLIDER4 ADC_Channel_9 // ADC1_IN9
429 #define ADC_CHANNEL_BATT ADC_Channel_10 // ADC1_IN10
430 #define ADC_EXT ADC3
431 #define ADC_EXT_DMA DMA2
432 #define ADC_EXT_DMA_Stream DMA2_Stream0
433 #define ADC_EXT_SET_DMA_FLAGS() ADC_DMA->LIFCR = (DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 | DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0)
434 #define ADC_EXT_TRANSFER_COMPLETE() (ADC_DMA->LISR & DMA_LISR_TCIF0)
435 #define ADC_EXT_SAMPTIME 3 // sample time = 56 cycles
436 #elif defined(PCBX9DP)
437 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2)
438 #define ADC_RCC_APB1Periph 0
439 #define ADC_RCC_APB2Periph RCC_APB2Periph_ADC1
440 #define ADC_GPIO_PIN_STICK_RV GPIO_Pin_0 // PA.00
441 #define ADC_GPIO_PIN_STICK_RH GPIO_Pin_1 // PA.01
442 #define ADC_GPIO_PIN_STICK_LH GPIO_Pin_2 // PA.02
443 #define ADC_GPIO_PIN_STICK_LV GPIO_Pin_3 // PA.03
444 #define ADC_CHANNEL_STICK_RV ADC_Channel_0 // ADC1_IN0
445 #define ADC_CHANNEL_STICK_RH ADC_Channel_1 // ADC1_IN1
446 #define ADC_CHANNEL_STICK_LH ADC_Channel_2 // ADC1_IN2
447 #define ADC_CHANNEL_STICK_LV ADC_Channel_3 // ADC1_IN3
448 #define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06
449 #define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
450 #define ADC_GPIO_PIN_POT3 GPIO_Pin_1 // PB.01
451 #define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_4 // PC.04
452 #define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_5 // PC.05
453 #define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
454 #define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_POT1)
455 #define ADC_GPIOB_PINS (ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_POT3)
456 #define ADC_GPIOC_PINS (ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2 | ADC_GPIO_PIN_BATT)
457 #define ADC_CHANNEL_POT1 ADC_Channel_6
458 #define ADC_CHANNEL_POT2 ADC_Channel_8
459 #define ADC_CHANNEL_POT3 ADC_Channel_9
460 #define ADC_CHANNEL_SLIDER1 ADC_Channel_14
461 #define ADC_CHANNEL_SLIDER2 ADC_Channel_15
462 #define ADC_CHANNEL_BATT ADC_Channel_10
463 #elif defined(PCBXLITE)
464 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2)
465 #define ADC_RCC_APB1Periph RCC_APB1Periph_TIM5
466 #define ADC_RCC_APB2Periph RCC_APB2Periph_ADC1
467 #define ADC_GPIO_PIN_STICK_RV GPIO_Pin_0 // PA.00
468 #define ADC_GPIO_PIN_STICK_RH GPIO_Pin_1 // PA.01
469 #define ADC_GPIO_PIN_STICK_LV GPIO_Pin_2 // PA.02
470 #define ADC_GPIO_PIN_STICK_LH GPIO_Pin_3 // PA.03
471 #define ADC_GPIO_PIN_POT1 GPIO_Pin_1 // PC.01
472 #define ADC_GPIO_PIN_POT2 GPIO_Pin_2 // PC.02
473 #define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
474 #define PWM_TIMER TIM5
475 #define PWM_GPIO GPIOA
476 #define PWM_GPIO_AF GPIO_AF_TIM5
477 #define PWM_IRQHandler TIM5_IRQHandler
478 #define PWM_IRQn TIM5_IRQn
479 #define PWM_GPIOA_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3)
480 #define ADC_GPIOA_PINS (STICKS_PWM_ENABLED() ? 0 : (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3))
481 #define ADC_GPIOC_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2)
482 #define ADC_CHANNEL_STICK_RV ADC_Channel_3 // ADC1_IN3
483 #define ADC_CHANNEL_STICK_RH ADC_Channel_2 // ADC1_IN2
484 #define ADC_CHANNEL_STICK_LV ADC_Channel_1 // ADC1_IN1
485 #define ADC_CHANNEL_STICK_LH ADC_Channel_0 // ADC1_IN0
486 #define ADC_CHANNEL_POT1 ADC_Channel_11 // ADC1_IN11
487 #define ADC_CHANNEL_POT2 ADC_Channel_12 // ADC1_IN12
488 #define ADC_CHANNEL_BATT ADC_Channel_10 // ADC1_IN10
489 #elif defined(PCBX7)
490 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2)
491 #define ADC_RCC_APB1Periph 0
492 #define ADC_RCC_APB2Periph RCC_APB2Periph_ADC1
493 #define ADC_GPIO_PIN_STICK_RV GPIO_Pin_0 // PA.00
494 #define ADC_GPIO_PIN_STICK_RH GPIO_Pin_1 // PA.01
495 #define ADC_GPIO_PIN_STICK_LV GPIO_Pin_2 // PA.02
496 #define ADC_GPIO_PIN_STICK_LH GPIO_Pin_3 // PA.03
497 #define ADC_CHANNEL_STICK_RV ADC_Channel_0 // ADC1_IN0
498 #define ADC_CHANNEL_STICK_RH ADC_Channel_1 // ADC1_IN1
499 #define ADC_CHANNEL_STICK_LV ADC_Channel_2 // ADC1_IN2
500 #define ADC_CHANNEL_STICK_LH ADC_Channel_3 // ADC1_IN3
501 #define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06
502 #define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
503 #define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
504 #define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_POT1)
505 #define ADC_GPIOB_PINS ADC_GPIO_PIN_POT2
506 #define ADC_GPIOC_PINS ADC_GPIO_PIN_BATT
507 #define ADC_CHANNEL_POT1 ADC_Channel_6
508 #define ADC_CHANNEL_POT2 ADC_Channel_8
509 #define ADC_CHANNEL_BATT ADC_Channel_10
510 #else
511 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2)
512 #define ADC_RCC_APB1Periph 0
513 #define ADC_RCC_APB2Periph RCC_APB2Periph_ADC1
514 #define ADC_GPIO_PIN_STICK_RV GPIO_Pin_0 // PA.00
515 #define ADC_GPIO_PIN_STICK_RH GPIO_Pin_1 // PA.01
516 #define ADC_GPIO_PIN_STICK_LH GPIO_Pin_2 // PA.02
517 #define ADC_GPIO_PIN_STICK_LV GPIO_Pin_3 // PA.03
518 #define ADC_CHANNEL_STICK_RV ADC_Channel_0 // ADC1_IN0
519 #define ADC_CHANNEL_STICK_RH ADC_Channel_1 // ADC1_IN1
520 #define ADC_CHANNEL_STICK_LH ADC_Channel_2 // ADC1_IN2
521 #define ADC_CHANNEL_STICK_LV ADC_Channel_3 // ADC1_IN3
522 #define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06
523 #define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
524 #define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_4 // PC.04
525 #define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_5 // PC.05
526 #define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
527 #define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_POT1)
528 #define ADC_GPIOB_PINS (ADC_GPIO_PIN_POT2)
529 #define ADC_GPIOC_PINS (ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2 | ADC_GPIO_PIN_BATT)
530 #define ADC_CHANNEL_POT1 ADC_Channel_6
531 #define ADC_CHANNEL_POT2 ADC_Channel_8
532 #define ADC_CHANNEL_POT3 ADC_Channel_9
533 #define ADC_CHANNEL_SLIDER1 ADC_Channel_14
534 #define ADC_CHANNEL_SLIDER2 ADC_Channel_15
535 #define ADC_CHANNEL_BATT ADC_Channel_10
536 #endif
538 // PWR and LED driver
539 #define PWR_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE)
541 #if defined(PCBXLITE)
542 #define PWR_SWITCH_GPIO GPIOA
543 #define PWR_SWITCH_GPIO_PIN GPIO_Pin_7 // PA.07
544 #define PWR_ON_GPIO GPIOE
545 #define PWR_ON_GPIO_PIN GPIO_Pin_9 // PE.09
546 #else
547 #define PWR_SWITCH_GPIO GPIOD
548 #define PWR_SWITCH_GPIO_PIN GPIO_Pin_1 // PD.01
549 #define PWR_ON_GPIO GPIOD
550 #define PWR_ON_GPIO_PIN GPIO_Pin_0 // PD.00
551 #endif
552 #define PWR_ON_GPIO_MODER GPIO_MODER_MODER0
553 #define PWR_ON_GPIO_MODER_OUT GPIO_MODER_MODER0_0
555 #if defined(PCBXLITE)
556 #define STATUS_LEDS
557 #define GPIO_LED_GPIO_ON GPIO_ResetBits
558 #define GPIO_LED_GPIO_OFF GPIO_SetBits
559 #define LED_BLUE_GPIO GPIOE
560 #define LED_BLUE_GPIO_PIN GPIO_Pin_6 // PE.06
561 #define LED_RED_GPIO GPIOE
562 #define LED_RED_GPIO_PIN GPIO_Pin_4 // PE.04
563 #define LED_GREEN_GPIO GPIOE
564 #define LED_GREEN_GPIO_PIN GPIO_Pin_5 // PE.05
565 #elif defined(PCBX7)
566 #define STATUS_LEDS
567 #define GPIO_LED_GPIO_ON GPIO_SetBits
568 #define GPIO_LED_GPIO_OFF GPIO_ResetBits
569 #define LED_GREEN_GPIO GPIOC
570 #define LED_GREEN_GPIO_PIN GPIO_Pin_4 // PC.04
571 #define LED_RED_GPIO GPIOC
572 #define LED_RED_GPIO_PIN GPIO_Pin_5 // PC.05
573 #define LED_BLUE_GPIO GPIOB
574 #define LED_BLUE_GPIO_PIN GPIO_Pin_1 // PB.01
575 #endif
577 // Internal Module
578 #if defined(PCBXLITE)
579 #define INTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA2)
580 #define INTMODULE_RCC_APB1Periph RCC_APB1Periph_TIM3
581 #define INTMODULE_RCC_APB2Periph RCC_APB2Periph_USART1
582 #define INTMODULE_PWR_GPIO GPIOD
583 #define INTMODULE_PWR_GPIO_PIN GPIO_Pin_9 // PD.09
584 #define INTMODULE_TX_GPIO GPIOB
585 #define INTMODULE_TX_GPIO_PIN GPIO_Pin_6 // PB.06
586 #define INTMODULE_RX_GPIO GPIOB
587 #define INTMODULE_RX_GPIO_PIN GPIO_Pin_7 // PB.07
588 #define INTMODULE_TX_GPIO_PinSource GPIO_PinSource6
589 #define INTMODULE_RX_GPIO_PinSource GPIO_PinSource7
590 #define INTMODULE_USART USART1
591 #define INTMODULE_TX_GPIO_AF GPIO_AF_USART1
592 #define INTMODULE_USART_IRQn USART1_IRQn
593 #define INTMODULE_DMA_STREAM DMA2_Stream7
594 #define INTMODULE_DMA_STREAM_IRQ DMA2_Stream7_IRQn
595 #define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream7_IRQHandler
596 #define INTMODULE_DMA_FLAG_TC DMA_IT_TCIF7
597 #define INTMODULE_DMA_CHANNEL DMA_Channel_4
598 #define INTMODULE_TIMER TIM3
599 #define INTMODULE_TIMER_IRQn TIM3_IRQn
600 #define INTMODULE_TIMER_IRQHandler TIM3_IRQHandler
601 #define INTMODULE_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
602 #elif defined(PCBX9E) || defined(PCBX9DP) || defined(PCBX7)
603 #define INTMODULE_PULSES
604 #define INTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2)
605 #define INTMODULE_RCC_APB1Periph 0
606 #define INTMODULE_RCC_APB2Periph RCC_APB2Periph_TIM1
607 #define INTMODULE_PWR_GPIO GPIOC
608 #define INTMODULE_PWR_GPIO_PIN GPIO_Pin_6 // PC.06
609 #define INTMODULE_TX_GPIO GPIOA
610 #define INTMODULE_TX_GPIO_PIN GPIO_Pin_10 // PA.10
611 #define INTMODULE_TX_GPIO_PinSource GPIO_PinSource10
612 #define INTMODULE_TIMER TIM1
613 #define INTMODULE_TIMER_CC_IRQn TIM1_CC_IRQn
614 #define INTMODULE_TIMER_CC_IRQHandler TIM1_CC_IRQHandler
615 #define INTMODULE_TX_GPIO_AF GPIO_AF_TIM1
616 #define INTMODULE_DMA_CHANNEL DMA_Channel_6
617 #define INTMODULE_DMA_STREAM DMA2_Stream5
618 #define INTMODULE_DMA_STREAM_IRQn DMA2_Stream5_IRQn
619 #define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream5_IRQHandler
620 #define INTMODULE_DMA_FLAG_TC DMA_IT_TCIF5
621 #define INTMODULE_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
622 #else
623 #define INTMODULE_PULSES
624 #define INTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA2)
625 #define INTMODULE_RCC_APB1Periph 0
626 #define INTMODULE_RCC_APB2Periph RCC_APB2Periph_TIM1
627 #define INTMODULE_PWR_GPIO GPIOD
628 #define INTMODULE_PWR_GPIO_PIN GPIO_Pin_15 // PD.15
629 #define INTMODULE_TX_GPIO GPIOA
630 #define INTMODULE_TX_GPIO_PIN GPIO_Pin_10 // PA.10
631 #define INTMODULE_TX_GPIO_PinSource GPIO_PinSource10
632 #define INTMODULE_TIMER TIM1
633 #define INTMODULE_TIMER_CC_IRQn TIM1_CC_IRQn
634 #define INTMODULE_TIMER_CC_IRQHandler TIM1_CC_IRQHandler
635 #define INTMODULE_TX_GPIO_AF GPIO_AF_TIM1
636 #define INTMODULE_DMA_CHANNEL DMA_Channel_6
637 #define INTMODULE_DMA_STREAM DMA2_Stream5
638 #define INTMODULE_DMA_STREAM_IRQn DMA2_Stream5_IRQn
639 #define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream5_IRQHandler
640 #define INTMODULE_DMA_FLAG_TC DMA_IT_TCIF5
641 #define INTMODULE_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
642 #endif
644 // External Module
645 #define EXTMODULE_PULSES
646 #if defined(PCBXLITE)
647 #define EXTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA2)
648 #define EXTMODULE_RCC_APB2Periph (RCC_APB2Periph_TIM8 | RCC_APB2Periph_USART6)
649 #define EXTMODULE_PWR_GPIO GPIOD
650 #define EXTMODULE_PWR_GPIO_PIN GPIO_Pin_11 // PD.11
651 #define EXTMODULE_TX_GPIO GPIOC
652 #define EXTMODULE_TX_GPIO_PIN GPIO_Pin_6 // PC.06
653 #define EXTMODULE_TX_GPIO_PinSource GPIO_PinSource6
654 #define EXTMODULE_TIMER TIM8
655 #define EXTMODULE_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
656 #define EXTMODULE_TIMER_CC_IRQn TIM8_CC_IRQn
657 #define EXTMODULE_TIMER_CC_IRQHandler TIM8_CC_IRQHandler
658 #define EXTMODULE_TIMER_TX_GPIO_AF GPIO_AF_TIM8 // TIM8_CH1
659 #define EXTMODULE_TIMER_DMA_CHANNEL DMA_Channel_7
660 #define EXTMODULE_TIMER_DMA_STREAM DMA2_Stream1
661 #define EXTMODULE_TIMER_DMA_STREAM_IRQn DMA2_Stream1_IRQn
662 #define EXTMODULE_TIMER_DMA_STREAM_IRQHandler DMA2_Stream1_IRQHandler
663 #define EXTMODULE_TIMER_DMA_FLAG_TC DMA_IT_TCIF1
664 #define EXTMODULE_TIMER_OUTPUT_ENABLE TIM_CCER_CC1E
665 #define EXTMODULE_TIMER_OUTPUT_POLARITY TIM_CCER_CC1P
666 #define EXTMODULE_USART_TX_GPIO_AF GPIO_AF_USART6
667 #define EXTMODULE_USART USART6
668 #define EXTMODULE_USART_IRQn USART6_IRQn
669 #define EXTMODULE_USART_DMA_CHANNEL DMA_Channel_5
670 #define EXTMODULE_USART_DMA_STREAM DMA2_Stream6
671 #define EXTMODULE_USART_DMA_STREAM_IRQn DMA2_Stream6_IRQn
672 #define EXTMODULE_USART_DMA_STREAM_IRQHandler DMA2_Stream6_IRQHandler
673 #define EXTMODULE_USART_DMA_FLAG_TC DMA_IT_TCIF6
674 #else
675 #define EXTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA2)
676 #define EXTMODULE_RCC_APB2Periph RCC_APB2Periph_TIM8
677 #define EXTMODULE_PWR_GPIO GPIOD
678 #define EXTMODULE_PWR_GPIO_PIN GPIO_Pin_8 // PD.08
679 #define EXTMODULE_TX_GPIO GPIOA
680 #define EXTMODULE_TX_GPIO_PIN GPIO_Pin_7 // PA.07
681 #define EXTMODULE_TX_GPIO_PinSource GPIO_PinSource7
682 #define EXTMODULE_TIMER TIM8
683 #define EXTMODULE_TIMER_TX_GPIO_AF GPIO_AF_TIM8 // TIM8_CH1N
684 #define EXTMODULE_TIMER_CC_IRQn TIM8_CC_IRQn
685 #define EXTMODULE_TIMER_CC_IRQHandler TIM8_CC_IRQHandler
686 #define EXTMODULE_TIMER_DMA_CHANNEL DMA_Channel_7
687 #define EXTMODULE_TIMER_DMA_STREAM DMA2_Stream1
688 #define EXTMODULE_TIMER_DMA_STREAM_IRQn DMA2_Stream1_IRQn
689 #define EXTMODULE_TIMER_DMA_STREAM_IRQHandler DMA2_Stream1_IRQHandler
690 #define EXTMODULE_TIMER_DMA_FLAG_TC DMA_IT_TCIF1
691 #define EXTMODULE_TIMER_OUTPUT_ENABLE TIM_CCER_CC1NE
692 #define EXTMODULE_TIMER_OUTPUT_POLARITY TIM_CCER_CC1NP
693 #define EXTMODULE_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
694 #endif
696 // Trainer Port
697 #if defined(PCBXLITE)
698 #define TRAINER_RCC_AHB1Periph 0
699 #define TRAINER_RCC_APB1Periph 0
700 #else
701 #define TRAINER_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC)
702 #define TRAINER_RCC_APB1Periph RCC_APB1Periph_TIM3
703 #define TRAINER_GPIO GPIOC
704 #define TRAINER_IN_GPIO_PIN GPIO_Pin_8 // PC.08
705 #define TRAINER_IN_GPIO_PinSource GPIO_PinSource8
706 #define TRAINER_OUT_GPIO_PIN GPIO_Pin_9 // PC.09
707 #define TRAINER_OUT_GPIO_PinSource GPIO_PinSource9
708 #define TRAINER_DETECT_GPIO GPIOA
709 #define TRAINER_DETECT_GPIO_PIN GPIO_Pin_8 // PA.08
710 #define TRAINER_TIMER TIM3
711 #define TRAINER_TIMER_IRQn TIM3_IRQn
712 #define TRAINER_GPIO_AF GPIO_AF_TIM3
713 #define TRAINER_DMA DMA1
714 #define TRAINER_DMA_CHANNEL DMA_Channel_5
715 #define TRAINER_DMA_STREAM DMA1_Stream2
716 #define TRAINER_DMA_IRQn DMA1_Stream2_IRQn
717 #define TRAINER_DMA_IRQHandler DMA1_Stream2_IRQHandler
718 #define TRAINER_DMA_FLAG_TC DMA_IT_TCIF2
719 #define TRAINER_TIMER_IRQn TIM3_IRQn
720 #define TRAINER_TIMER_IRQHandler TIM3_IRQHandler
721 #define TRAINER_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
722 #endif
724 // Serial Port
725 #if defined(PCBX7) || defined(PCBXLITE)
726 #define SERIAL_RCC_AHB1Periph 0
727 #define SERIAL_RCC_APB1Periph 0
728 #else
729 #define TRAINER_BATTERY_COMPARTMENT
730 #define SERIAL_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA1)
731 #define SERIAL_RCC_APB1Periph RCC_APB1Periph_USART3
732 #define SERIAL_GPIO GPIOB
733 #define SERIAL_GPIO_PIN_TX GPIO_Pin_10 // PB.10
734 #define SERIAL_GPIO_PIN_RX GPIO_Pin_11 // PB.11
735 #define SERIAL_GPIO_PinSource_TX GPIO_PinSource10
736 #define SERIAL_GPIO_PinSource_RX GPIO_PinSource11
737 #define SERIAL_GPIO_AF GPIO_AF_USART3
738 #define SERIAL_USART USART3
739 #define SERIAL_USART_IRQHandler USART3_IRQHandler
740 #define SERIAL_USART_IRQn USART3_IRQn
741 #define SERIAL_DMA_Stream_RX DMA1_Stream1
742 #define SERIAL_DMA_Channel_RX DMA_Channel_4
743 #endif
745 // Telemetry
746 #define TELEMETRY_RCC_AHB1Periph (RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
747 #define TELEMETRY_RCC_APB1Periph RCC_APB1Periph_USART2
748 #define TELEMETRY_DIR_GPIO GPIOD
749 #define TELEMETRY_DIR_GPIO_PIN GPIO_Pin_4 // PD.04
750 #if defined(PCBXLITE)
751 #define TELEMETRY_DIR_OUTPUT() TELEMETRY_DIR_GPIO->BSRRH = TELEMETRY_DIR_GPIO_PIN
752 #define TELEMETRY_DIR_INPUT() TELEMETRY_DIR_GPIO->BSRRL = TELEMETRY_DIR_GPIO_PIN
753 #else
754 #define TELEMETRY_DIR_OUTPUT() TELEMETRY_DIR_GPIO->BSRRL = TELEMETRY_DIR_GPIO_PIN
755 #define TELEMETRY_DIR_INPUT() TELEMETRY_DIR_GPIO->BSRRH = TELEMETRY_DIR_GPIO_PIN
756 #endif
757 #define TELEMETRY_GPIO GPIOD
758 #define TELEMETRY_TX_GPIO_PIN GPIO_Pin_5 // PD.05
759 #define TELEMETRY_RX_GPIO_PIN GPIO_Pin_6 // PD.06
760 #define TELEMETRY_GPIO_PinSource_TX GPIO_PinSource5
761 #define TELEMETRY_GPIO_PinSource_RX GPIO_PinSource6
762 #define TELEMETRY_GPIO_AF GPIO_AF_USART2
763 #define TELEMETRY_USART USART2
764 #define TELEMETRY_DMA_Stream_TX DMA1_Stream6
765 #define TELEMETRY_DMA_Channel_TX DMA_Channel_4
766 #define TELEMETRY_DMA_TX_Stream_IRQ DMA1_Stream6_IRQn
767 #define TELEMETRY_DMA_TX_IRQHandler DMA1_Stream6_IRQHandler
768 #define TELEMETRY_DMA_TX_FLAG_TC DMA_IT_TCIF6
769 #define TELEMETRY_USART_IRQHandler USART2_IRQHandler
770 #define TELEMETRY_USART_IRQn USART2_IRQn
772 // PCBREV
773 #if defined(PCBX7)
774 #define PCBREV_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
775 #define PCBREV_GPIO GPIOA
776 #define PCBREV_GPIO_PIN GPIO_Pin_14 // PA.14
777 #else
778 #define PCBREV_RCC_AHB1Periph 0
779 #endif
781 // S.Port update connector
782 #if defined(PCBXLITE)
783 #define SPORT_MAX_BAUDRATE 250000 // not tested
784 #define SPORT_UPDATE_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
785 #define SPORT_UPDATE_PWR_GPIO GPIOD
786 #define SPORT_UPDATE_PWR_GPIO_PIN GPIO_Pin_8 // PD.08
787 #define GPIO_SPORT_UPDATE_PWR_GPIO_ON GPIO_SetBits
788 #define GPIO_SPORT_UPDATE_PWR_GPIO_OFF GPIO_ResetBits
789 #elif defined(PCBX7)
790 #define SPORT_MAX_BAUDRATE 250000 // < 400000
791 #define SPORT_UPDATE_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
792 #define SPORT_UPDATE_PWR_GPIO GPIOB
793 #define SPORT_UPDATE_PWR_GPIO_PIN GPIO_Pin_2 // PB.02
794 #define GPIO_SPORT_UPDATE_PWR_GPIO_ON GPIO_SetBits
795 #define GPIO_SPORT_UPDATE_PWR_GPIO_OFF GPIO_ResetBits
796 #else
797 #define SPORT_MAX_BAUDRATE 400000
798 #define SPORT_UPDATE_RCC_AHB1Periph 0
799 #endif
801 // Heartbeat
802 #if defined(PCBXLITE)
803 #define HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
804 #define HEARTBEAT_RCC_APB2Periph 0
805 #define HEARTBEAT_GPIO GPIOD
806 #define HEARTBEAT_GPIO_PIN GPIO_Pin_15 // PD.15
807 #else
808 #define TRAINER_MODULE_HEARTBEAT
809 #define HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOC
810 #define HEARTBEAT_RCC_APB2Periph RCC_APB2Periph_USART6
811 #define HEARTBEAT_GPIO GPIOC
812 #define HEARTBEAT_GPIO_PIN GPIO_Pin_7 // PC.07
813 #define HEARTBEAT_GPIO_PinSource GPIO_PinSource7
814 #define HEARTBEAT_GPIO_AF_SBUS GPIO_AF_USART6
815 #define HEARTBEAT_GPIO_AF_CAPTURE GPIO_AF_TIM3
816 #define HEARTBEAT_USART USART6
817 #define HEARTBEAT_USART_IRQHandler USART6_IRQHandler
818 #define HEARTBEAT_USART_IRQn USART6_IRQn
819 #define HEARTBEAT_DMA_Stream DMA2_Stream1
820 #define HEARTBEAT_DMA_Channel DMA_Channel_5
821 #endif
823 // USB
824 #define USB_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOA
825 #define USB_GPIO GPIOA
826 #define USB_GPIO_PIN_VBUS GPIO_Pin_9 // PA.09
827 #define USB_GPIO_PIN_DM GPIO_Pin_11 // PA.11
828 #define USB_GPIO_PIN_DP GPIO_Pin_12 // PA.12
829 #define USB_GPIO_PinSource_DM GPIO_PinSource11
830 #define USB_GPIO_PinSource_DP GPIO_PinSource12
831 #define USB_GPIO_AF GPIO_AF_OTG1_FS
833 // BackLight
834 #if defined(PCBX9E)
835 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOE
836 #define BACKLIGHT_RCC_APB1Periph 0
837 #define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM9
838 #define BACKLIGHT_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
839 #define BACKLIGHT_TIMER TIM9
840 #define BACKLIGHT_GPIO GPIOE
841 #define BACKLIGHT_GPIO_PIN_1 GPIO_Pin_6 // PE.06
842 #define BACKLIGHT_GPIO_PIN_2 GPIO_Pin_5 // PE.05
843 #define BACKLIGHT_GPIO_PinSource_1 GPIO_PinSource6
844 #define BACKLIGHT_GPIO_PinSource_2 GPIO_PinSource5
845 #define BACKLIGHT_GPIO_AF_1 GPIO_AF_TIM9
846 #define BACKLIGHT_GPIO_AF_2 GPIO_AF_TIM9
847 #elif defined(PCBX9DP)
848 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
849 #define BACKLIGHT_RCC_APB1Periph RCC_APB1Periph_TIM4
850 #define BACKLIGHT_RCC_APB2Periph 0
851 #define BACKLIGHT_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
852 #define BACKLIGHT_TIMER TIM4
853 #define BACKLIGHT_GPIO GPIOD
854 #define BACKLIGHT_GPIO_PIN_1 GPIO_Pin_15 // PD.15
855 #define BACKLIGHT_GPIO_PIN_2 GPIO_Pin_13 // PD.13
856 #define BACKLIGHT_GPIO_PinSource_1 GPIO_PinSource15
857 #define BACKLIGHT_GPIO_PinSource_2 GPIO_PinSource13
858 #define BACKLIGHT_GPIO_AF_1 GPIO_AF_TIM4
859 #define BACKLIGHT_GPIO_AF_2 GPIO_AF_TIM4
860 #elif defined(PCBXLITE)
861 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
862 #define BACKLIGHT_RCC_APB1Periph 0
863 #define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM1
864 #define BACKLIGHT_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
865 #define BACKLIGHT_TIMER TIM1
866 #define BACKLIGHT_GPIO GPIOA
867 #define BACKLIGHT_GPIO_PIN GPIO_Pin_8 // PA.08
868 #define BACKLIGHT_GPIO_PinSource GPIO_PinSource8
869 #define BACKLIGHT_GPIO_AF GPIO_AF_TIM1
870 #define BACKLIGHT_CCMR1 TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 // Channel 1, PWM
871 #define BACKLIGHT_CCER TIM_CCER_CC1E
872 #define BACKLIGHT_COUNTER_REGISTER BACKLIGHT_TIMER->CCR1
873 #elif defined(PCBX7)
874 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
875 #define BACKLIGHT_RCC_APB1Periph RCC_APB1Periph_TIM4
876 #define BACKLIGHT_RCC_APB2Periph 0
877 #define BACKLIGHT_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
878 #define BACKLIGHT_TIMER TIM4
879 #define BACKLIGHT_GPIO GPIOD
880 #define BACKLIGHT_GPIO_PIN GPIO_Pin_13 // PD.13
881 #define BACKLIGHT_GPIO_PinSource GPIO_PinSource13
882 #define BACKLIGHT_GPIO_AF GPIO_AF_TIM4
883 #define BACKLIGHT_CCMR1 TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 // Channel2, PWM
884 #define BACKLIGHT_CCER TIM_CCER_CC2E
885 #define BACKLIGHT_COUNTER_REGISTER BACKLIGHT_TIMER->CCR2
886 #else
887 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
888 #define BACKLIGHT_RCC_APB1Periph 0
889 #define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM10
890 #define BACKLIGHT_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
891 #define BACKLIGHT_TIMER TIM10
892 #define BACKLIGHT_GPIO GPIOB
893 #define BACKLIGHT_GPIO_PIN GPIO_Pin_8 // PB.08
894 #define BACKLIGHT_GPIO_PinSource GPIO_PinSource8
895 #define BACKLIGHT_GPIO_AF GPIO_AF_TIM10
896 #endif
898 // LCD driver
899 #if defined(PCBX9E)
900 #define LCD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
901 #define LCD_RCC_APB1Periph RCC_APB1Periph_SPI3
902 #define LCD_SPI_GPIO GPIOC
903 #define LCD_MOSI_GPIO_PIN GPIO_Pin_12 // PC.12
904 #define LCD_MOSI_GPIO_PinSource GPIO_PinSource12
905 #define LCD_CLK_GPIO_PIN GPIO_Pin_10 // PC.10
906 #define LCD_CLK_GPIO_PinSource GPIO_PinSource10
907 #define LCD_A0_GPIO_PIN GPIO_Pin_11 // PC.11
908 #define LCD_NCS_GPIO GPIOA
909 #define LCD_NCS_GPIO_PIN GPIO_Pin_15 // PA.15
910 #define LCD_RST_GPIO GPIOD
911 #define LCD_RST_GPIO_PIN GPIO_Pin_15 // PD.15
912 #define LCD_DMA DMA1
913 #define LCD_DMA_Stream DMA1_Stream7
914 #define LCD_DMA_Stream_IRQn DMA1_Stream7_IRQn
915 #define LCD_DMA_Stream_IRQHandler DMA1_Stream7_IRQHandler
916 #define LCD_DMA_FLAGS (DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7)
917 #define LCD_DMA_FLAG_INT DMA_HIFCR_CTCIF7
918 #define LCD_SPI SPI3
919 #define LCD_GPIO_AF GPIO_AF_SPI3
920 #elif defined(PCBXLITE)
921 #define LCD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
922 #define LCD_RCC_APB1Periph RCC_APB1Periph_SPI3
923 #define LCD_SPI_GPIO GPIOC
924 #define LCD_MOSI_GPIO_PIN GPIO_Pin_12 // PC.12
925 #define LCD_MOSI_GPIO_PinSource GPIO_PinSource12
926 #define LCD_CLK_GPIO_PIN GPIO_Pin_10 // PC.10
927 #define LCD_CLK_GPIO_PinSource GPIO_PinSource10
928 #define LCD_A0_GPIO_PIN GPIO_Pin_11 // PC.11
929 #define LCD_NCS_GPIO GPIOD
930 #define LCD_NCS_GPIO_PIN GPIO_Pin_3 // PD.03
931 #define LCD_RST_GPIO GPIOD
932 #define LCD_RST_GPIO_PIN GPIO_Pin_2 // PD.02
933 #define LCD_DMA DMA1
934 #define LCD_DMA_Stream DMA1_Stream7
935 #define LCD_DMA_Stream_IRQn DMA1_Stream7_IRQn
936 #define LCD_DMA_Stream_IRQHandler DMA1_Stream7_IRQHandler
937 #define LCD_DMA_FLAGS (DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7)
938 #define LCD_DMA_FLAG_INT DMA_HIFCR_CTCIF7
939 #define LCD_SPI SPI3
940 #define LCD_GPIO_AF GPIO_AF_SPI3
941 #elif defined(PCBX9DP) || defined(PCBX7)
942 #define LCD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
943 #define LCD_RCC_APB1Periph RCC_APB1Periph_SPI3
944 #define LCD_SPI_GPIO GPIOC
945 #define LCD_MOSI_GPIO_PIN GPIO_Pin_12 // PC.12
946 #define LCD_MOSI_GPIO_PinSource GPIO_PinSource12
947 #define LCD_CLK_GPIO_PIN GPIO_Pin_10 // PC.10
948 #define LCD_CLK_GPIO_PinSource GPIO_PinSource10
949 #define LCD_A0_GPIO_PIN GPIO_Pin_11 // PC.11
950 #define LCD_NCS_GPIO GPIOA
951 #define LCD_NCS_GPIO_PIN GPIO_Pin_15 // PA.15
952 #define LCD_RST_GPIO GPIOD
953 #define LCD_RST_GPIO_PIN GPIO_Pin_12 // PD.12
954 #define LCD_DMA DMA1
955 #define LCD_DMA_Stream DMA1_Stream7
956 #define LCD_DMA_Stream_IRQn DMA1_Stream7_IRQn
957 #define LCD_DMA_Stream_IRQHandler DMA1_Stream7_IRQHandler
958 #define LCD_DMA_FLAGS (DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7)
959 #define LCD_DMA_FLAG_INT DMA_HIFCR_CTCIF7
960 #define LCD_SPI SPI3
961 #define LCD_GPIO_AF GPIO_AF_SPI3
962 #else
963 #define LCD_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
964 #define LCD_RCC_APB1Periph 0
965 #define LCD_SPI_GPIO GPIOD
966 #define LCD_MOSI_GPIO_PIN GPIO_Pin_10 // PD.10
967 #define LCD_CLK_GPIO_PIN GPIO_Pin_11 // PD.11
968 #define LCD_A0_GPIO_PIN GPIO_Pin_13 // PD.13
969 #define LCD_NCS_GPIO GPIOD
970 #define LCD_NCS_GPIO_PIN GPIO_Pin_14 // PD.14
971 #define LCD_RST_GPIO GPIOD
972 #define LCD_RST_GPIO_PIN GPIO_Pin_12 // PD.12
973 #endif
974 #define LCD_RCC_APB2Periph 0
976 // I2C Bus: EEPROM and CAT5137 digital pot for volume control
977 #define I2C_RCC_APB1Periph RCC_APB1Periph_I2C1
978 #define I2C I2C1
979 #define I2C_GPIO_AF GPIO_AF_I2C1
980 #if defined(PCBXLITE)
981 #define I2C_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD)
982 #define I2C_SPI_GPIO GPIOB
983 #define I2C_SDA_GPIO_PIN GPIO_Pin_9 // PB.09
984 #define I2C_SCL_GPIO_PIN GPIO_Pin_8 // PB.08
985 #define I2C_WP_GPIO GPIOD
986 #define I2C_WP_GPIO_PIN GPIO_Pin_7 // PD.07
987 #define I2C_SCL_GPIO_PinSource GPIO_PinSource8
988 #define I2C_SDA_GPIO_PinSource GPIO_PinSource9
989 #else
990 #define I2C_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
991 #define I2C_SPI_GPIO GPIOB
992 #define I2C_SCL_GPIO_PIN GPIO_Pin_6 // PB.06
993 #define I2C_SDA_GPIO_PIN GPIO_Pin_7 // PB.07
994 #define I2C_WP_GPIO GPIOB
995 #define I2C_WP_GPIO_PIN GPIO_Pin_9 // PB.09
996 #define I2C_SCL_GPIO_PinSource GPIO_PinSource6
997 #define I2C_SDA_GPIO_PinSource GPIO_PinSource7
998 #endif
999 #if defined(REV4a)
1000 #define I2C_SPEED 100000
1001 #else
1002 #define I2C_SPEED 400000
1003 #endif
1004 #define I2C_ADDRESS_EEPROM 0xA2
1005 #define I2C_ADDRESS_VOLUME 0x5C
1006 #define I2C_FLASH_PAGESIZE 64
1008 // SD - SPI2
1009 #define SD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA1)
1010 #define SD_RCC_APB1Periph RCC_APB1Periph_SPI2
1011 #define SD_GPIO_PRESENT_GPIO GPIOD
1012 #if defined(PCBXLITE)
1013 #define SD_GPIO_PRESENT_GPIO_PIN GPIO_Pin_10 // PD.10
1014 #else
1015 #define SD_GPIO_PRESENT_GPIO_PIN GPIO_Pin_9 // PD.09
1016 #endif
1017 #define SD_GPIO GPIOB
1018 #define SD_GPIO_PIN_CS GPIO_Pin_12 // PB.12
1019 #define SD_GPIO_PIN_SCK GPIO_Pin_13 // PB.13
1020 #define SD_GPIO_PIN_MISO GPIO_Pin_14 // PB.14
1021 #define SD_GPIO_PIN_MOSI GPIO_Pin_15 // PB.15
1022 #define SD_GPIO_AF GPIO_AF_SPI2
1023 #define SD_GPIO_PinSource_CS GPIO_PinSource12
1024 #define SD_GPIO_PinSource_SCK GPIO_PinSource13
1025 #define SD_GPIO_PinSource_MISO GPIO_PinSource14
1026 #define SD_GPIO_PinSource_MOSI GPIO_PinSource15
1027 #define SD_SPI SPI2
1028 #define SD_SPI_BaudRatePrescaler SPI_BaudRatePrescaler_4 // 10.5<20MHZ, make sure < 20MHZ
1030 #if !defined(BOOT)
1031 #define SD_USE_DMA // Enable the DMA for SD
1032 #define SD_DMA_Stream_SPI_RX DMA1_Stream3
1033 #define SD_DMA_Stream_SPI_TX DMA1_Stream4
1034 #define SD_DMA_FLAG_SPI_TC_RX DMA_FLAG_TCIF3
1035 #define SD_DMA_FLAG_SPI_TC_TX DMA_FLAG_TCIF4
1036 #define SD_DMA_Channel_SPI DMA_Channel_0
1037 #endif
1039 // Audio
1040 #define AUDIO_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA1)
1041 #define AUDIO_RCC_APB1Periph (RCC_APB1Periph_TIM6 | RCC_APB1Periph_DAC)
1042 #define AUDIO_OUTPUT_GPIO GPIOA
1043 #define AUDIO_OUTPUT_GPIO_PIN GPIO_Pin_4 // PA.04
1044 #define AUDIO_DMA_Stream DMA1_Stream5
1045 #define AUDIO_DMA_Stream_IRQn DMA1_Stream5_IRQn
1046 #define AUDIO_TIM_IRQn TIM6_DAC_IRQn
1047 #define AUDIO_TIM_IRQHandler TIM6_DAC_IRQHandler
1048 #define AUDIO_DMA_Stream_IRQHandler DMA1_Stream5_IRQHandler
1049 #define AUDIO_TIMER TIM6
1050 #define AUDIO_DMA DMA1
1052 // Haptic
1053 #if defined(PCBXLITE)
1054 #define HAPTIC_PWM
1055 #define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
1056 #define HAPTIC_RCC_APB1Periph RCC_APB1Periph_TIM2
1057 #define HAPTIC_RCC_APB2Periph 0
1058 #define HAPTIC_GPIO_PinSource GPIO_PinSource3
1059 #define HAPTIC_GPIO GPIOB
1060 #define HAPTIC_GPIO_PIN GPIO_Pin_3 // PB.03
1061 #define HAPTIC_GPIO_AF GPIO_AF_TIM2
1062 #define HAPTIC_TIMER TIM2
1063 #define HAPTIC_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
1064 #define HAPTIC_COUNTER_REGISTER HAPTIC_TIMER->CCR2
1065 #define HAPTIC_CCMR1 TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2
1066 #define HAPTIC_CCER TIM_CCER_CC2E
1067 #define BACKLIGHT_BDTR TIM_BDTR_MOE
1068 #elif defined(PCBX9E) || defined(PCBX9DP) || defined(PCBX7)
1069 #define HAPTIC_PWM
1070 #define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
1071 #define HAPTIC_RCC_APB2Periph RCC_APB2Periph_TIM10
1072 #define HAPTIC_RCC_APB1Periph 0
1073 #define HAPTIC_GPIO_PinSource GPIO_PinSource8
1074 #define HAPTIC_GPIO GPIOB
1075 #define HAPTIC_GPIO_PIN GPIO_Pin_8 // PB.08
1076 #define HAPTIC_GPIO_AF GPIO_AF_TIM10
1077 #define HAPTIC_TIMER TIM10
1078 #define HAPTIC_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
1079 #define HAPTIC_COUNTER_REGISTER HAPTIC_TIMER->CCR1
1080 #define HAPTIC_CCMR1 TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2
1081 #define HAPTIC_CCER TIM_CCER_CC1E
1082 #else
1083 #define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOC
1084 #define HAPTIC_RCC_APB2Periph 0
1085 #define HAPTIC_RCC_APB1Periph 0
1086 #define HAPTIC_GPIO GPIOC
1087 #define HAPTIC_GPIO_PIN GPIO_Pin_12
1088 #endif
1090 // Top LCD on X9E
1091 #if defined(PCBX9E)
1092 #define TOPLCD_RCC_AHB1Periph RCC_AHB1Periph_GPIOG
1093 #define TOPLCD_GPIO GPIOG
1094 #define TOPLCD_GPIO_PIN_DATA GPIO_Pin_5
1095 #define TOPLCD_GPIO_PIN_WR GPIO_Pin_4
1096 #define TOPLCD_GPIO_PIN_CS1 GPIO_Pin_3
1097 #define TOPLCD_GPIO_PIN_CS2 GPIO_Pin_15
1098 #define TOPLCD_GPIO_PIN_BL GPIO_Pin_2
1099 #endif
1101 // Bluetooth
1102 #if defined(PCBX9E)
1103 #define BT_USART USART6
1104 #define BT_GPIO_AF GPIO_AF_USART6
1105 #define BT_USART_IRQn USART6_IRQn
1106 #define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG)
1107 #define BT_RCC_APB1Periph 0
1108 #define BT_RCC_APB2Periph RCC_APB2Periph_USART6
1109 #define BT_GPIO_TXRX GPIOG
1110 #define BT_TX_GPIO_PIN GPIO_Pin_14 // PG.14
1111 #define BT_RX_GPIO_PIN GPIO_Pin_9 // PG.09
1112 #define BT_EN_GPIO GPIOD
1113 #define BT_EN_GPIO_PIN GPIO_Pin_11 // PD.11
1114 #define BT_BRTS_GPIO GPIOE
1115 #define BT_BRTS_GPIO_PIN GPIO_Pin_12 // PE.12
1116 #define BT_BCTS_GPIO GPIOG
1117 #define BT_BCTS_GPIO_PIN GPIO_Pin_6 // PG.06
1118 #define BT_TX_GPIO_PinSource GPIO_PinSource14
1119 #define BT_RX_GPIO_PinSource GPIO_PinSource9
1120 #define BT_USART_IRQHandler USART6_IRQHandler
1121 #elif defined(PCBX7) || defined(PCBXLITE)
1122 #define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_DMA1)
1123 #define BT_RCC_APB1Periph RCC_APB1Periph_USART3
1124 #define BT_RCC_APB2Periph 0
1125 #define BT_EN_GPIO GPIOE
1126 #if defined(PCBXLITE)
1127 #define BT_EN_GPIO_PIN GPIO_Pin_15 // PE.15
1128 #else
1129 #define BT_EN_GPIO_PIN GPIO_Pin_12 // PE.12
1130 #endif
1131 #define BT_GPIO_TXRX GPIOB
1132 #define BT_TX_GPIO_PIN GPIO_Pin_10 // PB.10
1133 #define BT_RX_GPIO_PIN GPIO_Pin_11 // PB.11
1134 #define BT_TX_GPIO_PinSource GPIO_PinSource10
1135 #define BT_RX_GPIO_PinSource GPIO_PinSource11
1136 #define BT_GPIO_AF GPIO_AF_USART3
1137 #define BT_USART USART3
1138 #define BT_USART_IRQHandler USART3_IRQHandler
1139 #define BT_USART_IRQn USART3_IRQn
1140 #define BT_DMA_Stream_RX DMA1_Stream1
1141 #define BT_DMA_Channel_RX DMA_Channel_4
1142 #else
1143 #define BT_RCC_AHB1Periph 0
1144 #define BT_RCC_APB1Periph 0
1145 #define BT_RCC_APB2Periph 0
1146 #endif
1148 // Xms Interrupt
1149 #define INTERRUPT_xMS_RCC_APB1Periph RCC_APB1Periph_TIM14
1150 #define INTERRUPT_xMS_TIMER TIM14
1151 #define INTERRUPT_xMS_IRQn TIM8_TRG_COM_TIM14_IRQn
1152 #define INTERRUPT_xMS_IRQHandler TIM8_TRG_COM_TIM14_IRQHandler
1154 // 2MHz Timer
1155 #define TIMER_2MHz_RCC_APB1Periph RCC_APB1Periph_TIM7
1156 #define TIMER_2MHz_TIMER TIM7
1158 #endif // _HAL_H_