From 71bb6de3dddc300d188efc9c78be2065e6a6ca9d Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Oct 2016 18:54:51 +0200 Subject: [PATCH] [X7D] Rotary encoder initialization --- radio/src/datastructs.h | 2 +- radio/src/targets/taranis/CMakeLists.txt | 4 ++++ .../src/targets/taranis/bluetooth_driver.cpp | 22 +++++++++++++------ radio/src/targets/taranis/board.cpp | 2 +- radio/src/targets/taranis/hal.h | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 5ac1a1f65..5c3696e4c 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -902,7 +902,7 @@ PACK(struct TrainerData { char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]; \ char anaNames[NUM_STICKS+NUM_POTS+NUM_SLIDERS][LEN_ANA_NAME]; #elif defined(PCBTARANIS) - #if defined(PCBX9E) + #if defined(PCBX9E) || defined(PCBX7D) #define BLUETOOTH_FIELDS \ uint8_t bluetoothEnable; \ char bluetoothName[LEN_BLUETOOTH_NAME]; diff --git a/radio/src/targets/taranis/CMakeLists.txt b/radio/src/targets/taranis/CMakeLists.txt index 81e3c783d..47a1a0783 100644 --- a/radio/src/targets/taranis/CMakeLists.txt +++ b/radio/src/targets/taranis/CMakeLists.txt @@ -59,6 +59,10 @@ elseif(PCB STREQUAL X7D) set(FLAVOUR x7d) add_definitions(-DPCBX7D -DSOFTWARE_VOLUME) add_definitions(-DEEPROM_VARIANT=0) + set(FIRMWARE_TARGET_SRC + ${FIRMWARE_TARGET_SRC} + bluetooth_driver.cpp + ) set(GUI_DIR 128x64) set(BITMAPS_TARGET 9x_bitmaps) set(LCD_DRIVER lcd_driver_spi.cpp) diff --git a/radio/src/targets/taranis/bluetooth_driver.cpp b/radio/src/targets/taranis/bluetooth_driver.cpp index 446b1440d..736be4657 100644 --- a/radio/src/targets/taranis/bluetooth_driver.cpp +++ b/radio/src/targets/taranis/bluetooth_driver.cpp @@ -51,22 +51,26 @@ void bluetoothInit(uint32_t baudrate) RCC_AHB1PeriphClockCmd(BT_RCC_AHB1Periph, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); - - GPIO_InitStructure.GPIO_Pin = BT_BRTS_GPIO_PIN; + + 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_Init(BT_BRTS_GPIO, &GPIO_InitStructure); - GPIO_SetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN); - - GPIO_InitStructure.GPIO_Pin = BT_EN_GPIO_PIN; GPIO_Init(BT_EN_GPIO, &GPIO_InitStructure); +#if defined(BT_BRTS_GPIO_PIN) + GPIO_InitStructure.GPIO_Pin = BT_BRTS_GPIO_PIN; + GPIO_Init(BT_BRTS_GPIO, &GPIO_InitStructure); + GPIO_SetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN); +#endif + +#if defined(BT_BCTS_GPIO_PIN) GPIO_InitStructure.GPIO_Pin = BT_BCTS_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(BT_BCTS_GPIO, &GPIO_InitStructure); - +#endif + 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; @@ -144,7 +148,9 @@ void bluetoothWriteWakeup(void) if (bluetoothWriteState == BLUETOOTH_WRITE_IDLE) { if (!btTxFifo.isEmpty()) { bluetoothWriteState = BLUETOOTH_WRITE_INIT; +#if defined(BT_BRTS_GPIO_PIN) GPIO_ResetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN); +#endif } } else if (bluetoothWriteState == BLUETOOTH_WRITE_INIT) { @@ -153,7 +159,9 @@ void bluetoothWriteWakeup(void) } else if (bluetoothWriteState == BLUETOOTH_WRITE_DONE) { bluetoothWriteState = BLUETOOTH_WRITE_IDLE; +#if defined(BT_BRTS_GPIO_PIN) GPIO_SetBits(BT_BRTS_GPIO, BT_BRTS_GPIO_PIN); +#endif } } diff --git a/radio/src/targets/taranis/board.cpp b/radio/src/targets/taranis/board.cpp index 86ceda9ad..acc5a808a 100644 --- a/radio/src/targets/taranis/board.cpp +++ b/radio/src/targets/taranis/board.cpp @@ -143,7 +143,7 @@ void boardInit() hapticInit(); #endif -#if defined(PCBX9E) +#if defined(PCBX9E) || defined(PCBX7D) bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE); #endif diff --git a/radio/src/targets/taranis/hal.h b/radio/src/targets/taranis/hal.h index 5f9ea6887..893ee9908 100644 --- a/radio/src/targets/taranis/hal.h +++ b/radio/src/targets/taranis/hal.h @@ -776,7 +776,7 @@ #define BT_RCC_APB1Periph RCC_APB1Periph_USART3 #define BT_EN_GPIO GPIOE #define BT_EN_GPIO_PIN GPIO_Pin_12 // PE.12 - #define BT_GPIO GPIOB + #define BT_GPIO_TXRX GPIOB #define BT_TX_GPIO_PIN GPIO_Pin_10 // PB.10 #define BT_RX_GPIO_PIN GPIO_Pin_11 // PB.11 #define BT_TX_GPIO_PinSource GPIO_PinSource10