1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +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

@ -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();