GPS support at runtime
This commit is contained in:
@@ -1466,7 +1466,6 @@ int cliShowJitter(const char ** argv)
|
||||
#if defined(INTERNAL_GPS)
|
||||
int cliGps(const char ** argv)
|
||||
{
|
||||
int baudrate = 0;
|
||||
|
||||
if (argv[1][0] == '$') {
|
||||
// send command to GPS
|
||||
@@ -1477,10 +1476,6 @@ int cliGps(const char ** argv)
|
||||
gpsTraceEnabled = !gpsTraceEnabled;
|
||||
}
|
||||
#endif
|
||||
else if (toInt(argv, 1, &baudrate) > 0 && baudrate > 0) {
|
||||
gpsInit(baudrate);
|
||||
cliSerialPrint("GPS baudrate set to %d", baudrate);
|
||||
}
|
||||
else {
|
||||
cliSerialPrint("%s: Invalid arguments", argv[0]);
|
||||
}
|
||||
|
||||
@@ -213,6 +213,8 @@ enum SerialPort {
|
||||
#define MAX_AUX_SERIAL (SP_AUX2 + 1)
|
||||
#define STORAGE_SERIAL_PORTS 4
|
||||
|
||||
// GPS
|
||||
#define PILOTPOS_MIN_HDOP 500
|
||||
|
||||
#define TRAINER_MODE_MIN() TRAINER_MODE_MASTER_TRAINER_JACK
|
||||
|
||||
@@ -255,6 +257,7 @@ enum UartModes {
|
||||
UART_MODE_SBUS_TRAINER,
|
||||
UART_MODE_LUA,
|
||||
UART_MODE_CLI,
|
||||
UART_MODE_GPS,
|
||||
UART_MODE_COUNT SKIP,
|
||||
UART_MODE_MAX SKIP = UART_MODE_COUNT-1
|
||||
};
|
||||
|
||||
+38
-7
@@ -320,10 +320,33 @@ void gpsNewData(uint8_t c)
|
||||
}
|
||||
}
|
||||
|
||||
static const etx_serial_driver_t* gpsSerialDrv = nullptr;
|
||||
static void* gpsSerialCtx = nullptr;
|
||||
|
||||
#if defined(DEBUG)
|
||||
uint8_t gpsTraceEnabled = false;
|
||||
#endif
|
||||
|
||||
void gpsSetSerialDriver(void* ctx, const etx_serial_driver_t* drv)
|
||||
{
|
||||
gpsSerialCtx = ctx;
|
||||
gpsSerialDrv = drv;
|
||||
}
|
||||
|
||||
void gpsWakeup()
|
||||
{
|
||||
if (!gpsSerialDrv) return;
|
||||
|
||||
auto _getByte = gpsSerialDrv->getByte;
|
||||
if (!_getByte) return;
|
||||
|
||||
uint8_t byte;
|
||||
while (gpsGetByte(&byte)) {
|
||||
while (_getByte(gpsSerialCtx, &byte)) {
|
||||
#if defined(DEBUG)
|
||||
if (gpsTraceEnabled) {
|
||||
dbgSerialPutc(byte);
|
||||
}
|
||||
#endif
|
||||
gpsNewData(byte);
|
||||
}
|
||||
}
|
||||
@@ -334,18 +357,26 @@ char hex(uint8_t b) {
|
||||
|
||||
void gpsSendFrame(const char * frame)
|
||||
{
|
||||
if (!gpsSerialDrv) return;
|
||||
|
||||
auto _sendByte = gpsSerialDrv->sendByte;
|
||||
if (!_sendByte) return;
|
||||
|
||||
// send given frame, add checksum and CRLF
|
||||
uint8_t parity = 0;
|
||||
TRACE_NOCRLF("gps> %s", frame);
|
||||
|
||||
while (*frame) {
|
||||
if (*frame != '$') parity ^= *frame;
|
||||
gpsSendByte(*frame);
|
||||
_sendByte(gpsSerialCtx, *frame);
|
||||
++frame;
|
||||
}
|
||||
gpsSendByte('*');
|
||||
gpsSendByte(hex(parity >> 4));
|
||||
gpsSendByte(hex(parity & 0x0F));
|
||||
gpsSendByte('\r');
|
||||
gpsSendByte('\n');
|
||||
|
||||
_sendByte(gpsSerialCtx, '*');
|
||||
_sendByte(gpsSerialCtx, hex(parity >> 4));
|
||||
_sendByte(gpsSerialCtx, hex(parity & 0x0F));
|
||||
_sendByte(gpsSerialCtx, '\r');
|
||||
_sendByte(gpsSerialCtx, '\n');
|
||||
|
||||
TRACE("*%02x", parity);
|
||||
}
|
||||
|
||||
@@ -39,8 +39,18 @@ struct gpsdata_t
|
||||
};
|
||||
|
||||
extern gpsdata_t gpsData;
|
||||
|
||||
#if defined(DEBUG)
|
||||
extern uint8_t gpsTraceEnabled;
|
||||
#endif
|
||||
|
||||
// Setup GPS serial port
|
||||
void gpsSetSerialDriver(void* ctx, const etx_serial_driver_t* drv);
|
||||
|
||||
// Periodic processing
|
||||
void gpsWakeup();
|
||||
|
||||
// Send a 0-terminated frame
|
||||
void gpsSendFrame(const char * frame);
|
||||
|
||||
#endif // _GPS_H_
|
||||
|
||||
@@ -34,7 +34,9 @@ TopbarImpl::TopbarImpl(Window * parent) :
|
||||
unsigned int TopbarImpl::getZonesCount() const
|
||||
{
|
||||
#if defined(INTERNAL_GPS)
|
||||
return MAX_TOPBAR_ZONES-1;
|
||||
if (hasSerialMode(UART_MODE_GPS)) {
|
||||
return MAX_TOPBAR_ZONES-1;
|
||||
}
|
||||
#endif
|
||||
return MAX_TOPBAR_ZONES;
|
||||
}
|
||||
@@ -96,13 +98,16 @@ void TopbarImpl::paint(BitmapBuffer * dc)
|
||||
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, FONT(XS) | CENTERED | COLOR_THEME_PRIMARY2);
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
if (gpsData.fix) {
|
||||
char s[10];
|
||||
sprintf(s, "%d", gpsData.numSat);
|
||||
dc->drawText(GPS_X, 4, s, FONT(XS) | CENTERED | COLOR_THEME_PRIMARY2);
|
||||
if (hasSerialMode(UART_MODE_GPS)) {
|
||||
if (gpsData.fix) {
|
||||
char s[10];
|
||||
sprintf(s, "%d", gpsData.numSat);
|
||||
dc->drawText(GPS_X, 4, s, FONT(XS) | CENTERED | COLOR_THEME_PRIMARY2);
|
||||
}
|
||||
dc->drawBitmapPattern(
|
||||
GPS_X - 10, 22, LBM_TOPMENU_GPS,
|
||||
(gpsData.fix) ? COLOR_THEME_PRIMARY2 : COLOR_THEME_PRIMARY3);
|
||||
}
|
||||
dc->drawBitmapPattern(GPS_X - 10, 22, LBM_TOPMENU_GPS,
|
||||
(gpsData.fix) ? COLOR_THEME_PRIMARY2 : COLOR_THEME_PRIMARY3);
|
||||
#endif
|
||||
|
||||
// USB icon
|
||||
|
||||
@@ -418,7 +418,7 @@ void RadioSetupPage::build(FormWindow * window)
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
// GPS
|
||||
{
|
||||
if (hasSerialMode(UART_MODE_GPS)) {
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_GPS, 0, COLOR_THEME_PRIMARY1);
|
||||
grid.nextLine();
|
||||
|
||||
|
||||
@@ -240,19 +240,21 @@ void DebugViewPage::build(FormWindow *window)
|
||||
#endif
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
new StaticText(window, grid.getLabelSlot(), STR_INT_GPS_LABEL, 0,
|
||||
COLOR_THEME_PRIMARY1);
|
||||
new DynamicText(
|
||||
window, grid.getFieldSlot(3, 0),
|
||||
[] { return std::string(gpsData.fix ? "[Fix] Yes" : "[Fix] No"); },
|
||||
COLOR_THEME_PRIMARY1);
|
||||
new DebugInfoNumber<uint8_t>(
|
||||
window, grid.getFieldSlot(3, 1), [] { return gpsData.numSat; },
|
||||
COLOR_THEME_PRIMARY1, "[Sats] ", nullptr);
|
||||
new DebugInfoNumber<uint16_t>(
|
||||
window, grid.getFieldSlot(3, 2), [] { return gpsData.hdop; },
|
||||
COLOR_THEME_PRIMARY1, "[Hdop] ", nullptr);
|
||||
grid.nextLine();
|
||||
if (hasSerialMode(UART_MODE_GPS)) {
|
||||
new StaticText(window, grid.getLabelSlot(), STR_INT_GPS_LABEL, 0,
|
||||
COLOR_THEME_PRIMARY1);
|
||||
new DynamicText(
|
||||
window, grid.getFieldSlot(3, 0),
|
||||
[] { return std::string(gpsData.fix ? "[Fix] Yes" : "[Fix] No"); },
|
||||
COLOR_THEME_PRIMARY1);
|
||||
new DebugInfoNumber<uint8_t>(
|
||||
window, grid.getFieldSlot(3, 1), [] { return gpsData.numSat; },
|
||||
COLOR_THEME_PRIMARY1, "[Sats] ", nullptr);
|
||||
new DebugInfoNumber<uint16_t>(
|
||||
window, grid.getFieldSlot(3, 2), [] { return gpsData.hdop; },
|
||||
COLOR_THEME_PRIMARY1, "[Hdop] ", nullptr);
|
||||
grid.nextLine();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Reset
|
||||
|
||||
@@ -793,6 +793,7 @@ bool isTrainerModeAvailable(int mode)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBTARANIS) || defined(AUX_SERIAL) || defined(AUX2_SERIAL)
|
||||
if (mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT) {
|
||||
#if defined(TRAINER_BATTERY_COMPARTMENT)
|
||||
return hasSerialMode(UART_MODE_SBUS_TRAINER) >= 0;
|
||||
@@ -800,6 +801,7 @@ bool isTrainerModeAvailable(int mode)
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BLUETOOTH) && !defined(PCBX9E)
|
||||
if (g_eeGeneral.bluetoothMode != BLUETOOTH_TRAINER && (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_SLAVE_BLUETOOTH))
|
||||
|
||||
@@ -179,6 +179,12 @@ static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* por
|
||||
cliSetSerialDriver(ctx, drv);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
case UART_MODE_GPS:
|
||||
gpsSetSerialDriver(ctx, drv);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -189,6 +195,7 @@ static void serialSetupPort(int mode, etx_serial_init& params, bool& power_requi
|
||||
|
||||
#if defined(DEBUG) || defined(CLI)
|
||||
case UART_MODE_DEBUG:
|
||||
case UART_MODE_CLI:
|
||||
params.baudrate = DEBUG_BAUDRATE;
|
||||
break;
|
||||
#endif
|
||||
@@ -230,6 +237,14 @@ static void serialSetupPort(int mode, etx_serial_init& params, bool& power_requi
|
||||
power_required = true;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
case UART_MODE_GPS:
|
||||
params.baudrate = GPS_USART_BAUDRATE;
|
||||
params.rx_enable = true;
|
||||
power_required = true;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,12 +92,7 @@ void aux_serial_deinit(void* ctx)
|
||||
#if defined(AUX_SERIAL)
|
||||
|
||||
Fifo<uint8_t, 512> auxSerialTxFifo;
|
||||
|
||||
#if defined(AUX_SERIAL_DMA_Stream_RX)
|
||||
AuxSerialRxFifo auxSerialRxFifo __DMA (AUX_SERIAL_DMA_Stream_RX);
|
||||
#else
|
||||
AuxSerialRxFifo auxSerialRxFifo;
|
||||
#endif
|
||||
|
||||
const LL_GPIO_InitTypeDef auxUSARTPinInit = {
|
||||
.Pin = AUX_SERIAL_GPIO_PIN_TX | AUX_SERIAL_GPIO_PIN_RX,
|
||||
@@ -117,15 +112,9 @@ const stm32_usart_t auxUSART = {
|
||||
.txDMA = nullptr,
|
||||
.txDMA_Stream = 0,
|
||||
.txDMA_Channel = 0,
|
||||
#if defined(AUX_SERIAL_DMA_Stream_RX)
|
||||
.rxDMA = AUX_SERIAL_DMA_RX,
|
||||
.rxDMA_Stream = AUX_SERIAL_DMA_Stream_RX_LL,
|
||||
.rxDMA_Channel = AUX_SERIAL_DMA_Channel_RX,
|
||||
#else
|
||||
.rxDMA = nullptr,
|
||||
.rxDMA_Stream = 0,
|
||||
.rxDMA_Channel = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
AuxSerialState auxSerialState = {
|
||||
@@ -175,7 +164,6 @@ extern "C" void AUX_SERIAL_USART_IRQHandler(void)
|
||||
#if defined(AUX2_SERIAL)
|
||||
|
||||
Fifo<uint8_t, 512> aux2SerialTxFifo;
|
||||
|
||||
AuxSerialRxFifo aux2SerialRxFifo __DMA (AUX2_SERIAL_DMA_Stream_RX);
|
||||
|
||||
const LL_GPIO_InitTypeDef aux2USARTPinInit = {
|
||||
|
||||
@@ -57,7 +57,6 @@ set(CLI ON CACHE BOOL "Enable CLI")
|
||||
|
||||
if (PCB STREQUAL X10)
|
||||
set(PCBREV "STD" CACHE STRING "PCB Revision")
|
||||
add_definitions(-DPCBX10)
|
||||
add_definitions(-DSOFTWARE_VOLUME)
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
@@ -96,14 +95,14 @@ if (PCB STREQUAL X10)
|
||||
add_definitions(-DRADIO_FAMILY_T16)
|
||||
set(DEFAULT_INTERNAL_MODULE MULTIMODULE CACHE STRING "Default internal module")
|
||||
option(BLUETOOTH "Support for bluetooth module" OFF)
|
||||
option(INTERNAL_GPS "Support for internal ublox GPS" OFF)
|
||||
option(INTERNAL_GPS "Support for internal ublox GPS" ON)
|
||||
set(HARDWARE_TOUCH YES)
|
||||
set(USB_CHARGER YES)
|
||||
set(DEFAULT_THEME "DARKBLUE")
|
||||
set(SBUS_TRAINER ON)
|
||||
set(AUX_SERIAL ON)
|
||||
add_definitions(-DMANUFACTURER_RADIOMASTER)
|
||||
if (NOT BLUETOOTH AND NOT INTERNAL_GPS)
|
||||
if (NOT BLUETOOTH)
|
||||
set(AUX2_SERIAL ON)
|
||||
endif()
|
||||
set(INTERNAL_GPS_BAUDRATE "9600" CACHE STRING "Baud rate for internal GPS")
|
||||
@@ -136,7 +135,7 @@ elseif (PCB STREQUAL X12S)
|
||||
endif()
|
||||
endif()
|
||||
set(INTERNAL_GPS_BAUDRATE "9600" CACHE STRING "Baud rate for internal GPS")
|
||||
add_definitions(-DPCBX12S)
|
||||
set(AUX2_SERIAL ON) # wire to GPS
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
audio_spi_driver.cpp
|
||||
@@ -149,6 +148,7 @@ elseif (PCB STREQUAL X12S)
|
||||
add_definitions(-DMANUFACTURER_FRSKY)
|
||||
endif()
|
||||
|
||||
add_definitions(-DPCB${PCB})
|
||||
add_definitions(-DPCBREV=${PCBREV})
|
||||
add_definitions(-DPCBREV_${PCBREV})
|
||||
|
||||
@@ -216,9 +216,8 @@ endif()
|
||||
|
||||
if(INTERNAL_GPS)
|
||||
set(SRC ${SRC} gps.cpp)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} gps_driver.cpp)
|
||||
add_definitions(-DINTERNAL_GPS)
|
||||
message("Horus: Internal GPS enabled")
|
||||
message("-- Internal GPS enabled")
|
||||
endif()
|
||||
|
||||
set(GVAR_SCREEN model_gvars.cpp)
|
||||
@@ -230,7 +229,7 @@ if(HARDWARE_TOUCH)
|
||||
endif()
|
||||
|
||||
if(USB_CHARGER)
|
||||
set(FIRMWARE_TARGET_SRC ${TARGET_SRC} usb_charger_driver.cpp)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} usb_charger_driver.cpp)
|
||||
add_definitions(-DUSB_CHARGER)
|
||||
endif()
|
||||
|
||||
@@ -351,7 +350,7 @@ if(PYTHONINTERP_FOUND)
|
||||
add_custom_command(
|
||||
OUTPUT ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
|
||||
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs_private.h -DPCBHORUS -DPCBX10 -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU -I. -Igui/colorlcd -Itargets/horus -Itargets/common/arm/stm32 -I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/libopenui/src -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/STM32F4xx_StdPeriph_Driver/inc -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Include ${gcc_include_path} -Wno-asm-operand-widths -Wno-pragma-once-outside-header ${SYSROOT_ARG} > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs_private.h -DPCBHORUS -DPCB${PCB} -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU -I. -Igui/colorlcd -Itargets/horus -Itargets/common/arm/stm32 -I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/libopenui/src -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/STM32F4xx_StdPeriph_Driver/inc -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Include ${gcc_include_path} -Wno-asm-operand-widths -Wno-pragma-once-outside-header ${SYSROOT_ARG} > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
|
||||
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py
|
||||
)
|
||||
|
||||
|
||||
@@ -117,7 +117,6 @@ void boardInit()
|
||||
INTMODULE_RCC_AHB1Periph |
|
||||
EXTMODULE_RCC_AHB1Periph |
|
||||
I2C_B1_RCC_AHB1Periph |
|
||||
GPS_RCC_AHB1Periph |
|
||||
SPORT_UPDATE_RCC_AHB1Periph |
|
||||
TOUCH_INT_RCC_AHB1Periph |
|
||||
TOUCH_RST_RCC_AHB1Periph,
|
||||
@@ -144,7 +143,6 @@ void boardInit()
|
||||
EXTMODULE_RCC_APB1Periph |
|
||||
I2C_B1_RCC_APB1Periph |
|
||||
MIXER_SCHEDULER_TIMER_RCC_APB1Periph |
|
||||
GPS_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
@@ -158,7 +156,6 @@ void boardInit()
|
||||
BT_RCC_APB2Periph |
|
||||
AUX_SERIAL_RCC_APB2Periph |
|
||||
AUX2_SERIAL_RCC_APB2Periph |
|
||||
GPS_RCC_APB2Periph |
|
||||
BACKLIGHT_RCC_APB2Periph,
|
||||
ENABLE);
|
||||
|
||||
@@ -231,9 +228,6 @@ void boardInit()
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE, true);
|
||||
#endif
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
gpsInit(GPS_USART_BAUDRATE);
|
||||
#endif
|
||||
|
||||
#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);
|
||||
|
||||
@@ -661,17 +661,6 @@ void hapticDone();
|
||||
void hapticOff();
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
|
||||
// GPS driver
|
||||
void gpsInit(uint32_t baudrate);
|
||||
uint8_t gpsGetByte(uint8_t * byte);
|
||||
#if defined(DEBUG)
|
||||
extern uint8_t gpsTraceEnabled;
|
||||
#endif
|
||||
void gpsSendByte(uint8_t byte);
|
||||
#if defined(INTERNAL_GPS)
|
||||
#define PILOTPOS_MIN_HDOP 500
|
||||
#endif
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
// BT driver
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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"
|
||||
|
||||
#if GPS_USART_BAUDRATE > 9600
|
||||
Fifo<uint8_t, 256> gpsRxFifo;
|
||||
#else
|
||||
Fifo<uint8_t, 64> gpsRxFifo;
|
||||
#endif
|
||||
|
||||
void gpsInit(uint32_t baudrate)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
// RX and TX pins
|
||||
GPIO_PinAFConfig(GPS_UART_GPIO, GPS_TX_GPIO_PinSource, GPS_GPIO_AF);
|
||||
GPIO_PinAFConfig(GPS_UART_GPIO, 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 = 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);
|
||||
|
||||
#if defined(GPS_PWR_GPIO)
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Pin = GPS_PWR_GPIO_PIN;
|
||||
GPIO_Init(GPS_PWR_GPIO, &GPIO_InitStructure);
|
||||
GPIO_SetBits(GPS_PWR_GPIO, GPS_PWR_GPIO_PIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
uint8_t gpsTraceEnabled = false;
|
||||
#endif
|
||||
|
||||
Fifo<uint8_t, 64> gpsTxFifo;
|
||||
|
||||
void gpsSendByte(uint8_t byte)
|
||||
{
|
||||
while (gpsTxFifo.isFull());
|
||||
gpsTxFifo.push(byte);
|
||||
USART_ITConfig(GPS_USART, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
|
||||
#define USART_FLAG_ERRORS \
|
||||
(USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
extern "C" void GPS_USART_IRQHandler(void)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
gpsRxFifo.push(data);
|
||||
}
|
||||
status = GPS_USART->SR;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t gpsGetByte(uint8_t * byte)
|
||||
{
|
||||
uint8_t result = gpsRxFifo.pop(*byte);
|
||||
#if defined(DEBUG)
|
||||
if (gpsTraceEnabled) {
|
||||
serialPutc(*byte);
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
@@ -442,6 +442,25 @@
|
||||
#endif
|
||||
|
||||
#if defined(AUX2_SERIAL)
|
||||
#if defined(PCBX12S)
|
||||
#define AUX2_SERIAL_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
|
||||
#define AUX2_SERIAL_RCC_APB1Periph RCC_APB1Periph_UART4
|
||||
#define AUX2_SERIAL_RCC_APB2Periph 0
|
||||
#define AUX2_SERIAL_USART UART4
|
||||
#define AUX2_SERIAL_GPIO_AF GPIO_AF_UART4
|
||||
#define AUX2_SERIAL_GPIO_AF_LL LL_GPIO_AF_8
|
||||
#define AUX2_SERIAL_USART_IRQn UART4_IRQn
|
||||
#define AUX2_SERIAL_USART_IRQHandler UART4_IRQHandler
|
||||
#define AUX2_SERIAL_GPIO GPIOA
|
||||
#define AUX2_SERIAL_GPIO_PIN_TX GPIO_Pin_0 // PA.00
|
||||
#define AUX2_SERIAL_GPIO_PIN_RX GPIO_Pin_1 // PA.01
|
||||
#define AUX2_SERIAL_GPIO_TX_PinSource GPIO_PinSource0
|
||||
#define AUX2_SERIAL_GPIO_RX_PinSource GPIO_PinSource1
|
||||
#define AUX2_SERIAL_DMA_RX DMA1
|
||||
#define AUX2_SERIAL_DMA_Stream_RX DMA1_Stream2
|
||||
#define AUX2_SERIAL_DMA_Channel_RX DMA_Channel_4
|
||||
#define AUX2_SERIAL_DMA_Stream_RX_LL LL_DMA_STREAM_2
|
||||
#else
|
||||
#define AUX2_SERIAL_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_DMA2)
|
||||
#define AUX2_SERIAL_RCC_APB1Periph 0
|
||||
#define AUX2_SERIAL_RCC_APB2Periph RCC_APB2Periph_USART6
|
||||
@@ -449,40 +468,23 @@
|
||||
#define AUX2_SERIAL_GPIO_AF GPIO_AF_USART6
|
||||
#define AUX2_SERIAL_GPIO_AF_LL LL_GPIO_AF_8
|
||||
#define AUX2_SERIAL_USART_IRQn USART6_IRQn
|
||||
#define AUX2_SERIAL_USART_IRQHandler USART6_IRQHandler
|
||||
#define AUX2_SERIAL_GPIO GPIOG
|
||||
#define AUX2_SERIAL_GPIO_PIN_TX GPIO_Pin_14 // PG.14
|
||||
#define AUX2_SERIAL_GPIO_PIN_RX GPIO_Pin_9 // PG.09
|
||||
#define AUX2_SERIAL_GPIO_PinSource_TX GPIO_PinSource14
|
||||
#define AUX2_SERIAL_GPIO_PinSource_RX GPIO_PinSource9
|
||||
#define AUX2_SERIAL_USART_IRQHandler USART6_IRQHandler
|
||||
#define AUX2_SERIAL_DMA_RX DMA2
|
||||
#define AUX2_SERIAL_DMA_Stream_RX DMA2_Stream1 // or DMA2_Stream2
|
||||
#define AUX2_SERIAL_DMA_Channel_RX DMA_Channel_5
|
||||
#define AUX2_SERIAL_DMA_Stream_RX_LL LL_DMA_STREAM_1
|
||||
#define AUX2_SERIAL_PWR_GPIO GPIOB
|
||||
#define AUX2_SERIAL_PWR_GPIO_PIN GPIO_Pin_0 // PB.00
|
||||
#endif
|
||||
#if defined(RADIO_TX16S)
|
||||
#define TRAINER_BATTERY_COMPARTMENT // allows serial port TTL trainer
|
||||
#endif
|
||||
#elif defined(RADIO_TX16S) && defined(INTERNAL_GPS)
|
||||
#define GPS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOG)
|
||||
#define GPS_RCC_APB1Periph 0
|
||||
#define GPS_RCC_APB2Periph RCC_APB2Periph_USART6
|
||||
#define GPS_USART USART6
|
||||
#define GPS_GPIO_AF GPIO_AF_USART6
|
||||
#define GPS_USART_IRQn USART6_IRQn
|
||||
#define GPS_USART_IRQHandler USART6_IRQHandler
|
||||
#define GPS_UART_GPIO GPIOG
|
||||
#define GPS_TX_GPIO_PIN GPIO_Pin_14 // PG.14
|
||||
#define GPS_RX_GPIO_PIN GPIO_Pin_9 // PG.09
|
||||
#define GPS_TX_GPIO_PinSource GPIO_PinSource14
|
||||
#define GPS_RX_GPIO_PinSource GPIO_PinSource9
|
||||
#define GPS_PWR_GPIO GPIOB
|
||||
#define GPS_PWR_GPIO_PIN GPIO_Pin_0 // PB.00
|
||||
#define AUX2_SERIAL_RCC_AHB1Periph 0
|
||||
#define AUX2_SERIAL_RCC_APB1Periph 0
|
||||
#define AUX2_SERIAL_RCC_APB2Periph 0
|
||||
#else
|
||||
#else // AUX2_SERIAL
|
||||
#define AUX2_SERIAL_RCC_AHB1Periph 0
|
||||
#define AUX2_SERIAL_RCC_APB1Periph 0
|
||||
#define AUX2_SERIAL_RCC_APB2Periph 0
|
||||
@@ -960,10 +962,6 @@
|
||||
#define TRAINER_GPIO_AF GPIO_AF_TIM3
|
||||
#define TRAINER_DMA DMA1
|
||||
#define TRAINER_DMA_CHANNEL DMA_Channel_5
|
||||
#define TRAINER_DMA_STREAM DMA1_Stream2
|
||||
#define TRAINER_DMA_IRQn DMA1_Stream2_IRQn
|
||||
#define TRAINER_DMA_IRQHandler DMA1_Stream2_IRQHandler
|
||||
#define TRAINER_DMA_FLAG_TC DMA_IT_TCIF2
|
||||
#define TRAINER_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)
|
||||
|
||||
// Xms Interrupt
|
||||
@@ -1019,24 +1017,4 @@
|
||||
#define BT_EN_GPIO_PIN GPIO_Pin_10 // PG.10
|
||||
#endif
|
||||
|
||||
// GPS
|
||||
#if defined(PCBX12S)
|
||||
#define GPS_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
|
||||
#define GPS_RCC_APB1Periph RCC_APB1Periph_UART4
|
||||
#define GPS_RCC_APB2Periph 0
|
||||
#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
|
||||
#elif !defined(INTERNAL_GPS)
|
||||
#define GPS_RCC_AHB1Periph 0
|
||||
#define GPS_RCC_APB1Periph 0
|
||||
#define GPS_RCC_APB2Periph 0
|
||||
#endif
|
||||
|
||||
#endif // _HAL_H_
|
||||
|
||||
@@ -21,7 +21,6 @@ set(SIMU_SRC
|
||||
backlight_driver.cpp
|
||||
gyro_driver.cpp
|
||||
bt_driver.cpp
|
||||
gps_driver.cpp
|
||||
)
|
||||
|
||||
if(SIMU_DISKIO)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void gpsGetByte(unsigned char*) {}
|
||||
void gpsSendByte(unsigned char) {}
|
||||
@@ -66,7 +66,6 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
|
||||
../targets/simu/backlight_driver.cpp
|
||||
../targets/simu/gyro_driver.cpp
|
||||
../targets/simu/bt_driver.cpp
|
||||
../targets/simu/gps_driver.cpp
|
||||
)
|
||||
add_dependencies(gtests-radio ${RADIO_DEPENDENCIES} ${FIRMWARE_DEPENDENCIES} gtests-radio-lib)
|
||||
if(PCB STREQUAL X12S OR PCB STREQUAL X10)
|
||||
|
||||
@@ -63,9 +63,9 @@
|
||||
|
||||
#define LEN_AUX_SERIAL_MODES "\015"
|
||||
#if defined(CLI) || defined(DEBUG)
|
||||
#define TR_AUX_SERIAL_MODES "Debug\0 ""Telem Mirror\0""Telemetry In\0""SBUS Trainer\0""LUA\0 ""CLI\0 "
|
||||
#define TR_AUX_SERIAL_MODES "Debug\0 ""Telem Mirror\0""Telemetry In\0""SBUS Trainer\0""LUA\0 ""CLI\0 ""GPS\0 "
|
||||
#else
|
||||
#define TR_AUX_SERIAL_MODES "OFF\0 ""Telem Mirror\0""Telemetry In\0""SBUS Trainer\0""LUA\0 ""CLI\0 "
|
||||
#define TR_AUX_SERIAL_MODES "OFF\0 ""Telem Mirror\0""Telemetry In\0""SBUS Trainer\0""LUA\0 ""CLI\0 ""GPS\0 "
|
||||
#endif
|
||||
|
||||
#define LEN_SWTYPES "\006"
|
||||
|
||||
Reference in New Issue
Block a user