mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-19 01:39:07 +00:00
feat(bt/bluedroid): Add events to indicate the initialization states of AVRCP
This commit is contained in:
@@ -135,6 +135,7 @@ typedef enum {
|
||||
ESP_AVRC_CT_REMOTE_FEATURES_EVT = 5, /*!< feature of remote device indication event */
|
||||
ESP_AVRC_CT_GET_RN_CAPABILITIES_RSP_EVT = 6, /*!< supported notification events capability of peer device */
|
||||
ESP_AVRC_CT_SET_ABSOLUTE_VOLUME_RSP_EVT = 7, /*!< set absolute volume response event */
|
||||
ESP_AVRC_CT_PROF_STATE_EVT = 8, /*!< Indicate AVRCP controller init or deinit complete */
|
||||
} esp_avrc_ct_cb_event_t;
|
||||
|
||||
/// AVRC Target callback events
|
||||
@@ -145,6 +146,7 @@ typedef enum {
|
||||
ESP_AVRC_TG_SET_ABSOLUTE_VOLUME_CMD_EVT = 3, /*!< set absolute volume command from remote device */
|
||||
ESP_AVRC_TG_REGISTER_NOTIFICATION_EVT = 4, /*!< register notification event */
|
||||
ESP_AVRC_TG_SET_PLAYER_APP_VALUE_EVT = 5, /*!< set application attribute value, attribute refer to esp_avrc_ps_attr_ids_t */
|
||||
ESP_AVRC_TG_PROF_STATE_EVT = 6, /*!< Indicate AVRCP target init or deinit complete */
|
||||
} esp_avrc_tg_cb_event_t;
|
||||
|
||||
/// AVRC metadata attribute mask
|
||||
@@ -285,6 +287,18 @@ typedef struct {
|
||||
bool avrc_tg_inited; /*!< AVRCP TG initialization */
|
||||
} esp_avrc_profile_status_t;
|
||||
|
||||
/**
|
||||
* @brief Bluetooth AVRCP Initiation states
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_AVRC_INIT_SUCCESS = 0, /*!< Indicate init successful */
|
||||
ESP_AVRC_INIT_ALREADY, /*!< Indicate init repeated */
|
||||
ESP_AVRC_INIT_FAIL, /*!< Indicate init fail */
|
||||
ESP_AVRC_DEINIT_SUCCESS, /*!< Indicate deinit successful */
|
||||
ESP_AVRC_DEINIT_ALREADY, /*!< Indicate deinit repeated */
|
||||
ESP_AVRC_DEINIT_FAIL, /*!< Indicate deinit fail */
|
||||
} esp_avrc_init_state_t;
|
||||
|
||||
/// AVRC controller callback parameters
|
||||
typedef union {
|
||||
/**
|
||||
@@ -345,6 +359,13 @@ typedef union {
|
||||
struct avrc_ct_set_volume_rsp_param {
|
||||
uint8_t volume; /*!< the volume which has actually been set, range is 0 to 0x7f, means 0% to 100% */
|
||||
} set_volume_rsp; /*!< set absolute volume response event */
|
||||
|
||||
/**
|
||||
* @brief ESP_AVRC_CT_PROF_STATE_EVT
|
||||
*/
|
||||
struct avrc_ct_init_stat_param {
|
||||
esp_avrc_init_state_t state; /*!< avrc ct initialization param */
|
||||
} avrc_ct_init_stat; /*!< status to indicate avrcp ct init or deinit */
|
||||
} esp_avrc_ct_cb_param_t;
|
||||
|
||||
/// AVRC target callback parameters
|
||||
@@ -397,6 +418,13 @@ typedef union {
|
||||
esp_avrc_set_app_value_param_t *p_vals; /*!< point to the id and value of player application attribute */
|
||||
} set_app_value; /*!< set player application value */
|
||||
|
||||
/**
|
||||
* @brief ESP_AVRC_TG_PROF_STATE_EVT
|
||||
*/
|
||||
struct avrc_tg_init_stat_param {
|
||||
esp_avrc_init_state_t state; /*!< avrc tg initialization param */
|
||||
} avrc_tg_init_stat; /*!< status to indicate avrcp tg init or deinit */
|
||||
|
||||
} esp_avrc_tg_cb_param_t;
|
||||
|
||||
/**
|
||||
@@ -437,6 +465,7 @@ esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback);
|
||||
* @brief Initialize the bluetooth AVRCP controller module, This function should be called
|
||||
* after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
|
||||
* AVRC should be used along with A2DP and AVRC should be initialized before A2DP.
|
||||
* ESP_AVRC_CT_PROF_STATE_EVT with ESP_AVRC_INIT_SUCCESS will reported to the APP layer.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
@@ -451,6 +480,7 @@ esp_err_t esp_avrc_ct_init(void);
|
||||
* @brief De-initialize AVRCP controller module. This function should be called after
|
||||
* after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
|
||||
* AVRC should be used along with A2DP and AVRC should be deinitialized before A2DP.
|
||||
* ESP_AVRC_CT_PROF_STATE_EVT with ESP_AVRC_DEINIT_SUCCESS will reported to the APP layer.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
@@ -579,6 +609,7 @@ esp_err_t esp_avrc_tg_register_callback(esp_avrc_tg_cb_t callback);
|
||||
* @brief Initialize the bluetooth AVRCP target module, This function should be called
|
||||
* after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
|
||||
* AVRC should be used along with A2DP and AVRC should be initialized before A2DP.
|
||||
* ESP_AVRC_TG_PROF_STATE_EVT with ESP_AVRC_INIT_SUCCESS will reported to the APP layer.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
@@ -593,6 +624,7 @@ esp_err_t esp_avrc_tg_init(void);
|
||||
* @brief De-initialize AVRCP target module. This function should be called after
|
||||
* after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
|
||||
* AVRC should be used along with A2DP and AVRC should be deinitialized before A2DP.
|
||||
* ESP_AVRC_TG_PROF_STATE_EVT with ESP_AVRC_DEINIT_SUCCESS will reported to the APP layer.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
|
@@ -252,10 +252,6 @@ static bool btc_avrc_tg_set_rn_supported_evt(uint16_t evt_set)
|
||||
|
||||
static inline void btc_avrc_ct_cb_to_app(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
|
||||
{
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
return;
|
||||
}
|
||||
|
||||
esp_avrc_ct_cb_t btc_avrc_ct_cb = (esp_avrc_ct_cb_t)btc_profile_cb_get(BTC_PID_AVRC_CT);
|
||||
if (btc_avrc_ct_cb) {
|
||||
btc_avrc_ct_cb(event, param);
|
||||
@@ -264,10 +260,6 @@ static inline void btc_avrc_ct_cb_to_app(esp_avrc_ct_cb_event_t event, esp_avrc_
|
||||
|
||||
static inline void btc_avrc_tg_cb_to_app(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param)
|
||||
{
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
return;
|
||||
}
|
||||
|
||||
esp_avrc_tg_cb_t btc_avrc_tg_cb = (esp_avrc_tg_cb_t)btc_profile_cb_get(BTC_PID_AVRC_TG);
|
||||
if (btc_avrc_tg_cb) {
|
||||
btc_avrc_tg_cb(event, param);
|
||||
@@ -998,27 +990,39 @@ BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr)
|
||||
*******************************************************************************/
|
||||
static void btc_avrc_ct_init(void)
|
||||
{
|
||||
esp_avrc_init_state_t state = ESP_AVRC_INIT_SUCCESS;
|
||||
|
||||
BTC_TRACE_DEBUG("## %s ##", __FUNCTION__);
|
||||
if (s_rc_ct_init == BTC_RC_CT_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s already initialized", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
/// initialize CT-specific resources
|
||||
s_rc_ct_init = BTC_RC_CT_INIT_MAGIC;
|
||||
do {
|
||||
|
||||
/// initialize CT-TG shared resources
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
|
||||
|
||||
if (!g_av_with_rc) {
|
||||
g_av_with_rc = true;
|
||||
if (s_rc_ct_init == BTC_RC_CT_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s already initialized", __FUNCTION__);
|
||||
state = ESP_AVRC_INIT_ALREADY;
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_a2dp_on_init) {
|
||||
BTC_TRACE_WARNING("AVRC Controller is expected to be initialized in advance of A2DP !!!");
|
||||
/// initialize CT-TG shared resources
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
if (g_a2dp_on_init) {
|
||||
BTC_TRACE_WARNING("AVRC Controller is expected to be initialized in advance of A2DP !!!");
|
||||
state = ESP_AVRC_INIT_FAIL;
|
||||
break;
|
||||
}
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
|
||||
|
||||
if (!g_av_with_rc) {
|
||||
g_av_with_rc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// initialize CT-specific resources
|
||||
s_rc_ct_init = BTC_RC_CT_INIT_MAGIC;
|
||||
} while (0);
|
||||
|
||||
esp_avrc_ct_cb_param_t param = {0};
|
||||
param.avrc_ct_init_stat.state = state;
|
||||
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_PROF_STATE_EVT, ¶m);
|
||||
}
|
||||
|
||||
|
||||
@@ -1033,29 +1037,37 @@ static void btc_avrc_ct_init(void)
|
||||
***************************************************************************/
|
||||
static void btc_avrc_ct_deinit(void)
|
||||
{
|
||||
esp_avrc_init_state_t state = ESP_AVRC_DEINIT_SUCCESS;
|
||||
|
||||
BTC_TRACE_API("## %s ##", __FUNCTION__);
|
||||
|
||||
if (g_a2dp_on_deinit) {
|
||||
BTC_TRACE_WARNING("A2DP already deinit, AVRC CT should deinit in advance of A2DP !!!");
|
||||
}
|
||||
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s not initialized", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
/// deinit CT-specific resources
|
||||
s_rc_ct_init = 0;
|
||||
|
||||
/// deinit CT-TG shared resources
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
|
||||
if (g_av_with_rc) {
|
||||
g_av_with_rc = false;
|
||||
do {
|
||||
if (g_a2dp_on_deinit) {
|
||||
BTC_TRACE_WARNING("A2DP already deinit, AVRC CT should deinit in advance of A2DP !!!");
|
||||
}
|
||||
}
|
||||
|
||||
BTC_TRACE_API("## %s ## completed", __FUNCTION__);
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s not initialized", __FUNCTION__);
|
||||
state = ESP_AVRC_DEINIT_ALREADY;
|
||||
break;
|
||||
}
|
||||
|
||||
/// deinit CT-specific resources
|
||||
s_rc_ct_init = 0;
|
||||
|
||||
/// deinit CT-TG shared resources
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
|
||||
if (g_av_with_rc) {
|
||||
g_av_with_rc = false;
|
||||
}
|
||||
}
|
||||
BTC_TRACE_API("## %s ## completed", __FUNCTION__);
|
||||
} while (0);
|
||||
|
||||
esp_avrc_ct_cb_param_t param = {0};
|
||||
param.avrc_ct_init_stat.state = state;
|
||||
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_PROF_STATE_EVT, ¶m);
|
||||
}
|
||||
|
||||
static bt_status_t btc_avrc_ct_send_set_player_value_cmd(uint8_t tl, uint8_t attr_id, uint8_t value_id)
|
||||
@@ -1274,30 +1286,42 @@ static bt_status_t btc_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code
|
||||
*******************************************************************************/
|
||||
static void btc_avrc_tg_init(void)
|
||||
{
|
||||
esp_avrc_init_state_t state = ESP_AVRC_INIT_SUCCESS;
|
||||
|
||||
BTC_TRACE_DEBUG("## %s ##", __FUNCTION__);
|
||||
if (s_rc_tg_init == BTC_RC_TG_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s already initialized", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
/// initialize TG-specific resources
|
||||
memcpy(s_psth_supported_cmd, cs_psth_dft_supported_cmd, sizeof(s_psth_supported_cmd));
|
||||
s_rn_supported_evt = cs_rn_dft_supported_evt;
|
||||
|
||||
/// initialize CT-TG shared resources
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb));
|
||||
|
||||
if (!g_av_with_rc) {
|
||||
g_av_with_rc = true;
|
||||
do {
|
||||
if (s_rc_tg_init == BTC_RC_TG_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s already initialized", __FUNCTION__);
|
||||
state = ESP_AVRC_INIT_ALREADY;
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_a2dp_on_init) {
|
||||
BTC_TRACE_WARNING("AVRC Target is expected to be initialized in advance of A2DP !!!");
|
||||
}
|
||||
}
|
||||
/// initialize CT-TG shared resources
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
if (g_a2dp_on_init) {
|
||||
BTC_TRACE_WARNING("AVRC Target is expected to be initialized in advance of A2DP !!!");
|
||||
state = ESP_AVRC_INIT_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
s_rc_tg_init = BTC_RC_TG_INIT_MAGIC;
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb));
|
||||
|
||||
if (!g_av_with_rc) {
|
||||
g_av_with_rc = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// initialize TG-specific resources
|
||||
memcpy(s_psth_supported_cmd, cs_psth_dft_supported_cmd, sizeof(s_psth_supported_cmd));
|
||||
s_rn_supported_evt = cs_rn_dft_supported_evt;
|
||||
|
||||
s_rc_tg_init = BTC_RC_TG_INIT_MAGIC;
|
||||
} while (0);
|
||||
|
||||
esp_avrc_tg_cb_param_t param = {0};
|
||||
param.avrc_tg_init_stat.state = state;
|
||||
btc_avrc_tg_cb_to_app(ESP_AVRC_TG_PROF_STATE_EVT, ¶m);
|
||||
}
|
||||
|
||||
|
||||
@@ -1312,31 +1336,40 @@ static void btc_avrc_tg_init(void)
|
||||
***************************************************************************/
|
||||
static void btc_avrc_tg_deinit(void)
|
||||
{
|
||||
esp_avrc_init_state_t state = ESP_AVRC_DEINIT_SUCCESS;
|
||||
|
||||
BTC_TRACE_API("## %s ##", __FUNCTION__);
|
||||
|
||||
if (g_a2dp_on_deinit) {
|
||||
BTC_TRACE_WARNING("A2DP already deinit, AVRC TG should deinit in advance of A2DP !!!");
|
||||
}
|
||||
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s not initialized", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
/// deinit TG-specific resources
|
||||
memset(s_psth_supported_cmd, 0, sizeof(s_psth_supported_cmd));
|
||||
s_rn_supported_evt = 0;
|
||||
s_rc_tg_init = 0;
|
||||
|
||||
/// deinit CT-TG shared resources
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb));
|
||||
if (g_av_with_rc) {
|
||||
g_av_with_rc = false;
|
||||
do {
|
||||
if (g_a2dp_on_deinit) {
|
||||
BTC_TRACE_WARNING("A2DP already deinit, AVRC TG should deinit in advance of A2DP !!!");
|
||||
}
|
||||
}
|
||||
|
||||
BTC_TRACE_API("## %s ## completed", __FUNCTION__);
|
||||
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
|
||||
BTC_TRACE_WARNING("%s not initialized", __FUNCTION__);
|
||||
state = ESP_AVRC_DEINIT_ALREADY;
|
||||
break;
|
||||
}
|
||||
|
||||
/// deinit TG-specific resources
|
||||
memset(s_psth_supported_cmd, 0, sizeof(s_psth_supported_cmd));
|
||||
s_rn_supported_evt = 0;
|
||||
s_rc_tg_init = 0;
|
||||
|
||||
/// deinit CT-TG shared resources
|
||||
if (s_rc_ct_init != BTC_RC_CT_INIT_MAGIC) {
|
||||
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb));
|
||||
if (g_av_with_rc) {
|
||||
g_av_with_rc = false;
|
||||
}
|
||||
}
|
||||
|
||||
BTC_TRACE_API("## %s ## completed", __FUNCTION__);
|
||||
} while (0);
|
||||
|
||||
esp_avrc_tg_cb_param_t param = {0};
|
||||
param.avrc_tg_init_stat.state = state;
|
||||
btc_avrc_tg_cb_to_app(ESP_AVRC_TG_PROF_STATE_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_avrc_tg_send_rn_rsp(esp_avrc_rn_event_ids_t event_id, esp_avrc_rn_rsp_t rsp, const esp_avrc_rn_param_t *param)
|
||||
|
Reference in New Issue
Block a user