Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / targets / horus / hal.h
blobe7afa6ddb87c44ba3ad1e305d13dd60d27837706
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 #define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOJ)
26 #if defined(PCBX12S)
27 #define KEYS_GPIO_REG_PGUP GPIOC->IDR
28 #define KEYS_GPIO_PIN_PGUP GPIO_Pin_13 // PC.13
29 #define KEYS_GPIO_REG_PGDN GPIOI->IDR
30 #define KEYS_GPIO_PIN_PGDN GPIO_Pin_8 // PI.08
31 #define KEYS_GPIO_REG_LEFT GPIOI->IDR
32 #define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
33 #define KEYS_GPIO_REG_ENTER GPIOC->IDR
34 #define KEYS_GPIO_PIN_ENTER GPIO_Pin_1 // PC.01
35 #define KEYS_GPIO_REG_UP GPIOG->IDR
36 #define KEYS_GPIO_PIN_UP GPIO_Pin_13 // PG.13
37 #define KEYS_GPIO_REG_DOWN GPIOI->IDR
38 #define KEYS_GPIO_PIN_DOWN GPIO_Pin_6 // PI.06
39 #define KEYS_GPIO_REG_RIGHT GPIOC->IDR
40 #define KEYS_GPIO_PIN_RIGHT GPIO_Pin_4 // PC.04
41 #elif defined(PCBX10)
42 #define KEYS_GPIO_REG_ENTER GPIOI->IDR
43 #define KEYS_GPIO_PIN_ENTER GPIO_Pin_8 // PI.08
44 #define KEYS_GPIO_REG_PGDN GPIOI->IDR
45 #define KEYS_GPIO_PIN_PGDN GPIO_Pin_11 // PI.11
46 #define KEYS_GPIO_REG_UP GPIOI->IDR
47 #define KEYS_GPIO_PIN_UP GPIO_Pin_4 // PI.04
48 #define KEYS_GPIO_REG_DOWN GPIOI->IDR
49 #define KEYS_GPIO_PIN_DOWN GPIO_Pin_6 // PI.06
50 #define KEYS_GPIO_REG_LEFT GPIOI->IDR
51 #define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
52 #define KEYS_GPIO_REG_RIGHT GPIOI->IDR
53 #define KEYS_GPIO_PIN_RIGHT GPIO_Pin_5 // PI.05
54 #endif
56 // Rotary Encoder
57 #define ROTARY_ENCODER_RCC_APB1Periph RCC_APB1Periph_TIM4
58 #define ROTARY_ENCODER_GPIO GPIOH
59 #define ROTARY_ENCODER_GPIO_PIN_A GPIO_Pin_11 // PH.11
60 #define ROTARY_ENCODER_GPIO_PIN_B GPIO_Pin_10 // PH.10
61 #define ROTARY_ENCODER_POSITION() ((ROTARY_ENCODER_GPIO->IDR >> 10) & 0x03)
62 #define ROTARY_ENCODER_EXTI_LINE1 EXTI_Line11
63 #define ROTARY_ENCODER_EXTI_LINE2 EXTI_Line10
64 #define ROTARY_ENCODER_EXTI_IRQn1 EXTI15_10_IRQn
65 #define ROTARY_ENCODER_EXTI_IRQHandler1 EXTI15_10_IRQHandler
66 #define ROTARY_ENCODER_EXTI_PortSource EXTI_PortSourceGPIOH
67 #define ROTARY_ENCODER_EXTI_PinSource1 EXTI_PinSource11
68 #define ROTARY_ENCODER_EXTI_PinSource2 EXTI_PinSource10
69 #define ROTARY_ENCODER_TIMER TIM4
70 #define ROTARY_ENCODER_TIMER_IRQn TIM4_IRQn
71 #define ROTARY_ENCODER_TIMER_IRQHandler TIM4_IRQHandler
73 // Switches
74 #define STORAGE_SWITCH_A
75 #define HARDWARE_SWITCH_A
76 #define SWITCHES_GPIO_REG_A_H GPIOH->IDR
77 #define SWITCHES_GPIO_PIN_A_H GPIO_Pin_9 // PH.09
78 #define SWITCHES_GPIO_REG_A_L GPIOI->IDR
79 #define SWITCHES_GPIO_PIN_A_L GPIO_Pin_15 // PI.15
80 #define STORAGE_SWITCH_B
81 #define HARDWARE_SWITCH_B
82 #define SWITCHES_GPIO_REG_B_H GPIOH->IDR
83 #define SWITCHES_GPIO_PIN_B_H GPIO_Pin_12 // PH.12
84 #define SWITCHES_GPIO_REG_B_L GPIOB->IDR
85 #define SWITCHES_GPIO_PIN_B_L GPIO_Pin_12 // PB.12
86 #define STORAGE_SWITCH_C
87 #define HARDWARE_SWITCH_C
88 #define SWITCHES_GPIO_REG_C_H GPIOD->IDR
89 #define SWITCHES_GPIO_PIN_C_H GPIO_Pin_11 // PD.11
90 #define SWITCHES_GPIO_REG_C_L GPIOB->IDR
91 #define SWITCHES_GPIO_PIN_C_L GPIO_Pin_15 // PB.15
92 #define STORAGE_SWITCH_D
93 #define HARDWARE_SWITCH_D
94 #define SWITCHES_GPIO_REG_D_H GPIOJ->IDR
95 #define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PJ.07
96 #define SWITCHES_GPIO_REG_D_L GPIOG->IDR
97 #define SWITCHES_GPIO_PIN_D_L GPIO_Pin_2 // PG.02
98 #define STORAGE_SWITCH_E
99 #define HARDWARE_SWITCH_E
100 #define SWITCHES_GPIO_REG_E_H GPIOH->IDR
101 #define SWITCHES_GPIO_PIN_E_H GPIO_Pin_4 // PH.04
102 #define SWITCHES_GPIO_REG_E_L GPIOE->IDR
103 #define SWITCHES_GPIO_PIN_E_L GPIO_Pin_3 // PE.03
104 #define STORAGE_SWITCH_F
105 #define HARDWARE_SWITCH_F
106 #define SWITCHES_GPIO_REG_F GPIOH->IDR
107 #define SWITCHES_GPIO_PIN_F GPIO_Pin_3 // PH.03
108 #define STORAGE_SWITCH_G
109 #define HARDWARE_SWITCH_G
110 #define SWITCHES_GPIO_REG_G_H GPIOG->IDR
111 #define SWITCHES_GPIO_PIN_G_H GPIO_Pin_6 // PG.06
112 #define SWITCHES_GPIO_REG_G_L GPIOG->IDR
113 #define SWITCHES_GPIO_PIN_G_L GPIO_Pin_3 // PG.03
114 #define STORAGE_SWITCH_H
115 #define HARDWARE_SWITCH_H
116 #define SWITCHES_GPIO_REG_H GPIOG->IDR
117 #define SWITCHES_GPIO_PIN_H GPIO_Pin_7 // PG.07
119 #if defined(PCBX10)
120 // Gimbal switch left
121 #define STORAGE_SWITCH_I
122 #define HARDWARE_SWITCH_I
123 #define SWITCHES_GPIO_REG_I GPIOH->IDR
124 #define SWITCHES_GPIO_PIN_I GPIO_Pin_14 // PH.14
125 // Gimbal switch right
126 #define STORAGE_SWITCH_J
127 #define HARDWARE_SWITCH_J
128 #define SWITCHES_GPIO_REG_J GPIOH->IDR
129 #define SWITCHES_GPIO_PIN_J GPIO_Pin_15 // PH.15
130 #elif defined(PCBX12S)
131 // Gimbal switch left
132 #define STORAGE_SWITCH_I
133 #define HARDWARE_SWITCH_I
134 #define SWITCHES_GPIO_REG_I GPIOB->IDR
135 #define SWITCHES_GPIO_PIN_I GPIO_Pin_1 // PB.01
136 // Gimbal switch right
137 #define STORAGE_SWITCH_J
138 #define HARDWARE_SWITCH_J
139 #define SWITCHES_GPIO_REG_J GPIOB->IDR
140 #define SWITCHES_GPIO_PIN_J GPIO_Pin_0 // PB.00
141 #endif
143 // Trims
144 #if defined(PCBX12S)
145 #define TRIMS_GPIO_REG_RHL GPIOC->IDR
146 #define TRIMS_GPIO_PIN_RHL GPIO_Pin_0 // PC.00
147 #define TRIMS_GPIO_REG_RHR GPIOI->IDR
148 #define TRIMS_GPIO_PIN_RHR GPIO_Pin_4 // PI.04
149 #define TRIMS_GPIO_REG_RVD GPIOG->IDR
150 #define TRIMS_GPIO_PIN_RVD GPIO_Pin_12 // PG.12
151 #define TRIMS_GPIO_REG_RVU GPIOJ->IDR
152 #define TRIMS_GPIO_PIN_RVU GPIO_Pin_14 // PJ.14
153 #define TRIMS_GPIO_REG_LVD GPIOJ->IDR
154 #define TRIMS_GPIO_PIN_LVD GPIO_Pin_13 // PJ.13
155 #define TRIMS_GPIO_REG_LHL GPIOD->IDR
156 #define TRIMS_GPIO_PIN_LHL GPIO_Pin_3 // PD.03
157 #define TRIMS_GPIO_REG_LVU GPIOJ->IDR
158 #define TRIMS_GPIO_PIN_LVU GPIO_Pin_12 // PJ.12
159 #define TRIMS_GPIO_REG_LHR GPIOD->IDR
160 #define TRIMS_GPIO_PIN_LHR GPIO_Pin_7 // PD.07
161 #define TRIMS_GPIO_REG_RSD GPIOJ->IDR
162 #define TRIMS_GPIO_PIN_RSD GPIO_Pin_8 // PJ.08
163 #define TRIMS_GPIO_REG_RSU GPIOD->IDR
164 #define TRIMS_GPIO_PIN_RSU GPIO_Pin_13 // PD.13
165 #define TRIMS_GPIO_REG_LSD GPIOB->IDR
166 #define TRIMS_GPIO_PIN_LSD GPIO_Pin_14 // PB.14
167 #define TRIMS_GPIO_REG_LSU GPIOB->IDR
168 #define TRIMS_GPIO_PIN_LSU GPIO_Pin_13 // PB.13
169 #elif defined(PCBX10)
170 #define TRIMS_GPIO_REG_LHL GPIOB->IDR
171 #define TRIMS_GPIO_PIN_LHL GPIO_Pin_8 // PB.08
172 #define TRIMS_GPIO_REG_LHR GPIOB->IDR
173 #define TRIMS_GPIO_PIN_LHR GPIO_Pin_9 // PB.09
174 #define TRIMS_GPIO_REG_LVD GPIOG->IDR
175 #define TRIMS_GPIO_PIN_LVD GPIO_Pin_12 // PG.12
176 #define TRIMS_GPIO_REG_LVU GPIOJ->IDR
177 #define TRIMS_GPIO_PIN_LVU GPIO_Pin_14 // PJ.14
178 #define TRIMS_GPIO_REG_RVD GPIOJ->IDR
179 #define TRIMS_GPIO_PIN_RVD GPIO_Pin_13 // PJ.13
180 #define TRIMS_GPIO_REG_RHL GPIOD->IDR
181 #define TRIMS_GPIO_PIN_RHL GPIO_Pin_3 // PD.03
182 #define TRIMS_GPIO_REG_RVU GPIOJ->IDR
183 #define TRIMS_GPIO_PIN_RVU GPIO_Pin_12 // PJ.12
184 #define TRIMS_GPIO_REG_RHR GPIOD->IDR
185 #define TRIMS_GPIO_PIN_RHR GPIO_Pin_7 // PD.07
186 #if defined(RADIO_T16)
187 #define TRIMS_GPIO_REG_LSU GPIOD->IDR
188 #define TRIMS_GPIO_PIN_LSU GPIO_Pin_13 // PD.13
189 #define TRIMS_GPIO_REG_LSD GPIOJ->IDR
190 #define TRIMS_GPIO_PIN_LSD GPIO_Pin_8 // PJ.08
191 #else
192 #define TRIMS_GPIO_REG_LSU GPIOJ->IDR
193 #define TRIMS_GPIO_PIN_LSU GPIO_Pin_8 // PJ.08
194 #define TRIMS_GPIO_REG_LSD GPIOD->IDR
195 #define TRIMS_GPIO_PIN_LSD GPIO_Pin_13 // PD.13
196 #endif
197 #define TRIMS_GPIO_REG_RSU GPIOB->IDR
198 #define TRIMS_GPIO_PIN_RSU GPIO_Pin_14 // PB.14
199 #define TRIMS_GPIO_REG_RSD GPIOB->IDR
200 #define TRIMS_GPIO_PIN_RSD GPIO_Pin_13 // PB.13
201 #endif
203 // Index of all keys
204 #if defined(PCBX12S)
205 #define KEYS_GPIOB_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15)
206 #define KEYS_GPIOC_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_13)
207 #define KEYS_GPIOD_PINS (GPIO_Pin_3 | GPIO_Pin_7 | GPIO_Pin_11 | GPIO_Pin_13)
208 #define KEYS_GPIOE_PINS (GPIO_Pin_3)
209 #define KEYS_GPIOG_PINS (KEYS_GPIO_PIN_UP | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | TRIMS_GPIO_PIN_RVD)
210 #define KEYS_GPIOH_PINS (GPIO_Pin_9 | GPIO_Pin_12 | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_F | ROTARY_ENCODER_GPIO_PIN_A | ROTARY_ENCODER_GPIO_PIN_B)
211 #define KEYS_GPIOI_PINS (KEYS_GPIO_PIN_PGDN | KEYS_GPIO_PIN_LEFT | KEYS_GPIO_PIN_DOWN | SWITCHES_GPIO_PIN_A_L | GPIO_Pin_4)
212 #define KEYS_GPIOJ_PINS (SWITCHES_GPIO_PIN_D_H | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_RSD)
213 #elif defined(PCBX10)
214 #define KEYS_GPIOB_PINS (GPIO_Pin_12 | GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_8 | GPIO_Pin_9)
215 #define KEYS_GPIOD_PINS (GPIO_Pin_11 | GPIO_Pin_3 | GPIO_Pin_7 | GPIO_Pin_13)
216 #define KEYS_GPIOE_PINS (GPIO_Pin_3)
217 #define KEYS_GPIOG_PINS (SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | TRIMS_GPIO_PIN_LVD)
218 #define KEYS_GPIOH_PINS (GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15)
219 #define KEYS_GPIOI_PINS (GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_15)
220 #define KEYS_GPIOJ_PINS (SWITCHES_GPIO_PIN_D_H | TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | GPIO_Pin_8)
221 #endif
223 // ADC
224 #if defined(PCBX12S)
225 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
226 #define ADC_RCC_APB1Periph 0
227 #define ADC_RCC_APB2Periph (RCC_APB2Periph_SPI4 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
228 #define ADC_SPI SPI4
229 #define ADC_GPIO_AF GPIO_AF_SPI4
230 #define ADC_SPI_GPIO GPIOE
231 #define ADC_SPI_PIN_SCK GPIO_Pin_2 // PE.02
232 #define ADC_SPI_PIN_CS GPIO_Pin_4 // PE.04
233 #define ADC_SPI_PIN_MOSI GPIO_Pin_6 // PE.06
234 #define ADC_SPI_PIN_MISO GPIO_Pin_5 // PE.05
235 #define ADC_SPI_PinSource_SCK GPIO_PinSource2
236 #define ADC_SPI_PinSource_MISO GPIO_PinSource5
237 #define ADC_SPI_PinSource_MOSI GPIO_PinSource6
238 #define ADC_GPIO_PIN_MOUSE1 GPIO_Pin_8 // PF.08 ADC3_IN6 J5 MOUSE_X
239 #define ADC_GPIO_PIN_MOUSE2 GPIO_Pin_9 // PF.09 ADC3_IN7 J6 MOUSE_Y
240 #define ADC_GPIO_MOUSE GPIOF
241 #define ADC_CHANNEL_MOUSE1 6
242 #define ADC_CHANNEL_MOUSE2 7
243 #define ADC_DMA DMA2
244 #define ADC_DMA_Stream DMA2_Stream0
245 #define ADC_SAMPTIME 3
246 #define ADC_VREF_PREC2 300
247 #elif defined(PCBX10)
248 #define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
249 #define ADC_RCC_APB1Periph (RCC_APB1Periph_TIM5)
250 #define ADC_RCC_APB2Periph (RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
251 #define ADC_GPIO_PIN_STICK_LH GPIO_Pin_0 // PA.00
252 #define ADC_GPIO_PIN_STICK_LV GPIO_Pin_1 // PA.01
253 #define ADC_GPIO_PIN_STICK_RH GPIO_Pin_2 // PA.02
254 #define ADC_GPIO_PIN_STICK_RV GPIO_Pin_3 // PA.03
255 #define ADC_GPIO_PIN_POT1 GPIO_Pin_0 // PC.00
256 #define ADC_GPIO_PIN_POT2 GPIO_Pin_1 // PC.01
257 #define ADC_GPIO_PIN_POT3 GPIO_Pin_2 // PC.02
258 #define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_6 // PF.06
259 #define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_3 // PC.03
260 #define ADC_GPIO_PIN_BATT GPIO_Pin_7 // PF.07
261 #define ADC_GPIO_PIN_EXT1 GPIO_Pin_8 // PF.08
262 #define ADC_GPIO_PIN_EXT2 GPIO_Pin_9 // PF.09
263 #define PWM_TIMER TIM5
264 #define PWM_GPIO GPIOA
265 #define PWM_GPIO_AF GPIO_AF_TIM5
266 #define PWM_IRQHandler TIM5_IRQHandler
267 #define PWM_IRQn TIM5_IRQn
268 #define PWM_GPIOA_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3)
269 #define ADC_GPIOA_PINS (STICKS_PWM_ENABLED() ? 0 : (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3))
270 #define ADC_GPIOC_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3)
271 #define ADC_GPIOF_PINS (GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9)
272 #define ADC_CHANNEL_STICK_LH ADC_Channel_0 // ADC3_IN0
273 #define ADC_CHANNEL_STICK_LV ADC_Channel_1 // ADC3_IN1
274 #define ADC_CHANNEL_STICK_RH ADC_Channel_2 // ADC3_IN2
275 #define ADC_CHANNEL_STICK_RV ADC_Channel_3 // ADC3_IN3
276 #define ADC_CHANNEL_POT1 ADC_Channel_10 // ADC3_IN10
277 #define ADC_CHANNEL_POT2 ADC_Channel_11 // ADC3_IN11
278 #define ADC_CHANNEL_POT3 ADC_Channel_12 // ADC3_IN12
279 #define ADC_CHANNEL_SLIDER1 ADC_Channel_4 // ADC3_IN4
280 #define ADC_CHANNEL_SLIDER2 ADC_Channel_13 // ADC3_IN13
281 #define ADC_CHANNEL_BATT ADC_Channel_5 // ADC3_IN5
282 #define ADC_CHANNEL_EXT1 ADC_Channel_6 // ADC3_IN6
283 #define ADC_CHANNEL_EXT2 ADC_Channel_7 // ADC3_IN7
284 #define ADC_MAIN ADC3
285 #define ADC_SAMPTIME 3
286 #define ADC_DMA DMA2
287 #define ADC_DMA_SxCR_CHSEL DMA_SxCR_CHSEL_1
288 #define ADC_DMA_Stream DMA2_Stream0
289 #define ADC_SET_DMA_FLAGS() ADC_DMA->LIFCR = (DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 | DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0)
290 #define ADC_TRANSFER_COMPLETE() (ADC_DMA->LISR & DMA_LISR_TCIF0)
291 #if defined(RADIO_T16)
292 #define ADC_VREF_PREC2 300
293 #else
294 #define ADC_VREF_PREC2 250
295 #endif
296 #endif
298 // Power
299 #define PWR_RCC_AHB1Periph RCC_AHB1Periph_GPIOJ
300 #define PWR_ON_GPIO GPIOJ
301 #define PWR_ON_GPIO_PIN GPIO_Pin_1 // PJ.01
302 #define PWR_SWITCH_GPIO GPIOJ
303 #define PWR_SWITCH_GPIO_PIN GPIO_Pin_0 // PJ.00
305 // S.Port update connector
306 #define SPORT_MAX_BAUDRATE 250000 // < 400000
307 #if defined(PCBX10) && !defined(RADIO_T16)
308 #define SPORT_UPDATE_RCC_AHB1Periph RCC_AHB1Periph_GPIOH
309 #define SPORT_UPDATE_PWR_GPIO GPIOH
310 #define SPORT_UPDATE_PWR_GPIO_PIN GPIO_Pin_13 // PH.13
311 #define HAS_SPORT_UPDATE_CONNECTOR() true
312 #else
313 #define SPORT_UPDATE_RCC_AHB1Periph 0
314 #define HAS_SPORT_UPDATE_CONNECTOR() false
315 #endif
317 // PCBREV
318 #if defined(PCBX10)
319 #define PCBREV_RCC_AHB1Periph RCC_AHB1Periph_GPIOH
320 #define PCBREV_GPIO_PIN (GPIO_Pin_7 | GPIO_Pin_8)
321 #define PCBREV_GPIO GPIOH
322 #define PCBREV_VALUE() (GPIO_ReadInputDataBit(PCBREV_GPIO, GPIO_Pin_7) + (GPIO_ReadInputDataBit(PCBREV_GPIO, GPIO_Pin_8) << 1))
323 #else
324 #define PCBREV_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
325 #define PCBREV_GPIO GPIOI
326 #define PCBREV_GPIO_PIN GPIO_Pin_11 // PI.11
327 #define PCBREV_VALUE() GPIO_ReadInputDataBit(PCBREV_GPIO, PCBREV_GPIO_PIN)
328 #endif
330 // Led
331 #define STATUS_LEDS
332 #if defined(PCBX12S)
333 #define LED_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
334 #define LED_GPIO GPIOI
335 #define LED_GPIO_PIN GPIO_Pin_5 // PI.05
336 #elif defined(PCBX10)
337 #define LED_RCC_AHB1Periph RCC_AHB1Periph_GPIOE
338 #define LED_GPIO GPIOE
339 #define LED_RED_GPIO_PIN GPIO_Pin_2
340 #define LED_GREEN_GPIO_PIN GPIO_Pin_4
341 #define LED_BLUE_GPIO_PIN GPIO_Pin_5
342 #define LED_GPIO_PIN (LED_RED_GPIO_PIN | LED_GREEN_GPIO_PIN | LED_BLUE_GPIO_PIN)
343 #endif
345 // Serial Port (DEBUG)
346 #if defined(PCBX12S)
347 #define AUX_SERIAL_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA1)
348 #define AUX_SERIAL_RCC_APB1Periph RCC_APB1Periph_USART3
349 #define AUX_SERIAL_GPIO GPIOB
350 #define AUX_SERIAL_GPIO_PIN_TX GPIO_Pin_10 // PB.10
351 #define AUX_SERIAL_GPIO_PIN_RX GPIO_Pin_11 // PB.11
352 #define AUX_SERIAL_GPIO_PinSource_TX GPIO_PinSource10
353 #define AUX_SERIAL_GPIO_PinSource_RX GPIO_PinSource11
354 #define AUX_SERIAL_GPIO_AF GPIO_AF_USART3
355 #define AUX_SERIAL_USART USART3
356 #define AUX_SERIAL_USART_IRQHandler USART3_IRQHandler
357 #define AUX_SERIAL_USART_IRQn USART3_IRQn
358 #define AUX_SERIAL_DMA_Stream_RX DMA1_Stream1
359 #define AUX_SERIAL_DMA_Channel_RX DMA_Channel_4
360 #else
361 #define AUX_SERIAL_RCC_AHB1Periph 0
362 #define AUX_SERIAL_RCC_APB1Periph 0
363 #endif
365 // Telemetry
366 #define TELEMETRY_RCC_AHB1Periph (RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
367 #define TELEMETRY_RCC_APB1Periph RCC_APB1Periph_USART2
368 #define TELEMETRY_RCC_APB2Periph RCC_APB2Periph_TIM10
369 #define TELEMETRY_DIR_GPIO GPIOD
370 #define TELEMETRY_DIR_GPIO_PIN GPIO_Pin_4 // PD.04
371 #define TELEMETRY_GPIO GPIOD
372 #define TELEMETRY_TX_GPIO_PIN GPIO_Pin_5 // PD.05
373 #define TELEMETRY_RX_GPIO_PIN GPIO_Pin_6 // PD.06
374 #define TELEMETRY_GPIO_PinSource_TX GPIO_PinSource5
375 #define TELEMETRY_GPIO_PinSource_RX GPIO_PinSource6
376 #define TELEMETRY_GPIO_AF GPIO_AF_USART2
377 #define TELEMETRY_USART USART2
378 #define TELEMETRY_EXTI_PortSource EXTI_PortSourceGPIOD
379 #define TELEMETRY_EXTI_PinSource EXTI_PinSource6
380 #define TELEMETRY_EXTI_LINE EXTI_Line6
381 #define TELEMETRY_EXTI_IRQn EXTI9_5_IRQn
382 #define TELEMETRY_EXTI_IRQHandler EXTI9_5_IRQHandler
383 #define TELEMETRY_EXTI_TRIGGER EXTI_Trigger_Rising
384 #define TELEMETRY_TIMER TIM11
385 #define TELEMETRY_TIMER_IRQn TIM1_TRG_COM_TIM11_IRQn
386 #define TELEMETRY_TIMER_IRQHandler TIM1_TRG_COM_TIM11_IRQHandler
387 #if defined(PCBX12S)
388 #define TELEMETRY_DMA_Stream_RX DMA1_Stream5
389 #define TELEMETRY_DMA_Channel_RX DMA_Channel_4
390 #endif
391 #define TELEMETRY_DMA_Stream_TX DMA1_Stream6
392 #define TELEMETRY_DMA_Channel_TX DMA_Channel_4
393 #define TELEMETRY_DMA_TX_Stream_IRQ DMA1_Stream6_IRQn
394 #define TELEMETRY_DMA_TX_IRQHandler DMA1_Stream6_IRQHandler
395 #define TELEMETRY_DMA_TX_FLAG_TC DMA_IT_TCIF6
396 #define TELEMETRY_USART_IRQHandler USART2_IRQHandler
397 #define TELEMETRY_USART_IRQn USART2_IRQn
399 // USB
400 #define USB_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOA
401 #define USB_GPIO GPIOA
402 #define USB_GPIO_PIN_VBUS GPIO_Pin_9 // PA.09
403 #define USB_GPIO_PIN_DM GPIO_Pin_11 // PA.11
404 #define USB_GPIO_PIN_DP GPIO_Pin_12 // PA.12
405 #define USB_GPIO_PinSource_DM GPIO_PinSource11
406 #define USB_GPIO_PinSource_DP GPIO_PinSource12
407 #define USB_GPIO_AF GPIO_AF_OTG1_FS
409 // LCD
410 #define LCD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOJ | RCC_AHB1Periph_GPIOK | RCC_AHB1Periph_DMA2D)
411 #define LCD_RCC_APB1Periph 0
412 #define LCD_RCC_APB2Periph RCC_APB2Periph_LTDC
413 #if defined(PCBX12S)
414 #define LCD_GPIO_NRST GPIOF
415 #define LCD_GPIO_PIN_NRST GPIO_Pin_10 // PF.10
416 #elif defined(PCBX10)
417 #define LCD_GPIO_NRST GPIOI
418 #define LCD_GPIO_PIN_NRST GPIO_Pin_10 // PI.10
419 #endif
420 #define LTDC_IRQ_PRIO 4
421 #define DMA_SCREEN_IRQ_PRIO 6
423 // Backlight
424 #if defined(PCBX12S)
425 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
426 #define BACKLIGHT_GPIO GPIOA
427 #if PCBREV >= 13
428 #define BACKLIGHT_TIMER TIM5
429 #define BACKLIGHT_GPIO_PIN GPIO_Pin_3 // PA.03
430 #define BACKLIGHT_GPIO_PinSource GPIO_PinSource3
431 #define BACKLIGHT_RCC_APB1Periph RCC_APB1Periph_TIM5
432 #define BACKLIGHT_RCC_APB2Periph 0
433 #define BACKLIGHT_GPIO_AF GPIO_AF_TIM5
434 #define BACKLIGHT_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
435 #else
436 #define BACKLIGHT_TIMER TIM8
437 #define BACKLIGHT_GPIO_PIN GPIO_Pin_5 // PA.05
438 #define BACKLIGHT_GPIO_PinSource GPIO_PinSource5
439 #define BACKLIGHT_RCC_APB1Periph 0
440 #define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM8
441 #define BACKLIGHT_GPIO_AF GPIO_AF_TIM8
442 #define BACKLIGHT_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
443 #endif
444 #elif defined(PCBX10)
445 #define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
446 #define BACKLIGHT_GPIO GPIOB
447 #define BACKLIGHT_TIMER TIM8
448 #define BACKLIGHT_GPIO_PIN GPIO_Pin_1 // PB.01
449 #define BACKLIGHT_GPIO_PinSource GPIO_PinSource1
450 #define BACKLIGHT_RCC_APB1Periph 0
451 #define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM8
452 #define BACKLIGHT_GPIO_AF GPIO_AF_TIM8
453 #define BACKLIGHT_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
454 #endif
456 // SD
457 #define SD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA2)
458 #define SD_RCC_APB1Periph 0
459 #define SD_PRESENT_GPIO GPIOC
460 #define SD_PRESENT_GPIO_PIN GPIO_Pin_5 // PC.05
461 #define SD_SDIO_DMA_STREAM DMA2_Stream3
462 #define SD_SDIO_DMA_CHANNEL DMA_Channel_4
463 #define SD_SDIO_DMA_FLAG_FEIF DMA_FLAG_FEIF3
464 #define SD_SDIO_DMA_FLAG_DMEIF DMA_FLAG_DMEIF3
465 #define SD_SDIO_DMA_FLAG_TEIF DMA_FLAG_TEIF3
466 #define SD_SDIO_DMA_FLAG_HTIF DMA_FLAG_HTIF3
467 #define SD_SDIO_DMA_FLAG_TCIF DMA_FLAG_TCIF3
468 #define SD_SDIO_DMA_IRQn DMA2_Stream3_IRQn
469 #define SD_SDIO_DMA_IRQHANDLER DMA2_Stream3_IRQHandler
470 #define SD_SDIO_FIFO_ADDRESS ((uint32_t)0x40012C80)
471 #define SD_SDIO_CLK_DIV(fq) ((48000000 / (fq)) - 2)
472 #define SD_SDIO_INIT_CLK_DIV SD_SDIO_CLK_DIV(400000)
473 #define SD_SDIO_TRANSFER_CLK_DIV SD_SDIO_CLK_DIV(24000000)
475 // EEPROM
476 #if defined(PCBX12S) && PCBREV >= 13
477 #define EEPROM_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
478 #define EEPROM_RCC_APB1Periph RCC_APB1Periph_SPI1
479 #define EEPROM_SPI_CS_GPIO GPIOA
480 #define EEPROM_SPI_CS_GPIO_PIN GPIO_Pin_15 // PA.15
481 #define EEPROM_SPI_SCK_GPIO GPIOA
482 #define EEPROM_SPI_SCK_GPIO_PIN GPIO_Pin_5 // PA.05
483 #define EEPROM_SPI_SCK_GPIO_PinSource GPIO_PinSource5
484 #define EEPROM_SPI_MISO_GPIO GPIOA
485 #define EEPROM_SPI_MISO_GPIO_PIN GPIO_Pin_6 // PA.06
486 #define EEPROM_SPI_MISO_GPIO_PinSource GPIO_PinSource6
487 #define EEPROM_SPI_MOSI_GPIO GPIOA
488 #define EEPROM_SPI_MOSI_GPIO_PIN GPIO_Pin_7 // PA.07
489 #define EEPROM_SPI_MOSI_GPIO_PinSource GPIO_PinSource7
490 #elif defined(PCBX10)
491 #define EEPROM_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
492 #define EEPROM_RCC_APB1Periph RCC_APB1Periph_SPI2
493 #define EEPROM_SPI_CS_GPIO GPIOI
494 #define EEPROM_SPI_CS_GPIO_PIN GPIO_Pin_0 // PI.00
495 #define EEPROM_SPI_SCK_GPIO GPIOI
496 #define EEPROM_SPI_SCK_GPIO_PIN GPIO_Pin_1 // PI.01
497 #define EEPROM_SPI_SCK_GPIO_PinSource GPIO_PinSource1
498 #define EEPROM_SPI_MISO_GPIO GPIOI
499 #define EEPROM_SPI_MISO_GPIO_PIN GPIO_Pin_2 // PI.02
500 #define EEPROM_SPI_MISO_GPIO_PinSource GPIO_PinSource2
501 #define EEPROM_SPI_MOSI_GPIO GPIOI
502 #define EEPROM_SPI_MOSI_GPIO_PIN GPIO_Pin_3 // PI.03
503 #define EEPROM_SPI_MOSI_GPIO_PinSource GPIO_PinSource3
504 #endif
506 // Audio
507 #if defined(PCBX12S)
508 #define AUDIO_RCC_AHB1Periph (RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOH)
509 #define AUDIO_RCC_APB1Periph RCC_APB1Periph_SPI2
510 #define AUDIO_SHUTDOWN_GPIO GPIOI
511 #define AUDIO_SHUTDOWN_GPIO_PIN GPIO_Pin_9 // PI.09
512 #define AUDIO_XDCS_GPIO GPIOI
513 #define AUDIO_XDCS_GPIO_PIN GPIO_Pin_0 // PI.00
514 #define AUDIO_CS_GPIO GPIOH
515 #define AUDIO_CS_GPIO_PIN GPIO_Pin_13 // PH.13
516 #define AUDIO_DREQ_GPIO GPIOH
517 #define AUDIO_DREQ_GPIO_PIN GPIO_Pin_14 // PH.14
518 #define AUDIO_RST_GPIO GPIOH
519 #define AUDIO_RST_GPIO_PIN GPIO_Pin_15 // PH.15
520 #define AUDIO_SPI SPI2
521 #define AUDIO_SPI_GPIO_AF GPIO_AF_SPI2
522 #define AUDIO_SPI_SCK_GPIO GPIOI
523 #define AUDIO_SPI_SCK_GPIO_PIN GPIO_Pin_1 // PI.01
524 #define AUDIO_SPI_SCK_GPIO_PinSource GPIO_PinSource1
525 #define AUDIO_SPI_MISO_GPIO GPIOI
526 #define AUDIO_SPI_MISO_GPIO_PIN GPIO_Pin_2 // PI.02
527 #define AUDIO_SPI_MISO_GPIO_PinSource GPIO_PinSource2
528 #define AUDIO_SPI_MOSI_GPIO GPIOI
529 #define AUDIO_SPI_MOSI_GPIO_PIN GPIO_Pin_3 // PI.03
530 #define AUDIO_SPI_MOSI_GPIO_PinSource GPIO_PinSource3
531 #elif defined (PCBX10)
532 #define AUDIO_RCC_APB1Periph (RCC_APB1Periph_TIM6 | RCC_APB1Periph_DAC)
533 #define AUDIO_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA1)
534 #define AUDIO_MUTE_GPIO GPIOA
535 #define AUDIO_MUTE_GPIO_PIN GPIO_Pin_7 // PA.07
536 #define AUDIO_OUTPUT_GPIO GPIOA
537 #define AUDIO_OUTPUT_GPIO_PIN GPIO_Pin_4 // PA.04
538 #define AUDIO_GPIO_AF GPIO_AF_DAC1
539 #define AUDIO_GPIO_PinSource GPIO_PinSource4
540 #define AUDIO_DMA_Stream DMA1_Stream5
541 #define AUDIO_DMA_Stream_IRQn DMA1_Stream5_IRQn
542 #define AUDIO_TIM_IRQn TIM6_DAC_IRQn
543 #define AUDIO_TIM_IRQHandler TIM6_DAC_IRQHandler
544 #define AUDIO_DMA_Stream_IRQHandler DMA1_Stream5_IRQHandler
545 #define AUDIO_TIMER TIM6
546 #define AUDIO_DMA DMA1
547 #endif
549 #if defined(RADIO_T16)
550 #define AUDIO_UNMUTE_DELAY 150
551 #endif
553 // I2C Bus
554 #define I2C_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
555 #define I2C_RCC_APB1Periph RCC_APB1Periph_I2C1
556 #define I2C I2C1
557 #define I2C_GPIO GPIOB
558 #define I2C_SCL_GPIO_PIN GPIO_Pin_8 // PB.08
559 #define I2C_SDA_GPIO_PIN GPIO_Pin_9 // PB.09
560 #define I2C_GPIO_AF GPIO_AF_I2C1
561 #define I2C_SCL_GPIO_PinSource GPIO_PinSource8
562 #define I2C_SDA_GPIO_PinSource GPIO_PinSource9
563 #define I2C_SPEED 400000
565 // Haptic
566 #define HAPTIC_PWM
567 #if defined(PCBX12S)
568 #define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
569 #define HAPTIC_RCC_APB2Periph RCC_APB2ENR_TIM9EN
570 #define HAPTIC_GPIO GPIOA
571 #define HAPTIC_GPIO_PIN GPIO_Pin_2
572 #define HAPTIC_GPIO_TIMER TIM9
573 #define HAPTIC_GPIO_AF GPIO_AF_TIM9
574 #define HAPTIC_GPIO_PinSource GPIO_PinSource2
575 #define HAPTIC_TIMER_OUTPUT_ENABLE TIM_CCER_CC1E
576 #define HAPTIC_TIMER_MODE TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2
577 #define HAPTIC_TIMER_COMPARE_VALUE HAPTIC_GPIO_TIMER->CCR1
578 #elif defined(PCBX10)
579 #define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOE
580 #define HAPTIC_RCC_APB2Periph RCC_APB2ENR_TIM9EN
581 #define HAPTIC_GPIO GPIOE
582 #define HAPTIC_GPIO_PIN GPIO_Pin_6 // PE.06
583 #define HAPTIC_GPIO_TIMER TIM9
584 #define HAPTIC_GPIO_AF GPIO_AF_TIM9
585 #define HAPTIC_GPIO_PinSource GPIO_PinSource6
586 #define HAPTIC_TIMER_OUTPUT_ENABLE TIM_CCER_CC2E
587 #define HAPTIC_TIMER_MODE TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2
588 #define HAPTIC_TIMER_COMPARE_VALUE HAPTIC_GPIO_TIMER->CCR2
589 #endif
591 #if !defined(RADIO_T16)
592 #define EXTERNAL_ANTENNA
593 #endif
594 #define INTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA2)
595 #define INTMODULE_PWR_GPIO GPIOA
596 #define INTMODULE_PWR_GPIO_PIN GPIO_Pin_8 // PA.08
597 #define INTMODULE_GPIO GPIOB
598 #define INTMODULE_TX_GPIO_PIN GPIO_Pin_6 // PB.06
599 #define INTMODULE_RX_GPIO_PIN GPIO_Pin_7 // PB.07
600 #define INTMODULE_GPIO_PinSource_TX GPIO_PinSource6
601 #define INTMODULE_GPIO_PinSource_RX GPIO_PinSource7
602 #define INTMODULE_USART USART1
603 #define INTMODULE_GPIO_AF GPIO_AF_USART1
604 #define INTMODULE_USART_IRQn USART1_IRQn
605 #define INTMODULE_USART_IRQHandler USART1_IRQHandler
606 #define INTMODULE_DMA_STREAM DMA2_Stream7
607 #define INTMODULE_DMA_STREAM_IRQ DMA2_Stream7_IRQn
608 #define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream7_IRQHandler
609 #define INTMODULE_DMA_FLAG_TC DMA_IT_TCIF7
610 #define INTMODULE_DMA_CHANNEL DMA_Channel_4
611 #if defined(PCBX12S)
612 #define INTMODULE_BOOTCMD_GPIO GPIOC
613 #define INTMODULE_BOOTCMD_GPIO_PIN GPIO_Pin_2 // PC.02
614 #elif defined(PCBX10)
615 #define INTMODULE_BOOTCMD_GPIO GPIOI
616 #define INTMODULE_BOOTCMD_GPIO_PIN GPIO_Pin_9 // PI.09
617 #endif
618 #if defined(PCBX10) || PCBREV >= 13
619 #define INTMODULE_RCC_APB1Periph RCC_APB1Periph_TIM2
620 #define INTMODULE_RCC_APB2Periph RCC_APB2Periph_USART1
621 #define INTMODULE_TIMER TIM2
622 #define INTMODULE_TIMER_IRQn TIM2_IRQn
623 #define INTMODULE_TIMER_IRQHandler TIM2_IRQHandler
624 #define INTMODULE_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
625 #else
626 #define INTMODULE_RCC_APB1Periph 0
627 #define INTMODULE_RCC_APB2Periph (RCC_APB2Periph_TIM1 | RCC_APB2Periph_USART1)
628 #define INTMODULE_TIMER TIM1
629 #define INTMODULE_TIMER_IRQn TIM1_CC_IRQn
630 #define INTMODULE_TIMER_IRQHandler TIM1_CC_IRQHandler
631 #define INTMODULE_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
632 #endif
634 // External Module
635 #define EXTMODULE_PWR_GPIO GPIOB
636 #define EXTMODULE_PWR_GPIO_PIN GPIO_Pin_3 // PB.03
637 #if defined(PCBX10) && defined(PCBREV_EXPRESS)
638 #define EXTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA1)
639 #define EXTMODULE_RCC_APB1Periph (RCC_APB1Periph_TIM2 | RCC_APB1Periph_USART3)
640 #define EXTMODULE_RCC_APB2Periph 0
641 #define EXTMODULE_TX_GPIO GPIOB
642 #define EXTMODULE_USART_GPIO EXTMODULE_TX_GPIO
643 #define EXTMODULE_TX_GPIO_PIN GPIO_Pin_10 // PB.10 (TIM2_CH3)
644 #define EXTMODULE_TX_GPIO_PinSource GPIO_PinSource10
645 #define EXTMODULE_RX_GPIO_PIN GPIO_Pin_11 // PB.11
646 #define EXTMODULE_RX_GPIO_PinSource GPIO_PinSource11
647 #define EXTMODULE_TIMER_TX_GPIO_AF GPIO_AF_TIM2
648 #define EXTMODULE_TIMER TIM2
649 #define EXTMODULE_TIMER_32BITS
650 #define EXTMODULE_TIMER_DMA_SIZE (DMA_SxCR_PSIZE_1 | DMA_SxCR_MSIZE_1)
651 #define EXTMODULE_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
652 #define EXTMODULE_TIMER_CC_IRQn TIM2_IRQn
653 #define EXTMODULE_TIMER_IRQHandler TIM2_IRQHandler
654 #define EXTMODULE_TIMER_DMA_CHANNEL DMA_Channel_3
655 #define EXTMODULE_TIMER_DMA_STREAM DMA1_Stream1
656 #define EXTMODULE_TIMER_DMA_FLAG_TC DMA_IT_TCIF1
657 #define EXTMODULE_TIMER_DMA_STREAM_IRQn DMA1_Stream1_IRQn
658 #define EXTMODULE_TIMER_DMA_IRQHandler DMA1_Stream1_IRQHandler
659 #define EXTMODULE_USART_GPIO_AF GPIO_AF_USART3
660 #define EXTMODULE_USART USART3
661 #define EXTMODULE_USART_IRQn USART3_IRQn
662 #define EXTMODULE_USART_IRQHandler USART3_IRQHandler
663 #define EXTMODULE_USART_TX_DMA_CHANNEL DMA_Channel_4
664 #define EXTMODULE_USART_TX_DMA_STREAM DMA1_Stream3
665 #define EXTMODULE_USART_RX_DMA_CHANNEL DMA_Channel_4
666 #define EXTMODULE_USART_RX_DMA_STREAM DMA1_Stream1
667 #elif defined(PCBX10) || PCBREV >= 13
668 #define EXTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA2)
669 #define EXTMODULE_RCC_APB1Periph 0
670 #define EXTMODULE_RCC_APB2Periph RCC_APB2Periph_TIM1
671 #define EXTMODULE_TX_GPIO GPIOA
672 #define EXTMODULE_TX_GPIO_PIN GPIO_Pin_10 // PA.10 (TIM1_CH3)
673 #define EXTMODULE_TX_GPIO_PinSource GPIO_PinSource10
674 #define EXTMODULE_TIMER_TX_GPIO_AF GPIO_AF_TIM1
675 #define EXTMODULE_TIMER TIM1
676 #define EXTMODULE_TIMER_DMA_SIZE (DMA_SxCR_PSIZE_0 | DMA_SxCR_MSIZE_0)
677 #define EXTMODULE_TIMER_CC_IRQn TIM1_CC_IRQn
678 #define EXTMODULE_TIMER_IRQHandler TIM1_CC_IRQHandler
679 #define EXTMODULE_TIMER_FREQ (PERI2_FREQUENCY * TIMER_MULT_APB2)
680 #define EXTMODULE_TIMER_DMA_CHANNEL DMA_Channel_6
681 #define EXTMODULE_TIMER_DMA_STREAM DMA2_Stream5
682 #define EXTMODULE_TIMER_DMA_STREAM_IRQn DMA2_Stream5_IRQn
683 #define EXTMODULE_TIMER_DMA_IRQHandler DMA2_Stream5_IRQHandler
684 #define EXTMODULE_TIMER_DMA_FLAG_TC DMA_IT_TCIF5
685 #else
686 #define EXTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA1)
687 #define EXTMODULE_RCC_APB1Periph RCC_APB1Periph_TIM2
688 #define EXTMODULE_RCC_APB2Periph 0
689 #define EXTMODULE_TX_GPIO GPIOA
690 #define EXTMODULE_TX_GPIO_PIN GPIO_Pin_15 // PA.15 (TIM2_CH1)
691 #define EXTMODULE_TX_GPIO_PinSource GPIO_PinSource15
692 #define EXTMODULE_TIMER_TX_GPIO_AF GPIO_AF_TIM2
693 #define EXTMODULE_TIMER TIM2
694 #define EXTMODULE_TIMER_32BITS
695 #define EXTMODULE_TIMER_DMA_SIZE (DMA_SxCR_PSIZE_1 | DMA_SxCR_MSIZE_1)
696 #define EXTMODULE_TIMER_CC_IRQn TIM2_IRQn
697 #define EXTMODULE_TIMER_IRQHandler TIM2_IRQHandler
698 #define EXTMODULE_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
699 #define EXTMODULE_TIMER_DMA_CHANNEL DMA_Channel_3
700 #define EXTMODULE_TIMER_DMA_STREAM DMA1_Stream7
701 #define EXTMODULE_TIMER_DMA_STREAM_IRQn DMA1_Stream7_IRQn
702 #define EXTMODULE_TIMER_DMA_IRQHandler DMA1_Stream7_IRQHandler
703 #define EXTMODULE_TIMER_DMA_FLAG_TC DMA_IT_TCIF7
704 #endif
706 // Heartbeat
707 #define INTMODULE_HEARTBEAT
708 #define INTMODULE_HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
709 #define INTMODULE_HEARTBEAT_GPIO GPIOD
710 #define INTMODULE_HEARTBEAT_GPIO_PIN GPIO_Pin_12
711 #define INTMODULE_HEARTBEAT_EXTI_PortSource EXTI_PortSourceGPIOD
712 #define INTMODULE_HEARTBEAT_EXTI_PinSource GPIO_PinSource12
713 #define INTMODULE_HEARTBEAT_EXTI_LINE EXTI_Line12
714 #define INTMODULE_HEARTBEAT_EXTI_IRQn EXTI15_10_IRQn
715 #define INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER
716 #if defined(PXX2)
717 #define INTMODULE_HEARTBEAT_TRIGGER EXTI_Trigger_Falling
718 #else
719 #define INTMODULE_HEARTBEAT_TRIGGER EXTI_Trigger_Rising
720 #endif
722 // Trainer Port
723 #define TRAINER_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA1)
724 #define TRAINER_RCC_APB1Periph RCC_APB1Periph_TIM3
725 #define TRAINER_GPIO GPIOC
726 #define TRAINER_IN_GPIO_PIN GPIO_Pin_6 // PC.06
727 #define TRAINER_IN_GPIO_PinSource GPIO_PinSource6
728 #define TRAINER_OUT_GPIO_PIN GPIO_Pin_7 // PC.07
729 #define TRAINER_OUT_GPIO_PinSource GPIO_PinSource7
730 #define TRAINER_DETECT_GPIO GPIOB
731 #define TRAINER_DETECT_GPIO_PIN GPIO_Pin_4 // PB.04
732 #define TRAINER_TIMER TIM3
733 #define TRAINER_TIMER_IRQn TIM3_IRQn
734 #define TRAINER_TIMER_IRQHandler TIM3_IRQHandler
735 #define TRAINER_GPIO_AF GPIO_AF_TIM3
736 #define TRAINER_DMA DMA1
737 #define TRAINER_DMA_CHANNEL DMA_Channel_5
738 #define TRAINER_DMA_STREAM DMA1_Stream2
739 #define TRAINER_DMA_IRQn DMA1_Stream2_IRQn
740 #define TRAINER_DMA_IRQHandler DMA1_Stream2_IRQHandler
741 #define TRAINER_DMA_FLAG_TC DMA_IT_TCIF2
742 #define TRAINER_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
744 // Xms Interrupt
745 #define INTERRUPT_xMS_RCC_APB1Periph RCC_APB1Periph_TIM14
746 #define INTERRUPT_xMS_TIMER TIM14
747 #define INTERRUPT_xMS_IRQn TIM8_TRG_COM_TIM14_IRQn
748 #define INTERRUPT_xMS_IRQHandler TIM8_TRG_COM_TIM14_IRQHandler
750 // 2MHz Timer
751 #define TIMER_2MHz_RCC_APB1Periph RCC_APB1Periph_TIM7
752 #define TIMER_2MHz_TIMER TIM7
754 // Bluetooth
755 #define STORAGE_BLUETOOTH
756 #define BT_RCC_APB2Periph RCC_APB2Periph_USART6
757 #define BT_USART USART6
758 #define BT_GPIO_AF GPIO_AF_USART6
759 #define BT_USART_IRQn USART6_IRQn
760 #define BT_USART_GPIO GPIOG
761 #define BT_TX_GPIO_PIN GPIO_Pin_14 // PG.14
762 #define BT_RX_GPIO_PIN GPIO_Pin_9 // PG.09
763 #define BT_TX_GPIO_PinSource GPIO_PinSource14
764 #define BT_RX_GPIO_PinSource GPIO_PinSource9
765 #define BT_USART_IRQHandler USART6_IRQHandler
766 #if defined(PCBX12S)
767 #if PCBREV >= 13
768 #define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOG)
769 #define BT_EN_GPIO GPIOI
770 #define BT_EN_GPIO_PIN GPIO_Pin_10 // PI.10
771 #else
772 #define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOG)
773 #define BT_EN_GPIO GPIOA
774 #define BT_EN_GPIO_PIN GPIO_Pin_6 // PA.06
775 #endif
776 #define BT_BRTS_GPIO GPIOG
777 #define BT_BRTS_GPIO_PIN GPIO_Pin_10 // PG.10
778 #define BT_BCTS_GPIO GPIOG
779 #define BT_BCTS_GPIO_PIN GPIO_Pin_11 // PG.11
780 #elif defined(PCBX10)
781 #define BT_RCC_AHB1Periph RCC_AHB1Periph_GPIOG
782 #define BT_EN_GPIO GPIOG
783 #define BT_EN_GPIO_PIN GPIO_Pin_10 // PG.10
784 #endif
786 // GPS
787 #if defined(PCBX12S)
788 #define GPS_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
789 #define GPS_RCC_APB1Periph RCC_APB1Periph_UART4
790 #define GPS_USART UART4
791 #define GPS_GPIO_AF GPIO_AF_UART4
792 #define GPS_USART_IRQn UART4_IRQn
793 #define GPS_USART_IRQHandler UART4_IRQHandler
794 #define GPS_UART_GPIO GPIOA
795 #define GPS_TX_GPIO_PIN GPIO_Pin_0 // PA.00
796 #define GPS_RX_GPIO_PIN GPIO_Pin_1 // PA.01
797 #define GPS_TX_GPIO_PinSource GPIO_PinSource0
798 #define GPS_RX_GPIO_PinSource GPIO_PinSource1
799 #else
800 #define GPS_RCC_AHB1Periph 0
801 #define GPS_RCC_APB1Periph 0
802 #endif
804 #endif // _HAL_H_