Skip to content

Commit

Permalink
Merge branch 'feature/use_vsc_to_op_coex_st' into 'master'
Browse files Browse the repository at this point in the history
feat(bt/Bluedroid): Implemented esp_coex_status_set/clear using vendor HCI

Closes BTQABR2023-66

See merge request espressif/esp-idf!25938
  • Loading branch information
wmy-espressif committed Sep 20, 2023
2 parents d057bac + d0e0928 commit 7e91e90
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 5 deletions.
7 changes: 7 additions & 0 deletions components/bt/host/bluedroid/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ config BT_BLUEDROID_MEM_DEBUG
help
Bluedroid memory debug

config BT_BLUEDROID_ESP_COEX_VSC
bool "Enable Espressif Vendor-specific HCI commands for coexist status configuration"
depends on BT_BLUEDROID_ENABLED
default y
help
Enable Espressif Vendor-specific HCI commands for coexist status configuration

config BT_CLASSIC_ENABLED
bool "Classic Bluetooth"
depends on BT_BLUEDROID_ENABLED && IDF_TARGET_ESP32
Expand Down
21 changes: 21 additions & 0 deletions components/bt/host/bluedroid/api/esp_bt_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,24 @@ esp_err_t esp_bt_dev_set_device_name(const char *name)

return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

#if (ESP_COEX_VSC_INCLUDED == TRUE)
esp_err_t esp_bt_dev_coex_status_config(esp_bt_dev_coex_type_t type, esp_bt_dev_coex_op_t op, uint8_t status)
{
btc_msg_t msg = {0};
btc_dev_args_t arg;

if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_DEV;
msg.act = BTC_DEV_ACT_CFG_COEX_STATUS;
arg.cfg_coex_status.type = type;
arg.cfg_coex_status.op = op;
arg.cfg_coex_status.status = status;

return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif
37 changes: 37 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_bt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@
extern "C" {
#endif

// coexist status for MESH
#define ESP_BT_DEV_COEX_BLE_ST_MESH_CONFIG 0x08
#define ESP_BT_DEV_COEX_BLE_ST_MESH_TRAFFIC 0x10
#define ESP_BT_DEV_COEX_BLE_ST_MESH_STANDBY 0x20
// coexist status for A2DP
#define ESP_BT_DEV_COEX_BT_ST_A2DP_STREAMING 0x10
#define ESP_BT_DEV_COEX_BT_ST_A2DP_PAUSED 0x20

// coexist operation
#define ESP_BT_DEV_COEX_OP_CLEAR 0x00
#define ESP_BT_DEV_COEX_OP_SET 0x01
typedef uint8_t esp_bt_dev_coex_op_t;

/**
* @brief Bluetooth device coex type
*/
typedef enum {
ESP_BT_DEV_COEX_TYPE_BLE = 1,
ESP_BT_DEV_COEX_TYPE_BT,
} esp_bt_dev_coex_type_t;

/**
*
* @brief Get bluetooth device address. Must use after "esp_bluedroid_enable".
Expand All @@ -42,6 +63,22 @@ const uint8_t *esp_bt_dev_get_address(void);
*/
esp_err_t esp_bt_dev_set_device_name(const char *name);

/**
* @brief Config bluetooth device coexis status. This function should be called after esp_bluedroid_enable()
* completes successfully.
*
* @param[in] type : coexist type to operate on
* @param[in] op : clear or set coexist status
* @param[in] status : coexist status to be configured
*
* @return
* - ESP_OK : Succeed
* - ESP_ERR_INVALID_ARG : if name is NULL pointer or empty, or string length out of limit
* - ESP_ERR_INVALID_STATE : if bluetooth stack is not yet enabled
* - ESP_FAIL : others
*/
esp_err_t esp_bt_dev_coex_status_config(esp_bt_dev_coex_type_t type, esp_bt_dev_coex_op_t op, uint8_t status);

#ifdef __cplusplus
}
#endif
Expand Down
19 changes: 19 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,25 @@ void bta_dm_get_dev_name (tBTA_DM_MSG *p_data)
}
}

/*******************************************************************************
**
** Function bta_dm_cfg_coex_status
**
** Description config coexistance status
**
**
** Returns void
**
*******************************************************************************/
#if (ESP_COEX_VSC_INCLUDED == TRUE)
void bta_dm_cfg_coex_status (tBTA_DM_MSG *p_data)
{
BTM_ConfigCoexStatus(p_data->cfg_coex_status.op,
p_data->cfg_coex_status.type,
p_data->cfg_coex_status.status);
}
#endif

/*******************************************************************************
**
** Function bta_dm_set_afh_channels
Expand Down
25 changes: 25 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,31 @@ void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback)
}
}

/*******************************************************************************
**
** Function BTA_DmCfgCoexStatus
**
** Description This function configures the coexist status
**
**
** Returns void
**
*******************************************************************************/
#if (ESP_COEX_VSC_INCLUDED == TRUE)
void BTA_DmCfgCoexStatus(UINT8 op, UINT8 type, UINT8 status)
{
tBTA_DM_API_CFG_COEX_STATUS *p_msg;

if ((p_msg = (tBTA_DM_API_CFG_COEX_STATUS *) osi_malloc(sizeof(tBTA_DM_API_CFG_COEX_STATUS))) != NULL) {
p_msg->hdr.event = BTA_DM_API_CFG_COEX_ST_EVT;
p_msg->op = op;
p_msg->type = type;
p_msg->status = status;
bta_sys_sendmsg(p_msg);
}
}
#endif

