Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
lisa_m_common.h
Go to the documentation of this file.
1 #ifndef CONFIG_LISA_M_COMMON_H
2 #define CONFIG_LISA_M_COMMON_H
3 
4 #include "std.h"
5 
6 /* SPI slave mapping */
7 
8 #define SPI_SELECT_SLAVE0_PORT GPIOA
9 #define SPI_SELECT_SLAVE0_PIN GPIO15
10 
11 #define SPI_SELECT_SLAVE1_PORT GPIOA
12 #define SPI_SELECT_SLAVE1_PIN GPIO4
13 
14 #define SPI_SELECT_SLAVE2_PORT GPIOB
15 #define SPI_SELECT_SLAVE2_PIN GPIO12
16 
17 #define SPI_SELECT_SLAVE3_PORT GPIOC
18 #define SPI_SELECT_SLAVE3_PIN GPIO13
19 
20 #define SPI_SELECT_SLAVE4_PORT GPIOC
21 #define SPI_SELECT_SLAVE4_PIN GPIO12
22 
23 #define SPI_SELECT_SLAVE5_PORT GPIOC
24 #define SPI_SELECT_SLAVE5_PIN GPIO4
25 
26 
27 
28 /*
29  * UART pin configuration
30  *
31  * sets on which pins the UARTs are connected
32  */
33 #define UART1_GPIO_AF 0
34 #define UART1_GPIO_PORT_RX GPIO_BANK_USART1_RX
35 #define UART1_GPIO_RX GPIO_USART1_RX
36 #define UART1_GPIO_PORT_TX GPIO_BANK_USART1_TX
37 #define UART1_GPIO_TX GPIO_USART1_TX
38 
39 #define UART2_GPIO_AF 0
40 #define UART2_GPIO_PORT_RX GPIO_BANK_USART2_RX
41 #define UART2_GPIO_RX GPIO_USART2_RX
42 #define UART2_GPIO_PORT_TX GPIO_BANK_USART2_TX
43 #define UART2_GPIO_TX GPIO_USART2_TX
44 
45 #if REMAP_UART3 // For UART4 we need to remap UART 3
46 #define UART3_GPIO_AF 0
47 #define UART3_GPIO_PORT_RX GPIO_BANK_USART3_RX
48 #define UART3_GPIO_RX GPIO_USART3_RX
49 #define UART3_GPIO_PORT_TX GPIO_BANK_USART3_TX
50 #define UART3_GPIO_TX GPIO_USART3_TX
51 
52 #define UART4_GPIO_AF 0
53 #define UART4_GPIO_PORT_RX GPIOC
54 #define UART4_GPIO_RX GPIO10
55 #define UART4_GPIO_PORT_TX GPIOC
56 #define UART4_GPIO_TX GPIO11
57 
58 #else
59 #define UART3_GPIO_AF AFIO_MAPR_USART3_REMAP_PARTIAL_REMAP
60 #define UART3_GPIO_PORT_RX GPIO_BANK_USART3_PR_RX
61 #define UART3_GPIO_RX GPIO_USART3_PR_RX
62 #define UART3_GPIO_PORT_TX GPIO_BANK_USART3_PR_TX
63 #define UART3_GPIO_TX GPIO_USART3_PR_TX
64 #endif
65 
66 #define UART5_GPIO_AF 0
67 #define UART5_GPIO_PORT_RX GPIO_BANK_UART5_RX
68 #define UART5_GPIO_RX GPIO_UART5_RX
69 #define UART5_GPIO_PORT_TX GPIO_BANK_UART5_TX
70 #define UART5_GPIO_TX GPIO_UART5_TX
71 
72 
73 /*
74  * Spektrum
75  */
76 /* The line that is pulled low at power up to initiate the bind process */
77 /* It was common for all Lisa/M up to version 2.1. */
78 /* #define SPEKTRUM_BIND_PIN GPIO3 */
79 /* #define SPEKTRUM_BIND_PIN_PORT GPIOC */
80 
81 #define SPEKTRUM_UART1_RCC RCC_USART1
82 #define SPEKTRUM_UART1_BANK GPIO_BANK_USART1_RX
83 #define SPEKTRUM_UART1_PIN GPIO_USART1_RX
84 #define SPEKTRUM_UART1_AF 0
85 #define SPEKTRUM_UART1_IRQ NVIC_USART1_IRQ
86 #define SPEKTRUM_UART1_ISR usart1_isr
87 #define SPEKTRUM_UART1_DEV USART1
88 
89 #define SPEKTRUM_UART3_RCC RCC_USART3
90 #define SPEKTRUM_UART3_BANK GPIO_BANK_USART3_PR_RX
91 #define SPEKTRUM_UART3_PIN GPIO_USART3_PR_RX
92 #define SPEKTRUM_UART3_AF AFIO_MAPR_USART3_REMAP_PARTIAL_REMAP
93 #define SPEKTRUM_UART3_IRQ NVIC_USART3_IRQ
94 #define SPEKTRUM_UART3_ISR usart3_isr
95 #define SPEKTRUM_UART3_DEV USART3
96 
97 #define SPEKTRUM_UART5_RCC RCC_UART5
98 #define SPEKTRUM_UART5_BANK GPIO_BANK_UART5_RX
99 #define SPEKTRUM_UART5_PIN GPIO_UART5_RX
100 #define SPEKTRUM_UART5_AF 0
101 #define SPEKTRUM_UART5_IRQ NVIC_UART5_IRQ
102 #define SPEKTRUM_UART5_ISR uart5_isr
103 #define SPEKTRUM_UART5_DEV UART5
104 
105 
106 /* PPM
107  *
108  * Default is PPM config 2, input on GPIO01 (Servo pin 6)
109  */
110 #if USE_PPM
111 #ifndef PPM_CONFIG
112 #define PPM_CONFIG 2
113 #endif
114 
115 #if PPM_CONFIG == 1
116 /* input on PA01 (UART1_RX) */
117 #define USE_PPM_TIM1 1
118 #define PPM_CHANNEL TIM_IC3
119 #define PPM_TIMER_INPUT TIM_IC_IN_TI3
120 #define PPM_IRQ NVIC_TIM1_UP_IRQ
121 #define PPM_IRQ2 NVIC_TIM1_CC_IRQ
122 // Capture/Compare InteruptEnable and InterruptFlag
123 #define PPM_CC_IE TIM_DIER_CC3IE
124 #define PPM_CC_IF TIM_SR_CC3IF
125 #define PPM_GPIO_PORT GPIOA
126 #define PPM_GPIO_PIN GPIO10
127 #define PPM_GPIO_AF 0
128 
129 #elif PPM_CONFIG == 2
130 /* input on PA10 (Servo 6 pin) */
131 #define USE_PPM_TIM2 1
132 #define PPM_CHANNEL TIM_IC2
133 #define PPM_TIMER_INPUT TIM_IC_IN_TI2
134 #define PPM_IRQ NVIC_TIM2_IRQ
135 // Capture/Compare InteruptEnable and InterruptFlag
136 #define PPM_CC_IE TIM_DIER_CC2IE
137 #define PPM_CC_IF TIM_SR_CC2IF
138 #define PPM_GPIO_PORT GPIOA
139 #define PPM_GPIO_PIN GPIO1
140 #define PPM_GPIO_AF 0
141 
142 // Move default ADC timer
143 #if USE_AD_TIM2
144 #undef USE_AD_TIM2
145 #endif
146 #define USE_AD_TIM1 1
147 
148 #else
149 #error "Unknown PPM config"
150 
151 #endif // PPM_CONFIG
152 #endif // USE_PPM
153 
154 /*
155  * ADC
156  */
157 
158 /* Onboard ADCs */
159 /*
160  ADC1 PC3/ADC13
161  ADC2 PC0/ADC10
162  ADC3 PC1/ADC11
163  ADC4 PC5/ADC15
164  ADC6 PC2/ADC12
165  BATT PC4/ADC14 (ADC5)
166 
167 */
168 
169 /* provide defines that can be used to access the ADC_x in the code or airframe file
170  * these directly map to the index number of the 4 adc channels defined above
171  * 4th (index 3) is used for bat monitoring by default
172  */
173 #if USE_ADC_1
174 #define AD1_1_CHANNEL 13
175 #define ADC_1 AD1_1
176 #define ADC_1_GPIO_PORT GPIOC
177 #define ADC_1_GPIO_PIN GPIO3
178 #endif
179 
180 #if USE_ADC_2
181 #define AD1_2_CHANNEL 10
182 #define ADC_2 AD1_2
183 #define ADC_2_GPIO_PORT GPIOC
184 #define ADC_2_GPIO_PIN GPIO0
185 #endif
186 
187 #if USE_ADC_3
188 #define AD1_3_CHANNEL 11
189 #define ADC_3 AD1_3
190 #define ADC_3_GPIO_PORT GPIOC
191 #define ADC_3_GPIO_PIN GPIO1
192 #endif
193 
194 #if USE_ADC_4
195 #define AD2_1_CHANNEL 15
196 #define ADC_4 AD2_1
197 #define ADC_4_GPIO_PORT GPIOC
198 #define ADC_4_GPIO_PIN GPIO5
199 #endif
200 
201 // Internal ADC for battery enabled by default
202 #ifndef USE_ADC_5
203 #define USE_ADC_5 1
204 #endif
205 #if USE_ADC_5
206 #define AD1_4_CHANNEL 14
207 #define ADC_5 AD1_4
208 #define ADC_5_GPIO_PORT GPIOC
209 #define ADC_5_GPIO_PIN GPIO4
210 #endif
211 
212 #if USE_ADC_6
213 #define AD2_2_CHANNEL 12
214 #define ADC_6 AD2_2
215 #define ADC_6_GPIO_PORT GPIOC
216 #define ADC_6_GPIO_PIN GPIO2
217 #endif
218 
219 /* allow to define ADC_CHANNEL_VSUPPLY in the airframe file*/
220 #ifndef ADC_CHANNEL_VSUPPLY
221 #define ADC_CHANNEL_VSUPPLY ADC_5
222 #endif
223 
224 /*
225  * I2C
226  *
227  */
228 #define I2C1_GPIO_PORT GPIOB
229 #define I2C1_GPIO_SCL GPIO6
230 #define I2C1_GPIO_SDA GPIO7
231 
232 #define I2C2_GPIO_PORT GPIOB
233 #define I2C2_GPIO_SCL GPIO10
234 #define I2C2_GPIO_SDA GPIO11
235 
236 
237 /*
238  * PWM
239  *
240  */
241 #define PWM_USE_TIM3 1
242 #define PWM_USE_TIM5 1
243 
244 #define USE_PWM1 1
245 #define USE_PWM2 1
246 #define USE_PWM3 1
247 #define USE_PWM4 1
248 
249 #if DUAL_PWM_ON
250 #define DUAL_PWM_USE_TIM5 1
251 
252 #define USE_DUAL_PWM5 1
253 #define USE_DUAL_PWM6 1
254 #else
255 #define USE_PWM5 1
256 #if (!defined USE_PWM6) && (PPM_CONFIG != 2) // PWM6 only activated by default if PPM_CONFIG is not 2
257 #define USE_PWM6 1
258 #endif
259 #endif
260 
261 #if (USE_PPM && PPM_CONFIG == 2) && USE_PWM6 == 1
262 #warning "You cannot USE_PWM6 and SERVO6 (or equivalent) at the same time"
263 #endif
264 
265 #if USE_SERVOS_7AND8
266 #if USE_I2C1
267 #error "You cannot USE_SERVOS_7AND8 and USE_I2C1 at the same time"
268 #else
269 #define ACTUATORS_PWM_NB 8
270 #define USE_PWM7 1
271 #define USE_PWM8 1
272 #define PWM_USE_TIM4 1
273 #endif
274 #else
275 #define ACTUATORS_PWM_NB 6
276 #endif
277 
278 // Servo numbering on LisaM silkscreen/docs starts with 1
279 
280 // PWM_SERVO_x is the index of the servo in the actuators_pwm_values array
281 #if USE_PWM1
282 #define PWM_SERVO_1 0
283 #define PWM_SERVO_1_TIMER TIM3
284 #define PWM_SERVO_1_GPIO GPIOC
285 #define PWM_SERVO_1_PIN GPIO6
286 #define PWM_SERVO_1_AF AFIO_MAPR_TIM3_REMAP_FULL_REMAP
287 #define PWM_SERVO_1_OC TIM_OC1
288 #define PWM_SERVO_1_OC_BIT (1<<0)
289 #else
290 #define PWM_SERVO_1_OC_BIT 0
291 #endif
292 
293 #if USE_PWM2
294 #define PWM_SERVO_2 1
295 #define PWM_SERVO_2_TIMER TIM3
296 #define PWM_SERVO_2_GPIO GPIOC
297 #define PWM_SERVO_2_PIN GPIO7
298 #define PWM_SERVO_2_AF AFIO_MAPR_TIM3_REMAP_FULL_REMAP
299 #define PWM_SERVO_2_OC TIM_OC2
300 #define PWM_SERVO_2_OC_BIT (1<<1)
301 #else
302 #define PWM_SERVO_2_OC_BIT 0
303 #endif
304 
305 #if USE_PWM3
306 #define PWM_SERVO_3 2
307 #define PWM_SERVO_3_TIMER TIM3
308 #define PWM_SERVO_3_GPIO GPIOC
309 #define PWM_SERVO_3_PIN GPIO8
310 #define PWM_SERVO_3_AF AFIO_MAPR_TIM3_REMAP_FULL_REMAP
311 #define PWM_SERVO_3_OC TIM_OC3
312 #define PWM_SERVO_3_OC_BIT (1<<2)
313 #else
314 #define PWM_SERVO_3_OC_BIT 0
315 #endif
316 
317 #if USE_PWM4
318 #define PWM_SERVO_4 3
319 #define PWM_SERVO_4_TIMER TIM3
320 #define PWM_SERVO_4_GPIO GPIOC
321 #define PWM_SERVO_4_PIN GPIO9
322 #define PWM_SERVO_4_AF AFIO_MAPR_TIM3_REMAP_FULL_REMAP
323 #define PWM_SERVO_4_OC TIM_OC4
324 #define PWM_SERVO_4_OC_BIT (1<<3)
325 #else
326 #define PWM_SERVO_4_OC_BIT 0
327 #endif
328 
329 #if USE_PWM5
330 #define PWM_SERVO_5 4
331 #define PWM_SERVO_5_TIMER TIM5
332 #define PWM_SERVO_5_GPIO GPIOA
333 #define PWM_SERVO_5_PIN GPIO0
334 #define PWM_SERVO_5_AF 0
335 #define PWM_SERVO_5_OC TIM_OC1
336 #define PWM_SERVO_5_OC_BIT (1<<0)
337 #elif USE_DUAL_PWM5
338 #define DUAL_PWM_SERVO_5 4
339 
340 #define DUAL_PWM_SERVO_5_P1 0
341 #define DUAL_PWM_SERVO_5_P2 1
342 
343 #define DUAL_PWM_SERVO_5_TIMER TIM5
344 #define DUAL_PWM_SERVO_5_GPIO GPIOA
345 #define DUAL_PWM_SERVO_5_PIN GPIO0
346 #define DUAL_PWM_SERVO_5_AF 0
347 #define DUAL_PWM_SERVO_5_OC TIM_OC1
348 #define PWM_SERVO_5_OC_BIT (1<<0)
349 #else
350 #define PWM_SERVO_5_OC_BIT 0
351 #endif
352 
353 #if USE_PWM6
354 #define PWM_SERVO_6 5
355 #define PWM_SERVO_6_TIMER TIM5
356 #define PWM_SERVO_6_GPIO GPIOA
357 #define PWM_SERVO_6_PIN GPIO1
358 #define PWM_SERVO_6_AF 0
359 #define PWM_SERVO_6_OC TIM_OC2
360 #define PWM_SERVO_6_OC_BIT (1<<1)
361 #elif USE_DUAL_PWM6
362 #define DUAL_PWM_SERVO_6 5
363 
364 #define DUAL_PWM_SERVO_6_P1 0
365 #define DUAL_PWM_SERVO_6_P2 1
366 
367 #define DUAL_PWM_SERVO_6_TIMER TIM5
368 #define DUAL_PWM_SERVO_6_GPIO GPIOA
369 #define DUAL_PWM_SERVO_6_PIN GPIO1
370 #define DUAL_PWM_SERVO_6_AF 0
371 #define DUAL_PWM_SERVO_6_OC TIM_OC2
372 #define PWM_SERVO_6_OC_BIT (1<<1)
373 #else
374 #define PWM_SERVO_6_OC_BIT 0
375 #endif
376 
377 
378 
379 
380 
381 
382 #if USE_PWM7
383 #define PWM_SERVO_7 6
384 #define PWM_SERVO_7_TIMER TIM4
385 #define PWM_SERVO_7_GPIO GPIOB
386 #define PWM_SERVO_7_PIN GPIO6
387 #define PWM_SERVO_7_AF 0
388 #define PWM_SERVO_7_OC TIM_OC1
389 #define PWM_SERVO_7_OC_BIT (1<<0)
390 #else
391 #define PWM_SERVO_7_OC_BIT 0
392 #endif
393 
394 #if USE_PWM8
395 #define PWM_SERVO_8 7
396 #define PWM_SERVO_8_TIMER TIM4
397 #define PWM_SERVO_8_GPIO GPIOB
398 #define PWM_SERVO_8_PIN GPIO7
399 #define PWM_SERVO_8_AF 0
400 #define PWM_SERVO_8_OC TIM_OC2
401 #define PWM_SERVO_8_OC_BIT (1<<1)
402 #else
403 #define PWM_SERVO_8_OC_BIT 0
404 #endif
405 
406 /* servos 1-4 on TIM3 */
407 #define PWM_TIM3_CHAN_MASK (PWM_SERVO_1_OC_BIT|PWM_SERVO_2_OC_BIT|PWM_SERVO_3_OC_BIT|PWM_SERVO_4_OC_BIT)
408 /* servos 5-6 on TIM5 */
409 #define PWM_TIM5_CHAN_MASK (PWM_SERVO_5_OC_BIT|PWM_SERVO_6_OC_BIT)
410 /* servos 7-8 on TIM4 if USE_SERVOS_7AND8 */
411 #define PWM_TIM4_CHAN_MASK (PWM_SERVO_7_OC_BIT|PWM_SERVO_8_OC_BIT)
412 
413 
414 #endif
415