component/bt: implement classic Bluetooth profiles A2DP(sink) and AVRCP(controller)
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define A2DP_SINK_TAG "A2DP_SINK"
|
||||
|
||||
extern void bte_main_boot_entry(void *);
|
||||
extern void bt_app_task_start_up(void);
|
||||
@@ -15,11 +18,21 @@ extern void bt_app_core_start(void);
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_err_t ret;
|
||||
nvs_flash_init();
|
||||
esp_bt_controller_init();
|
||||
|
||||
if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) {
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(A2DP_SINK_TAG, "%s initialize controller failed\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
||||
if (ret) {
|
||||
ESP_LOGE(A2DP_SINK_TAG, "%s enable controller failed\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_app_task_start_up();
|
||||
}
|
||||
|
||||
@@ -13,10 +13,13 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "bt.h"
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *tag = "BLE_ADV";
|
||||
|
||||
#define HCI_H4_CMD_PREAMBLE_SIZE (4)
|
||||
|
||||
@@ -214,9 +217,15 @@ void bleAdvtTask(void *pvParameters)
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_bt_controller_init();
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
|
||||
if (esp_bt_controller_init(&bt_cfg) != ESP_OK) {
|
||||
ESP_LOGI(tag, "Bluetooth controller initialize failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) {
|
||||
ESP_LOGI(tag, "Bluetooth controller enable failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +315,11 @@ void app_main()
|
||||
ESP_ERROR_CHECK( nvs_flash_init() );
|
||||
initialise_wifi();
|
||||
|
||||
esp_bt_controller_init();
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
BLUFI_ERROR("%s initialize bt controller failed\n", __func__);
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
||||
if (ret) {
|
||||
|
||||
8
examples/bluetooth/controller_hci_uart/Makefile
Normal file
8
examples/bluetooth/controller_hci_uart/Makefile
Normal file
@@ -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
|
||||
7
examples/bluetooth/controller_hci_uart/README.rst
Normal file
7
examples/bluetooth/controller_hci_uart/README.rst
Normal file
@@ -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.
|
||||
|
||||
|
||||
4
examples/bluetooth/controller_hci_uart/main/component.mk
Normal file
4
examples/bluetooth/controller_hci_uart/main/component.mk
Normal file
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bt.h"
|
||||
#include "driver/uart.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *tag = "CONTROLLER_UART_HCI";
|
||||
|
||||
static void uart_gpio_reset(void)
|
||||
{
|
||||
#if CONFIG_BT_HCI_UART_NO
|
||||
ESP_LOGI(tag, "HCI UART%d Pin select: TX 5, RX, 18, CTS 23, RTS 19", CONFIG_BT_HCI_UART_NO);
|
||||
|
||||
uart_set_pin(CONFIG_BT_HCI_UART_NO, 5, 18, 19, 23);
|
||||
#endif
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
/* As the UART1/2 pin conflict with flash pin, so do matrix of the signal and pin */
|
||||
uart_gpio_reset();
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(tag, "Bluetooth Controller initialize failed, ret %d", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(tag, "Bluetooth Controller initialize failed, ret %d", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
10
examples/bluetooth/controller_hci_uart/sdkconfig.defaults
Normal file
10
examples/bluetooth/controller_hci_uart/sdkconfig.defaults
Normal file
@@ -0,0 +1,10 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_HCI_UART=y
|
||||
CONFIG_BT_HCI_UART_NO_DEFAULT=1
|
||||
CONFIG_BT_HCI_UART_BAUDRATE_DEFAULT=921600
|
||||
@@ -402,7 +402,8 @@ void gattc_client_test(void)
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_bt_controller_init();
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
esp_bt_controller_init(&bt_cfg);
|
||||
esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
||||
|
||||
gattc_client_test();
|
||||
|
||||
@@ -398,7 +398,12 @@ void app_main()
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
esp_bt_controller_init();
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(GATTS_TAG, "%s initialize controller failed\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
||||
if (ret) {
|
||||
|
||||
@@ -313,7 +313,12 @@ void app_main()
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
esp_bt_controller_init();
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
||||
if (ret) {
|
||||
|
||||
Reference in New Issue
Block a user