diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 7b91842fd06..de2134f5cfe 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -27,6 +27,10 @@ #include "tasks.h" #include "tasks/mixer_task.h" +#if defined(BLUETOOTH) + #include "bluetooth_driver.h" +#endif + #if defined(LIBOPENUI) #include "libopenui.h" // #include "shutdown_animation.h" @@ -1180,6 +1184,12 @@ void opentxStart(const uint8_t startOptions = OPENTX_START_DEFAULT_ARGS) uint8_t calibration_needed = !(startOptions & OPENTX_START_NO_CALIBRATION) && (g_eeGeneral.chkSum != evalChkSum()); +#if defined(BLUETOOTH_PROBE) + extern volatile uint8_t btChipPresent; + auto oldBtMode = g_eeGeneral.bluetoothMode; + g_eeGeneral.bluetoothMode = BLUETOOTH_TELEMETRY; +#endif + #if defined(GUI) if (!calibration_needed && !(startOptions & OPENTX_START_NO_SPLASH)) { AUDIO_HELLO(); @@ -1216,6 +1226,12 @@ void opentxStart(const uint8_t startOptions = OPENTX_START_DEFAULT_ARGS) PLAY_MODEL_NAME(); } #endif + +#if defined(BLUETOOTH_PROBE) + if (bluetooth.localAddr[0] != '\0') + btChipPresent = 1; + g_eeGeneral.bluetoothMode = oldBtMode; +#endif } void opentxClose(uint8_t shutdown) diff --git a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp index e8d6629bfa5..24a363fa601 100644 --- a/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp +++ b/radio/src/targets/common/arm/stm32/bluetooth_driver.cpp @@ -107,50 +107,6 @@ void bluetoothDisable() } } -// @Cliff -// ISR is handled by the serial driver, -// however, it is unclear at this point -// how the detection should be implemented. -// Maybe setting a temporary callback on -// the interface, or trying to pull some data. -// -// Also, it is quite unclear why we would need -// to disable sending when the TX buffer is exahausted. -// The serial driver does take care of that but does not -// set any particular piece of state that could be queried -// to deduct the state of this TX buffer. -#if _OBSOLETE_ -extern "C" void BT_USART_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 defined(BLUETOOTH_PROBE) - if (!btChipPresent) { - // This is to differentiate X7 and X7S and X-Lite with/without BT - btChipPresent = 1; - bluetoothDisable(); - } -#endif - } - - 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); - // => BLUETOOTH_WRITE_IDLE - bluetoothWriteState = BLUETOOTH_WRITE_DONE; - } - } -} -#endif - void bluetoothWrite(const void* buffer, uint32_t len) { if (!_bt_usart_ctx) return; diff --git a/radio/src/targets/simu/bt_driver.cpp b/radio/src/targets/simu/bt_driver.cpp index 2648f5d2690..032fae5bce8 100644 --- a/radio/src/targets/simu/bt_driver.cpp +++ b/radio/src/targets/simu/bt_driver.cpp @@ -26,4 +26,5 @@ void bluetoothWrite(const void*, uint32_t) {} int bluetoothRead(uint8_t*) { return 0; } void bluetoothDisable() {} bool bluetoothIsWriting() { return false; } +volatile uint8_t btChipPresent;