mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component/bt: modify AVRCP APIs to post events and arguments to be handled by BTC task
This commit is contained in:
parent
af13acdc29
commit
e6f36f2dc5
91
components/bt/bluedroid/api/esp_avrc_api.c
Normal file
91
components/bt/bluedroid/api/esp_avrc_api.c
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// 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 <string.h>
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_avrc_api.h"
|
||||||
|
#include "esp_bt_main.h"
|
||||||
|
#include "btc_manage.h"
|
||||||
|
#include "btc_avrc.h"
|
||||||
|
|
||||||
|
esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback)
|
||||||
|
{
|
||||||
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback == NULL) {
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
btc_profile_cb_set(BTC_PID_AVRC, callback);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_avrc_ct_init(void)
|
||||||
|
{
|
||||||
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
btc_msg_t msg;
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
|
msg.pid = BTC_PID_AVRC;
|
||||||
|
msg.act = BTC_AVRC_CTRL_API_INIT_EVT;
|
||||||
|
|
||||||
|
/* Switch to BTC context */
|
||||||
|
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
||||||
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_avrc_ct_deinit(void)
|
||||||
|
{
|
||||||
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
btc_msg_t msg;
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
|
msg.pid = BTC_PID_AVRC;
|
||||||
|
msg.act = BTC_AVRC_CTRL_API_DEINIT_EVT;
|
||||||
|
|
||||||
|
/* Switch to BTC context */
|
||||||
|
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
||||||
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
|
||||||
|
{
|
||||||
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
btc_msg_t msg;
|
||||||
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
|
msg.pid = BTC_PID_AVRC;
|
||||||
|
msg.act = BTC_AVRC_CTRL_API_SND_PTCMD_EVT;
|
||||||
|
|
||||||
|
btc_avrc_args_t arg;
|
||||||
|
memset(&arg, 0, sizeof(btc_avrc_args_t));
|
||||||
|
|
||||||
|
arg.pt_cmd.tl = tl;
|
||||||
|
arg.pt_cmd.key_code = key_code;
|
||||||
|
arg.pt_cmd.key_state = key_state;
|
||||||
|
|
||||||
|
/* Switch to BTC context */
|
||||||
|
bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_avrc_args_t), NULL);
|
||||||
|
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||||
|
}
|
@ -110,7 +110,7 @@ esp_err_t esp_avrc_ct_init(void);
|
|||||||
* @brief This function is called to deinit AVRCP controller module
|
* @brief This function is called to deinit AVRCP controller module
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void esp_avrc_ct_deinit(void);
|
esp_err_t esp_avrc_ct_deinit(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "btc_dm.h"
|
#include "btc_dm.h"
|
||||||
#include "btc_profile_queue.h"
|
#include "btc_profile_queue.h"
|
||||||
#include "btc_av.h"
|
#include "btc_av.h"
|
||||||
|
#include "btc_avrc.h"
|
||||||
#include "bta_gatt_api.h"
|
#include "bta_gatt_api.h"
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +49,8 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
|
|||||||
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
||||||
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
||||||
[BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL },
|
[BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL },
|
||||||
[BTC_PID_A2DP] = {btc_a2dp_evt_handler, btc_a2dp_evt_handler }
|
[BTC_PID_A2DP] = {btc_a2dp_evt_handler, btc_a2dp_evt_handler },
|
||||||
|
[BTC_PID_AVRC] = {btc_avrc_evt_handler, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -48,6 +48,7 @@ typedef enum {
|
|||||||
BTC_PID_DM_SEC,
|
BTC_PID_DM_SEC,
|
||||||
BTC_PID_PRF_QUE,
|
BTC_PID_PRF_QUE,
|
||||||
BTC_PID_A2DP,
|
BTC_PID_A2DP,
|
||||||
|
BTC_PID_AVRC,
|
||||||
BTC_PID_NUM,
|
BTC_PID_NUM,
|
||||||
} btc_pid_t; //btc profile id
|
} btc_pid_t; //btc profile id
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "btc_util.h"
|
#include "btc_util.h"
|
||||||
#include "btc_av.h"
|
#include "btc_av.h"
|
||||||
#include "btc_avrc.h"
|
#include "btc_avrc.h"
|
||||||
|
#include "btc_manage.h"
|
||||||
#include "uinput.h"
|
#include "uinput.h"
|
||||||
#include "esp_avrc_api.h"
|
#include "esp_avrc_api.h"
|
||||||
|
|
||||||
@ -181,15 +182,6 @@ static void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg);
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
static btc_rc_cb_t btc_rc_vb;
|
static btc_rc_cb_t btc_rc_vb;
|
||||||
static btrc_callbacks_t *bt_rc_callbacks = NULL;
|
static btrc_callbacks_t *bt_rc_callbacks = NULL;
|
||||||
// static btrc_ctrl_callbacks_t *bt_rc_ctrl_callbacks = NULL;
|
|
||||||
static esp_avrc_ct_cb_t bt_rc_ctrl_callback = NULL;
|
|
||||||
|
|
||||||
// TODO: need protection against race
|
|
||||||
#define BTC_AVRC_CT_CB_TO_APP(_event, _param) do { \
|
|
||||||
if (bt_rc_ctrl_callback) { \
|
|
||||||
bt_rc_ctrl_callback(_event, _param); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
** Static functions
|
** Static functions
|
||||||
@ -205,6 +197,14 @@ extern BOOLEAN btc_hf_call_terminated_recently();
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
** Local uinput helper functions
|
** Local uinput helper functions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
static inline void btc_avrc_ct_cb_to_app(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
|
||||||
|
{
|
||||||
|
esp_a2d_cb_t btc_avrc_cb = (esp_a2d_cb_t)btc_profile_cb_get(BTC_PID_AVRC);
|
||||||
|
if (btc_avrc_cb) {
|
||||||
|
btc_avrc_cb(event, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void send_key (int fd, uint16_t key, int pressed)
|
void send_key (int fd, uint16_t key, int pressed)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("%s fd:%d key:%u pressed:%d, func not implemented", __FUNCTION__,
|
LOG_DEBUG("%s fd:%d key:%u pressed:%d, func not implemented", __FUNCTION__,
|
||||||
@ -337,7 +337,7 @@ static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
|
|||||||
param.conn_stat.connected = true;
|
param.conn_stat.connected = true;
|
||||||
param.conn_stat.feat_mask = btc_rc_vb.rc_features;
|
param.conn_stat.feat_mask = btc_rc_vb.rc_features;
|
||||||
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
|
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
|
||||||
BTC_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -396,7 +396,7 @@ static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
|
|||||||
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
||||||
param.conn_stat.connected = false;
|
param.conn_stat.connected = false;
|
||||||
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
|
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
|
||||||
BTC_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -547,7 +547,7 @@ static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
|
|||||||
param.psth_rsp.tl = p_remote_rsp->label;
|
param.psth_rsp.tl = p_remote_rsp->label;
|
||||||
param.psth_rsp.key_code = p_remote_rsp->rc_id;
|
param.psth_rsp.key_code = p_remote_rsp->rc_id;
|
||||||
param.psth_rsp.key_state = key_state;
|
param.psth_rsp.key_state = key_state;
|
||||||
BTC_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m);
|
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m);
|
||||||
} while (0);
|
} while (0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1123,6 +1123,7 @@ static void btc_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, U
|
|||||||
** AVRCP API Functions
|
** AVRCP API Functions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if 0
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
** Function esp_avrc_ct_register_callback
|
** Function esp_avrc_ct_register_callback
|
||||||
@ -1140,28 +1141,25 @@ esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback)
|
|||||||
bt_rc_ctrl_callback = callback;
|
bt_rc_ctrl_callback = callback;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
** Function esp_avrc_ct_init
|
** Function btc_avrc_ct_init
|
||||||
**
|
**
|
||||||
** Description Initializes the AVRC interface
|
** Description Initializes the AVRC interface
|
||||||
**
|
**
|
||||||
** Returns esp_err_t
|
** Returns esp_err_t
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
esp_err_t esp_avrc_ct_init(void)
|
static void btc_avrc_ct_init(void)
|
||||||
{
|
{
|
||||||
LOG_INFO("## %s ##", __FUNCTION__);
|
LOG_INFO("## %s ##", __FUNCTION__);
|
||||||
esp_err_t result = ESP_OK;
|
|
||||||
|
|
||||||
memset (&btc_rc_vb, 0, sizeof(btc_rc_vb));
|
memset (&btc_rc_vb, 0, sizeof(btc_rc_vb));
|
||||||
btc_rc_vb.rc_vol_label=MAX_LABEL;
|
btc_rc_vb.rc_vol_label=MAX_LABEL;
|
||||||
btc_rc_vb.rc_volume=MAX_VOLUME;
|
btc_rc_vb.rc_volume=MAX_VOLUME;
|
||||||
lbl_init();
|
lbl_init();
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1296,20 +1294,16 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
|
|||||||
** Returns void
|
** Returns void
|
||||||
**
|
**
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void esp_avrc_ct_deinit(void)
|
static void btc_avrc_ct_deinit(void)
|
||||||
{
|
{
|
||||||
LOG_INFO("## %s ##", __FUNCTION__);
|
LOG_INFO("## %s ##", __FUNCTION__);
|
||||||
|
|
||||||
if (bt_rc_ctrl_callback)
|
|
||||||
{
|
|
||||||
bt_rc_ctrl_callback = NULL;
|
|
||||||
}
|
|
||||||
memset(&btc_rc_vb, 0, sizeof(btc_rc_cb_t));
|
memset(&btc_rc_vb, 0, sizeof(btc_rc_cb_t));
|
||||||
lbl_destroy();
|
lbl_destroy();
|
||||||
LOG_INFO("## %s ## completed", __FUNCTION__);
|
LOG_INFO("## %s ## completed", __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
|
static bt_status_t btc_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
|
||||||
{
|
{
|
||||||
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
|
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
|
||||||
if (tl >= 16 ||
|
if (tl >= 16 ||
|
||||||
@ -1336,11 +1330,7 @@ esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t
|
|||||||
LOG_DEBUG("%s: feature not enabled", __FUNCTION__);
|
LOG_DEBUG("%s: feature not enabled", __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (status) {
|
return status;
|
||||||
case BT_STATUS_SUCCESS: return ESP_OK;
|
|
||||||
case BT_STATUS_UNSUPPORTED: return ESP_ERR_NOT_SUPPORTED;
|
|
||||||
default: return ESP_FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -1495,3 +1485,27 @@ void lbl_destroy()
|
|||||||
{
|
{
|
||||||
pthread_mutex_destroy(&(device.lbllock));
|
pthread_mutex_destroy(&(device.lbllock));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void btc_avrc_evt_handler(btc_msg_t *msg)
|
||||||
|
{
|
||||||
|
btc_avrc_args_t *arg = (btc_avrc_args_t *)(msg->arg);
|
||||||
|
switch (msg->act) {
|
||||||
|
case BTC_AVRC_CTRL_API_INIT_EVT: {
|
||||||
|
btc_avrc_ct_init();
|
||||||
|
// todo: callback to application
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BTC_AVRC_CTRL_API_DEINIT_EVT: {
|
||||||
|
btc_avrc_ct_deinit();
|
||||||
|
// todo: callback to application
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BTC_AVRC_CTRL_API_SND_PTCMD_EVT: {
|
||||||
|
btc_avrc_ct_send_passthrough_cmd(arg->pt_cmd.tl, arg->pt_cmd.key_code, arg->pt_cmd.key_state);
|
||||||
|
// todo: callback to application
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
LOG_WARN("%s : unhandled event: %d\n", __FUNCTION__, msg->act);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -107,6 +107,28 @@ typedef struct {
|
|||||||
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
|
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
|
||||||
} btrc_player_settings_t;
|
} btrc_player_settings_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BTC_AVRC_CTRL_API_INIT_EVT = 0,
|
||||||
|
BTC_AVRC_CTRL_API_DEINIT_EVT,
|
||||||
|
BTC_AVRC_CTRL_API_SND_PTCMD_EVT
|
||||||
|
} btc_avrc_act_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t tl; /* transaction label */
|
||||||
|
uint8_t key_code;
|
||||||
|
uint8_t key_state;
|
||||||
|
} pt_cmd_t;
|
||||||
|
|
||||||
|
/* btc_avrc_args_t */
|
||||||
|
typedef union {
|
||||||
|
// BTC_AVRC_CTRL_API_SND_PT_CMD_EVT
|
||||||
|
struct {
|
||||||
|
uint8_t tl;
|
||||||
|
uint8_t key_code;
|
||||||
|
uint8_t key_state;
|
||||||
|
} pt_cmd;
|
||||||
|
} btc_avrc_args_t;
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
{
|
{
|
||||||
btrc_play_status_t play_status;
|
btrc_play_status_t play_status;
|
||||||
@ -266,22 +288,22 @@ typedef struct {
|
|||||||
} btrc_interface_t;
|
} btrc_interface_t;
|
||||||
|
|
||||||
|
|
||||||
|
/** BT-RC Controller callback structure. */
|
||||||
|
|
||||||
typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
|
typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
|
||||||
|
|
||||||
typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
|
typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
|
||||||
|
|
||||||
/** BT-RC Controller callback structure. */
|
|
||||||
typedef struct {
|
|
||||||
/** set to sizeof(BtRcCallbacks) */
|
|
||||||
size_t size;
|
|
||||||
btrc_passthrough_rsp_callback passthrough_rsp_cb;
|
|
||||||
btrc_connection_state_callback connection_state_cb;
|
|
||||||
} btrc_ctrl_callbacks_t;
|
|
||||||
|
|
||||||
void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data);
|
void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data);
|
||||||
|
|
||||||
BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr);
|
BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr);
|
||||||
|
|
||||||
void btc_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
|
void btc_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** BTC AVRC API
|
||||||
|
********************************************************************************/
|
||||||
|
void btc_avrc_evt_handler(btc_msg_t *msg);
|
||||||
|
|
||||||
#endif /* __BTC_AVRC_H__ */
|
#endif /* __BTC_AVRC_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user