mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component/bt: clean up the A2DP sink example
This commit is contained in:
parent
8ec94418de
commit
2a5d01a930
@ -4,34 +4,34 @@ menuconfig BT_ENABLED
|
|||||||
Select this option to enable Bluetooth stack and show the submenu with Bluetooth configuration choices.
|
Select this option to enable Bluetooth stack and show the submenu with Bluetooth configuration choices.
|
||||||
|
|
||||||
config BTC_TASK_STACK_SIZE
|
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
|
depends on BT_ENABLED
|
||||||
default 3072
|
default 3072
|
||||||
help
|
help
|
||||||
This select btc task stack size
|
This select btc task stack size
|
||||||
|
|
||||||
config BLUEDROID_MEM_DEBUG
|
config BLUEDROID_MEM_DEBUG
|
||||||
bool "Bluedroid memory debug"
|
bool "Bluedroid memory debug"
|
||||||
depends on BT_ENABLED
|
depends on BT_ENABLED
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
Bluedroid memory debug
|
Bluedroid memory debug
|
||||||
|
|
||||||
config CLASSIC_BT_ENABLED
|
config CLASSIC_BT_ENABLED
|
||||||
bool "Classic Bluetooth"
|
bool "Classic Bluetooth"
|
||||||
depends on BT_ENABLED
|
depends on BT_ENABLED
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
BT_DRAM_RELEASE should be set TRUE if Classic Bluetooth is enabled
|
BT_DRAM_RELEASE should be set TRUE if Classic Bluetooth is enabled
|
||||||
|
|
||||||
config BT_DRAM_RELEASE
|
config BT_DRAM_RELEASE
|
||||||
bool "Release DRAM from Classic BT controller"
|
bool "Release DRAM from Classic BT controller"
|
||||||
depends on BT_ENABLED
|
depends on BT_ENABLED
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
This option should only be used when BLE only.
|
This option should only be used when BLE only.
|
||||||
Open this option will release about 30K DRAM from Classic BT.
|
Open this option will release about 30K DRAM from Classic BT.
|
||||||
The released DRAM will be used as system heap memory.
|
The released DRAM will be used as system heap memory.
|
||||||
|
|
||||||
# Memory reserved at start of DRAM for Bluetooth stack
|
# Memory reserved at start of DRAM for Bluetooth stack
|
||||||
config BT_RESERVE_DRAM
|
config BT_RESERVE_DRAM
|
||||||
|
@ -22,15 +22,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
// #include <sys/stat.h>
|
|
||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "bt_trace.h"
|
#include "bt_trace.h"
|
||||||
|
|
||||||
#define CONFIG_FILE_MAX_SIZE (512)
|
#define CONFIG_FILE_MAX_SIZE (1024)
|
||||||
#define CONFIG_KEY "cfg_key1"
|
#define CONFIG_KEY "bt_cfg_key"
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *key;
|
char *key;
|
||||||
char *value;
|
char *value;
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
ESP-IDF A2DP-SINK
|
ESP-IDF A2DP-SINK demo
|
||||||
=======================
|
======================
|
||||||
|
|
||||||
Demo of A2DP audio sink role
|
Demo of A2DP audio sink role
|
||||||
|
|
||||||
|
This is the demo for user to use ESP_APIs to create a GATT Server.
|
||||||
|
|
||||||
|
Options choose step:
|
||||||
|
1. make menuconfig.
|
||||||
|
2. enter menuconfig "Component config", choose "Bluetooth"
|
||||||
|
3. enter menu Bluetooth, choose "Classic Bluetooth" and do not choose "Release DRAM from Classic BT controller"
|
||||||
|
4. choose your options.
|
||||||
|
|
||||||
|
After the program started, other bluetooth devices such as smart phones can discover this device named "ESP_SPEAKER", and after connection is established, audio data can be transmitted and there will occur a count of audio data packets printed.
|
||||||
|
@ -73,7 +73,7 @@ static void bt_app_task_handler(void *arg)
|
|||||||
bt_app_msg_t msg;
|
bt_app_msg_t msg;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (pdTRUE == xQueueReceive(bt_app_task_queue, &msg, (portTickType)portMAX_DELAY)) {
|
if (pdTRUE == xQueueReceive(bt_app_task_queue, &msg, (portTickType)portMAX_DELAY)) {
|
||||||
BT_APP_TRACE_EVENT("btapp handle evt, sig 0x%x, 0x%x\n", msg.sig, msg.event);
|
BT_APP_TRACE_EVENT("btapp handle evt, sig 0x%x, 0x%x\n", msg.sig, msg.event);
|
||||||
switch (msg.sig) {
|
switch (msg.sig) {
|
||||||
case BT_APP_SIG_CONTEXT_SWITCH:
|
case BT_APP_SIG_CONTEXT_SWITCH:
|
||||||
bt_app_context_switched(&msg);
|
bt_app_context_switched(&msg);
|
@ -2,13 +2,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/timers.h"
|
#include "freertos/timers.h"
|
||||||
|
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
|
||||||
#include "bt_app_common.h"
|
#include "bt_app_common.h"
|
||||||
#include "esp_bt_main.h"
|
#include "esp_bt_main.h"
|
||||||
#include "esp_bt_device.h"
|
#include "esp_bt_device.h"
|
||||||
@ -16,47 +13,49 @@
|
|||||||
#include "esp_a2dp_api.h"
|
#include "esp_a2dp_api.h"
|
||||||
#include "esp_avrc_api.h"
|
#include "esp_avrc_api.h"
|
||||||
|
|
||||||
static uint32_t m_pkt_cnt = 0;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BT_APP_EVT_STACK_ON = 0xa0,
|
BT_APP_EVT_STACK_ON = 0xa0,
|
||||||
BT_APP_EVT_MAX
|
BT_APP_EVT_MAX
|
||||||
} bt_app_evt_t;
|
} bt_app_evt_t;
|
||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
esp_a2d_cb_param_t a2d;
|
esp_a2d_cb_param_t a2d;
|
||||||
esp_avrc_ct_cb_event_t rc;
|
esp_avrc_ct_cb_event_t rc;
|
||||||
} bt_app_evt_arg;
|
} bt_app_evt_arg;
|
||||||
|
|
||||||
|
|
||||||
|
static uint32_t m_pkt_cnt = 0;
|
||||||
static esp_a2d_audio_state_t m_audio_state = ESP_A2D_AUDIO_STATE_STOPPED;
|
static esp_a2d_audio_state_t m_audio_state = ESP_A2D_AUDIO_STATE_STOPPED;
|
||||||
|
|
||||||
static void bt_app_handle_evt(uint16_t event, void *p_param);
|
static void bt_app_handle_evt(uint16_t event, void *p_param);
|
||||||
|
|
||||||
static void bt_app_handle_rc_evt(uint16_t event, void *p_param);
|
static void bt_app_handle_rc_evt(uint16_t event, void *p_param);
|
||||||
|
static void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
|
||||||
|
static void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len);
|
||||||
|
static void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
|
||||||
|
static void bt_app_handle_evt(uint16_t event, void *p_param);
|
||||||
|
|
||||||
static void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
|
static void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
|
||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ESP_A2D_CONNECTION_STATE_EVT:
|
case ESP_A2D_CONNECTION_STATE_EVT:
|
||||||
case ESP_A2D_AUDIO_STATE_EVT:
|
case ESP_A2D_AUDIO_STATE_EVT:
|
||||||
case ESP_A2D_AUDIO_CFG_EVT:
|
case ESP_A2D_AUDIO_CFG_EVT: {
|
||||||
{
|
bt_app_transfer_context(bt_app_handle_evt, event, param, sizeof(bt_app_evt_arg), NULL);
|
||||||
bt_app_transfer_context(bt_app_handle_evt, event, param, sizeof(bt_app_evt_arg), NULL);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d\n", event);
|
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d===\n", event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
|
static void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
|
||||||
{
|
{
|
||||||
if (++m_pkt_cnt % 50 == 0) {
|
if (++m_pkt_cnt % 100 == 0) {
|
||||||
BT_APP_TRACE_ERROR("audio data pkt cnt %u\n", m_pkt_cnt);
|
BT_APP_TRACE_ERROR("audio data pkt cnt %u\n", m_pkt_cnt);
|
||||||
}
|
}
|
||||||
// EspAudioPlayerStreamWrite((uint8_t *)data, len, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
|
static void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
|
||||||
@ -68,20 +67,20 @@ static void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d\n", event);
|
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d===\n", event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_app_handle_evt(uint16_t event, void *p_param)
|
static void bt_app_handle_evt(uint16_t event, void *p_param)
|
||||||
{
|
{
|
||||||
BT_APP_TRACE_DEBUG("bt_app_handle_evt 0x%x\n", event);
|
BT_APP_TRACE_DEBUG("===bt_app_handle_evt 0x%x===\n", event);
|
||||||
esp_a2d_cb_param_t *a2d = NULL;
|
esp_a2d_cb_param_t *a2d = NULL;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case BT_APP_EVT_STACK_ON: {
|
case BT_APP_EVT_STACK_ON: {
|
||||||
char *dev_name = "ESP_SPEAKER";
|
char *dev_name = "ESP_SPEAKER";
|
||||||
|
|
||||||
esp_bt_dev_set_device_name(dev_name);
|
esp_bt_dev_set_device_name(dev_name);
|
||||||
|
|
||||||
esp_a2d_register_callback(&bt_app_a2d_cb);
|
esp_a2d_register_callback(&bt_app_a2d_cb);
|
||||||
esp_a2d_register_data_callback(bt_app_a2d_data_cb);
|
esp_a2d_register_data_callback(bt_app_a2d_data_cb);
|
||||||
@ -107,18 +106,15 @@ static void bt_app_handle_evt(uint16_t event, void *p_param)
|
|||||||
}
|
}
|
||||||
case ESP_A2D_AUDIO_CFG_EVT: {
|
case ESP_A2D_AUDIO_CFG_EVT: {
|
||||||
a2d = (esp_a2d_cb_param_t *)(p_param);
|
a2d = (esp_a2d_cb_param_t *)(p_param);
|
||||||
BT_APP_TRACE_EVENT("===a2dp audio_cfg_cb type %d ===\n", a2d->audio_cfg.mcc.type);
|
BT_APP_TRACE_EVENT("===a2dp audio_cfg_cb type %d===\n", a2d->audio_cfg.mcc.type);
|
||||||
|
// for now only SBC stream is supported
|
||||||
if (a2d->audio_cfg.mcc.type == ESP_A2D_MCT_SBC) {
|
if (a2d->audio_cfg.mcc.type == ESP_A2D_MCT_SBC) {
|
||||||
// temporarily hardcoded the PCM configuaration
|
|
||||||
BT_APP_TRACE_EVENT("configure audio player\n");
|
BT_APP_TRACE_EVENT("configure audio player\n");
|
||||||
// EspAudioPlayerStreamCfg(StreamSampleRate_44k, 2, StreamBitLen_16BIT);
|
|
||||||
// EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
|
|
||||||
// EspAudio_SetVolume(99);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BT_APP_TRACE_ERROR("===application invalid event: %d\n", event);
|
BT_APP_TRACE_ERROR("===application invalid event: %d===\n", event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +136,7 @@ void bt_app_handle_rc_evt(uint16_t event, void *p_param)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BT_APP_TRACE_ERROR("===application invalid event: %d\n", event);
|
BT_APP_TRACE_ERROR("===application invalid event: %d===\n", event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ extern int bt_app_trace_level;
|
|||||||
|
|
||||||
#define BT_APP_TRACE_ERROR(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_ERROR) BT_APP_PRINTF(fmt, ## args);}
|
#define BT_APP_TRACE_ERROR(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_ERROR) BT_APP_PRINTF(fmt, ## args);}
|
||||||
#define BT_APP_TRACE_WARNING(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_WARNING) BT_APP_PRINTF(fmt, ## args);}
|
#define BT_APP_TRACE_WARNING(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_WARNING) BT_APP_PRINTF(fmt, ## args);}
|
||||||
#define BT_APP_TRACE_API(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_API) BT_APP_PRINTF(fmt, ## args);}
|
#define BT_APP_TRACE_API(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_API) BT_APP_PRINTF(fmt, ## args);}
|
||||||
#define BT_APP_TRACE_EVENT(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_EVENT) BT_APP_PRINTF(fmt, ## args);}
|
#define BT_APP_TRACE_EVENT(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_EVENT) BT_APP_PRINTF(fmt, ## args);}
|
||||||
#define BT_APP_TRACE_DEBUG(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_DEBUG) BT_APP_PRINTF(fmt, ## args);}
|
#define BT_APP_TRACE_DEBUG(fmt, args...) {if (bt_app_trace_level >= BT_APP_TRACE_LEVEL_DEBUG) BT_APP_PRINTF(fmt, ## args);}
|
||||||
|
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
// #include "EspAudio.h"
|
|
||||||
|
|
||||||
extern void bte_main_boot_entry(void *);
|
extern void bte_main_boot_entry(void *);
|
||||||
extern void bt_app_task_start_up(void);
|
extern void bt_app_task_start_up(void);
|
||||||
@ -17,9 +16,6 @@ extern void bt_app_core_start(void);
|
|||||||
void app_main()
|
void app_main()
|
||||||
{
|
{
|
||||||
nvs_flash_init();
|
nvs_flash_init();
|
||||||
// system_init();
|
|
||||||
// printf("Free memory: %d bytes\n", system_get_free_heap_size());
|
|
||||||
// EspAudio_Init();
|
|
||||||
esp_bt_controller_init();
|
esp_bt_controller_init();
|
||||||
|
|
||||||
if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) {
|
if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) {
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright 2010-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 "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "freertos/queue.h"
|
|
||||||
#include "string.h"
|
|
||||||
#include "stdlib.h"
|
|
||||||
|
|
||||||
void psram_cache_enable(void);
|
|
||||||
|
|
||||||
void psram_cache_memcpy(uint8_t *dst, uint8_t *src, uint16_t len);
|
|
6
examples/bluetooth/a2dp_sink/sdkconfig.defaults
Normal file
6
examples/bluetooth/a2dp_sink/sdkconfig.defaults
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Override some defaults so BT stack is enabled and
|
||||||
|
# Classic BT is enabled and BT_DRAM_RELEASE is disabled
|
||||||
|
CONFIG_BT_ENABLED=y
|
||||||
|
CONFIG_CLASSIC_BT_ENABLED=y
|
||||||
|
# CONFIG_BT_DRAM_RELEASE is not set
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user