#if (CLASSIC_BT_INCLUDED == TRUE)

void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config)
Expand Down
18 changes: 14 additions & 4 deletions components/bt/host/bluedroid/bta/dm/bta_dm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "bta/bta_api.h"
#include "bta/bta_sys.h"
#include "bta_dm_int.h"
#if (ESP_COEX_VSC_INCLUDED == TRUE)
#include "stack/btm_api.h"
#endif
#include "osi/allocator.h"
#include <string.h>

Expand Down Expand Up @@ -59,6 +62,9 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_disable, /* BTA_DM_API_DISABLE_EVT */
bta_dm_set_dev_name, /* BTA_DM_API_SET_NAME_EVT */
bta_dm_get_dev_name, /* BTA_DM_API_GET_NAME_EVT */
#if (ESP_COEX_VSC_INCLUDED == TRUE)
bta_dm_cfg_coex_status, /* BTA_DM_API_CFG_COEX_ST_EVT */
#endif
#if (CLASSIC_BT_INCLUDED == TRUE)
bta_dm_config_eir, /* BTA_DM_API_CONFIG_EIR_EVT */
bta_dm_set_page_timeout, /* BTA_DM_API_PAGE_TO_SET_EVT */
Expand Down Expand Up @@ -464,12 +470,16 @@ void BTA_DmCoexEventTrigger(uint32_t event)
case BTA_COEX_EVT_ACL_DISCONNECTED:
break;
case BTA_COEX_EVT_STREAMING_STARTED:
esp_coex_status_bit_set(ESP_COEX_ST_TYPE_BT, ESP_COEX_BT_ST_A2DP_STREAMING);
esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BT, ESP_COEX_BT_ST_A2DP_PAUSED);
#if (ESP_COEX_VSC_INCLUDED == TRUE)
BTM_ConfigCoexStatus(BTM_COEX_OP_SET, BTM_COEX_TYPE_BT, BTM_COEX_BT_ST_A2DP_STREAMING);
BTM_ConfigCoexStatus(BTM_COEX_OP_CLEAR, BTM_COEX_TYPE_BT, BTM_COEX_BT_ST_A2DP_PAUSED);
#endif
break;
case BTA_COEX_EVT_STREAMING_STOPPED:
esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BT, ESP_COEX_BT_ST_A2DP_STREAMING);
esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BT, ESP_COEX_BT_ST_A2DP_PAUSED);
#if (ESP_COEX_VSC_INCLUDED == TRUE)
BTM_ConfigCoexStatus(BTM_COEX_OP_CLEAR, BTM_COEX_TYPE_BT, BTM_COEX_BT_ST_A2DP_STREAMING);
BTM_ConfigCoexStatus(BTM_COEX_OP_CLEAR, BTM_COEX_TYPE_BT, BTM_COEX_BT_ST_A2DP_PAUSED);
#endif
break;
default:
break;
Expand Down
18 changes: 18 additions & 0 deletions components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ enum {
BTA_DM_API_DISABLE_EVT,
BTA_DM_API_SET_NAME_EVT,
BTA_DM_API_GET_NAME_EVT,
#if (ESP_COEX_VSC_INCLUDED == TRUE)
BTA_DM_API_CFG_COEX_ST_EVT,
#endif
#if (CLASSIC_BT_INCLUDED == TRUE)
BTA_DM_API_CONFIG_EIR_EVT,
BTA_DM_API_PAGE_TO_SET_EVT,
Expand Down Expand Up @@ -244,6 +247,15 @@ typedef struct {
tBTA_GET_DEV_NAME_CBACK *p_cback;
} tBTA_DM_API_GET_NAME;

#if (ESP_COEX_VSC_INCLUDED == TRUE)
typedef struct {
BT_HDR hdr;
UINT8 op;
UINT8 type;
UINT8 status;
} tBTA_DM_API_CFG_COEX_STATUS;
#endif

/* data type for BTA_DM_API_CONFIG_EIR_EVT */
typedef struct {
BT_HDR hdr;
Expand Down Expand Up @@ -1090,6 +1102,9 @@ typedef union {

tBTA_DM_API_SET_NAME set_name;
tBTA_DM_API_GET_NAME get_name;
#if (ESP_COEX_VSC_INCLUDED == TRUE)
tBTA_DM_API_CFG_COEX_STATUS cfg_coex_status;
#endif
tBTA_DM_API_CONFIG_EIR config_eir;

tBTA_DM_API_SET_AFH_CHANNELS set_afh_channels;
Expand Down Expand Up @@ -1593,6 +1608,9 @@ extern void bta_dm_enable (tBTA_DM_MSG *p_data);
extern void bta_dm_disable (tBTA_DM_MSG *p_data);
extern void bta_dm_set_dev_name (tBTA_DM_MSG *p_data);
extern void bta_dm_get_dev_name (tBTA_DM_MSG *p_data);
#if (ESP_COEX_VSC_INCLUDED == TRUE)
extern void bta_dm_cfg_coex_status(tBTA_DM_MSG *p_data);
#endif
#if (CLASSIC_BT_INCLUDED == TRUE)
extern void bta_dm_config_eir (tBTA_DM_MSG *p_data);
extern void bta_dm_set_page_timeout (tBTA_DM_MSG *p_data);
Expand Down
14 changes: 14 additions & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,20 @@ extern void BTA_DmSetDeviceName(const char *p_name);
*******************************************************************************/
extern void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback);

/*******************************************************************************
**
** Function BTA_DmCfgCoexStatus
**
** Description This function configures coexist status.
**
**
** Returns void
**
*******************************************************************************/
#if (ESP_COEX_VSC_INCLUDED == TRUE)
extern void BTA_DmCfgCoexStatus(UINT8 op, UINT8 type, UINT8 status);
#endif

/*******************************************************************************
**
** Function BTA_DmGetRemoteName
Expand Down
11 changes: 11 additions & 0 deletions components/bt/host/bluedroid/btc/core/btc_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ void btc_dev_arg_deep_free(btc_msg_t *msg)
}
break;
}
#if (ESP_COEX_VSC_INCLUDED == TRUE)
case BTC_DEV_ACT_CFG_COEX_STATUS:
break;
#endif
default:
BTC_TRACE_DEBUG("Unhandled deep free %d\n", msg->act);
break;
Expand All @@ -39,6 +43,13 @@ void btc_dev_call_handler(btc_msg_t *msg)
case BTC_DEV_ACT_SET_DEVICE_NAME:
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
break;
#if (ESP_COEX_VSC_INCLUDED == TRUE)
case BTC_DEV_ACT_CFG_COEX_STATUS:
BTA_DmCfgCoexStatus(arg->cfg_coex_status.op,
arg->cfg_coex_status.type,
arg->cfg_coex_status.status);
break;
#endif
default:
break;
}
Expand Down
14 changes: 13 additions & 1 deletion components/bt/host/bluedroid/btc/include/btc/btc_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "btc/btc_task.h"

typedef enum {
BTC_DEV_ACT_SET_DEVICE_NAME
BTC_DEV_ACT_SET_DEVICE_NAME,
#if (ESP_COEX_VSC_INCLUDED == TRUE)
BTC_DEV_ACT_CFG_COEX_STATUS,
#endif
} btc_dev_act_t;

/* btc_dev_args_t */
Expand All @@ -21,6 +24,15 @@ typedef union {
struct set_bt_dev_name_args {
char *device_name;
} set_dev_name;

#if (ESP_COEX_VSC_INCLUDED == TRUE)
// BTC_DEV_ACT_CFG_COEX_STATUS
struct cfg_bt_dev_coex_st_args {
esp_bt_dev_coex_type_t type;
esp_bt_dev_coex_op_t op;
uint8_t status;
} cfg_coex_status;
#endif
} btc_dev_args_t;

void btc_dev_call_handler(btc_msg_t *msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@
#define UC_BT_BLUEDROID_MEM_DEBUG FALSE
#endif

//ESP COEXIST VSC
#ifdef CONFIG_BT_BLUEDROID_ESP_COEX_VSC
#define UC_BT_BLUEDROID_ESP_COEX_VSC CONFIG_BT_BLUEDROID_ESP_COEX_VSC
#else
#define UC_BT_BLUEDROID_ESP_COEX_VSC FALSE
#endif


/**********************************************************
* Trace reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
/* OS Configuration from User config (eg: sdkconfig) */
#define BT_BTU_TASK_STACK_SIZE UC_BTU_TASK_STACK_SIZE

#if (UC_BT_BLUEDROID_ESP_COEX_VSC == TRUE)
#define ESP_COEX_VSC_INCLUDED TRUE
#else
#define ESP_COEX_VSC_INCLUDED FALSE
#endif

/******************************************************************************
**
** Classic BT features
Expand Down
13 changes: 13 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_devctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,19 @@ tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,

}

#if (ESP_COEX_VSC_INCLUDED == TRUE)
tBTM_STATUS BTM_ConfigCoexStatus(tBTM_COEX_OPERATION op, tBTM_COEX_TYPE type, UINT8 status)
{
UINT8 param[3];
UINT8 *p = (UINT8 *)param;

UINT8_TO_STREAM(p, type);
UINT8_TO_STREAM(p, op);
UINT8_TO_STREAM(p, status);

return BTM_VendorSpecificCommand(HCI_VENDOR_COMMON_COEX_STATUS_CMD_OPCODE, 3, param, NULL);
}
#endif

/*******************************************************************************
**
Expand Down
Loading

0 comments on commit 7e91e90

Please sign in to comment.