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
@ -22,15 +22,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
// #include <sys/stat.h>
|
||||
|
||||
#include "allocator.h"
|
||||
#include "config.h"
|
||||
#include "list.h"
|
||||
#include "bt_trace.h"
|
||||
|
||||
#define CONFIG_FILE_MAX_SIZE (512)
|
||||
#define CONFIG_KEY "cfg_key1"
|
||||
#define CONFIG_FILE_MAX_SIZE (1024)
|
||||
#define CONFIG_KEY "bt_cfg_key"
|
||||
typedef struct {
|
||||
char *key;
|
||||
char *value;
|
||||
|
@ -1,5 +1,14 @@
|
||||
ESP-IDF A2DP-SINK
|
||||
=======================
|
||||
ESP-IDF A2DP-SINK demo
|
||||
======================
|
||||
|
||||
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.
|
||||
|
@ -2,13 +2,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "bt_app_common.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
@ -16,47 +13,49 @@
|
||||
#include "esp_a2dp_api.h"
|
||||
#include "esp_avrc_api.h"
|
||||
|
||||
static uint32_t m_pkt_cnt = 0;
|
||||
|
||||
|
||||
typedef enum {
|
||||
BT_APP_EVT_STACK_ON = 0xa0,
|
||||
BT_APP_EVT_MAX
|
||||
} bt_app_evt_t;
|
||||
|
||||
|
||||
typedef union {
|
||||
esp_a2d_cb_param_t a2d;
|
||||
esp_avrc_ct_cb_event_t rc;
|
||||
} 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 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_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)
|
||||
{
|
||||
switch (event) {
|
||||
case ESP_A2D_CONNECTION_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);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d\n", event);
|
||||
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d===\n", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
// 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)
|
||||
@ -68,14 +67,14 @@ static void bt_app_rc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d\n", event);
|
||||
BT_APP_TRACE_ERROR("===a2dp invalid cb event: %d===\n", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
switch (event) {
|
||||
case BT_APP_EVT_STACK_ON: {
|
||||
@ -107,18 +106,15 @@ static void bt_app_handle_evt(uint16_t event, void *p_param)
|
||||
}
|
||||
case ESP_A2D_AUDIO_CFG_EVT: {
|
||||
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) {
|
||||
// temporarily hardcoded the PCM configuaration
|
||||
BT_APP_TRACE_EVENT("configure audio player\n");
|
||||
// EspAudioPlayerStreamCfg(StreamSampleRate_44k, 2, StreamBitLen_16BIT);
|
||||
// EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
|
||||
// EspAudio_SetVolume(99);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_APP_TRACE_ERROR("===application invalid event: %d\n", event);
|
||||
BT_APP_TRACE_ERROR("===application invalid event: %d===\n", event);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -140,7 +136,7 @@ void bt_app_handle_rc_evt(uint16_t event, void *p_param)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BT_APP_TRACE_ERROR("===application invalid event: %d\n", event);
|
||||
BT_APP_TRACE_ERROR("===application invalid event: %d===\n", event);
|
||||
break;
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_system.h"
|
||||
// #include "EspAudio.h"
|
||||
|
||||
extern void bte_main_boot_entry(void *);
|
||||
extern void bt_app_task_start_up(void);
|
||||
@ -17,9 +16,6 @@ extern void bt_app_core_start(void);
|
||||
void app_main()
|
||||
{
|
||||
nvs_flash_init();
|
||||
// system_init();
|
||||
// printf("Free memory: %d bytes\n", system_get_free_heap_size());
|
||||
// EspAudio_Init();
|
||||
esp_bt_controller_init();
|
||||
|
||||
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