Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / targets / boards / gpsplatinum / board_hw_defs.c
blob95f43d2f0d72f057cf78a03962ae71e036ee0eba
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 GPS 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
27 #define BOARD_REVISION_GPSP 1
29 * GPS Platinum board.
30 * pins allocation:
31 * port | Pins
32 * -------------|-------------
33 * GPS I2C | PB7 SDA
34 * | PB6 SCL
35 * ---------------------------
36 * Led HB | PB4
37 * ---------------------------
38 * Mag/Flash SPI| PA4 MAG SS
39 * | PA5 SCK
40 * | PA6 MISO
41 * | PA7 MOSI
42 * | PB1 FLASH SS
43 * | PB0 Mag Int
44 *----------------------------
45 * Main Port | PA9 TX
46 * | PA10 RX
47 *----------------------------
49 #if defined(PIOS_INCLUDE_LED)
51 #include <pios_led_priv.h>
53 static const struct pios_gpio pios_leds_gpsp[] = {
54 // PB4
55 [PIOS_LED_HEARTBEAT] = {
56 .pin = {
57 .gpio = GPIOB,
58 .init = {
59 .GPIO_Pin = GPIO_Pin_4,
60 .GPIO_Mode = GPIO_Mode_OUT,
61 .GPIO_OType = GPIO_OType_OD,
62 .GPIO_Speed = GPIO_Speed_Level_1,
65 .active_low = true
69 static const struct pios_gpio_cfg pios_led_cfg_gpsp = {
70 .gpios = pios_leds_gpsp,
71 .num_gpios = NELEMENTS(pios_leds_gpsp),
74 const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision)
76 return &pios_led_cfg_gpsp;
79 #endif /* PIOS_INCLUDE_LED */
81 #if defined(PIOS_INCLUDE_SPI)
83 #include <pios_spi_priv.h>
85 void PIOS_SPI_mag_flash_irq_handler(void);
86 void DMA1_Channel2_3_IRQHandler() __attribute__((alias("PIOS_SPI_mag_flash_irq_handler")));
89 static uint32_t pios_spi_mag_flash_id;
90 static const struct pios_spi_cfg pios_spi_mag_flash_cfg = {
91 .remap = GPIO_AF_0,
92 .regs = SPI1,
93 .init = {
94 .SPI_Mode = SPI_Mode_Master,
95 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
96 .SPI_DataSize = SPI_DataSize_8b,
97 .SPI_NSS = SPI_NSS_Soft,
98 .SPI_FirstBit = SPI_FirstBit_MSB,
99 .SPI_CRCPolynomial = 7,
100 .SPI_CPOL = SPI_CPOL_High,
101 .SPI_CPHA = SPI_CPHA_2Edge,
102 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
104 .dma = {
105 .ahb_clk = RCC_AHBPeriph_DMA1,
107 .irq = {
108 .flags = (DMA1_FLAG_TC2 | DMA1_FLAG_TE2 | DMA1_FLAG_HT2 | DMA1_FLAG_GL2),
109 .init = {
110 .NVIC_IRQChannel = DMA1_Channel2_3_IRQn,
111 .NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_MID,
112 .NVIC_IRQChannelCmd = ENABLE,
116 .rx = {
117 .channel = DMA1_Channel2,
118 .init = {
119 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
120 .DMA_DIR = DMA_DIR_PeripheralSRC,
121 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
122 .DMA_MemoryInc = DMA_MemoryInc_Enable,
123 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
124 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
125 .DMA_Mode = DMA_Mode_Normal,
126 .DMA_Priority = DMA_Priority_Medium,
127 .DMA_M2M = DMA_M2M_Disable,
130 .tx = {
131 .channel = DMA1_Channel3,
132 .init = {
133 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
134 .DMA_DIR = DMA_DIR_PeripheralDST,
135 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
136 .DMA_MemoryInc = DMA_MemoryInc_Enable,
137 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
138 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
139 .DMA_Mode = DMA_Mode_Normal,
140 .DMA_Priority = DMA_Priority_Medium,
141 .DMA_M2M = DMA_M2M_Disable,
145 .use_crc = false,
146 .sclk = {
147 .gpio = GPIOA,
148 .init = {
149 .GPIO_Pin = GPIO_Pin_5,
150 .GPIO_Speed = GPIO_Speed_10MHz,
151 .GPIO_Mode = GPIO_Mode_AF,
152 .GPIO_OType = GPIO_OType_PP,
155 .miso = {
156 .gpio = GPIOA,
157 .init = {
158 .GPIO_Pin = GPIO_Pin_6,
159 .GPIO_Speed = GPIO_Speed_10MHz,
160 .GPIO_Mode = GPIO_Mode_AF,
161 .GPIO_OType = GPIO_OType_OD,
164 .mosi = {
165 .gpio = GPIOA,
166 .init = {
167 .GPIO_Pin = GPIO_Pin_7,
168 .GPIO_Speed = GPIO_Speed_10MHz,
169 .GPIO_Mode = GPIO_Mode_AF,
170 .GPIO_OType = GPIO_OType_PP,
173 .slave_count = 2,
174 .ssel = {
176 .gpio = GPIOA,
177 .init = {
178 .GPIO_Pin = GPIO_Pin_4,
179 .GPIO_Speed = GPIO_Speed_10MHz,
180 .GPIO_Mode = GPIO_Mode_OUT,
181 .GPIO_OType = GPIO_OType_PP,
185 .gpio = GPIOB,
186 .init = {
187 .GPIO_Pin = GPIO_Pin_1,
188 .GPIO_Speed = GPIO_Speed_10MHz,
189 .GPIO_Mode = GPIO_Mode_OUT,
190 .GPIO_OType = GPIO_OType_PP,
196 void PIOS_SPI_mag_flash_irq_handler(void)
198 /* Call into the generic code to handle the IRQ for this specific device */
199 PIOS_SPI_IRQ_Handler(pios_spi_mag_flash_id);
202 #ifdef PIOS_INCLUDE_FLASH
203 #include "pios_flash_jedec_priv.h"
204 #include "pios_flash.h"
205 #endif /* PIOS_INCLUDE_FLASH */
207 #if defined(PIOS_INCLUDE_HMC5X83)
208 #include "pios_hmc5x83.h"
209 pios_hmc5x83_dev_t onboard_mag;
211 #ifdef PIOS_HMC5X83_HAS_GPIOS
212 bool pios_board_mag_handler()
214 return PIOS_HMC5x83_IRQHandler(onboard_mag);
216 static const struct pios_exti_cfg pios_exti_mag_cfg __exti_config = {
217 .vector = pios_board_mag_handler,
218 .line = EXTI_Line0,
219 .pin = {
220 .gpio = GPIOB,
221 .init = {
222 .GPIO_Pin = GPIO_Pin_0,
223 .GPIO_Speed = GPIO_Speed_Level_3,
224 .GPIO_Mode = GPIO_Mode_IN,
225 .GPIO_OType = GPIO_OType_OD,
226 .GPIO_PuPd = GPIO_PuPd_NOPULL,
229 .irq = {
230 .init = {
231 .NVIC_IRQChannel = EXTI0_1_IRQn,
232 .NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_LOW,
233 .NVIC_IRQChannelCmd = ENABLE,
236 .exti = {
237 .init = {
238 .EXTI_Line = EXTI_Line0, // matches above GPIO pin
239 .EXTI_Mode = EXTI_Mode_Interrupt,
240 .EXTI_Trigger = EXTI_Trigger_Rising,
241 .EXTI_LineCmd = ENABLE,
245 #endif /* ifdef PIOS_HMC5X83_HAS_GPIOS */
247 static const struct pios_hmc5x83_cfg pios_mag_cfg = {
248 #ifdef PIOS_HMC5X83_HAS_GPIOS
249 .exti_cfg = &pios_exti_mag_cfg,
250 #endif
251 .M_ODR = PIOS_HMC5x83_ODR_30,
252 .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL,
253 .Gain = PIOS_HMC5x83_GAIN_1_3,
254 .Mode = PIOS_HMC5x83_MODE_CONTINUOUS,
255 .Driver = &PIOS_HMC5x83_SPI_DRIVER,
256 .TempCompensation = true,
257 .Orientation = PIOS_HMC5X83_ORIENTATION_WEST_NORTH_DOWN,
259 #endif /* PIOS_INCLUDE_HMC5883 */
262 #endif /* PIOS_INCLUDE_SPI */
264 #if defined(PIOS_INCLUDE_USART)
266 #include "pios_usart_priv.h"
268 static const struct pios_usart_cfg pios_usart_generic_main_cfg = {
269 .regs = USART1,
270 .remap = GPIO_AF_1,
271 .rx = {
272 .gpio = GPIOA,
273 .init = {
274 .GPIO_Pin = GPIO_Pin_10,
275 .GPIO_Speed = GPIO_Speed_2MHz,
276 .GPIO_OType = GPIO_OType_OD,
277 .GPIO_Mode = GPIO_Mode_AF,
280 .tx = {
281 .gpio = GPIOA,
282 .init = {
283 .GPIO_Pin = GPIO_Pin_9,
284 .GPIO_Speed = GPIO_Speed_2MHz,
285 .GPIO_OType = GPIO_OType_PP,
286 .GPIO_Mode = GPIO_Mode_AF,
291 #endif /* PIOS_INCLUDE_USART */
293 #if defined(PIOS_INCLUDE_COM)
295 #include "pios_com_priv.h"
297 #endif /* PIOS_INCLUDE_COM */
299 #if defined(PIOS_INCLUDE_RTC)
301 * Realtime Clock (RTC)
303 #include <pios_rtc_priv.h>
305 void PIOS_RTC_IRQ_Handler(void);
306 void RTC_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
307 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
308 .clksrc = RCC_RTCCLKSource_LSI,
309 .prescaler = 100,
310 .irq = {
311 .init = {
312 .NVIC_IRQChannel = RTC_IRQn,
313 .NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_MID,
314 .NVIC_IRQChannelCmd = ENABLE,
319 void PIOS_RTC_IRQ_Handler(void)
321 PIOS_RTC_irq_handler();
324 #endif /* if defined(PIOS_INCLUDE_RTC) */
326 #if defined(PIOS_INCLUDE_I2C)
328 #include <pios_i2c_priv.h>
331 * I2C Adapters
334 void PIOS_I2C_gps_irq_handler(void);
335 void I2C1_IRQHandler() __attribute__((alias("PIOS_I2C_gps_irq_handler")));
337 static const struct pios_i2c_adapter_cfg pios_i2c_gps_cfg = {
338 .remapSDA = GPIO_AF_1,
339 .remapSCL = GPIO_AF_1,
340 .regs = I2C1,
341 .init = {
342 .I2C_Mode = I2C_Mode_I2C,
343 .I2C_AnalogFilter = I2C_AnalogFilter_Enable,
344 .I2C_DigitalFilter = 0x00,
345 .I2C_OwnAddress1 = 0x00,
346 .I2C_Ack = I2C_Ack_Enable,
347 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
348 .I2C_Timing = (uint32_t)0x00210507,
350 .transfer_timeout_ms = 50,
351 .scl = {
352 .gpio = GPIOB,
353 .init = {
354 .GPIO_Pin = GPIO_Pin_6,
355 .GPIO_Speed = GPIO_Speed_2MHz,
356 .GPIO_OType = GPIO_OType_OD,
357 .GPIO_PuPd = GPIO_PuPd_NOPULL,
358 .GPIO_Mode = GPIO_Mode_AF,
360 .pin_source = GPIO_PinSource6,
362 .sda = {
363 .gpio = GPIOB,
364 .init = {
365 .GPIO_Pin = GPIO_Pin_7,
366 .GPIO_Speed = GPIO_Speed_2MHz,
367 .GPIO_OType = GPIO_OType_OD,
368 .GPIO_PuPd = GPIO_PuPd_NOPULL,
369 .GPIO_Mode = GPIO_Mode_AF,
371 .pin_source = GPIO_PinSource7,
373 .event = {
374 .flags = 0,
375 .init = {
376 .NVIC_IRQChannel = I2C1_IRQn,
377 .NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_HIGH,
378 .NVIC_IRQChannelCmd = ENABLE,
381 .error = {
382 .flags = 0,
383 .init = {
384 .NVIC_IRQChannel = I2C1_IRQn,
385 .NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_HIGH,
386 .NVIC_IRQChannelCmd = ENABLE,
391 uint32_t pios_i2c_gps_id;
392 void PIOS_I2C_gps_irq_handler(void)
394 /* Call into the generic code to handle the IRQ for this specific device */
395 PIOS_I2C_IRQ_Handler(pios_i2c_gps_id);
399 #endif /* PIOS_INCLUDE_I2C */
401 #if defined(PIOS_INCLUDE_COM_MSG)
403 #include <pios_com_msg_priv.h>
405 #endif /* PIOS_INCLUDE_COM_MSG */