1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 09:15:38 +03:00

[X12S] GPS low level driver added

This commit is contained in:
Bertrand Songis 2016-08-18 17:23:46 +02:00
parent 5d7f4ebc0b
commit 3e4f3b2a8e
5 changed files with 114 additions and 7 deletions

View file

@ -52,6 +52,7 @@ set(TARGET_SRC
board.cpp
led_driver.cpp
extmodule_driver.cpp
gps_driver.cpp
../common/arm/stm32/rtc_driver.cpp
)
set(FIRMWARE_TARGET_SRC

View file

@ -123,16 +123,18 @@ void boardInit()
AUDIO_RCC_AHB1Periph |
HAPTIC_RCC_AHB1Periph |
INTMODULE_RCC_AHB1Periph |
EXTMODULE_RCC_AHB1Periph,
EXTMODULE_RCC_AHB1Periph |
GPS_RCC_AHB1Periph,
ENABLE);
RCC_APB1PeriphClockCmd(INTERRUPT_5MS_APB1Periph |
TIMER_2MHz_APB1Periph |
RCC_APB1PeriphClockCmd(INTERRUPT_5MS_RCC_APB1Periph |
TIMER_2MHz_RCC_APB1Periph |
AUDIO_RCC_APB1Periph |
SERIAL_RCC_APB1Periph |
TELEMETRY_RCC_APB1Periph |
TRAINER_RCC_APB1Periph |
AUDIO_RCC_APB1Periph |
EXTMODULE_RCC_APB1Periph,
EXTMODULE_RCC_APB1Periph |
GPS_RCC_APB1Periph,
ENABLE);
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph |
ADC_RCC_APB2Periph |
@ -162,6 +164,8 @@ void boardInit()
// bt_open();
gpsInit();
#if defined(DEBUG)
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM4_STOP|DBGMCU_TIM5_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM7_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM9_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM11_STOP|DBGMCU_TIM12_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif

View file

@ -389,6 +389,9 @@ void hapticOff(void);
#define HAPTIC_OFF() hapticOff()
void hapticOn(uint32_t pwmPercent);
// GPS driver
void gpsInit(void);
// Second serial port driver
#define DEBUG_BAUDRATE 115200
extern uint8_t serial2Mode;
@ -414,4 +417,5 @@ extern DMAFifo<512> telemetryFifo;
extern DMAFifo<32> serial2RxFifo;
#endif
#endif // _BOARD_HORUS_H_

View file

@ -0,0 +1,83 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
void gpsInit()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// RX and TX pins
GPIO_PinAFConfig(GPIOA, GPS_TX_GPIO_PinSource, GPS_GPIO_AF);
GPIO_PinAFConfig(GPIOA, GPS_RX_GPIO_PinSource, GPS_GPIO_AF);
GPIO_InitStructure.GPIO_Pin = (GPS_TX_GPIO_PIN | GPS_RX_GPIO_PIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPS_UART_GPIO, &GPIO_InitStructure);
// UART config
USART_InitStructure.USART_BaudRate = GPS_USART_BAUDRATE;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(GPS_USART, &USART_InitStructure);
USART_Cmd(GPS_USART, ENABLE);
USART_ITConfig(GPS_USART, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = GPS_USART_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x9;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
extern "C" void GPS_USART_IRQHandler(void)
{
#if 0
// Send
if (USART_GetITStatus(GPS_USART, USART_IT_TXE) != RESET) {
uint8_t txchar;
if (gpsTxFifo.pop(txchar)) {
/* Write one byte to the transmit data register */
USART_SendData(GPS_USART, txchar);
}
else {
USART_ITConfig(GPS_USART, USART_IT_TXE, DISABLE);
}
}
#endif
// Receive
uint32_t status = GPS_USART->SR;
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
uint8_t data = GPS_USART->DR;
if (!(status & USART_FLAG_ERRORS)) {
// TODO gpsRxFifo.push(data);
}
status = GPS_USART->SR;
}
}

View file

@ -331,20 +331,21 @@
#define TRAINER_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
// 5ms Interrupt
#define INTERRUPT_5MS_APB1Periph RCC_APB1Periph_TIM14
#define INTERRUPT_5MS_RCC_APB1Periph RCC_APB1Periph_TIM14
#define INTERRUPT_5MS_TIMER TIM14
#define INTERRUPT_5MS_IRQn TIM8_TRG_COM_TIM14_IRQn
#define INTERRUPT_5MS_IRQHandler TIM8_TRG_COM_TIM14_IRQHandler
// 2MHz Timer
#define TIMER_2MHz_APB1Periph RCC_APB1Periph_TIM7
#define TIMER_2MHz_RCC_APB1Periph RCC_APB1Periph_TIM7
#define TIMER_2MHz_TIMER TIM7
// Bluetooth
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOG)
#define BT_RCC_APB1Periph RCC_APB1Periph_UART6
#define BT_USART USART6
#define BT_GPIO_AF GPIO_AF_USART6
#define BT_USART_IRQn USART6_IRQn
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOG)
#define BT_GPIO_TXRX GPIOG
#define BT_GPIO_PIN_TX GPIO_Pin_14 // PG.14
#define BT_GPIO_PIN_RX GPIO_Pin_9 // PG.09
@ -357,4 +358,18 @@
#define BT_GPIO_PinSource_TX GPIO_PinSource14
#define BT_GPIO_PinSource_RX GPIO_PinSource9
// GPS
#define GPS_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
#define GPS_RCC_APB1Periph RCC_APB1Periph_UART4
#define GPS_USART UART4
#define GPS_GPIO_AF GPIO_AF_UART4
#define GPS_USART_IRQn UART4_IRQn
#define GPS_USART_IRQHandler UART4_IRQHandler
#define GPS_UART_GPIO GPIOA
#define GPS_TX_GPIO_PIN GPIO_Pin_0 // PA.00
#define GPS_RX_GPIO_PIN GPIO_Pin_1 // PA.01
#define GPS_TX_GPIO_PinSource GPIO_PinSource0
#define GPS_RX_GPIO_PinSource GPIO_PinSource1
#define GPS_USART_BAUDRATE 9600
#endif // _HAL_H_