1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-21 07:15:12 +03:00

BT fixes on X-LiteS

This commit is contained in:
Bertrand Songis 2019-02-15 18:51:40 +01:00
parent 2afe8794aa
commit 22f35c6d27
11 changed files with 49 additions and 52 deletions

View file

@ -45,10 +45,10 @@ enum BluetoothStates {
#define LEN_BLUETOOTH_ADDR 16
#if (defined(PCBX7) || defined(PCBXLITE)) && !defined(SIMU)
extern uint8_t btChipPresent;
#define IS_BLUETOOTH_CHIP_PRESENT() (btChipPresent)
extern volatile uint8_t btChipPresent;
#define IS_BLUETOOTH_CHIP_PRESENT() (btChipPresent)
#else
#define IS_BLUETOOTH_CHIP_PRESENT() (true)
#define IS_BLUETOOTH_CHIP_PRESENT() (true)
#endif
extern volatile uint8_t bluetoothState;

View file

@ -205,9 +205,7 @@ enum BeeperMode {
};
#endif
#if defined(PCBXLITES)
#define TRAINER_MODE_MAX() TRAINER_MODE_SLAVE
#elif defined(BLUETOOTH)
#if defined(BLUETOOTH)
#define TRAINER_MODE_MAX() TRAINER_MODE_SLAVE_BLUETOOTH
#elif defined(PCBX7) || defined(PCBXLITE)
#define TRAINER_MODE_MAX() TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE

View file

@ -122,9 +122,9 @@ enum MenuModelSetupItems {
#if defined(PCBX7)
ITEM_MODEL_TRAINER_LABEL,
ITEM_MODEL_TRAINER_MODE,
#if defined(BLUETOOTH)
#if defined(BLUETOOTH)
ITEM_MODEL_TRAINER_BLUETOOTH,
#endif
#endif
ITEM_MODEL_TRAINER_CHANNELS,
ITEM_MODEL_TRAINER_PARAMS,
#elif defined(PCBXLITE)

View file

@ -136,12 +136,13 @@ enum MenuRadioHardwareItems {
#endif
#if defined(PCBTARANIS)
#define BLUETOOTH_ROWS uint8_t(IS_BLUETOOTH_CHIP_PRESENT() ? 0 : HIDDEN_ROW), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY ? -1 : 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),
#define BLUETOOTH_ROWS uint8_t(IS_BLUETOOTH_CHIP_PRESENT() ? 0 : HIDDEN_ROW), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY ? -1 : 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),
#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
#define BLUETOOTH_ROWS
#endif
#if defined(PCBXLITES)
#define SWITCH_TYPE_MAX(sw) (sw >= MIXSRC_SE-MIXSRC_FIRST_SWITCH ? SWITCH_2POS : SWITCH_3POS)
#elif defined(PCBXLITE)

View file

@ -655,6 +655,16 @@ bool isTrainerModeAvailable(int mode)
else
return true;
}
#elif defined(PCBXLITES)
bool isTrainerModeAvailable(int mode)
{
if (mode == TRAINER_MODE_MASTER_TRAINER_JACK || mode == TRAINER_MODE_SLAVE)
return true;
else if (g_eeGeneral.bluetoothMode == BLUETOOTH_TRAINER && (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_SLAVE_BLUETOOTH))
return true;
else
return false;
}
#elif defined(PCBXLITE)
bool isTrainerModeAvailable(int mode)
{

View file

@ -1933,10 +1933,6 @@ 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(PCBHORUS)
loadFonts();
#endif

View file

@ -190,13 +190,13 @@
#define IS_FAI_FORBIDDEN(idx) (IS_FAI_ENABLED() && isFaiForbidden(idx))
#if defined(BLUETOOTH)
#if defined(X9E) && !defined(USEHORUSBT)
#if defined(X9E) && !defined(USEHORUSBT)
#define IS_BLUETOOTH_TRAINER() (g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH)
#define IS_SLAVE_TRAINER() (g_model.trainerData.mode == TRAINER_MODE_SLAVE)
#else
#else
#define IS_BLUETOOTH_TRAINER() (g_model.trainerData.mode == TRAINER_MODE_MASTER_BLUETOOTH || g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH)
#define IS_SLAVE_TRAINER() (g_model.trainerData.mode == TRAINER_MODE_SLAVE || g_model.trainerData.mode == TRAINER_MODE_SLAVE_BLUETOOTH)
#endif
#endif
#else
#define IS_BLUETOOTH_TRAINER() false
#define IS_SLAVE_TRAINER() (g_model.trainerData.mode == TRAINER_MODE_SLAVE)

View file

@ -24,7 +24,7 @@ Fifo<uint8_t, 64> btTxFifo;
Fifo<uint8_t, 64> btRxFifo;
#if defined(PCBX7) || defined(PCBXLITE)
uint8_t btChipPresent = 0;
volatile uint8_t btChipPresent = 0;
#endif
enum BluetoothWriteState
@ -40,15 +40,11 @@ volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
void bluetoothInit(uint32_t baudrate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_DeInit(BT_USART);
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_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(BT_EN_GPIO, &GPIO_InitStructure);
#if defined(BT_BRTS_GPIO_PIN)
@ -63,32 +59,28 @@ void bluetoothInit(uint32_t baudrate)
GPIO_Init(BT_BCTS_GPIO, &GPIO_InitStructure);
#endif
GPIO_InitStructure.GPIO_Pin = BT_TX_GPIO_PIN|BT_RX_GPIO_PIN;
GPIO_PinAFConfig(BT_GPIO_TXRX, BT_TX_GPIO_PinSource, BT_GPIO_AF);
GPIO_PinAFConfig(BT_GPIO_TXRX, BT_RX_GPIO_PinSource, BT_GPIO_AF);
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_InitTypeDef USART_InitStructure;
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_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
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);
USART_ITConfig(BT_USART, USART_IT_RXNE, ENABLE);
NVIC_SetPriority(BT_USART_IRQn, 6);
NVIC_EnableIRQ(BT_USART_IRQn);
btRxFifo.clear();
btTxFifo.clear();

View file

@ -44,7 +44,7 @@ int getSelectedUsbMode()
void setSelectedUsbMode(int mode)
{
selectedUsbMode = usbMode (mode);
selectedUsbMode = usbMode(mode);
}
int usbPlugged()

View file

@ -165,6 +165,10 @@ void boardInit()
EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph |
BT_RCC_APB2Periph, ENABLE);
#if defined(BLUETOOTH)
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
#endif
#if !defined(PCBX9E)
// some X9E boards need that the pwrInit() is moved a little bit later
pwrInit();
@ -204,10 +208,6 @@ void boardInit()
hapticInit();
#endif
#if defined(BLUETOOTH)
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
#endif
#if defined(DEBUG)
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif

View file

@ -1178,7 +1178,7 @@
#define BT_RX_GPIO_PinSource GPIO_PinSource9
#define BT_USART_IRQHandler USART6_IRQHandler
#elif defined(PCBX7) || defined(PCBXLITE)
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_DMA1)
#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
@ -1196,8 +1196,8 @@
#define BT_USART USART3
#define BT_USART_IRQHandler USART3_IRQHandler
#define BT_USART_IRQn USART3_IRQn
#define BT_DMA_Stream_RX DMA1_Stream1
#define BT_DMA_Channel_RX DMA_Channel_4
// #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