1. Add more notification events to the enum according to the event list in AVRCP specification. 2. Add API and callback events for basic AVRCP target functionalities to do init, deinit, callback-registration, connection status indication. 3. Implement API to set/get supported PASSTHROUGH command on local AVRCP TG, implement callback events for remote passthrough command indication. 4. Implement API to set/get supported notification eventIDs on local AVRCP TG, implement API to send event notifications to remote CT. \ Currently supported event in TG only includes ESP_AVRC_RN_VOLUME_CHANGE(0xd), which can be extended in later commits. 5. Implement callback events for SetAbsoluteVolume command indication on TG. 6. Add limitation of event_ids supported in RegisterNotification command in CT. The supported event_ids include: \ ESP_AVRC_RN_PLAY_STATUS_CHANGE(0x1), ESP_AVRC_RN_TRACK_CHANGE(0x2), ESP_AVRC_RN_PLAY_POS_CHANGE(0x5), ESP_AVRC_RN_VOLUME_CHANGE(0xd). 7. Add feature bit mask in parameter of callback event ESP_AVRC_CT_REMOTE_FEATURES_EVT for peer feature information got from SDP. 8. Add API and callback event to AVRCP CT to retrieve remote TG's supported notification event capabilities. 9. Modify data type for parameter of callback event ESP_AVRC_CT_CHANGE_NOTIFY_EVT. 10. Change AVRCP version from 1.3 to 1.4 for compatibility cause in using AbsoluteVolume feature. 11. Modify local AVRCP device to be category 1 as CT and category 2 as TG that applies to bluetooth headphones or speakers. 12. Update the use of AVRCP APIs and events in the two examples: a2dp_sink and a2dp_gatts_coex, which include the demo of volume control and notification.
113 lines
3.2 KiB
C
113 lines
3.2 KiB
C
/*
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include "freertos/xtensa_api.h"
|
|
#include "freertos/FreeRTOSConfig.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/queue.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_log.h"
|
|
#include "bt_app_core.h"
|
|
|
|
static void bt_app_task_handler(void *arg);
|
|
static bool bt_app_send_msg(bt_app_msg_t *msg);
|
|
static void bt_app_work_dispatched(bt_app_msg_t *msg);
|
|
|
|
static xQueueHandle s_bt_app_task_queue = NULL;
|
|
static xTaskHandle s_bt_app_task_handle = NULL;
|
|
|
|
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
|
|
{
|
|
ESP_LOGD(BT_APP_CORE_TAG, "%s event 0x%x, param len %d", __func__, event, param_len);
|
|
|
|
bt_app_msg_t msg;
|
|
memset(&msg, 0, sizeof(bt_app_msg_t));
|
|
|
|
msg.sig = BT_APP_SIG_WORK_DISPATCH;
|
|
msg.event = event;
|
|
msg.cb = p_cback;
|
|
|
|
if (param_len == 0) {
|
|
return bt_app_send_msg(&msg);
|
|
} else if (p_params && param_len > 0) {
|
|
if ((msg.param = malloc(param_len)) != NULL) {
|
|
memcpy(msg.param, p_params, param_len);
|
|
/* check if caller has provided a copy callback to do the deep copy */
|
|
if (p_copy_cback) {
|
|
p_copy_cback(&msg, msg.param, p_params);
|
|
}
|
|
return bt_app_send_msg(&msg);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static bool bt_app_send_msg(bt_app_msg_t *msg)
|
|
{
|
|
if (msg == NULL) {
|
|
return false;
|
|
}
|
|
|
|
if (xQueueSend(s_bt_app_task_queue, msg, 10 / portTICK_RATE_MS) != pdTRUE) {
|
|
ESP_LOGE(BT_APP_CORE_TAG, "%s xQueue send failed", __func__);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static void bt_app_work_dispatched(bt_app_msg_t *msg)
|
|
{
|
|
if (msg->cb) {
|
|
msg->cb(msg->event, msg->param);
|
|
}
|
|
}
|
|
|
|
static void bt_app_task_handler(void *arg)
|
|
{
|
|
bt_app_msg_t msg;
|
|
for (;;) {
|
|
if (pdTRUE == xQueueReceive(s_bt_app_task_queue, &msg, (portTickType)portMAX_DELAY)) {
|
|
ESP_LOGD(BT_APP_CORE_TAG, "%s, sig 0x%x, 0x%x", __func__, msg.sig, msg.event);
|
|
switch (msg.sig) {
|
|
case BT_APP_SIG_WORK_DISPATCH:
|
|
bt_app_work_dispatched(&msg);
|
|
break;
|
|
default:
|
|
ESP_LOGW(BT_APP_CORE_TAG, "%s, unhandled sig: %d", __func__, msg.sig);
|
|
break;
|
|
} // switch (msg.sig)
|
|
|
|
if (msg.param) {
|
|
free(msg.param);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void bt_app_task_start_up(void)
|
|
{
|
|
s_bt_app_task_queue = xQueueCreate(10, sizeof(bt_app_msg_t));
|
|
xTaskCreate(bt_app_task_handler, "BtAppT", 3072, NULL, configMAX_PRIORITIES - 3, &s_bt_app_task_handle);
|
|
return;
|
|
}
|
|
|
|
void bt_app_task_shut_down(void)
|
|
{
|
|
if (s_bt_app_task_handle) {
|
|
vTaskDelete(s_bt_app_task_handle);
|
|
s_bt_app_task_handle = NULL;
|
|
}
|
|
if (s_bt_app_task_queue) {
|
|
vQueueDelete(s_bt_app_task_queue);
|
|
s_bt_app_task_queue = NULL;
|
|
}
|
|
}
|