From d13fb8918f029291ff7553016b28f02ba871c565 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sun, 19 Nov 2017 23:49:38 +0100 Subject: [PATCH] - X7S option removed (#5388) - runtime detection of bluetooth chip --- radio/src/CMakeLists.txt | 6 +++--- radio/src/bluetooth.h | 4 ++++ radio/src/gui/128x64/radio_hardware.cpp | 7 ++++++- radio/src/gui/128x64/view_statistics.cpp | 4 ++++ radio/src/opentx.cpp | 4 ++++ .../targets/common/arm/stm32/bluetooth_driver.cpp | 12 +++++++++++- radio/src/targets/taranis/CMakeLists.txt | 13 ++++--------- tools/commit-tests.sh | 11 +---------- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 35b29c0a7..672574f08 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -1,7 +1,7 @@ include(CMakeForceCompiler) include(Bitmaps) -set(PCB_TYPES X7 X7S X9D X9D+ X9E X10 X12S 9X 9XR 9X128 9XR128 9X2561 GRUVIN9X MEGA2560 SKY9X 9XRPRO AR9X) +set(PCB_TYPES X7 X9D X9D+ X9E X10 X12S 9X 9XR 9X128 9XR128 9X2561 GRUVIN9X MEGA2560 SKY9X 9XRPRO AR9X) set(GUI_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL) set(TTS_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU) @@ -83,7 +83,7 @@ set(FATFS_SRC if(PCB STREQUAL X12S OR PCB STREQUAL X10) include(targets/horus/CMakeLists.txt) -elseif(PCB STREQUAL X9E OR PCB STREQUAL X9D+ OR PCB STREQUAL X9D OR PCB STREQUAL X7 OR PCB STREQUAL X7S) +elseif(PCB STREQUAL X9E OR PCB STREQUAL X9D+ OR PCB STREQUAL X9D OR PCB STREQUAL X7) include(targets/taranis/CMakeLists.txt) elseif(PCB STREQUAL SKY9X OR PCB STREQUAL 9XRPRO OR PCB STREQUAL AR9X) include(targets/sky9x/CMakeLists.txt) @@ -491,7 +491,7 @@ if(NOT MSVC) endif() - if(PCB STREQUAL X9D OR PCB STREQUAL X9D+ OR PCB STREQUAL X9E OR PCB STREQUAL X7 OR PCB STREQUAL X7S) + if(PCB STREQUAL X9D OR PCB STREQUAL X9D+ OR PCB STREQUAL X9E OR PCB STREQUAL X7) add_subdirectory(targets/${TARGET_DIR}/bootloader) include_directories(${CMAKE_CURRENT_BINARY_DIR}/targets/${TARGET_DIR}/bootloader) set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} bootloader) diff --git a/radio/src/bluetooth.h b/radio/src/bluetooth.h index 2b0a3dd0c..8e757a01b 100644 --- a/radio/src/bluetooth.h +++ b/radio/src/bluetooth.h @@ -44,6 +44,10 @@ enum BluetoothStates { #define LEN_BLUETOOTH_ADDR 16 +#if defined(PCBX7) +extern uint8_t btChipPresent; +#endif + extern volatile uint8_t bluetoothState; extern char bluetoothLocalAddr[LEN_BLUETOOTH_ADDR+1]; extern char bluetoothDistantAddr[LEN_BLUETOOTH_ADDR+1]; diff --git a/radio/src/gui/128x64/radio_hardware.cpp b/radio/src/gui/128x64/radio_hardware.cpp index 644fee81b..4dc186958 100644 --- a/radio/src/gui/128x64/radio_hardware.cpp +++ b/radio/src/gui/128x64/radio_hardware.cpp @@ -124,7 +124,9 @@ enum MenuRadioHardwareItems { #define POTS_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1 #define SWITCHES_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1 -#if defined(BLUETOOTH) +#if defined(PCBX7) +#define BLUETOOTH_ROWS uint8_t(btChipPresent ? 0 : HIDDEN_ROW), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : 0), +#elif defined(BLUETOOTH) #define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? HIDDEN_ROW : 0), #else #define BLUETOOTH_ROWS @@ -230,6 +232,9 @@ void menuRadioHardware(event_t event) case ITEM_RADIO_HARDWARE_BLUETOOTH_MODE: lcdDrawTextAlignedLeft(y, STR_BLUETOOTH); lcdDrawTextAtIndex(HW_SETTINGS_COLUMN2, y, STR_BLUETOOTH_MODES, g_eeGeneral.bluetoothMode, attr); + if ((g_eeGeneral.bluetoothMode != BLUETOOTH_OFF) && !btChipPresent) { + g_eeGeneral.bluetoothMode = BLUETOOTH_OFF; + } if (attr) { g_eeGeneral.bluetoothMode = checkIncDecGen(event, g_eeGeneral.bluetoothMode, BLUETOOTH_OFF, BLUETOOTH_TRAINER); } diff --git a/radio/src/gui/128x64/view_statistics.cpp b/radio/src/gui/128x64/view_statistics.cpp index 7c49b4e20..d359efee8 100644 --- a/radio/src/gui/128x64/view_statistics.cpp +++ b/radio/src/gui/128x64/view_statistics.cpp @@ -117,6 +117,7 @@ void menuStatisticsView(event_t event) #define MENU_DEBUG_COL2_OFS (17*FW) #define MENU_DEBUG_Y_CURRENT (1*FH) #define MENU_DEBUG_ROW1 (1*FH+1) + #define MENU_DEBUG_ROW2 (2*FH+1) #define MENU_DEBUG_Y_MAH (2*FH) #define MENU_DEBUG_Y_CPU_TEMP (3*FH) #define MENU_DEBUG_Y_COPROC (4*FH) @@ -308,6 +309,9 @@ void menuStatisticsDebug2(event_t event) lcdDrawTextAlignedLeft(MENU_DEBUG_ROW1, "Tlm RX Err"); lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW1, telemetryErrors, RIGHT); + lcdDrawTextAlignedLeft(MENU_DEBUG_ROW2, "BT status"); + lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW2, btChipPresent, RIGHT); + lcdDrawText(4*FW, 7*FH+1, STR_MENUTORESET); lcdInvertLastLine(); } diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index f678ba990..861cb4741 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2655,6 +2655,10 @@ int main() boardInit(); +#if defined(PCBX7) + bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE); //BT is turn on for a brief period to differentiate X7 and X7S +#endif + #if defined(GUI) && !defined(PCBTARANIS) && !defined(PCBFLAMENCO) && !defined(PCBHORUS) // TODO remove this lcdInit(); diff --git a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp index 65caaa252..539f292f5 100644 --- a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp +++ b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -23,6 +23,10 @@ Fifo btTxFifo; Fifo btRxFifo; +#if defined(PCBX7) +uint8_t btChipPresent = 0; +#endif + enum BluetoothWriteState { BLUETOOTH_WRITE_IDLE, @@ -105,6 +109,12 @@ extern "C" void BT_USART_IRQHandler(void) USART_ClearITPendingBit(BT_USART, USART_IT_RXNE); uint8_t byte = USART_ReceiveData(BT_USART); btRxFifo.push(byte); +#if defined(PCBX7) + if (!btChipPresent) { //This is to differentiate X7 and X7S + btChipPresent = 1; + bluetoothDone(); + } +#endif } if (USART_GetITStatus(BT_USART, USART_IT_TXE) != RESET) { diff --git a/radio/src/targets/taranis/CMakeLists.txt b/radio/src/targets/taranis/CMakeLists.txt index 317813a97..f678b1fb5 100644 --- a/radio/src/targets/taranis/CMakeLists.txt +++ b/radio/src/targets/taranis/CMakeLists.txt @@ -55,19 +55,14 @@ elseif(PCB STREQUAL X9D) 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 OR PCB STREQUAL X7S) +elseif(PCB STREQUAL X7) 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) - if(PCB STREQUAL X7S) - add_definitions(-DPCBX7S) - set(FLAVOUR x7s) - else() - set(FLAVOUR x7) - endif() + set(FLAVOUR x7) add_definitions(-DPCBX7 -DSOFTWARE_VOLUME) add_definitions(-DEEPROM_VARIANT=0x4000) add_definitions(-DPWR_BUTTON_${PWR_BUTTON}) @@ -76,7 +71,7 @@ elseif(PCB STREQUAL X7 OR PCB STREQUAL X7S) set(LCD_DRIVER lcd_driver_spi.cpp) endif() -if(PCB STREQUAL X9E OR PCB STREQUAL X7S) +if(PCB STREQUAL X9E OR PCB STREQUAL X7) add_definitions(-DBLUETOOTH) set(TARGET_SRC ${TARGET_SRC} @@ -115,7 +110,7 @@ set(GUI_SRC ${GUI_SRC} ../screenshot.cpp ) -if(PCB STREQUAL X7 OR PCB STREQUAL X7S) +if(PCB STREQUAL X7) set(LED_DRIVER led_driver.cpp) endif() diff --git a/tools/commit-tests.sh b/tools/commit-tests.sh index 9f0a67105..38f5cb1e7 100755 --- a/tools/commit-tests.sh +++ b/tools/commit-tests.sh @@ -133,16 +133,7 @@ fi if [[ " X7 ALL " =~ " ${FLAVOR} " ]] ; then # OpenTX on X7 rm -rf * - cmake ${COMMON_OPTIONS} -DPCB=X7 -DHELI=YES ${SRCDIR} - make -j${CORES} ${FIRMARE_TARGET} - make -j${CORES} simu - make -j${CORES} gtests ; ./gtests ${TEST_OPTIONS} -fi - -if [[ " X7S ALL " =~ " ${FLAVOR} " ]] ; then - # OpenTX on X7S - rm -rf * - cmake ${COMMON_OPTIONS} -DPCB=X7S -DHELI=YES -DLUA=YES -DGVARS=YES ${SRCDIR} + cmake ${COMMON_OPTIONS} -DPCB=X7 -DHELI=YES -DGVARS=YES ${SRCDIR} make -j${CORES} ${FIRMARE_TARGET} make -j${CORES} simu make -j${CORES} gtests ; ./gtests ${TEST_OPTIONS}