Skip to content

Commit

Permalink
fix: X7S BT detection (#3754)
Browse files Browse the repository at this point in the history
* Add X7S BT detection

* Compile fix

* chore: remove obsolte section
  • Loading branch information
3djc authored and pfeerick committed Jul 19, 2023
1 parent 903029b commit f942761
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 44 deletions.
16 changes: 16 additions & 0 deletions radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 0 additions & 44 deletions radio/src/targets/common/arm/stm32/bluetooth_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions radio/src/targets/simu/bt_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f942761

Please sign in to comment.