Bsongis/x7 bluetooth (#5068)

* Trainer Bluetooth support added
X7S board added (X7 has no bluetooth while X7S has)
X10 HAL updated

* Bluetooth Telemetry

* En fix
Add all languages

* Temporary test for @bsongis

* Missing translations
This commit is contained in:
Bertrand Songis
2017-08-12 00:49:54 +02:00
committed by GitHub
parent 51be7b000e
commit 8d8fef23c9
51 changed files with 972 additions and 636 deletions
@@ -23,14 +23,6 @@
Fifo<uint8_t, 64> btTxFifo;
Fifo<uint8_t, 64> btRxFifo;
enum BluetoothState
{
BLUETOOTH_INIT,
BLUETOOTH_WAIT_TTM,
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
BLUETOOTH_OK,
};
enum BluetoothWriteState
{
BLUETOOTH_WRITE_IDLE,
@@ -39,7 +31,6 @@ enum BluetoothWriteState
BLUETOOTH_WRITE_DONE
};
volatile uint8_t bluetoothState = BLUETOOTH_INIT;
volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
void bluetoothInit(uint32_t baudrate)
@@ -49,9 +40,6 @@ void bluetoothInit(uint32_t baudrate)
USART_DeInit(BT_USART);
RCC_AHB1PeriphClockCmd(BT_RCC_AHB1Periph, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
GPIO_InitStructure.GPIO_Pin = BT_EN_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
@@ -106,7 +94,7 @@ void bluetoothDone()
GPIO_SetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // close bluetooth
}
extern "C" void USART6_IRQHandler(void)
extern "C" void BT_USART_IRQHandler(void)
{
DEBUG_INTERRUPT(INT_BLUETOOTH);
if (USART_GetITStatus(BT_USART, USART_IT_RXNE) != RESET) {
@@ -128,21 +116,6 @@ extern "C" void USART6_IRQHandler(void)
}
}
void bluetoothWrite(const void * buffer, int len)
{
uint8_t * data = (uint8_t *)buffer;
for (int i=0; i<len; ++i) {
btTxFifo.push(data[i]);
}
}
void bluetoothWriteString(const char * str)
{
while (*str != 0) {
btTxFifo.push(*str++);
}
}
void bluetoothWriteWakeup(void)
{
if (bluetoothWriteState == BLUETOOTH_WRITE_IDLE) {
@@ -164,86 +137,3 @@ void bluetoothWriteWakeup(void)
#endif
}
}
void bluetoothWakeup(void)
{
if (!g_eeGeneral.bluetoothEnable) {
if (bluetoothState != BLUETOOTH_INIT) {
bluetoothDone();
bluetoothState = BLUETOOTH_INIT;
}
}
else {
if (bluetoothState != BLUETOOTH_OK) {
static tmr10ms_t waitEnd = 0;
if (bluetoothState == BLUETOOTH_INIT) {
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
const char btMessage[] = "TTM:REN-";
bluetoothWriteString(btMessage);
uint8_t len = ZLEN(g_eeGeneral.bluetoothName);
for (int i=0; i<len; i++) {
btTxFifo.push(idx2char(g_eeGeneral.bluetoothName[i]));
}
bluetoothState = BLUETOOTH_WAIT_TTM;
waitEnd = get_tmr10ms() + 25; // 250ms
}
else if (bluetoothState == BLUETOOTH_WAIT_TTM) {
if (get_tmr10ms() > waitEnd) {
char ttm[] = "TTM:REN";
int index = 0;
uint8_t c;
bool found = false;
while (btRxFifo.pop(c)) {
if (c == ttm[index]) {
index++;
if (index == sizeof(ttm)-1) {
found = true;
break;
}
}
else {
index = 0;
}
}
if (found) {
bluetoothState = BLUETOOTH_OK;
}
else {
bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE);
const char btMessage[] = "TTM:BPS-115200";
bluetoothWriteString(btMessage);
bluetoothState = BLUETOOTH_WAIT_BAUDRATE_CHANGE;
waitEnd = get_tmr10ms() + 250; // 2.5s
}
}
}
else if (bluetoothState == BLUETOOTH_WAIT_BAUDRATE_CHANGE) {
if (get_tmr10ms() > waitEnd) {
bluetoothState = BLUETOOTH_INIT;
}
}
}
bluetoothWriteWakeup();
}
}
uint8_t bluetoothReady()
{
return (bluetoothState == BLUETOOTH_OK);
}
int bluetoothRead(void * buffer, int len)
{
int result = 0;
uint8_t * data = (uint8_t *)buffer;
while (result < len) {
uint8_t byte;
if (!btRxFifo.pop(byte)) {
break;
}
data[result++] = byte;
}
return result;
}
+13 -12
View File
@@ -1,5 +1,4 @@
option(DISK_CACHE "Enable SD card disk cache" YES)
option(BLUETOOTH_CLI_PASSTHROUGH "Enable direct communicaton with Bluetooth module from CLI" NO)
option(UNEXPECTED_SHUTDOWN "Enable the Unexpected Shutdown screen" YES)
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
@@ -103,14 +102,19 @@ if(INTERNAL_GPS)
add_definitions(-DINTERNAL_GPS)
message("Horus: Internal GPS enabled")
endif()
set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
set(GVAR_SCREEN model_gvars.cpp)
set(TARGET_SRC
${TARGET_SRC}
board.cpp
led_driver.cpp
extmodule_driver.cpp
../common/arm/stm32/bluetooth_driver.cpp
)
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
sdio_sd.c
@@ -120,17 +124,14 @@ set(FIRMWARE_TARGET_SRC
sdram_driver.c
startup_stm32f42_43xxx.s
)
if(PCB STREQUAL X12S)
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
bluetooth_driver.cpp
)
add_definitions(-DBLUETOOTH)
endif()
if(BLUETOOTH_CLI_PASSTHROUGH)
add_definitions(-DBLUETOOTH_CLI_PASSTHROUGH)
message("Horus: Bluetooth pass-trough enabled")
endif()
add_definitions(-DBLUETOOTH)
set(SRC
${SRC}
bluetooth.cpp
)
set(STM32LIB_SRC
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_sdio.c
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c
@@ -1,261 +0,0 @@
/*
* 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"
Fifo<uint8_t, 64> btTxFifo;
Fifo<uint8_t, 64> btRxFifo;
enum BluetoothState
{
BLUETOOTH_INIT,
BLUETOOTH_WAIT_TTM,
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
BLUETOOTH_OK,
};
enum BluetoothWriteState
{
BLUETOOTH_WRITE_IDLE,
BLUETOOTH_WRITE_INIT,
BLUETOOTH_WRITING,
BLUETOOTH_WRITE_DONE
};
volatile uint8_t bluetoothState = BLUETOOTH_INIT;
volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
void bluetoothInit(uint32_t baudrate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_DeInit(BT_USART);
RCC_AHB1PeriphClockCmd(BT_RCC_AHB1Periph, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
GPIO_InitStructure.GPIO_Pin = BT_EN_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(BT_EN_GPIO, &GPIO_InitStructure);
#if defined(BT_BRTS_GPIO_PIN)
GPIO_InitStructure.GPIO_Pin = BT_BRTS_GPIO_PIN;
GPIO_Init(BT_BRTS_GPIO, &GPIO_InitStructure);
GPIO_SetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN);
#endif
#if defined(BT_BCTS_GPIO_PIN)
GPIO_InitStructure.GPIO_Pin = BT_BCTS_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(BT_BCTS_GPIO, &GPIO_InitStructure);
#endif
GPIO_InitStructure.GPIO_Pin = BT_TX_GPIO_PIN|BT_RX_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(BT_GPIO_TXRX, &GPIO_InitStructure);
GPIO_PinAFConfig(BT_GPIO_TXRX, BT_TX_GPIO_PinSource, BT_GPIO_AF);
GPIO_PinAFConfig(BT_GPIO_TXRX, BT_RX_GPIO_PinSource, BT_GPIO_AF);
USART_DeInit(BT_USART);
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(BT_USART, &USART_InitStructure);
USART_Cmd(BT_USART, ENABLE);
USART_ITConfig(BT_USART, USART_IT_RXNE, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = BT_USART_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_ResetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // open bluetooth
}
void bluetoothDone()
{
GPIO_SetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // close bluetooth
}
extern "C" void USART6_IRQHandler(void)
{
DEBUG_INTERRUPT(INT_BLUETOOTH);
if (USART_GetITStatus(BT_USART, USART_IT_RXNE) != RESET) {
USART_ClearITPendingBit(BT_USART, USART_IT_RXNE);
uint8_t byte = USART_ReceiveData(BT_USART);
btRxFifo.push(byte);
}
if (USART_GetITStatus(BT_USART, USART_IT_TXE) != RESET) {
uint8_t byte;
bool result = btTxFifo.pop(byte);
if (result) {
USART_SendData(BT_USART, byte);
}
else {
USART_ITConfig(BT_USART, USART_IT_TXE, DISABLE);
bluetoothWriteState = BLUETOOTH_WRITE_DONE;
}
}
}
void bluetoothWrite(const void * buffer, int len)
{
uint8_t * data = (uint8_t *)buffer;
for (int i=0; i<len; ++i) {
btTxFifo.push(data[i]);
}
}
void bluetoothWriteString(const char * str)
{
while (*str != 0) {
btTxFifo.push(*str++);
}
}
void bluetoothWriteWakeup(void)
{
if (bluetoothWriteState == BLUETOOTH_WRITE_IDLE) {
if (!btTxFifo.isEmpty()) {
bluetoothWriteState = BLUETOOTH_WRITE_INIT;
#if defined(BT_BRTS_GPIO_PIN)
GPIO_ResetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN);
#endif
}
}
else if (bluetoothWriteState == BLUETOOTH_WRITE_INIT) {
bluetoothWriteState = BLUETOOTH_WRITING;
USART_ITConfig(BT_USART, USART_IT_TXE, ENABLE);
}
else if (bluetoothWriteState == BLUETOOTH_WRITE_DONE) {
bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
#if defined(BT_BRTS_GPIO_PIN)
GPIO_SetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN);
#endif
}
}
void bluetoothWakeup(void)
{
#if defined(BLUETOOTH_CLI_PASSTHROUGH)
bluetoothWriteWakeup();
return;
#else // #if defined(BLUETOOTH_CLI_PASSTHROUGH)
// NOTICE: code below doesn't work on Horus beta!
if (!g_eeGeneral.bluetoothEnable) {
if (bluetoothState != BLUETOOTH_INIT) {
bluetoothDone();
bluetoothState = BLUETOOTH_INIT;
}
}
else {
if (bluetoothState != BLUETOOTH_OK) {
static tmr10ms_t waitEnd = 0;
if (bluetoothState == BLUETOOTH_INIT) {
TRACE("BLUETOOTH_INIT");
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
const char btMessage[] = "TTM:REN-";
bluetoothWriteString(btMessage);
uint8_t len = ZLEN(g_eeGeneral.bluetoothName);
for (int i=0; i<len; i++) {
btTxFifo.push(idx2char(g_eeGeneral.bluetoothName[i]));
}
bluetoothState = BLUETOOTH_WAIT_TTM;
waitEnd = get_tmr10ms() + 25; // 250ms
}
else if (bluetoothState == BLUETOOTH_WAIT_TTM) {
if (get_tmr10ms() > waitEnd) {
TRACE("bt rename");
char ttm[] = "TTM:REN";
int index = 0;
uint8_t c;
bool found = false;
while (btRxFifo.pop(c)) {
if (c == ttm[index]) {
index++;
if (index == sizeof(ttm)-1) {
found = true;
break;
}
}
else {
index = 0;
}
}
if (found) {
TRACE("bt OK");
bluetoothState = BLUETOOTH_OK;
}
else {
TRACE("bt failure");
bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE);
const char btMessage[] = "TTM:BPS-115200";
bluetoothWriteString(btMessage);
bluetoothState = BLUETOOTH_WAIT_BAUDRATE_CHANGE;
waitEnd = get_tmr10ms() + 250; // 2.5s
}
}
}
else if (bluetoothState == BLUETOOTH_WAIT_BAUDRATE_CHANGE) {
if (get_tmr10ms() > waitEnd) {
bluetoothState = BLUETOOTH_INIT;
}
}
}
bluetoothWriteWakeup();
}
#endif // #if defined(BLUETOOTH_CLI_PASSTHROUGH)
}
uint8_t bluetoothReady()
{
return (bluetoothState == BLUETOOTH_OK);
}
int bluetoothRead(void * buffer, int len)
{
int result = 0;
uint8_t * data = (uint8_t *)buffer;
while (result < len) {
uint8_t byte;
if (!btRxFifo.pop(byte)) {
break;
}
data[result++] = byte;
}
return result;
}
+4 -2
View File
@@ -119,6 +119,7 @@ void boardInit()
SERIAL_RCC_AHB1Periph |
TELEMETRY_RCC_AHB1Periph |
TRAINER_RCC_AHB1Periph |
BT_RCC_AHB1Periph |
AUDIO_RCC_AHB1Periph |
HAPTIC_RCC_AHB1Periph |
INTMODULE_RCC_AHB1Periph |
@@ -145,6 +146,7 @@ void boardInit()
HAPTIC_RCC_APB2Periph |
INTMODULE_RCC_APB2Periph |
EXTMODULE_RCC_APB2Periph |
BT_RCC_APB2Periph |
BL_RCC_APB2Periph,
ENABLE);
@@ -180,10 +182,10 @@ void boardInit()
hapticInit();
#if defined(BLUETOOTH)
bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE);
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
#endif
#if defined(PCBX12S)
#if defined(INTERNAL_GPS)
gpsInit(GPS_USART_BAUDRATE);
#endif
+1 -6
View File
@@ -527,13 +527,8 @@ int sbusGetByte(uint8_t * byte);
// BT driver
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
#define BLUETOOTH_FACTORY_BAUDRATE 9600
uint8_t bluetoothReady(void);
void bluetoothInit(uint32_t baudrate);
void bluetoothWrite(const void * buffer, int len);
void bluetoothWriteString(const char * str);
int bluetoothRead(void * buffer, int len);
void bluetoothWakeup(void);
void bluetoothWriteWakeup(void);
void bluetoothDone(void);
extern uint8_t currentTrainerMode;
+58 -32
View File
@@ -39,16 +39,20 @@
#define KEYS_GPIO_REG_RIGHT GPIOC->IDR
#define KEYS_GPIO_PIN_RIGHT GPIO_Pin_4 // PC.04
#elif defined(PCBX10)
#define KEYS_GPIO_REG_PGDN GPIOI->IDR
#define KEYS_GPIO_PIN_PGDN GPIO_Pin_11 // PI.11
#define KEYS_GPIO_REG_LEFT GPIOI->IDR
#define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
#define KEYS_GPIO_REG_PGUP GPIOH->IDR
#define KEYS_GPIO_PIN_PGUP GPIO_Pin_14 // PH.14
#define KEYS_GPIO_REG_PGDN GPIOH->IDR
#define KEYS_GPIO_PIN_PGDN GPIO_Pin_15 // PH.15
#define KEYS_GPIO_REG_ENTER GPIOI->IDR
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_8 // PI.08
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_11 // PI.11
#define KEYS_GPIO_REG_PUSH GPIOI->IDR
#define KEYS_GPIO_PIN_PUSH GPIO_Pin_8 // PI.08
#define KEYS_GPIO_REG_UP GPIOI->IDR
#define KEYS_GPIO_PIN_UP GPIO_Pin_4 // PI.04
#define KEYS_GPIO_REG_DOWN GPIOI->IDR
#define KEYS_GPIO_PIN_DOWN GPIO_Pin_6 // PI.06
#define KEYS_GPIO_REG_LEFT GPIOI->IDR
#define KEYS_GPIO_PIN_LEFT GPIO_Pin_7 // PI.07
#define KEYS_GPIO_REG_RIGHT GPIOI->IDR
#define KEYS_GPIO_PIN_RIGHT GPIO_Pin_5 // PI.05
#endif
@@ -471,13 +475,13 @@
#define HAPTIC_GPIO_AF GPIO_AF_TIM9
#define HAPTIC_GPIO_PinSource GPIO_PinSource2
#elif defined(PCBX10)
#define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
#define HAPTIC_RCC_APB2Periph RCC_APB2ENR_TIM8EN
#define HAPTIC_GPIO GPIOB
#define HAPTIC_GPIO_PIN GPIO_Pin_0 // PB.00
#define HAPTIC_GPIO_TIMER TIM8
#define HAPTIC_GPIO_AF GPIO_AF_TIM8
#define HAPTIC_GPIO_PinSource GPIO_PinSource0
#define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOE
#define HAPTIC_RCC_APB2Periph RCC_APB2ENR_TIM9EN
#define HAPTIC_GPIO GPIOE
#define HAPTIC_GPIO_PIN GPIO_Pin_6 // PE.06
#define HAPTIC_GPIO_TIMER TIM9
#define HAPTIC_GPIO_AF GPIO_AF_TIM9
#define HAPTIC_GPIO_PinSource GPIO_PinSource6
#endif
// Internal Module
@@ -498,6 +502,13 @@
#define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream7_IRQHandler
#define INTMODULE_DMA_FLAG_TC DMA_IT_TCIF7
#define INTMODULE_DMA_CHANNEL DMA_Channel_4
#if defined(PCBX12S)
#define INTMODULE_BOOT_GPIO GPIOI
#define INTMODULE_BOOT_GPIO_PIN GPIO_PIN_9 // PC.02
#elif defined(PCBX10)
#define INTMODULE_BOOT_GPIO GPIOI
#define INTMODULE_BOOT_GPIO_PIN GPIO_PIN_9 // PI.09
#endif
#if PCBREV >= 13
#define INTMODULE_RCC_APB1Periph RCC_APB1Periph_TIM2
#define INTMODULE_RCC_APB2Periph RCC_APB2Periph_USART1
@@ -553,6 +564,11 @@
#define EXTMODULE_DMA_FLAG_TC DMA_IT_TCIF7
#endif
// Heartbeat (not used)
#define HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
#define HEARTBEAT_GPIO GPIOD
#define HEARTBEAT_GPIO_PIN GPIO_Pin_12 // PD.12
// Trainer Port
#define TRAINER_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA1)
#define TRAINER_RCC_APB1Periph RCC_APB1Periph_TIM3
@@ -586,14 +602,17 @@
#define TIMER_2MHz_TIMER TIM7
// Bluetooth
#define BT_RCC_APB2Periph RCC_APB2Periph_USART6
#define BT_USART USART6
#define BT_GPIO_AF GPIO_AF_USART6
#define BT_USART_IRQn USART6_IRQn
#define BT_GPIO_TXRX GPIOG
#define BT_TX_GPIO_PIN GPIO_Pin_14 // PG.14
#define BT_RX_GPIO_PIN GPIO_Pin_9 // PG.09
#define BT_TX_GPIO_PinSource GPIO_PinSource14
#define BT_RX_GPIO_PinSource GPIO_PinSource9
#define BT_USART_IRQHandler USART6_IRQHandler
#if defined(PCBX12S)
#define BT_RCC_APB2Periph RCC_APB2Periph_USART6
#define BT_USART USART6
#define BT_GPIO_AF GPIO_AF_USART6
#define BT_USART_IRQn USART6_IRQn
#define BT_GPIO_TXRX GPIOG
#define BT_TX_GPIO_PIN GPIO_Pin_14 // PG.14
#define BT_RX_GPIO_PIN GPIO_Pin_9 // PG.09
#if PCBREV >= 13
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOG)
#define BT_EN_GPIO GPIOI
@@ -607,21 +626,28 @@
#define BT_BRTS_GPIO_PIN GPIO_Pin_10 // PG.10
#define BT_BCTS_GPIO GPIOG
#define BT_BCTS_GPIO_PIN GPIO_Pin_11 // PG.11
#define BT_TX_GPIO_PinSource GPIO_PinSource14
#define BT_RX_GPIO_PinSource GPIO_PinSource9
#elif defined(PCBX10)
#define BT_RCC_AHB1Periph RCC_AHB1Periph_GPIOG
#define BT_EN_GPIO GPIOG
#define BT_EN_GPIO_PIN GPIO_Pin_10 // PG.10
#endif
// 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
#if defined(PCBX12S)
#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
#else
#define GPS_RCC_AHB1Periph 0
#define GPS_RCC_APB1Periph 0
#endif
#endif // _HAL_H_
+5 -5
View File
@@ -28,7 +28,7 @@ void btSetBaudrate(uint32_t index)
void btInit()
{
btSetBaudrate(g_eeGeneral.btBaudrate);
btSetBaudrate(g_eeGeneral.bluetoothBaudrate);
}
OS_FlagID btFlag;
@@ -207,7 +207,7 @@ Or maybe just AT and get OK back
uint32_t btStatus;
void btTask(void* pdata)
void bluetoothTask(void * pdata)
{
uint8_t byte;
@@ -218,7 +218,7 @@ void btTask(void* pdata)
// Already initialised to g_eeGeneral.bt_baudrate
// 0 : 115200, 1 : 9600, 2 : 19200
uint32_t x = g_eeGeneral.btBaudrate;
uint32_t x = g_eeGeneral.bluetoothBaudrate;
btStatus = btPollDevice() ; // Do we get a response?
@@ -236,8 +236,8 @@ void btTask(void* pdata)
if (btStatus) {
btStatus = x + 1 ;
if ( x != g_eeGeneral.btBaudrate ) {
x = g_eeGeneral.btBaudrate ;
if ( x != g_eeGeneral.bluetoothBaudrate ) {
x = g_eeGeneral.bluetoothBaudrate ;
// Need to change Bt Baudrate
btChangeBaudrate( x ) ;
btStatus += (x+1) * 10 ;
+1 -1
View File
@@ -369,7 +369,7 @@ void hapticOn(uint32_t pwmPercent);
// BlueTooth driver
#if defined(BLUETOOTH)
void btInit();
void btTask(void* pdata);
void bluetoothTask(void * pdata);
void btPushByte(uint8_t data);
#endif
+23 -12
View File
@@ -11,14 +11,12 @@ if(PCB STREQUAL X9E)
set(HAPTIC YES)
set(LUA_EXPORT lua_export_x9e)
set(FLAVOUR x9e)
add_definitions(-DSTM32F40_41xxx -DPCBX9E)
add_definitions(-DSTM32F40_41xxx -DPCBX9E -DPCBX9)
add_definitions(-DEEPROM_VARIANT=0x8000)
add_definitions(-DBLUETOOTH)
add_definitions(-DPWR_BUTTON_${PWR_BUTTON})
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
top_lcd_driver.cpp
bluetooth_driver.cpp
startup_stm32f40_41xxx.s
)
set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
@@ -36,7 +34,7 @@ elseif(PCB STREQUAL X9D+)
set(HAPTIC YES)
set(LUA_EXPORT lua_export_x9d)
set(FLAVOUR x9d+)
add_definitions(-DPCBX9DP)
add_definitions(-DPCBX9DP -DPCBX9)
add_definitions(-DEEPROM_VARIANT=0)
set(GUI_DIR 212x64)
set(BITMAPS_TARGET taranis_bitmaps)
@@ -50,33 +48,46 @@ elseif(PCB STREQUAL X9D)
option(HAPTIC "Haptic support" OFF)
set(LUA_EXPORT lua_export_x9d)
set(FLAVOUR x9d)
add_definitions(-DPCBX9D)
add_definitions(-DPCBX9D -DPCBX9)
add_definitions(-DEEPROM_VARIANT=0)
set(GUI_DIR 212x64)
set(BITMAPS_TARGET taranis_bitmaps)
set(LCD_DRIVER lcd_driver_aspi.cpp)
set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
set(GVAR_SCREEN model_gvars.cpp)
elseif(PCB STREQUAL X7)
elseif(PCB STREQUAL X7 OR PCB STREQUAL X7S)
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
set(CPU_TYPE STM32F2)
set(CPU_TYPE_FULL STM32F205xE) # for size report
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
set(HAPTIC YES)
set(LUA_EXPORT lua_export_x7)
set(FLAVOUR x7)
if(PCB STREQUAL X7S)
add_definitions(-DPCBX7S)
set(FLAVOUR x7s)
else()
set(FLAVOUR x7)
endif()
add_definitions(-DPCBX7 -DSOFTWARE_VOLUME)
add_definitions(-DEEPROM_VARIANT=0x4000)
add_definitions(-DPWR_BUTTON_${PWR_BUTTON})
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
bluetooth_driver.cpp
)
set(GUI_DIR 128x64)
set(BITMAPS_TARGET 9x_bitmaps)
set(LCD_DRIVER lcd_driver_spi.cpp)
endif()
if(PCB STREQUAL X9E OR PCB STREQUAL X7S)
add_definitions(-DBLUETOOTH)
set(TARGET_SRC
${TARGET_SRC}
../common/arm/stm32/bluetooth_driver.cpp
)
set(SRC
${SRC}
bluetooth.cpp
)
endif()
set(HSE_VALUE 12000000)
set(SDCARD YES)
set(EEPROM EEPROM_RLC)
@@ -104,7 +115,7 @@ set(GUI_SRC ${GUI_SRC}
../screenshot.cpp
)
if(PCB STREQUAL X7)
if(PCB STREQUAL X7 OR PCB STREQUAL X7S)
set(LED_DRIVER led_driver.cpp)
endif()
+6 -6
View File
@@ -146,9 +146,9 @@ void sportUpdatePowerOff()
void boardInit()
{
#if !defined(SIMU)
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | PCBREV_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | AUDIO_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SPORT_UPDATE_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph, ENABLE);
RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | AUDIO_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph, ENABLE);
RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph | EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph, ENABLE);
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | PCBREV_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | AUDIO_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SPORT_UPDATE_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph | BT_RCC_AHB1Periph, ENABLE);
RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | AUDIO_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph | BT_RCC_APB1Periph, ENABLE);
RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph | EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph | BT_RCC_APB2Periph, ENABLE);
#if !defined(PCBX9E)
// some X9E boards need that the pwrInit() is moved a little bit later
@@ -180,7 +180,7 @@ void boardInit()
hapticInit();
#endif
#if defined(PCBX9E) || defined(PCBX7)
#if defined(BLUETOOTH)
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
#endif
@@ -298,7 +298,7 @@ void checkTrainerSettings()
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
stop_sbus_on_heartbeat_capture() ;
break;
#if defined(SERIAL2)
#if !defined(PCBX7) && !defined(PCBX9E)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
serial2Stop();
#endif
@@ -315,7 +315,7 @@ void checkTrainerSettings()
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
init_sbus_on_heartbeat_capture() ;
break;
#if defined(SERIAL2)
#if !defined(PCBX7) && !defined(PCBX9E)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
if (g_eeGeneral.serial2Mode == UART_MODE_SBUS_TRAINER) {
serial2SbusInit();
+1 -6
View File
@@ -549,13 +549,8 @@ void serial2Stop(void);
// BT driver
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
#define BLUETOOTH_FACTORY_BAUDRATE 9600
uint8_t bluetoothReady(void);
void bluetoothInit(uint32_t baudrate);
void bluetoothWrite(const void * buffer, int len);
void bluetoothWriteString(const char * str);
int bluetoothRead(void * buffer, int len);
void bluetoothWakeup(void);
void bluetoothWriteWakeup(void);
void bluetoothDone(void);
// LED driver
+9 -1
View File
@@ -790,7 +790,9 @@
#define BT_USART USART6
#define BT_GPIO_AF GPIO_AF_USART6
#define BT_USART_IRQn USART6_IRQn
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB)
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG)
#define BT_RCC_APB1Periph 0
#define BT_RCC_APB2Periph RCC_APB2Periph_USART6
#define BT_GPIO_TXRX GPIOG
#define BT_TX_GPIO_PIN GPIO_Pin_14 // PG.14
#define BT_RX_GPIO_PIN GPIO_Pin_9 // PG.09
@@ -802,9 +804,11 @@
#define BT_BCTS_GPIO_PIN GPIO_Pin_6 // PG.06
#define BT_TX_GPIO_PinSource GPIO_PinSource14
#define BT_RX_GPIO_PinSource GPIO_PinSource9
#define BT_USART_IRQHandler USART6_IRQHandler
#elif defined(PCBX7)
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_DMA1)
#define BT_RCC_APB1Periph RCC_APB1Periph_USART3
#define BT_RCC_APB2Periph 0
#define BT_EN_GPIO GPIOE
#define BT_EN_GPIO_PIN GPIO_Pin_12 // PE.12
#define BT_GPIO_TXRX GPIOB
@@ -818,6 +822,10 @@
#define BT_USART_IRQn USART3_IRQn
#define BT_DMA_Stream_RX DMA1_Stream1
#define BT_DMA_Channel_RX DMA_Channel_4
#else
#define BT_RCC_AHB1Periph 0
#define BT_RCC_APB1Periph 0
#define BT_RCC_APB2Periph 0
#endif
// 5ms Interrupt
+1 -1
View File
@@ -265,7 +265,7 @@ int sbusGetByte(uint8_t * byte)
switch (currentTrainerMode) {
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
return heartbeatFifo.pop(*byte);
#if defined(SERIAL2)
#if !defined(PCBX7) && !defined(PCBX9E)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
return serial2RxFifo.pop(*byte);
#endif