REVONANO - Add support for eeprom and objlist fs
[librepilot.git] / flight / targets / boards / revonano / board_hw_defs.c
blob3d7f59b99144278cb2ea5f8e40bc9f7984779a2f
1 /**
2 ******************************************************************************
3 * @file board_hw_defs.c
4 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
5 * @addtogroup OpenPilotSystem OpenPilot System
6 * @{
7 * @addtogroup OpenPilotCore OpenPilot Core
8 * @{
9 * @brief Defines board specific static initializers for hardware for the Revolution board.
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <pios.h>
28 /* I/O mapping
29 * I/O | PIN | Channel | Alternate function
30 * I1 | PB10 | TIM2_CH3 | x
31 * i2 | PB1 | TIM3_CH4 | ADC1_9
32 * I3 | PB0 | TIM3_CH3 | ADC1_8
33 * I4 | PA7 | TIM3_CH2 | SPI1_MOSI/ADC1_7
34 * I5 | PA6 | TIM3_CH1 | SPI1_MISO/ADC1_6
35 * I6 | PA5 | TIM2_CH1 | SPI1_SCK/ADC1_5
36 *------------------------------------
37 * o1 | PA10 | TIM1_CH3 | USART1_RX
38 * o2 | PB3 | TIM2_CH2 | I2C2_SDA,
39 * o3 | PB8 | TIM10_CH1
40 * o4 | PB9 | TIM11_CH1
41 * o5 | PA0 | TIM5_CH1 | ADC1_0
42 * o6 | PA1 | TIM5_CH2 | ADC1_1
44 #define MAIN_USART_REGS USART2
45 #define MAIN_USART_REMAP GPIO_AF_USART2
46 #define MAIN_USART_IRQ USART2_IRQn
47 #define MAIN_USART_RX_GPIO GPIOA
48 #define MAIN_USART_RX_PIN GPIO_Pin_3
49 #define MAIN_USART_TX_GPIO GPIOA
50 #define MAIN_USART_TX_PIN GPIO_Pin_2
51 // Inverter for SBUS handling
52 #define MAIN_USART_INVERTER_GPIO GPIOC
53 #define MAIN_USART_INVERTER_PIN GPIO_Pin_15
54 #define MAIN_USART_INVERTER_CLOCK_FUNC RCC_AHB1PeriphClockCmd
55 #define MAIN_USART_INVERTER_CLOCK_PERIPH RCC_AHB1Periph_GPIOC
57 #define FLEXI_USART_REGS USART1
58 #define FLEXI_USART_REMAP GPIO_AF_USART1
59 #define FLEXI_USART_IRQ USART1_IRQn
60 #define FLEXI_USART_RX_GPIO GPIOB
61 #define FLEXI_USART_RX_PIN GPIO_Pin_7
62 #define FLEXI_USART_TX_GPIO GPIOB
63 #define FLEXI_USART_TX_PIN GPIO_Pin_6
66 #if defined(PIOS_INCLUDE_LED)
68 #include <pios_led_priv.h>
69 static const struct pios_gpio pios_leds[] = {
70 [PIOS_LED_HEARTBEAT] = {
71 .pin = {
72 .gpio = GPIOC,
73 .init = {
74 .GPIO_Pin = GPIO_Pin_14,
75 .GPIO_Speed = GPIO_Speed_50MHz,
76 .GPIO_Mode = GPIO_Mode_OUT,
77 .GPIO_OType = GPIO_OType_PP,
78 .GPIO_PuPd = GPIO_PuPd_UP
81 .active_low = true
83 [PIOS_LED_ALARM] = {
84 .pin = {
85 .gpio = GPIOC,
86 .init = {
87 .GPIO_Pin = GPIO_Pin_13,
88 .GPIO_Speed = GPIO_Speed_50MHz,
89 .GPIO_Mode = GPIO_Mode_OUT,
90 .GPIO_OType = GPIO_OType_PP,
91 .GPIO_PuPd = GPIO_PuPd_UP
94 .active_low = true
98 static const struct pios_gpio_cfg pios_led_cfg = {
99 .gpios = pios_leds,
100 .num_gpios = NELEMENTS(pios_leds),
103 const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision)
105 return &pios_led_cfg;
108 #endif /* PIOS_INCLUDE_LED */
110 #if defined(PIOS_INCLUDE_SPI)
111 #include <pios_spi_priv.h>
114 * SPI1 Interface
115 * Used for MPU6000 gyro and accelerometer
117 void PIOS_SPI_gyro_irq_handler(void);
118 void DMA1_Stream3_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
119 void DMA1_Stream4_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
120 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
121 .regs = SPI2,
122 .remap = GPIO_AF_SPI2,
123 .init = {
124 .SPI_Mode = SPI_Mode_Master,
125 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
126 .SPI_DataSize = SPI_DataSize_8b,
127 .SPI_NSS = SPI_NSS_Soft,
128 .SPI_FirstBit = SPI_FirstBit_MSB,
129 .SPI_CRCPolynomial = 7,
130 .SPI_CPOL = SPI_CPOL_High,
131 .SPI_CPHA = SPI_CPHA_2Edge,
132 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16,
134 .use_crc = false,
135 .dma = {
136 .irq = {
137 .flags = (DMA_IT_TCIF0 | DMA_IT_TEIF0 | DMA_IT_HTIF0),
138 .init = {
139 .NVIC_IRQChannel = DMA1_Stream3_IRQn,
140 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
141 .NVIC_IRQChannelSubPriority = 0,
142 .NVIC_IRQChannelCmd = ENABLE,
146 .rx = {
147 .channel = DMA1_Stream3,
148 .init = {
149 .DMA_Channel = DMA_Channel_0,
150 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
151 .DMA_DIR = DMA_DIR_PeripheralToMemory,
152 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
153 .DMA_MemoryInc = DMA_MemoryInc_Enable,
154 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
155 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
156 .DMA_Mode = DMA_Mode_Normal,
157 .DMA_Priority = DMA_Priority_Medium,
158 .DMA_FIFOMode = DMA_FIFOMode_Disable,
159 /* .DMA_FIFOThreshold */
160 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
161 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
164 .tx = {
165 .channel = DMA1_Stream4,
166 .init = {
167 .DMA_Channel = DMA_Channel_0,
168 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
169 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
170 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
171 .DMA_MemoryInc = DMA_MemoryInc_Enable,
172 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
173 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
174 .DMA_Mode = DMA_Mode_Normal,
175 .DMA_Priority = DMA_Priority_High,
176 .DMA_FIFOMode = DMA_FIFOMode_Disable,
177 /* .DMA_FIFOThreshold */
178 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
179 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
183 .sclk = {
184 .gpio = GPIOB,
185 .init = {
186 .GPIO_Pin = GPIO_Pin_13,
187 .GPIO_Speed = GPIO_Speed_100MHz,
188 .GPIO_Mode = GPIO_Mode_AF,
189 .GPIO_OType = GPIO_OType_PP,
190 .GPIO_PuPd = GPIO_PuPd_UP
193 .miso = {
194 .gpio = GPIOB,
195 .init = {
196 .GPIO_Pin = GPIO_Pin_14,
197 .GPIO_Speed = GPIO_Speed_50MHz,
198 .GPIO_Mode = GPIO_Mode_AF,
199 .GPIO_OType = GPIO_OType_PP,
200 .GPIO_PuPd = GPIO_PuPd_UP
203 .mosi = {
204 .gpio = GPIOB,
205 .init = {
206 .GPIO_Pin = GPIO_Pin_15,
207 .GPIO_Speed = GPIO_Speed_50MHz,
208 .GPIO_Mode = GPIO_Mode_AF,
209 .GPIO_OType = GPIO_OType_PP,
210 .GPIO_PuPd = GPIO_PuPd_UP
213 .slave_count = 1,
214 .ssel = {
216 .gpio = GPIOB,
217 .init = {
218 .GPIO_Pin = GPIO_Pin_12,
219 .GPIO_Speed = GPIO_Speed_50MHz,
220 .GPIO_Mode = GPIO_Mode_OUT,
221 .GPIO_OType = GPIO_OType_PP,
222 .GPIO_PuPd = GPIO_PuPd_UP
228 static uint32_t pios_spi_gyro_id;
229 void PIOS_SPI_gyro_irq_handler(void)
231 /* Call into the generic code to handle the IRQ for this specific device */
232 PIOS_SPI_IRQ_Handler(pios_spi_gyro_id);
235 #endif /* PIOS_INCLUDE_SPI */
237 #include <pios_usart_priv.h>
239 #ifdef PIOS_INCLUDE_COM_TELEM
242 * MAIN USART
244 static const struct pios_usart_cfg pios_usart_main_cfg = {
245 .regs = MAIN_USART_REGS,
246 .remap = MAIN_USART_REMAP,
247 .init = {
248 .USART_BaudRate = 57600,
249 .USART_WordLength = USART_WordLength_8b,
250 .USART_Parity = USART_Parity_No,
251 .USART_StopBits = USART_StopBits_1,
252 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
253 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
255 .irq = {
256 .init = {
257 .NVIC_IRQChannel = MAIN_USART_IRQ,
258 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
259 .NVIC_IRQChannelSubPriority = 0,
260 .NVIC_IRQChannelCmd = ENABLE,
263 .rx = {
264 .gpio = MAIN_USART_RX_GPIO,
265 .init = {
266 .GPIO_Pin = MAIN_USART_RX_PIN,
267 .GPIO_Speed = GPIO_Speed_2MHz,
268 .GPIO_Mode = GPIO_Mode_AF,
269 .GPIO_OType = GPIO_OType_PP,
270 .GPIO_PuPd = GPIO_PuPd_UP
273 .tx = {
274 .gpio = MAIN_USART_TX_GPIO,
275 .init = {
276 .GPIO_Pin = MAIN_USART_TX_PIN,
277 .GPIO_Speed = GPIO_Speed_2MHz,
278 .GPIO_Mode = GPIO_Mode_AF,
279 .GPIO_OType = GPIO_OType_PP,
280 .GPIO_PuPd = GPIO_PuPd_UP
284 #endif /* PIOS_INCLUDE_COM_TELEM */
286 #ifdef PIOS_INCLUDE_DSM
288 #include "pios_dsm_priv.h"
289 static const struct pios_usart_cfg pios_usart_dsm_main_cfg = {
290 .regs = MAIN_USART_REGS,
291 .remap = MAIN_USART_REMAP,
292 .init = {
293 .USART_BaudRate = 115200,
294 .USART_WordLength = USART_WordLength_8b,
295 .USART_Parity = USART_Parity_No,
296 .USART_StopBits = USART_StopBits_1,
297 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
298 .USART_Mode = USART_Mode_Rx,
300 .irq = {
301 .init = {
302 .NVIC_IRQChannel = MAIN_USART_IRQ,
303 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
304 .NVIC_IRQChannelSubPriority = 0,
305 .NVIC_IRQChannelCmd = ENABLE,
308 .rx = {
309 .gpio = MAIN_USART_RX_GPIO,
310 .init = {
311 .GPIO_Pin = MAIN_USART_RX_PIN,
312 .GPIO_Speed = GPIO_Speed_2MHz,
313 .GPIO_Mode = GPIO_Mode_AF,
314 .GPIO_OType = GPIO_OType_PP,
315 .GPIO_PuPd = GPIO_PuPd_UP
318 .tx = {
319 .gpio = MAIN_USART_TX_GPIO,
320 .init = {
321 .GPIO_Pin = MAIN_USART_TX_PIN,
322 .GPIO_Speed = GPIO_Speed_2MHz,
323 .GPIO_Mode = GPIO_Mode_AF,
324 .GPIO_OType = GPIO_OType_PP,
325 .GPIO_PuPd = GPIO_PuPd_UP
330 // Because of the inverter on the main port this will not
331 // work. Notice the mode is set to IN to maintain API
332 // compatibility but protect the pins
333 static const struct pios_dsm_cfg pios_dsm_main_cfg = {
334 .bind = {
335 .gpio = MAIN_USART_RX_GPIO,
336 .init = {
337 .GPIO_Pin = MAIN_USART_RX_PIN,
338 .GPIO_Speed = GPIO_Speed_2MHz,
339 .GPIO_Mode = GPIO_Mode_IN,
340 .GPIO_OType = GPIO_OType_PP,
341 .GPIO_PuPd = GPIO_PuPd_NOPULL
346 #endif /* PIOS_INCLUDE_DSM */
348 #include <pios_sbus_priv.h>
349 #if defined(PIOS_INCLUDE_SBUS)
351 * S.Bus USART
353 #include <pios_sbus_priv.h>
355 static const struct pios_usart_cfg pios_usart_sbus_main_cfg = {
356 .regs = MAIN_USART_REGS,
357 .remap = MAIN_USART_REMAP,
358 .init = {
359 .USART_BaudRate = 100000,
360 .USART_WordLength = USART_WordLength_8b,
361 .USART_Parity = USART_Parity_Even,
362 .USART_StopBits = USART_StopBits_2,
363 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
364 .USART_Mode = USART_Mode_Rx,
366 .irq = {
367 .init = {
368 .NVIC_IRQChannel = MAIN_USART_IRQ,
369 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
370 .NVIC_IRQChannelSubPriority = 0,
371 .NVIC_IRQChannelCmd = ENABLE,
374 .rx = {
375 .gpio = MAIN_USART_RX_GPIO,
376 .init = {
377 .GPIO_Pin = MAIN_USART_RX_PIN,
378 .GPIO_Speed = GPIO_Speed_2MHz,
379 .GPIO_Mode = GPIO_Mode_AF,
380 .GPIO_OType = GPIO_OType_PP,
381 .GPIO_PuPd = GPIO_PuPd_UP
384 .tx = {
385 .gpio = MAIN_USART_TX_GPIO,
386 .init = {
387 .GPIO_Pin = MAIN_USART_TX_PIN,
388 .GPIO_Speed = GPIO_Speed_2MHz,
389 .GPIO_Mode = GPIO_Mode_OUT,
390 .GPIO_OType = GPIO_OType_PP,
391 .GPIO_PuPd = GPIO_PuPd_NOPULL
396 #endif /* PIOS_INCLUDE_SBUS */
398 // Need this defined regardless to be able to turn it off
399 static const struct pios_sbus_cfg pios_sbus_cfg = {
400 /* Inverter configuration */
401 .inv = {
402 .gpio = MAIN_USART_INVERTER_GPIO,
403 .init = {
404 .GPIO_Pin = MAIN_USART_INVERTER_PIN,
405 .GPIO_Speed = GPIO_Speed_2MHz,
406 .GPIO_Mode = GPIO_Mode_OUT,
407 .GPIO_OType = GPIO_OType_PP,
408 .GPIO_PuPd = GPIO_PuPd_UP
411 .gpio_inv_enable = Bit_SET,
412 .gpio_inv_disable = Bit_RESET,
413 .gpio_clk_func = MAIN_USART_INVERTER_CLOCK_FUNC,
414 .gpio_clk_periph = MAIN_USART_INVERTER_CLOCK_PERIPH,
418 #ifdef PIOS_INCLUDE_COM_FLEXI
420 * FLEXI PORT
422 static const struct pios_usart_cfg pios_usart_flexi_cfg = {
423 .regs = FLEXI_USART_REGS,
424 .remap = FLEXI_USART_REMAP,
425 .init = {
426 .USART_BaudRate = 57600,
427 .USART_WordLength = USART_WordLength_8b,
428 .USART_Parity = USART_Parity_No,
429 .USART_StopBits = USART_StopBits_1,
430 .USART_HardwareFlowControl =
431 USART_HardwareFlowControl_None,
432 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
434 .irq = {
435 .init = {
436 .NVIC_IRQChannel = FLEXI_USART_IRQ,
437 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
438 .NVIC_IRQChannelSubPriority = 0,
439 .NVIC_IRQChannelCmd = ENABLE,
442 .rx = {
443 .gpio = FLEXI_USART_RX_GPIO,
444 .init = {
445 .GPIO_Pin = FLEXI_USART_RX_PIN,
446 .GPIO_Speed = GPIO_Speed_2MHz,
447 .GPIO_Mode = GPIO_Mode_AF,
448 .GPIO_OType = GPIO_OType_PP,
449 .GPIO_PuPd = GPIO_PuPd_UP
452 .tx = {
453 .gpio = FLEXI_USART_TX_GPIO,
454 .init = {
455 .GPIO_Pin = FLEXI_USART_TX_PIN,
456 .GPIO_Speed = GPIO_Speed_2MHz,
457 .GPIO_Mode = GPIO_Mode_AF,
458 .GPIO_OType = GPIO_OType_PP,
459 .GPIO_PuPd = GPIO_PuPd_UP
464 #endif /* PIOS_INCLUDE_COM_FLEXI */
466 #ifdef PIOS_INCLUDE_DSM
468 #include "pios_dsm_priv.h"
469 static const struct pios_usart_cfg pios_usart_dsm_flexi_cfg = {
470 .regs = FLEXI_USART_REGS,
471 .remap = FLEXI_USART_REMAP,
472 .init = {
473 .USART_BaudRate = 115200,
474 .USART_WordLength = USART_WordLength_8b,
475 .USART_Parity = USART_Parity_No,
476 .USART_StopBits = USART_StopBits_1,
477 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
478 .USART_Mode = USART_Mode_Rx,
480 .irq = {
481 .init = {
482 .NVIC_IRQChannel = FLEXI_USART_IRQ,
483 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
484 .NVIC_IRQChannelSubPriority = 0,
485 .NVIC_IRQChannelCmd = ENABLE,
488 .rx = {
489 .gpio = FLEXI_USART_RX_GPIO,
490 .init = {
491 .GPIO_Pin = FLEXI_USART_RX_PIN,
492 .GPIO_Speed = GPIO_Speed_2MHz,
493 .GPIO_Mode = GPIO_Mode_AF,
494 .GPIO_OType = GPIO_OType_PP,
495 .GPIO_PuPd = GPIO_PuPd_UP
498 .tx = {
499 .gpio = FLEXI_USART_TX_GPIO,
500 .init = {
501 .GPIO_Pin = FLEXI_USART_TX_PIN,
502 .GPIO_Speed = GPIO_Speed_2MHz,
503 .GPIO_Mode = GPIO_Mode_AF,
504 .GPIO_OType = GPIO_OType_PP,
505 .GPIO_PuPd = GPIO_PuPd_UP
510 static const struct pios_dsm_cfg pios_dsm_flexi_cfg = {
511 .bind = {
512 .gpio = FLEXI_USART_RX_GPIO,
513 .init = {
514 .GPIO_Pin = FLEXI_USART_RX_PIN,
515 .GPIO_Speed = GPIO_Speed_2MHz,
516 .GPIO_Mode = GPIO_Mode_OUT,
517 .GPIO_OType = GPIO_OType_PP,
518 .GPIO_PuPd = GPIO_PuPd_NOPULL
523 #endif /* PIOS_INCLUDE_DSM */
526 * HK OSD
528 static const struct pios_usart_cfg pios_usart_hkosd_main_cfg = {
529 .regs = MAIN_USART_REGS,
530 .remap = MAIN_USART_REMAP,
531 .init = {
532 .USART_BaudRate = 57600,
533 .USART_WordLength = USART_WordLength_8b,
534 .USART_Parity = USART_Parity_No,
535 .USART_StopBits = USART_StopBits_1,
536 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
537 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
539 .irq = {
540 .init = {
541 .NVIC_IRQChannel = MAIN_USART_IRQ,
542 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
543 .NVIC_IRQChannelSubPriority = 0,
544 .NVIC_IRQChannelCmd = ENABLE,
547 .rx = {
548 .gpio = MAIN_USART_RX_GPIO,
549 .init = {
550 .GPIO_Pin = MAIN_USART_RX_PIN,
551 .GPIO_Speed = GPIO_Speed_2MHz,
552 .GPIO_Mode = GPIO_Mode_AF,
553 .GPIO_OType = GPIO_OType_PP,
554 .GPIO_PuPd = GPIO_PuPd_UP
557 .tx = {
558 .gpio = MAIN_USART_TX_GPIO,
559 .init = {
560 .GPIO_Pin = MAIN_USART_TX_PIN,
561 .GPIO_Speed = GPIO_Speed_2MHz,
562 .GPIO_Mode = GPIO_Mode_AF,
563 .GPIO_OType = GPIO_OType_PP,
564 .GPIO_PuPd = GPIO_PuPd_UP
569 static const struct pios_usart_cfg pios_usart_hkosd_flexi_cfg = {
570 .regs = FLEXI_USART_REGS,
571 .remap = FLEXI_USART_REMAP,
572 .init = {
573 .USART_BaudRate = 57600,
574 .USART_WordLength = USART_WordLength_8b,
575 .USART_Parity = USART_Parity_No,
576 .USART_StopBits = USART_StopBits_1,
577 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
578 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
580 .irq = {
581 .init = {
582 .NVIC_IRQChannel = FLEXI_USART_IRQ,
583 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
584 .NVIC_IRQChannelSubPriority = 0,
585 .NVIC_IRQChannelCmd = ENABLE,
588 .rx = {
589 .gpio = FLEXI_USART_RX_GPIO,
590 .init = {
591 .GPIO_Pin = FLEXI_USART_RX_PIN,
592 .GPIO_Speed = GPIO_Speed_2MHz,
593 .GPIO_Mode = GPIO_Mode_AF,
594 .GPIO_OType = GPIO_OType_PP,
595 .GPIO_PuPd = GPIO_PuPd_UP
598 .tx = {
599 .gpio = FLEXI_USART_TX_GPIO,
600 .init = {
601 .GPIO_Pin = FLEXI_USART_TX_PIN,
602 .GPIO_Speed = GPIO_Speed_2MHz,
603 .GPIO_Mode = GPIO_Mode_AF,
604 .GPIO_OType = GPIO_OType_PP,
605 .GPIO_PuPd = GPIO_PuPd_UP
610 #if defined(PIOS_INCLUDE_COM)
612 #include <pios_com_priv.h>
614 #endif /* PIOS_INCLUDE_COM */
616 #if defined(PIOS_INCLUDE_I2C)
618 #include <pios_i2c_priv.h>
621 * I2C Adapters
623 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
624 void PIOS_I2C_pressureadapter_er_irq_handler(void);
625 void I2C3_EV_IRQHandler()
626 __attribute__((alias("PIOS_I2C_pressure_adapter_ev_irq_handler")));
627 void I2C3_ER_IRQHandler()
628 __attribute__((alias("PIOS_I2C_pressure_adapter_er_irq_handler")));
630 static const struct pios_i2c_adapter_cfg pios_i2c_pressure_adapter_cfg = {
631 .regs = I2C3,
632 .remapSCL = GPIO_AF_I2C3,
633 .remapSDA = GPIO_AF9_I2C3,
634 .init = {
635 .I2C_Mode = I2C_Mode_I2C,
636 .I2C_OwnAddress1 = 0,
637 .I2C_Ack = I2C_Ack_Enable,
638 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
639 .I2C_DutyCycle = I2C_DutyCycle_2,
640 .I2C_ClockSpeed = 400000, /* bits/s */
642 .transfer_timeout_ms = 50,
643 .scl = {
644 .gpio = GPIOA,
645 .init = {
646 .GPIO_Pin = GPIO_Pin_8,
647 .GPIO_Mode = GPIO_Mode_AF,
648 .GPIO_Speed = GPIO_Speed_50MHz,
649 .GPIO_OType = GPIO_OType_OD,
650 .GPIO_PuPd = GPIO_PuPd_NOPULL,
653 .sda = {
654 .gpio = GPIOB,
655 .init = {
656 .GPIO_Pin = GPIO_Pin_4,
657 .GPIO_Mode = GPIO_Mode_AF,
658 .GPIO_Speed = GPIO_Speed_50MHz,
659 .GPIO_OType = GPIO_OType_OD,
660 .GPIO_PuPd = GPIO_PuPd_NOPULL,
663 .event = {
664 .flags = 0, /* FIXME: check this */
665 .init = {
666 .NVIC_IRQChannel = I2C3_EV_IRQn,
667 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
668 .NVIC_IRQChannelSubPriority = 0,
669 .NVIC_IRQChannelCmd = ENABLE,
672 .error = {
673 .flags = 0, /* FIXME: check this */
674 .init = {
675 .NVIC_IRQChannel = I2C3_ER_IRQn,
676 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
677 .NVIC_IRQChannelSubPriority = 0,
678 .NVIC_IRQChannelCmd = ENABLE,
683 uint32_t pios_i2c_pressure_adapter_id;
684 void PIOS_I2C_pressure_adapter_ev_irq_handler(void)
686 /* Call into the generic code to handle the IRQ for this specific device */
687 PIOS_I2C_EV_IRQ_Handler(pios_i2c_pressure_adapter_id);
690 void PIOS_I2C_pressure_adapter_er_irq_handler(void)
692 /* Call into the generic code to handle the IRQ for this specific device */
693 PIOS_I2C_ER_IRQ_Handler(pios_i2c_pressure_adapter_id);
697 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
698 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
699 void I2C1_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
700 void I2C1_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler")));
702 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = {
703 .regs = I2C1,
704 .remapSCL = GPIO_AF_I2C1,
705 .remapSDA = GPIO_AF_I2C1,
706 .init = {
707 .I2C_Mode = I2C_Mode_I2C,
708 .I2C_OwnAddress1 = 0,
709 .I2C_Ack = I2C_Ack_Enable,
710 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
711 .I2C_DutyCycle = I2C_DutyCycle_2,
712 .I2C_ClockSpeed = 400000, /* bits/s */
714 .transfer_timeout_ms = 50,
715 .scl = {
716 .gpio = GPIOB,
717 .init = {
718 .GPIO_Pin = GPIO_Pin_6,
719 .GPIO_Mode = GPIO_Mode_AF,
720 .GPIO_Speed = GPIO_Speed_50MHz,
721 .GPIO_OType = GPIO_OType_OD,
722 .GPIO_PuPd = GPIO_PuPd_NOPULL,
725 .sda = {
726 .gpio = GPIOB,
727 .init = {
728 .GPIO_Pin = GPIO_Pin_7,
729 .GPIO_Mode = GPIO_Mode_AF,
730 .GPIO_Speed = GPIO_Speed_50MHz,
731 .GPIO_OType = GPIO_OType_OD,
732 .GPIO_PuPd = GPIO_PuPd_NOPULL,
735 .event = {
736 .flags = 0, /* FIXME: check this */
737 .init = {
738 .NVIC_IRQChannel = I2C1_EV_IRQn,
739 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
740 .NVIC_IRQChannelSubPriority = 0,
741 .NVIC_IRQChannelCmd = ENABLE,
744 .error = {
745 .flags = 0, /* FIXME: check this */
746 .init = {
747 .NVIC_IRQChannel = I2C1_ER_IRQn,
748 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
749 .NVIC_IRQChannelSubPriority = 0,
750 .NVIC_IRQChannelCmd = ENABLE,
755 uint32_t pios_i2c_flexiport_adapter_id;
756 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
758 /* Call into the generic code to handle the IRQ for this specific device */
759 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id);
762 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
764 /* Call into the generic code to handle the IRQ for this specific device */
765 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id);
769 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
770 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
772 #endif /* PIOS_INCLUDE_I2C */
774 #if defined(PIOS_INCLUDE_RTC)
776 * Realtime Clock (RTC)
778 #include <pios_rtc_priv.h>
780 void PIOS_RTC_IRQ_Handler(void);
781 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
782 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
783 .clksrc = RCC_RTCCLKSource_HSE_Div8, // Divide 8 Mhz crystal down to 1
784 // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
785 // by another 16 to give a nominal 62.5 khz clock
786 .prescaler = 100, // Every 100 cycles gives 625 Hz
787 .irq = {
788 .init = {
789 .NVIC_IRQChannel = RTC_WKUP_IRQn,
790 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
791 .NVIC_IRQChannelSubPriority = 0,
792 .NVIC_IRQChannelCmd = ENABLE,
797 void PIOS_RTC_IRQ_Handler(void)
799 PIOS_RTC_irq_handler();
802 #endif /* if defined(PIOS_INCLUDE_RTC) */
804 #include "pios_tim_priv.h"
806 static const TIM_TimeBaseInitTypeDef tim_2_3_4_5_time_base = {
807 .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1,
808 .TIM_ClockDivision = TIM_CKD_DIV1,
809 .TIM_CounterMode = TIM_CounterMode_Up,
810 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
811 .TIM_RepetitionCounter = 0x0000,
813 static const TIM_TimeBaseInitTypeDef tim_1_9_10_11_time_base = {
814 .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
815 .TIM_ClockDivision = TIM_CKD_DIV1,
816 .TIM_CounterMode = TIM_CounterMode_Up,
817 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
818 .TIM_RepetitionCounter = 0x0000,
821 static const struct pios_tim_clock_cfg tim_2_cfg = {
822 .timer = TIM2,
823 .time_base_init = &tim_2_3_4_5_time_base,
824 .irq = {
825 .init = {
826 .NVIC_IRQChannel = TIM2_IRQn,
827 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
828 .NVIC_IRQChannelSubPriority = 0,
829 .NVIC_IRQChannelCmd = ENABLE,
834 static const struct pios_tim_clock_cfg tim_3_cfg = {
835 .timer = TIM3,
836 .time_base_init = &tim_2_3_4_5_time_base,
837 .irq = {
838 .init = {
839 .NVIC_IRQChannel = TIM3_IRQn,
840 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
841 .NVIC_IRQChannelSubPriority = 0,
842 .NVIC_IRQChannelCmd = ENABLE,
847 static const struct pios_tim_clock_cfg tim_5_cfg = {
848 .timer = TIM5,
849 .time_base_init = &tim_2_3_4_5_time_base,
850 .irq = {
851 .init = {
852 .NVIC_IRQChannel = TIM5_IRQn,
853 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
854 .NVIC_IRQChannelSubPriority = 0,
855 .NVIC_IRQChannelCmd = ENABLE,
860 static const struct pios_tim_clock_cfg tim_1_cfg = {
861 .timer = TIM1,
862 .time_base_init = &tim_1_9_10_11_time_base,
863 .irq = {
864 .init = {
865 .NVIC_IRQChannel = TIM1_CC_IRQn,
866 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
867 .NVIC_IRQChannelSubPriority = 0,
868 .NVIC_IRQChannelCmd = ENABLE,
873 static const struct pios_tim_clock_cfg tim_9_cfg = {
874 .timer = TIM9,
875 .time_base_init = &tim_1_9_10_11_time_base,
876 .irq = {
877 .init = {
878 .NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn,
879 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
880 .NVIC_IRQChannelSubPriority = 0,
881 .NVIC_IRQChannelCmd = ENABLE,
886 static const struct pios_tim_clock_cfg tim_10_cfg = {
887 .timer = TIM10,
888 .time_base_init = &tim_1_9_10_11_time_base,
889 .irq = {
890 .init = {
891 .NVIC_IRQChannel = TIM1_UP_TIM10_IRQn,
892 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
893 .NVIC_IRQChannelSubPriority = 0,
894 .NVIC_IRQChannelCmd = ENABLE,
899 static const struct pios_tim_clock_cfg tim_11_cfg = {
900 .timer = TIM11,
901 .time_base_init = &tim_1_9_10_11_time_base,
902 .irq = {
903 .init = {
904 .NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn,
905 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
906 .NVIC_IRQChannelSubPriority = 0,
907 .NVIC_IRQChannelCmd = ENABLE,
912 // Set up timers that only have inputs on APB1
913 // TIM2,3,4,5
914 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base = {
915 .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1,
916 .TIM_ClockDivision = TIM_CKD_DIV1,
917 .TIM_CounterMode = TIM_CounterMode_Up,
918 .TIM_Period = 0xFFFF,
919 .TIM_RepetitionCounter = 0x0000,
923 // Set up timers that only have inputs on APB2
924 // TIM1,9,10,11
925 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base = {
926 .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
927 .TIM_ClockDivision = TIM_CKD_DIV1,
928 .TIM_CounterMode = TIM_CounterMode_Up,
929 .TIM_Period = 0xFFFF,
930 .TIM_RepetitionCounter = 0x0000,
934 static const struct pios_tim_clock_cfg tim_3_cfg = {
935 .timer = TIM3,
936 .time_base_init = &tim_apb1_time_base,
937 .irq = {
938 .init = {
939 .NVIC_IRQChannel = TIM3_IRQn,
940 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
941 .NVIC_IRQChannelSubPriority = 0,
942 .NVIC_IRQChannelCmd = ENABLE,
949 * Pios servo configuration structures
950 * I/O | PIN | Channel | Alternate function
951 * I1 | PB10 | TIM2_CH3 | x
952 * i2 | PB1 | TIM3_CH4 | ADC1_9
953 * I3 | PB0 | TIM3_CH3 | ADC1_8
954 * I4 | PA7 | TIM3_CH2 | SPI1_MOSI/ADC1_7
955 * I5 | PA6 | TIM3_CH1 | SPI1_MISO/ADC1_6
956 * I6 | PA5 | TIM2_CH1 | SPI1_SCK/ADC1_5
957 *------------------------------------
958 * o1 | PA10 | TIM1_CH3 | USART1_RX
959 * o2 | PB3 | TIM2_CH2 | I2C2_SDA,
960 * o3 | PB8 | TIM10_CH1
961 * o4 | PB9 | TIM11_CH1
962 * o5 | PA0 | TIM5_CH1 | ADC1_0
963 * o6 | PA1 | TIM5_CH2 | ADC1_1
965 #include <pios_servo_priv.h>
966 #include <pios_servo_config.h>
967 static const struct pios_tim_channel pios_tim_servoport_all_pins[] = {
968 // TIMER, CHANNEL, GPIO, PIN
969 TIM_SERVO_CHANNEL_CONFIG(TIM1, 3, A, 10),
970 TIM_SERVO_CHANNEL_CONFIG(TIM2, 2, B, 3),
971 TIM_SERVO_CHANNEL_CONFIG(TIM10, 1, B, 8),
972 TIM_SERVO_CHANNEL_CONFIG(TIM11, 1, B, 9),
973 TIM_SERVO_CHANNEL_CONFIG(TIM5, 1, A, 0),
974 TIM_SERVO_CHANNEL_CONFIG(TIM5, 2, A, 1),
975 // PWM pins on FlexiIO(receiver) port
977 TIM_SERVO_CHANNEL_CONFIG(TIM2, 3, B, 10),
978 TIM_SERVO_CHANNEL_CONFIG(TIM3, 4, B, 1),
979 TIM_SERVO_CHANNEL_CONFIG(TIM3, 3, B, 0),
980 TIM_SERVO_CHANNEL_CONFIG(TIM3, 2, A, 7),
981 TIM_SERVO_CHANNEL_CONFIG(TIM3, 1, A, 6),
982 TIM_SERVO_CHANNEL_CONFIG(TIM2, 1, A, 5),
984 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT 6
985 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM 11
986 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN 12
988 const struct pios_servo_cfg pios_servo_cfg_out = {
989 .tim_oc_init = {
990 .TIM_OCMode = TIM_OCMode_PWM1,
991 .TIM_OutputState = TIM_OutputState_Enable,
992 .TIM_OutputNState = TIM_OutputNState_Disable,
993 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
994 .TIM_OCPolarity = TIM_OCPolarity_High,
995 .TIM_OCNPolarity = TIM_OCPolarity_High,
996 .TIM_OCIdleState = TIM_OCIdleState_Reset,
997 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
999 .channels = pios_tim_servoport_all_pins,
1000 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT,
1002 // All servo outputs, servo input ch1 ppm, ch2-6 outputs
1003 const struct pios_servo_cfg pios_servo_cfg_out_in_ppm = {
1004 .tim_oc_init = {
1005 .TIM_OCMode = TIM_OCMode_PWM1,
1006 .TIM_OutputState = TIM_OutputState_Enable,
1007 .TIM_OutputNState = TIM_OutputNState_Disable,
1008 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1009 .TIM_OCPolarity = TIM_OCPolarity_High,
1010 .TIM_OCNPolarity = TIM_OCPolarity_High,
1011 .TIM_OCIdleState = TIM_OCIdleState_Reset,
1012 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1014 .channels = pios_tim_servoport_all_pins,
1015 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM,
1017 // All servo outputs, servo inputs ch1-6 Outputs
1018 const struct pios_servo_cfg pios_servo_cfg_out_in = {
1019 .tim_oc_init = {
1020 .TIM_OCMode = TIM_OCMode_PWM1,
1021 .TIM_OutputState = TIM_OutputState_Enable,
1022 .TIM_OutputNState = TIM_OutputNState_Disable,
1023 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1024 .TIM_OCPolarity = TIM_OCPolarity_High,
1025 .TIM_OCNPolarity = TIM_OCPolarity_High,
1026 .TIM_OCIdleState = TIM_OCIdleState_Reset,
1027 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1029 .channels = pios_tim_servoport_all_pins,
1030 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN,
1035 * PWM Inputs
1036 * TIM1, TIM8, TIM12
1038 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
1039 #include <pios_pwm_priv.h>
1040 static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = {
1041 TIM_SERVO_CHANNEL_CONFIG(TIM2, 3, B, 10),
1042 TIM_SERVO_CHANNEL_CONFIG(TIM3, 4, B, 1),
1043 TIM_SERVO_CHANNEL_CONFIG(TIM3, 3, B, 0),
1044 TIM_SERVO_CHANNEL_CONFIG(TIM3, 2, A, 7),
1045 TIM_SERVO_CHANNEL_CONFIG(TIM3, 1, A, 6),
1046 TIM_SERVO_CHANNEL_CONFIG(TIM2, 1, A, 5),
1049 const struct pios_pwm_cfg pios_pwm_cfg = {
1050 .tim_ic_init = {
1051 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1052 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1053 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1054 .TIM_ICFilter = 0x0,
1056 .channels = pios_tim_rcvrport_all_channels,
1057 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels),
1059 // this configures outputs 2-6 as pwm inputs
1060 const struct pios_pwm_cfg pios_pwm_ppm_cfg = {
1061 .tim_ic_init = {
1062 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1063 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1064 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1065 .TIM_ICFilter = 0x0,
1067 .channels = &pios_tim_rcvrport_all_channels[1],
1068 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels) - 1,
1071 #endif /* if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM) */
1074 * PPM Input
1076 #if defined(PIOS_INCLUDE_PPM)
1077 #include <pios_ppm_priv.h>
1078 static const struct pios_ppm_cfg pios_ppm_cfg = {
1079 .tim_ic_init = {
1080 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1081 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1082 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1083 .TIM_ICFilter = 0x0,
1084 .TIM_Channel = TIM_Channel_1,
1086 /* Use only the first channel for ppm */
1087 .channels = &pios_tim_rcvrport_all_channels[0],
1088 .num_channels = 1,
1091 #endif // PPM
1093 #if defined(PIOS_INCLUDE_GCSRCVR)
1094 #include "pios_gcsrcvr_priv.h"
1095 #endif /* PIOS_INCLUDE_GCSRCVR */
1097 #if defined(PIOS_INCLUDE_RCVR)
1098 #include "pios_rcvr_priv.h"
1099 #endif /* PIOS_INCLUDE_RCVR */
1101 #if defined(PIOS_INCLUDE_USB)
1102 #include "pios_usb_priv.h"
1104 static const struct pios_usb_cfg pios_usb_main_rnano_cfg = {
1105 .irq = {
1106 .init = {
1107 .NVIC_IRQChannel = OTG_FS_IRQn,
1108 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1109 .NVIC_IRQChannelSubPriority = 0,
1110 .NVIC_IRQChannelCmd = ENABLE,
1113 .vsense = {
1114 .gpio = GPIOA,
1115 .init = {
1116 .GPIO_Pin = GPIO_Pin_9,
1117 .GPIO_Speed = GPIO_Speed_25MHz,
1118 .GPIO_Mode = GPIO_Mode_IN,
1119 .GPIO_OType = GPIO_OType_OD,
1122 .vsense_active_low = false
1126 const struct pios_usb_cfg *PIOS_BOARD_HW_DEFS_GetUsbCfg(uint32_t board_revision)
1128 switch (board_revision) {
1129 default:
1130 return &pios_usb_main_rnano_cfg;
1132 break;
1134 return NULL;
1137 #include "pios_usb_board_data_priv.h"
1138 #include "pios_usb_desc_hid_cdc_priv.h"
1139 #include "pios_usb_desc_hid_only_priv.h"
1140 #include "pios_usbhook.h"
1142 #endif /* PIOS_INCLUDE_USB */
1144 #if defined(PIOS_INCLUDE_COM_MSG)
1146 #include <pios_com_msg_priv.h>
1148 #endif /* PIOS_INCLUDE_COM_MSG */
1150 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
1151 #include <pios_usb_hid_priv.h>
1153 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
1154 .data_if = 0,
1155 .data_rx_ep = 1,
1156 .data_tx_ep = 1,
1158 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
1160 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
1161 #include <pios_usb_cdc_priv.h>
1163 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
1164 .ctrl_if = 0,
1165 .ctrl_tx_ep = 2,
1167 .data_if = 1,
1168 .data_rx_ep = 3,
1169 .data_tx_ep = 3,
1172 #include <pios_usb_hid_priv.h>
1174 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
1175 .data_if = 2,
1176 .data_rx_ep = 1,
1177 .data_tx_ep = 1,
1179 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
1181 #ifdef PIOS_INCLUDE_WS2811
1182 #include <pios_ws2811_cfg.h>
1183 #include <hwsettings.h>
1184 #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
1186 void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
1187 // list of pin configurable as ws281x outputs.
1188 // this will not clash with PWM in or servo output as
1189 // pins will be reconfigured as _OUT so the alternate function is disabled.
1190 const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg[] = {
1191 [HWSETTINGS_WS2811LED_OUT_SERVOOUT1] = {
1192 .gpio = GPIOB,
1193 .gpioInit = {
1194 .GPIO_Pin = GPIO_Pin_0,
1195 .GPIO_Speed = GPIO_Speed_25MHz,
1196 .GPIO_Mode = GPIO_Mode_OUT,
1197 .GPIO_OType = GPIO_OType_PP,
1200 [HWSETTINGS_WS2811LED_OUT_SERVOOUT2] = {
1201 .gpio = GPIOB,
1202 .gpioInit = {
1203 .GPIO_Pin = GPIO_Pin_1,
1204 .GPIO_Speed = GPIO_Speed_25MHz,
1205 .GPIO_Mode = GPIO_Mode_OUT,
1206 .GPIO_OType = GPIO_OType_PP,
1209 [HWSETTINGS_WS2811LED_OUT_SERVOOUT3] = {
1210 .gpio = GPIOA,
1211 .gpioInit = {
1212 .GPIO_Pin = GPIO_Pin_3,
1213 .GPIO_Speed = GPIO_Speed_25MHz,
1214 .GPIO_Mode = GPIO_Mode_OUT,
1215 .GPIO_OType = GPIO_OType_PP,
1218 [HWSETTINGS_WS2811LED_OUT_SERVOOUT4] = {
1219 .gpio = GPIOA,
1220 .gpioInit = {
1221 .GPIO_Pin = GPIO_Pin_2,
1222 .GPIO_Speed = GPIO_Speed_25MHz,
1223 .GPIO_Mode = GPIO_Mode_OUT,
1224 .GPIO_OType = GPIO_OType_PP,
1227 [HWSETTINGS_WS2811LED_OUT_SERVOOUT5] = {
1228 .gpio = GPIOA,
1229 .gpioInit = {
1230 .GPIO_Pin = GPIO_Pin_1,
1231 .GPIO_Speed = GPIO_Speed_25MHz,
1232 .GPIO_Mode = GPIO_Mode_OUT,
1233 .GPIO_OType = GPIO_OType_PP,
1236 [HWSETTINGS_WS2811LED_OUT_SERVOOUT6] = {
1237 .gpio = GPIOA,
1238 .gpioInit = {
1239 .GPIO_Pin = GPIO_Pin_0,
1240 .GPIO_Speed = GPIO_Speed_25MHz,
1241 .GPIO_Mode = GPIO_Mode_OUT,
1242 .GPIO_OType = GPIO_OType_PP,
1245 [HWSETTINGS_WS2811LED_OUT_FLEXIPIN3] = {
1246 .gpio = GPIOB,
1247 .gpioInit = {
1248 .GPIO_Pin = GPIO_Pin_12,
1249 .GPIO_Speed = GPIO_Speed_25MHz,
1250 .GPIO_Mode = GPIO_Mode_OUT,
1251 .GPIO_OType = GPIO_OType_PP,
1254 [HWSETTINGS_WS2811LED_OUT_FLEXIPIN4] = {
1255 .gpio = GPIOB,
1256 .gpioInit = {
1257 .GPIO_Pin = GPIO_Pin_13,
1258 .GPIO_Speed = GPIO_Speed_25MHz,
1259 .GPIO_Mode = GPIO_Mode_OUT,
1260 .GPIO_OType = GPIO_OType_PP,
1265 const struct pios_ws2811_cfg pios_ws2811_cfg = {
1266 .timer = TIM1,
1267 .timerInit = {
1268 .TIM_Prescaler = PIOS_WS2811_TIM_DIVIDER - 1,
1269 .TIM_ClockDivision = TIM_CKD_DIV1,
1270 .TIM_CounterMode = TIM_CounterMode_Up,
1271 // period (1.25 uS per period
1272 .TIM_Period = PIOS_WS2811_TIM_PERIOD,
1273 .TIM_RepetitionCounter = 0x0000,
1276 .timerCh1 = 1,
1277 .streamCh1 = DMA2_Stream1,
1278 .timerCh2 = 3,
1279 .streamCh2 = DMA2_Stream6,
1280 .streamUpdate = DMA2_Stream5,
1282 // DMA streamCh1, triggered by timerCh1 pwm signal.
1283 // if FrameBuffer indicates, reset output value early to indicate "0" bit to ws2812
1284 .dmaInitCh1 = PIOS_WS2811_DMA_CH1_CONFIG(DMA_Channel_6),
1285 .dmaItCh1 = DMA_IT_TEIF1 | DMA_IT_TCIF1,
1287 // DMA streamCh2, triggered by timerCh2 pwm signal.
1288 // Reset output value late to indicate "1" bit to ws2812.
1289 .dmaInitCh2 = PIOS_WS2811_DMA_CH2_CONFIG(DMA_Channel_6),
1290 .dmaItCh2 = DMA_IT_TEIF6 | DMA_IT_TCIF6,
1292 // DMA streamUpdate Triggered by timer update event
1293 // Outputs a high logic level at beginning of a cycle
1294 .dmaInitUpdate = PIOS_WS2811_DMA_UPDATE_CONFIG(DMA_Channel_6),
1295 .dmaItUpdate = DMA_IT_TEIF5 | DMA_IT_TCIF5,
1296 .dmaSource = TIM_DMA_CC1 | TIM_DMA_CC3 | TIM_DMA_Update,
1298 // DMAInitCh1 interrupt vector, used to block timer at end of framebuffer transfer
1299 .irq = {
1300 .flags = (DMA_IT_TCIF1),
1301 .init = {
1302 .NVIC_IRQChannel = DMA2_Stream1_IRQn,
1303 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1304 .NVIC_IRQChannelSubPriority = 0,
1305 .NVIC_IRQChannelCmd = ENABLE,
1310 void PIOS_WS2811_irq_handler(void)
1312 PIOS_WS2811_DMA_irq_handler();
1314 #endif // PIOS_INCLUDE_WS2811
1317 #ifdef PIOS_INCLUDE_FLASH_OBJLIST
1318 #include <pios_flashfs_objlist.h>
1319 struct flashfs_cfg flash_main_fs_cfg = {
1320 .table_magic = 0x01020304,
1321 .obj_magic = 0x19293949,
1322 .obj_table_start = 0,
1323 .obj_table_end = 0xC000, // spaces for 192 UAVOs
1324 .sector_size = 0xFF,
1325 .chip_size = 0x10000
1327 #endif /* PIOS_INCLUDE_FLASH_OBJLIST */
1329 #ifdef PIOS_INCLUDE_FLASH_EEPROM
1330 #include <pios_flash_eeprom.h>
1331 struct pios_flash_eeprom_cfg flash_main_chip_cfg = {
1332 .page_len = 128,
1333 .total_size = 0x10000,
1335 // .i2c_address = 0x50,
1336 #endif /* PIOS_INCLUDE_FLASH_EEPROM */