From f5ebeb4c4db8cea3b5caed3f0d9a729847287cae Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Thu, 16 Mar 2017 17:14:20 +0800 Subject: [PATCH] component/bt : add uart(1/2) as HCI IO directly --- components/bt/Kconfig | 59 ++++++++++++++----- components/bt/bt.c | 36 +++++++++-- components/bt/lib | 2 +- .../bluetooth/controller_hci_uart/Makefile | 8 +++ .../bluetooth/controller_hci_uart/README.rst | 7 +++ .../controller_hci_uart/main/component.mk | 4 ++ .../bluetooth/controller_hci_uart/main/main.c | 44 ++++++++++++++ .../controller_hci_uart/sdkconfig.defaults | 10 ++++ 8 files changed, 151 insertions(+), 19 deletions(-) create mode 100644 examples/bluetooth/controller_hci_uart/Makefile create mode 100644 examples/bluetooth/controller_hci_uart/README.rst create mode 100644 examples/bluetooth/controller_hci_uart/main/component.mk create mode 100644 examples/bluetooth/controller_hci_uart/main/main.c create mode 100644 examples/bluetooth/controller_hci_uart/sdkconfig.defaults diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 9b329e61e..92d060999 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -11,27 +11,58 @@ config BLUEDROID_ENABLED This enables the default Bluedroid Bluetooth stack config BTC_TASK_STACK_SIZE - int "Bluetooth event (callback to application) task stack size" + int "Bluetooth event (callback to application) task stack size" depends on BT_ENABLED - default 3072 - help - This select btc task stack size + default 3072 + help + This select btc task stack size config BLUEDROID_MEM_DEBUG - bool "Bluedroid memory debug" + bool "Bluedroid memory debug" depends on BT_ENABLED - default n - help - Bluedroid memory debug + default n + help + Bluedroid memory debug config BT_DRAM_RELEASE - bool "Release DRAM from Classic BT controller" + bool "Release DRAM from Classic BT controller" depends on BT_ENABLED - default n - help - This option should only be used when BLE only. - Open this option will release about 30K DRAM from Classic BT. - The released DRAM will be used as system heap memory. + default n + help + This option should only be used when BLE only. + Open this option will release about 30K DRAM from Classic BT. + The released DRAM will be used as system heap memory. + +#config BTDM_CONTROLLER_RUN_APP_CPU +# bool "Run controller on APP CPU" +# depends on BT_ENABLED +# default n +# help +# Run controller on APP CPU. + +menuconfig HCI_UART + bool "HCI use UART as IO" + depends on BT_ENABLED + default n + help + Default HCI use VHCI, if this option choose, HCI will use UART(0/1/2) as IO. + Besides, it can set uart number and uart baudrate. + +config HCI_UART_NO + int "UART Number for HCI" + depends on HCI_UART + range 1 2 + default 1 + help + Uart number for HCI. + +config HCI_UART_BAUDRATE + int "UART Baudrate for HCI" + depends on HCI_UART + range 115200 921600 + default 921600 + help + UART Baudrate for HCI. Please use standard baudrate. # Memory reserved at start of DRAM for Bluetooth stack config BT_RESERVE_DRAM diff --git a/components/bt/bt.c b/components/bt/bt.c index e8f4204ef..6182c5eb5 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -33,13 +33,21 @@ #if CONFIG_BT_ENABLED /* Bluetooth system and controller config */ -#define BTDM_CFG_BT_EM_RELEASE (1<<0) -#define BTDM_CFG_BT_DATA_RELEASE (1<<1) +#define BTDM_CFG_BT_EM_RELEASE (1<<0) +#define BTDM_CFG_BT_DATA_RELEASE (1<<1) +#define BTDM_CFG_HCI_UART (1<<2) +#define BTDM_CFG_CONTROLLER_RUN_APP_CPU (1<<3) /* Other reserved for future */ +/* Controller config options, depend on config mask */ +struct btdm_config_options { + uint8_t hci_uart_no; + uint32_t hci_uart_baudrate; +}; + /* not for user call, so don't put to include file */ extern void btdm_osi_funcs_register(void *osi_funcs); -extern void btdm_controller_init(uint32_t config_mask); +extern void btdm_controller_init(uint32_t config_mask, struct btdm_config_options *opts); extern void btdm_controller_schedule(void); extern void btdm_controller_deinit(void); extern int btdm_controller_enable(esp_bt_mode_t mode); @@ -170,18 +178,38 @@ static uint32_t btdm_config_mask_load(void) #ifdef CONFIG_BT_DRAM_RELEASE mask |= (BTDM_CFG_BT_EM_RELEASE | BTDM_CFG_BT_DATA_RELEASE); +#endif +#ifdef CONFIG_HCI_UART + mask |= BTDM_CFG_HCI_UART; +#endif +#ifdef CONFIG_BTDM_CONTROLLER_RUN_APP_CPU + mask |= BTDM_CFG_CONTROLLER_RUN_APP_CPU; #endif return mask; } +static void btdm_config_opts_load(struct btdm_config_options *opts) +{ + if (opts == NULL) { + return; + } +#ifdef CONFIG_HCI_UART + opts->hci_uart_no = CONFIG_HCI_UART_NO; + opts->hci_uart_baudrate = CONFIG_HCI_UART_BAUDRATE; +#endif +} + static void bt_controller_task(void *pvParam) { + struct btdm_config_options btdm_cfg_opts; uint32_t btdm_cfg_mask = 0; btdm_osi_funcs_register(&osi_funcs); btdm_cfg_mask = btdm_config_mask_load(); - btdm_controller_init(btdm_cfg_mask); + btdm_config_opts_load(&btdm_cfg_opts); + + btdm_controller_init(btdm_cfg_mask, &btdm_cfg_opts); btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; diff --git a/components/bt/lib b/components/bt/lib index 9a4bb1d52..f1c0c6517 160000 --- a/components/bt/lib +++ b/components/bt/lib @@ -1 +1 @@ -Subproject commit 9a4bb1d5287572664f170f9df4dbfd71babdfc68 +Subproject commit f1c0c65171e5bd02e1d63137b3582af3bcbb85a4 diff --git a/examples/bluetooth/controller_hci_uart/Makefile b/examples/bluetooth/controller_hci_uart/Makefile new file mode 100644 index 000000000..077393199 --- /dev/null +++ b/examples/bluetooth/controller_hci_uart/Makefile @@ -0,0 +1,8 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := controller_hci_uart + +include $(IDF_PATH)/make/project.mk diff --git a/examples/bluetooth/controller_hci_uart/README.rst b/examples/bluetooth/controller_hci_uart/README.rst new file mode 100644 index 000000000..f51c6c2c6 --- /dev/null +++ b/examples/bluetooth/controller_hci_uart/README.rst @@ -0,0 +1,7 @@ +ESP-IDF UART HCI Controller +=========================== + +This is a btdm controller use UART as HCI IO. This require the UART device support RTS/CTS mandatory. +It can do the configuration of UART number and UART baudrate by menuconfig. + + diff --git a/examples/bluetooth/controller_hci_uart/main/component.mk b/examples/bluetooth/controller_hci_uart/main/component.mk new file mode 100644 index 000000000..a98f634ea --- /dev/null +++ b/examples/bluetooth/controller_hci_uart/main/component.mk @@ -0,0 +1,4 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) diff --git a/examples/bluetooth/controller_hci_uart/main/main.c b/examples/bluetooth/controller_hci_uart/main/main.c new file mode 100644 index 000000000..3f6de6f47 --- /dev/null +++ b/examples/bluetooth/controller_hci_uart/main/main.c @@ -0,0 +1,44 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "bt.h" +#include "driver/uart.h" +#include "esp_log.h" + +static const char *tag = "CONTROLLER_UART_HCI"; + +static void uart_gpio_reset(void) +{ + ESP_LOGI(tag, "HCI UART Pin select: TX 5, RX, 18, CTS 23, RTS 19\n"); + +#if CONFIG_HCI_UART_NO + uart_set_pin(CONFIG_HCI_UART_NO, 5, 18, 19, 23); +#endif +} + +void app_main() +{ + /* As the UART1/2 pin conflict with flash pin, so do matrix of the signal and pin */ + uart_gpio_reset(); + + esp_bt_controller_init(); + + if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) { + return; + } +} + diff --git a/examples/bluetooth/controller_hci_uart/sdkconfig.defaults b/examples/bluetooth/controller_hci_uart/sdkconfig.defaults new file mode 100644 index 000000000..4e1001ba4 --- /dev/null +++ b/examples/bluetooth/controller_hci_uart/sdkconfig.defaults @@ -0,0 +1,10 @@ +# Override some defaults so BT stack is enabled +# in this example + +# +# BT config +# +CONFIG_BT_ENABLED=y +CONFIG_HCI_UART=y +CONFIG_HCI_UART_NO=1 +CONFIG_HCI_UART_BAUDRATE=921600