2016-11-04 03:08:30 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
|
|
|
|
#include "bt_app_common.h"
|
|
|
|
#include "btif_stack_manager.h"
|
2016-11-26 00:09:55 -05:00
|
|
|
#include "esp_gap_bt_api.h"
|
2016-11-04 03:08:30 -04:00
|
|
|
#include "bta_api.h"
|
2016-12-01 01:57:44 -05:00
|
|
|
// #include "bt_av.h"
|
|
|
|
#include "esp_a2dp_api.h"
|
2016-11-15 01:32:22 -05:00
|
|
|
|
|
|
|
/* utl_set_device_class() */
|
|
|
|
#include "utl.h"
|
2016-11-04 03:08:30 -04:00
|
|
|
|
|
|
|
#include "alarm.h"
|
|
|
|
typedef enum {
|
|
|
|
BT_APP_EVT_STACK_ON,
|
|
|
|
BT_APP_EVT_STACK_OFF,
|
2016-11-15 01:32:22 -05:00
|
|
|
BT_APP_EVT_AV_OPEN_TO,
|
2016-11-04 03:08:30 -04:00
|
|
|
BT_APP_EVT
|
|
|
|
} tBT_APP_EVT;
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
uint32_t dummy;
|
|
|
|
} tBT_APP_EVT_DATA;
|
|
|
|
|
2016-12-01 01:57:44 -05:00
|
|
|
// extern const btav_interface_t *btif_av_get_sink_interface(void);
|
2016-11-04 03:08:30 -04:00
|
|
|
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data);
|
|
|
|
static void bt_stack_state_changed(bt_state_t state);
|
|
|
|
|
2016-12-01 06:48:51 -05:00
|
|
|
// static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
|
2016-11-04 03:08:30 -04:00
|
|
|
|
|
|
|
static bt_callbacks_t bt_callbacks = {
|
|
|
|
bt_stack_state_changed
|
|
|
|
};
|
|
|
|
|
|
|
|
osi_alarm_t *app_alarm = NULL;
|
|
|
|
|
2016-12-01 06:48:51 -05:00
|
|
|
static void btav_conn_state_cb(esp_a2d_connection_state_t state,
|
2016-12-01 01:57:44 -05:00
|
|
|
esp_bd_addr_t *bd_addr)
|
2016-11-04 03:08:30 -04:00
|
|
|
{
|
2016-12-01 01:57:44 -05:00
|
|
|
LOG_ERROR("===esp_a2dp_conn_state_cb %d ===\n", state);
|
2016-11-15 01:32:22 -05:00
|
|
|
(void) bd_addr;
|
2016-11-04 03:08:30 -04:00
|
|
|
}
|
|
|
|
|
2016-12-01 06:48:51 -05:00
|
|
|
static void btav_audio_state_cb(esp_a2d_audio_state_t state, esp_bd_addr_t *bd_addr)
|
2016-11-15 01:32:22 -05:00
|
|
|
{
|
2016-12-01 01:57:44 -05:00
|
|
|
LOG_ERROR("===esp_a2dp_audio_state_cb %d ===\n", state);
|
2016-11-15 01:32:22 -05:00
|
|
|
(void) bd_addr;
|
|
|
|
}
|
|
|
|
|
2016-12-01 01:57:44 -05:00
|
|
|
static void btav_audio_cfg_cb(esp_bd_addr_t *bd_addr, uint32_t sample_rate, uint8_t channel_count)
|
2016-11-15 01:32:22 -05:00
|
|
|
{
|
2016-12-01 01:57:44 -05:00
|
|
|
LOG_ERROR("===esp_a2dp_audio_cfg_cb %d %d===\n", sample_rate, channel_count);
|
2016-11-15 01:32:22 -05:00
|
|
|
(void) bd_addr;
|
|
|
|
}
|
|
|
|
|
2016-12-01 06:48:51 -05:00
|
|
|
static esp_a2d_callbacks_t btav_cbs = {
|
2016-11-15 01:32:22 -05:00
|
|
|
btav_conn_state_cb,
|
|
|
|
btav_audio_state_cb,
|
|
|
|
btav_audio_cfg_cb
|
|
|
|
};
|
|
|
|
|
|
|
|
static void btav_open_to(void *context)
|
2016-11-04 03:08:30 -04:00
|
|
|
{
|
|
|
|
(void)(context);
|
2016-11-15 01:32:22 -05:00
|
|
|
bt_stack_evt(BT_APP_EVT_AV_OPEN_TO, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void btav_set_device_class(void)
|
|
|
|
{
|
|
|
|
tBTA_UTL_COD cod;
|
|
|
|
memset(&cod, 0, sizeof(tBTA_UTL_COD));
|
|
|
|
cod.major = BTM_COD_MAJOR_AUDIO;
|
|
|
|
cod.minor = BTM_COD_MINOR_LOUDSPEAKER;
|
|
|
|
cod.service = BTM_COD_SERVICE_CAPTURING | BTM_COD_SERVICE_AUDIO;
|
|
|
|
utl_set_device_class(&cod, BTA_UTL_SET_COD_ALL);
|
|
|
|
LOG_ERROR("set class of device: major 0x%x, minor 0x%x, service 0x%x\n",
|
|
|
|
cod.major, cod.minor, cod.service);
|
2016-11-04 03:08:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bt_app_stack_evt(UINT16 event, char *p_param)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case BT_APP_EVT_STACK_ON: {
|
2016-11-26 00:09:55 -05:00
|
|
|
char *dev_name = "SDP_SERVER_CLIENT";
|
|
|
|
BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
|
2016-11-15 01:32:22 -05:00
|
|
|
btav_set_device_class();
|
2016-11-26 00:09:55 -05:00
|
|
|
BTA_DmSetDeviceName(dev_name);
|
2016-11-04 03:08:30 -04:00
|
|
|
esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
2016-12-01 06:48:51 -05:00
|
|
|
esp_a2d_sink_init(&btav_cbs);
|
2016-12-01 01:57:44 -05:00
|
|
|
// btif_av_get_sink_interface()->init(&btav_cbs);
|
2016-11-26 00:09:55 -05:00
|
|
|
|
2016-11-15 01:32:22 -05:00
|
|
|
// app_alarm = osi_alarm_new("app_alarm", bt_sdp_add_record_to, NULL, 1000, false);
|
|
|
|
app_alarm = osi_alarm_new("app_alarm", btav_open_to, NULL, 1000, false);
|
2016-11-04 03:08:30 -04:00
|
|
|
osi_alarm_set(app_alarm, 1000);
|
|
|
|
}
|
2016-11-26 00:09:55 -05:00
|
|
|
break;
|
2016-11-15 01:32:22 -05:00
|
|
|
case BT_APP_EVT_AV_OPEN_TO: {
|
|
|
|
LOG_ERROR("**BT_APP_EVT_AV_OPEN_TO\n");
|
2016-11-26 00:09:55 -05:00
|
|
|
// btif_av_get_sink_interface()->connect(&peer_bd_addr);
|
2016-11-04 03:08:30 -04:00
|
|
|
osi_alarm_free(app_alarm);
|
|
|
|
app_alarm = NULL;
|
|
|
|
}
|
2016-11-26 00:09:55 -05:00
|
|
|
break;
|
2016-11-04 03:08:30 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
|
|
|
|
{
|
|
|
|
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
2016-11-26 00:09:55 -05:00
|
|
|
bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
|
|
|
|
(void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
|
2016-11-04 03:08:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bt_stack_state_changed(bt_state_t state)
|
|
|
|
{
|
|
|
|
if (state == BT_STATE_ON) {
|
|
|
|
bt_stack_evt(BT_APP_EVT_STACK_ON, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void app_main_entry(void)
|
|
|
|
{
|
|
|
|
bt_status_t stat;
|
|
|
|
stat = BTIF_InitStack(&bt_callbacks);
|
|
|
|
if (stat == BT_STATUS_SUCCESS) {
|
|
|
|
BTIF_EnableStack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|