2017-03-01 03:18:08 -05:00
|
|
|
// 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.
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2017-03-01 03:18:08 -05:00
|
|
|
* Filename: btc_avrc.c
|
2017-01-05 02:43:44 -05:00
|
|
|
*
|
|
|
|
* Description: Bluetooth AVRC implementation
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
#include <string.h>
|
|
|
|
#include "bta_api.h"
|
|
|
|
#include "bta_av_api.h"
|
|
|
|
#include "avrc_defs.h"
|
|
|
|
#include "gki.h"
|
|
|
|
|
2017-03-01 22:47:59 -05:00
|
|
|
#include "btc_common.h"
|
2017-03-07 02:09:52 -05:00
|
|
|
#include "btc_util.h"
|
2017-03-01 03:18:08 -05:00
|
|
|
#include "btc_av.h"
|
|
|
|
#include "btc_avrc.h"
|
2017-03-08 00:48:56 -05:00
|
|
|
#include "btc_manage.h"
|
2017-01-19 02:23:46 -05:00
|
|
|
#include "esp_avrc_api.h"
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** Constants & Macros
|
|
|
|
******************************************************************************/
|
|
|
|
/* for AVRC 1.4 need to change this */
|
|
|
|
#define MAX_RC_NOTIFICATIONS AVRC_EVT_APP_SETTING_CHANGE
|
|
|
|
|
|
|
|
#define MAX_VOLUME 128
|
|
|
|
#define MAX_LABEL 16
|
|
|
|
#define MAX_TRANSACTIONS_PER_SESSION 16
|
|
|
|
#define MAX_CMD_QUEUE_LEN 8
|
|
|
|
|
2017-01-19 02:23:46 -05:00
|
|
|
#define CHECK_ESP_RC_CONNECTED do { \
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("## %s ##", __FUNCTION__); \
|
|
|
|
if (btc_rc_vb.rc_connected == FALSE) { \
|
|
|
|
LOG_WARN("Function %s() called when RC is not connected", __FUNCTION__); \
|
2017-01-19 02:23:46 -05:00
|
|
|
return ESP_ERR_INVALID_STATE; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2017-01-05 02:43:44 -05:00
|
|
|
/*****************************************************************************
|
|
|
|
** Local type definitions
|
|
|
|
******************************************************************************/
|
|
|
|
typedef struct {
|
|
|
|
UINT8 bNotify;
|
|
|
|
UINT8 label;
|
2017-03-01 03:18:08 -05:00
|
|
|
} btc_rc_reg_notifications_t;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UINT8 label;
|
|
|
|
UINT8 ctype;
|
|
|
|
BOOLEAN is_rsp_pending;
|
2017-03-01 03:18:08 -05:00
|
|
|
} btc_rc_cmd_ctxt_t;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
/* TODO : Merge btc_rc_reg_notifications_t and btc_rc_cmd_ctxt_t to a single struct */
|
2017-01-05 02:43:44 -05:00
|
|
|
typedef struct {
|
|
|
|
BOOLEAN rc_connected;
|
|
|
|
UINT8 rc_handle;
|
|
|
|
tBTA_AV_FEAT rc_features;
|
|
|
|
BD_ADDR rc_addr;
|
|
|
|
UINT16 rc_pending_play;
|
2017-03-01 03:18:08 -05:00
|
|
|
btc_rc_cmd_ctxt_t rc_pdu_info[MAX_CMD_QUEUE_LEN];
|
|
|
|
btc_rc_reg_notifications_t rc_notif[MAX_RC_NOTIFICATIONS];
|
2017-01-05 02:43:44 -05:00
|
|
|
unsigned int rc_volume;
|
|
|
|
uint8_t rc_vol_label;
|
2017-03-01 03:18:08 -05:00
|
|
|
} btc_rc_cb_t;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
BOOLEAN in_use;
|
|
|
|
UINT8 lbl;
|
|
|
|
UINT8 handle;
|
|
|
|
} rc_transaction_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
pthread_mutex_t lbllock;
|
|
|
|
rc_transaction_t transaction[MAX_TRANSACTIONS_PER_SESSION];
|
|
|
|
} rc_device_t;
|
|
|
|
|
|
|
|
rc_device_t device;
|
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open);
|
|
|
|
static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close);
|
|
|
|
static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp);
|
2017-03-08 06:25:58 -05:00
|
|
|
|
2017-01-05 02:43:44 -05:00
|
|
|
/*****************************************************************************
|
|
|
|
** Static variables
|
|
|
|
******************************************************************************/
|
2017-03-01 03:18:08 -05:00
|
|
|
static btc_rc_cb_t btc_rc_vb;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** Externs
|
|
|
|
******************************************************************************/
|
|
|
|
/*****************************************************************************
|
2017-03-08 06:25:58 -05:00
|
|
|
** Static functions
|
2017-01-05 02:43:44 -05:00
|
|
|
******************************************************************************/
|
2017-03-08 00:48:56 -05:00
|
|
|
static inline void btc_avrc_ct_cb_to_app(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
|
|
|
|
{
|
2017-03-08 06:25:58 -05:00
|
|
|
esp_avrc_ct_cb_t btc_avrc_cb = (esp_avrc_ct_cb_t)btc_profile_cb_get(BTC_PID_AVRC);
|
2017-03-08 00:48:56 -05:00
|
|
|
if (btc_avrc_cb) {
|
|
|
|
btc_avrc_cb(event, param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 06:25:58 -05:00
|
|
|
static void handle_rc_features(void)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
btrc_remote_features_t rc_features = BTRC_FEAT_NONE;
|
|
|
|
bt_bdaddr_t rc_addr;
|
2017-03-01 03:18:08 -05:00
|
|
|
bdcpy(rc_addr.address, btc_rc_vb.rc_addr);
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
// TODO(eisenbach): If devices need to be blacklisted for absolute
|
|
|
|
// volume, it should be added to device/include/interop_database.h
|
|
|
|
// For now, everything goes... If blacklisting is necessary, exclude
|
|
|
|
// the following bit here:
|
2017-03-01 03:18:08 -05:00
|
|
|
// btc_rc_vb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_features & BTA_AV_FEAT_BROWSE)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
rc_features |= BTRC_FEAT_BROWSE;
|
|
|
|
}
|
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
if ( (btc_rc_vb.rc_features & BTA_AV_FEAT_ADV_CTRL) &&
|
|
|
|
(btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG))
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
|
|
|
|
}
|
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_features & BTA_AV_FEAT_METADATA)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
rc_features |= BTRC_FEAT_METADATA;
|
|
|
|
}
|
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: rc_features=0x%x", __FUNCTION__, rc_features);
|
2017-01-19 02:23:46 -05:00
|
|
|
// todo: uncomment the following line when added the AVRC target role
|
2017-03-01 22:47:59 -05:00
|
|
|
// BTC_HAL_CBACK(bt_rc_callbacks, remote_features_cb, &rc_addr, rc_features)
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Function handle_rc_connect
|
|
|
|
*
|
|
|
|
* - Argument: tBTA_AV_RC_OPEN RC open data structure
|
|
|
|
*
|
|
|
|
* - Description: RC connection event handler
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2017-03-01 03:18:08 -05:00
|
|
|
static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
|
2017-01-05 02:43:44 -05:00
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
|
|
|
bt_bdaddr_t rc_addr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(p_rc_open->status == BTA_AV_SUCCESS)
|
|
|
|
{
|
|
|
|
//check if already some RC is connected
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_connected)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_ERROR("Got RC OPEN in connected state, Connected RC: %d \
|
|
|
|
and Current RC: %d", btc_rc_vb.rc_handle,p_rc_open->rc_handle );
|
|
|
|
if ((btc_rc_vb.rc_handle != p_rc_open->rc_handle)
|
|
|
|
&& (bdcmp(btc_rc_vb.rc_addr, p_rc_open->peer_addr)))
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("Got RC connected for some other handle");
|
2017-01-05 02:43:44 -05:00
|
|
|
BTA_AvCloseRc(p_rc_open->rc_handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-03-01 03:18:08 -05:00
|
|
|
memcpy(btc_rc_vb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR));
|
|
|
|
btc_rc_vb.rc_features = p_rc_open->peer_features;
|
2017-03-08 06:25:58 -05:00
|
|
|
btc_rc_vb.rc_vol_label = MAX_LABEL;
|
|
|
|
btc_rc_vb.rc_volume = MAX_VOLUME;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
btc_rc_vb.rc_connected = TRUE;
|
|
|
|
btc_rc_vb.rc_handle = p_rc_open->rc_handle;
|
2017-01-05 02:43:44 -05:00
|
|
|
|
|
|
|
/* on locally initiated connection we will get remote features as part of connect */
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_features != 0)
|
2017-01-05 02:43:44 -05:00
|
|
|
handle_rc_features();
|
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
2017-03-01 03:18:08 -05:00
|
|
|
bdcpy(rc_addr.address, btc_rc_vb.rc_addr);
|
2017-01-05 02:43:44 -05:00
|
|
|
/* report connection state if device is AVRCP target */
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) {
|
2017-01-19 02:23:46 -05:00
|
|
|
esp_avrc_ct_cb_param_t param;
|
|
|
|
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
|
|
|
param.conn_stat.connected = true;
|
2017-03-01 03:18:08 -05:00
|
|
|
param.conn_stat.feat_mask = btc_rc_vb.rc_features;
|
2017-01-19 02:23:46 -05:00
|
|
|
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
|
2017-03-08 00:48:56 -05:00
|
|
|
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_ERROR("%s Connect failed with error code: %d",
|
2017-01-05 02:43:44 -05:00
|
|
|
__FUNCTION__, p_rc_open->status);
|
2017-03-01 03:18:08 -05:00
|
|
|
btc_rc_vb.rc_connected = FALSE;
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Function handle_rc_disconnect
|
|
|
|
*
|
|
|
|
* - Argument: tBTA_AV_RC_CLOSE RC close data structure
|
|
|
|
*
|
|
|
|
* - Description: RC disconnection event handler
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2017-03-01 03:18:08 -05:00
|
|
|
static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
|
|
|
bt_bdaddr_t rc_addr;
|
|
|
|
tBTA_AV_FEAT features;
|
|
|
|
#endif
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle);
|
|
|
|
if ((p_rc_close->rc_handle != btc_rc_vb.rc_handle)
|
|
|
|
&& (bdcmp(btc_rc_vb.rc_addr, p_rc_close->peer_addr)))
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_ERROR("Got disconnect of unknown device");
|
2017-01-05 02:43:44 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
btc_rc_vb.rc_handle = 0;
|
|
|
|
btc_rc_vb.rc_connected = FALSE;
|
|
|
|
memset(btc_rc_vb.rc_addr, 0, sizeof(BD_ADDR));
|
|
|
|
memset(btc_rc_vb.rc_notif, 0, sizeof(btc_rc_vb.rc_notif));
|
2017-01-05 02:43:44 -05:00
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
2017-03-01 03:18:08 -05:00
|
|
|
features = btc_rc_vb.rc_features;
|
2017-01-05 02:43:44 -05:00
|
|
|
#endif
|
2017-03-01 03:18:08 -05:00
|
|
|
btc_rc_vb.rc_features = 0;
|
|
|
|
btc_rc_vb.rc_vol_label=MAX_LABEL;
|
|
|
|
btc_rc_vb.rc_volume=MAX_VOLUME;
|
2017-01-05 02:43:44 -05:00
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
2017-03-01 03:18:08 -05:00
|
|
|
bdcpy(rc_addr.address, btc_rc_vb.rc_addr);
|
2017-01-05 02:43:44 -05:00
|
|
|
#endif
|
2017-03-01 03:18:08 -05:00
|
|
|
memset(btc_rc_vb.rc_addr, 0, sizeof(BD_ADDR));
|
2017-01-05 02:43:44 -05:00
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
|
|
|
/* report connection state if device is AVRCP target */
|
|
|
|
if (features & BTA_AV_FEAT_RCTG) {
|
2017-01-19 02:23:46 -05:00
|
|
|
esp_avrc_ct_cb_param_t param;
|
|
|
|
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
|
|
|
param.conn_stat.connected = false;
|
|
|
|
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
|
2017-03-08 00:48:56 -05:00
|
|
|
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Function handle_rc_passthrough_rsp
|
|
|
|
*
|
|
|
|
* - Argument: tBTA_AV_REMOTE_RSP passthrough command response
|
|
|
|
*
|
|
|
|
* - Description: Remote control passthrough response handler
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2017-03-01 03:18:08 -05:00
|
|
|
static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
|
|
|
const char *status;
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
int key_state;
|
|
|
|
if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
|
|
|
|
{
|
|
|
|
status = "released";
|
|
|
|
key_state = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = "pressed";
|
|
|
|
key_state = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status);
|
2017-01-05 02:43:44 -05:00
|
|
|
|
2017-01-19 02:23:46 -05:00
|
|
|
do {
|
|
|
|
esp_avrc_ct_cb_param_t param;
|
|
|
|
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
|
|
|
param.psth_rsp.tl = p_remote_rsp->label;
|
|
|
|
param.psth_rsp.key_code = p_remote_rsp->rc_id;
|
|
|
|
param.psth_rsp.key_state = key_state;
|
2017-03-08 00:48:56 -05:00
|
|
|
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m);
|
2017-01-19 02:23:46 -05:00
|
|
|
} while (0);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
#else
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
**
|
2017-03-01 03:18:08 -05:00
|
|
|
** Function btc_rc_handler
|
2017-01-05 02:43:44 -05:00
|
|
|
**
|
|
|
|
** Description RC event handler
|
|
|
|
**
|
|
|
|
***************************************************************************/
|
2017-03-01 03:18:08 -05:00
|
|
|
void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event));
|
2017-01-05 02:43:44 -05:00
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case BTA_AV_RC_OPEN_EVT:
|
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("Peer_features:%x", p_data->rc_open.peer_features);
|
2017-01-05 02:43:44 -05:00
|
|
|
handle_rc_connect( &(p_data->rc_open) );
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case BTA_AV_RC_CLOSE_EVT:
|
|
|
|
{
|
|
|
|
handle_rc_disconnect( &(p_data->rc_close) );
|
|
|
|
}break;
|
|
|
|
|
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
|
|
|
case BTA_AV_REMOTE_RSP_EVT:
|
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("RSP: rc_id:0x%x key_state:%d", p_data->remote_rsp.rc_id,
|
2017-03-08 06:25:58 -05:00
|
|
|
p_data->remote_rsp.key_state);
|
2017-01-05 02:43:44 -05:00
|
|
|
handle_rc_passthrough_rsp( (&p_data->remote_rsp) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case BTA_AV_RC_FEAT_EVT:
|
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("Peer_features:%x", p_data->rc_feat.peer_features);
|
|
|
|
btc_rc_vb.rc_features = p_data->rc_feat.peer_features;
|
2017-01-05 02:43:44 -05:00
|
|
|
handle_rc_features();
|
|
|
|
}
|
|
|
|
break;
|
2017-03-08 06:25:58 -05:00
|
|
|
|
|
|
|
// below events are not handled for now
|
2017-01-05 02:43:44 -05:00
|
|
|
case BTA_AV_META_MSG_EVT:
|
2017-03-08 06:25:58 -05:00
|
|
|
case BTA_AV_REMOTE_CMD_EVT:
|
2017-01-05 02:43:44 -05:00
|
|
|
default:
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("Unhandled RC event : 0x%x", event);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
**
|
2017-03-01 03:18:08 -05:00
|
|
|
** Function btc_rc_get_connected_peer
|
2017-01-05 02:43:44 -05:00
|
|
|
**
|
|
|
|
** Description Fetches the connected headset's BD_ADDR if any
|
|
|
|
**
|
|
|
|
***************************************************************************/
|
2017-03-01 03:18:08 -05:00
|
|
|
BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_connected == TRUE) {
|
|
|
|
bdcpy(peer_addr, btc_rc_vb.rc_addr);
|
2017-01-05 02:43:44 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
** AVRCP API Functions
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
2017-03-08 00:48:56 -05:00
|
|
|
** Function btc_avrc_ct_init
|
2017-01-05 02:43:44 -05:00
|
|
|
**
|
|
|
|
** Description Initializes the AVRC interface
|
|
|
|
**
|
2017-01-19 02:23:46 -05:00
|
|
|
** Returns esp_err_t
|
2017-01-05 02:43:44 -05:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-03-08 00:48:56 -05:00
|
|
|
static void btc_avrc_ct_init(void)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_INFO("## %s ##", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
memset (&btc_rc_vb, 0, sizeof(btc_rc_vb));
|
|
|
|
btc_rc_vb.rc_vol_label=MAX_LABEL;
|
|
|
|
btc_rc_vb.rc_volume=MAX_VOLUME;
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
**
|
|
|
|
** Function cleanup_ctrl
|
|
|
|
**
|
|
|
|
** Description Closes the AVRC Controller interface
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
***************************************************************************/
|
2017-03-08 00:48:56 -05:00
|
|
|
static void btc_avrc_ct_deinit(void)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_INFO("## %s ##", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
|
2017-03-01 03:18:08 -05:00
|
|
|
memset(&btc_rc_vb, 0, sizeof(btc_rc_cb_t));
|
|
|
|
LOG_INFO("## %s ## completed", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
|
2017-03-08 00:48:56 -05:00
|
|
|
static bt_status_t btc_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
|
|
|
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
|
2017-01-19 02:23:46 -05:00
|
|
|
if (tl >= 16 ||
|
|
|
|
key_state > ESP_AVRC_PT_CMD_STATE_RELEASED) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2017-01-05 02:43:44 -05:00
|
|
|
#if (AVRC_CTLR_INCLUDED == TRUE)
|
2017-01-19 02:23:46 -05:00
|
|
|
CHECK_ESP_RC_CONNECTED;
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
|
2017-01-05 02:43:44 -05:00
|
|
|
key_code, key_state);
|
2017-03-01 03:18:08 -05:00
|
|
|
if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)
|
2017-01-05 02:43:44 -05:00
|
|
|
{
|
2017-03-01 03:18:08 -05:00
|
|
|
BTA_AvRemoteCmd(btc_rc_vb.rc_handle, tl,
|
2017-01-19 02:23:46 -05:00
|
|
|
(tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state);
|
|
|
|
status = BT_STATUS_SUCCESS;
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_INFO("%s: succesfully sent passthrough command to BTA", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-19 02:23:46 -05:00
|
|
|
status = BT_STATUS_FAIL;
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: feature not supported", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
#else
|
2017-03-01 03:18:08 -05:00
|
|
|
LOG_DEBUG("%s: feature not enabled", __FUNCTION__);
|
2017-01-05 02:43:44 -05:00
|
|
|
#endif
|
2017-01-19 02:23:46 -05:00
|
|
|
|
2017-03-08 00:48:56 -05:00
|
|
|
return status;
|
2017-01-05 02:43:44 -05:00
|
|
|
}
|
|
|
|
|
2017-03-08 08:08:11 -05:00
|
|
|
void btc_avrc_call_handler(btc_msg_t *msg)
|
2017-03-08 00:48:56 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|