Skip to content

Commit e3940cb

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'feat/add_profile_state_event_v5.3' into 'release/v5.3'
feat(bt/bluedroid): added events to indicate the profile states of HFP (v5.3) See merge request espressif/esp-idf!35149
2 parents e797b89 + 4643ceb commit e3940cb

File tree

7 files changed

+141
-21
lines changed

7 files changed

+141
-21
lines changed

components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -63,6 +63,7 @@ typedef enum
6363
ESP_HF_WBS_RESPONSE_EVT, /*!< Codec Status */
6464
ESP_HF_BCS_RESPONSE_EVT, /*!< Final Codec Choice */
6565
ESP_HF_PKT_STAT_NUMS_GET_EVT, /*!< Request number of packet different status */
66+
ESP_HF_PROF_STATE_EVT, /*!< Indicate HF init or deinit complete */
6667
} esp_hf_cb_event_t;
6768

6869
/// Dial type of ESP_HF_DIAL_EVT
@@ -223,6 +224,13 @@ typedef union
223224
uint32_t tx_discarded; /*!< the total number of packets send lost */
224225
} pkt_nums; /*!< AG callback param of ESP_HF_PKT_STAT_NUMS_GET_EVT */
225226

227+
/**
228+
* @brief ESP_HF_PROF_STATE_EVT
229+
*/
230+
struct ag_prof_stat_param {
231+
esp_hf_prof_state_t state; /*!< hf profile state param */
232+
} prof_stat; /*!< status to indicate hf prof init or deinit */
233+
226234
} esp_hf_cb_param_t; /*!< HFP AG callback param compound*/
227235

228236
/**
@@ -284,6 +292,7 @@ esp_err_t esp_hf_ag_register_callback(esp_hf_cb_t callback);
284292
*
285293
* @brief Initialize the bluetooth HF AG module.
286294
* This function should be called after esp_bluedroid_enable() completes successfully.
295+
* ESP_HF_PROF_STATE_EVT with ESP_HF_INIT_SUCCESS will reported to the APP layer.
287296
*
288297
* @return
289298
* - ESP_OK: if the initialization request is sent successfully
@@ -297,6 +306,7 @@ esp_err_t esp_hf_ag_init(void);
297306
*
298307
* @brief De-initialize for HF AG module.
299308
* This function should be called only after esp_bluedroid_enable() completes successfully.
309+
* ESP_HF_PROF_STATE_EVT with ESP_HF_DEINIT_SUCCESS will reported to the APP layer.
300310
*
301311
* @return
302312
* - ESP_OK: success
@@ -504,13 +514,13 @@ esp_err_t esp_hf_ag_cind_response(esp_bd_addr_t remote_addr,
504514

505515
/**
506516
*
507-
* @brief Reponse for AT+COPS command from HF Client.
517+
* @brief Response for AT+COPS command from HF Client.
508518
* As a precondition to use this API, Service Level Connection shall exist with HFP client.
509519
*
510520
* @param[in] remote_addr: remote bluetooth device address
511521
* @param[in] name: current operator name
512522
* @return
513-
* - ESP_OK: reponse for AT+COPS command is sent to lower layer
523+
* - ESP_OK: response for AT+COPS command is sent to lower layer
514524
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
515525
* - ESP_FAIL: others
516526
*
@@ -529,7 +539,7 @@ esp_err_t esp_hf_ag_cops_response(esp_bd_addr_t remote_addr, char *name);
529539
* @param[in] mode: current call mode (voice/data/fax)
530540
* @param[in] mpty: single or multi type
531541
* @param[in] number: current call number
532-
* @param[in] type: international type or unknow
542+
* @param[in] type: international type or unknown
533543
* @return
534544
* - ESP_OK: response to AT+CLCC command is sent to lower layer
535545
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled

components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -97,6 +97,7 @@ typedef enum {
9797
ESP_HF_CLIENT_BINP_EVT, /*!< requested number of last voice tag from AG */
9898
ESP_HF_CLIENT_RING_IND_EVT, /*!< ring indication event */
9999
ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT, /*!< requested number of packet different status */
100+
ESP_HF_CLIENT_PROF_STATE_EVT, /*!< Indicate HF CLIENT init or deinit complete */
100101
} esp_hf_client_cb_event_t;
101102

102103
/// HFP client callback parameters
@@ -266,6 +267,13 @@ typedef union {
266267
uint32_t tx_discarded; /*!< the total number of packets send lost */
267268
} pkt_nums; /*!< HF callback param of ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT */
268269

270+
/**
271+
* @brief ESP_HF_CLIENT_PROF_STATE_EVT
272+
*/
273+
struct hf_client_prof_stat_param {
274+
esp_hf_prof_state_t state; /*!< hf client profile state param */
275+
} prof_stat; /*!< status to indicate hf client prof init or deinit */
276+
269277
} esp_hf_client_cb_param_t; /*!< HFP client callback parameters */
270278

271279
/**
@@ -323,6 +331,7 @@ esp_err_t esp_hf_client_register_callback(esp_hf_client_cb_t callback);
323331
*
324332
* @brief Initialize the bluetooth HFP client module.
325333
* This function should be called after esp_bluedroid_enable() completes successfully.
334+
* ESP_HF_CLIENT_PROF_STATE_EVT with ESP_HF_INIT_SUCCESS will reported to the APP layer.
326335
*
327336
* @return
328337
* - ESP_OK: if the initialization request is sent successfully
@@ -336,6 +345,7 @@ esp_err_t esp_hf_client_init(void);
336345
*
337346
* @brief De-initialize for HFP client module.
338347
* This function should be called only after esp_bluedroid_enable() completes successfully.
348+
* ESP_HF_CLIENT_PROF_STATE_EVT with ESP_HF_DEINIT_SUCCESS will reported to the APP layer.
339349
*
340350
* @return
341351
* - ESP_OK: success
@@ -422,7 +432,7 @@ esp_err_t esp_hf_client_start_voice_recognition(void);
422432
* As a precondition to use this API, Service Level Connection shall exist with AG.
423433
*
424434
* @return
425-
* - ESP_OK: stoping voice recognition is sent to lower layer
435+
* - ESP_OK: stopping voice recognition is sent to lower layer
426436
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
427437
* - ESP_FAIL: others
428438
*

components/bt/host/bluedroid/api/include/api/esp_hf_defs.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -13,6 +13,16 @@
1313
extern "C" {
1414
#endif
1515

16+
/// profile states
17+
typedef enum {
18+
ESP_HF_INIT_SUCCESS = 0, /*!< Indicate init successful */
19+
ESP_HF_INIT_ALREADY, /*!< Indicate init repeated */
20+
ESP_HF_INIT_FAIL, /*!< Indicate init fail */
21+
ESP_HF_DEINIT_SUCCESS, /*!< Indicate deinit successful */
22+
ESP_HF_DEINIT_ALREADY, /*!< Indicate deinit repeated */
23+
ESP_HF_DEINIT_FAIL, /*!< Indicate deinit fail */
24+
} esp_hf_prof_state_t;
25+
1626
/// in-band ring tone state
1727
typedef enum {
1828
ESP_HF_IN_BAND_RINGTONE_NOT_PROVIDED = 0,
@@ -128,7 +138,7 @@ typedef enum {
128138

129139
/// +CLCC address type
130140
typedef enum {
131-
ESP_HF_CALL_ADDR_TYPE_UNKNOWN = 0x81, /*!< unkown address type */
141+
ESP_HF_CALL_ADDR_TYPE_UNKNOWN = 0x81, /*!< unknown address type */
132142
ESP_HF_CALL_ADDR_TYPE_INTERNATIONAL = 0x91, /*!< international address */
133143
} esp_hf_call_addr_type_t;
134144

@@ -160,7 +170,7 @@ typedef enum
160170
ESP_HF_NREC_START
161171
} esp_hf_nrec_t;
162172

163-
///+CCWA resposne status
173+
///+CCWA response status
164174
typedef enum {
165175
ESP_HF_CALL_WAITING_INACTIVE,
166176
ESP_HF_CALL_WAITING_ACTIVE,

components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ bt_status_t btc_hf_init(void)
316316
{
317317
int idx = 0;
318318

319+
#if HFP_DYNAMIC_MEMORY == TRUE
320+
if (hf_local_param)
321+
#endif
322+
{
323+
if (hf_local_param[idx].btc_hf_cb.initialized) {
324+
esp_hf_cb_param_t param = {
325+
.prof_stat.state = ESP_HF_INIT_ALREADY,
326+
};
327+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
328+
return BT_STATUS_SUCCESS;
329+
}
330+
}
331+
319332
BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients);
320333

321334
#if HFP_DYNAMIC_MEMORY == TRUE
@@ -338,8 +351,6 @@ bt_status_t btc_hf_init(void)
338351
#endif
339352
clear_phone_state();
340353
memset(&hf_local_param[idx].btc_hf_cb, 0, sizeof(btc_hf_cb_t));
341-
// custom initialization here
342-
hf_local_param[idx].btc_hf_cb.initialized = true;
343354
// set audio path
344355
#if (BT_CONTROLLER_INCLUDED == TRUE)
345356
#if BTM_SCO_HCI_INCLUDED
@@ -349,14 +360,30 @@ bt_status_t btc_hf_init(void)
349360
#endif
350361
esp_bredr_sco_datapath_set(data_path);
351362
#endif
363+
352364
return BT_STATUS_SUCCESS;
353365
}
354366

355367
void btc_hf_deinit(void)
356368
{
357369
BTC_TRACE_EVENT("%s", __FUNCTION__);
370+
371+
int idx = 0;
372+
373+
#if HFP_DYNAMIC_MEMORY == TRUE
374+
if (hf_local_param)
375+
#endif
376+
{
377+
if (!hf_local_param[idx].btc_hf_cb.initialized) {
378+
esp_hf_cb_param_t param = {
379+
.prof_stat.state = ESP_HF_DEINIT_ALREADY,
380+
};
381+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
382+
return;
383+
}
384+
}
385+
358386
btc_dm_disable_service(BTA_HFP_SERVICE_ID);
359-
hf_local_param[0].btc_hf_cb.initialized = false;
360387
}
361388

362389
static void btc_hf_cb_release(void)
@@ -1268,7 +1295,18 @@ void btc_hf_cb_handler(btc_msg_t *msg)
12681295
break;
12691296
case BTA_AG_DISABLE_EVT:
12701297
{
1271-
btc_hf_cb_release();
1298+
idx = 0;
1299+
#if HFP_DYNAMIC_MEMORY == TRUE
1300+
if (hf_local_param)
1301+
#endif
1302+
{
1303+
if (hf_local_param[idx].btc_hf_cb.initialized) {
1304+
hf_local_param[idx].btc_hf_cb.initialized = false;
1305+
btc_hf_cb_release();
1306+
param.prof_stat.state = ESP_HF_DEINIT_SUCCESS;
1307+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
1308+
}
1309+
}
12721310
break;
12731311
}
12741312
case BTA_AG_REGISTER_EVT:
@@ -1278,6 +1316,11 @@ void btc_hf_cb_handler(btc_msg_t *msg)
12781316
hf_local_param[idx].btc_hf_cb.handle = p_data->reg.hdr.handle;
12791317
BTC_TRACE_DEBUG("%s: BTA_AG_REGISTER_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d",
12801318
__FUNCTION__, idx, hf_local_param[idx].btc_hf_cb.handle);
1319+
if (!hf_local_param[idx].btc_hf_cb.initialized) {
1320+
param.prof_stat.state = ESP_HF_INIT_SUCCESS;
1321+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
1322+
}
1323+
hf_local_param[idx].btc_hf_cb.initialized = true;
12811324
break;
12821325
}
12831326

components/bt/host/bluedroid/btc/profile/std/hf_client/btc_hf_client.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -169,12 +169,18 @@ bt_status_t btc_hf_client_init(void)
169169
{
170170
BTC_TRACE_EVENT("%s", __FUNCTION__);
171171

172+
if (hf_client_local_param.btc_hf_client_cb.initialized) {
173+
esp_hf_client_cb_param_t param = {
174+
.prof_stat.state = ESP_HF_INIT_ALREADY,
175+
};
176+
btc_hf_client_cb_to_app(ESP_HF_CLIENT_PROF_STATE_EVT, &param);
177+
return BT_STATUS_SUCCESS;
178+
}
179+
172180
btc_dm_enable_service(BTA_HFP_HS_SERVICE_ID);
173181

174182
clear_state();
175183

176-
hf_client_local_param.btc_hf_client_cb.initialized = true;
177-
178184
#if (BT_CONTROLLER_INCLUDED == TRUE)
179185
#if BTM_SCO_HCI_INCLUDED
180186
uint8_t data_path = ESP_SCO_DATA_PATH_HCI;
@@ -232,9 +238,15 @@ void btc_hf_client_deinit( void )
232238
{
233239
BTC_TRACE_EVENT("%s", __FUNCTION__);
234240

235-
btc_dm_disable_service(BTA_HFP_HS_SERVICE_ID);
241+
if (!hf_client_local_param.btc_hf_client_cb.initialized) {
242+
esp_hf_client_cb_param_t param = {
243+
.prof_stat.state = ESP_HF_DEINIT_ALREADY,
244+
};
245+
btc_hf_client_cb_to_app(ESP_HF_CLIENT_PROF_STATE_EVT, &param);
246+
return;
247+
}
236248

237-
hf_client_local_param.btc_hf_client_cb.initialized = false;
249+
btc_dm_disable_service(BTA_HFP_HS_SERVICE_ID);
238250
}
239251

240252
/*******************************************************************************
@@ -852,10 +864,21 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
852864
switch (event)
853865
{
854866
case BTA_HF_CLIENT_ENABLE_EVT:
867+
break;
855868
case BTA_HF_CLIENT_DISABLE_EVT:
869+
if (hf_client_local_param.btc_hf_client_cb.initialized) {
870+
param.prof_stat.state = ESP_HF_DEINIT_SUCCESS,
871+
btc_hf_client_cb_to_app(ESP_HF_CLIENT_PROF_STATE_EVT, &param);
872+
}
873+
hf_client_local_param.btc_hf_client_cb.initialized = false;
856874
break;
857875
case BTA_HF_CLIENT_REGISTER_EVT:
858876
hf_client_local_param.btc_hf_client_cb.handle = p_data->reg.handle;
877+
if (!hf_client_local_param.btc_hf_client_cb.initialized) {
878+
param.prof_stat.state = ESP_HF_INIT_SUCCESS,
879+
btc_hf_client_cb_to_app(ESP_HF_CLIENT_PROF_STATE_EVT, &param);
880+
}
881+
hf_client_local_param.btc_hf_client_cb.initialized = true;
859882
break;
860883
case BTA_HF_CLIENT_OPEN_EVT:
861884
if (p_data->open.status == BTA_HF_CLIENT_SUCCESS)

examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const char *c_hf_evt_str[] = {
4646
"WBS_EVT", /*!< CURRENT CODEC EVT */
4747
"BCS_EVT", /*!< CODEC NEGO EVT */
4848
"PKT_STAT_EVT", /*!< REQUEST PACKET STATUS EVT */
49+
"PROF_STATE_EVT", /*!< Indicate HF init or deinit complete */
4950
};
5051

5152
//esp_hf_connection_state_t
@@ -293,7 +294,7 @@ void bt_app_send_data_shut_down(void)
293294

294295
void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
295296
{
296-
if (event <= ESP_HF_PKT_STAT_NUMS_GET_EVT) {
297+
if (event <= ESP_HF_PROF_STATE_EVT) {
297298
ESP_LOGI(BT_HF_TAG, "APP HFP event: %s", c_hf_evt_str[event]);
298299
} else {
299300
ESP_LOGE(BT_HF_TAG, "APP HFP invalid event %d", event);
@@ -499,6 +500,17 @@ void bt_app_hf_cb(esp_hf_cb_event_t event, esp_hf_cb_param_t *param)
499500
ESP_LOGI(BT_HF_TAG, "ESP_HF_PKT_STAT_NUMS_GET_EVT: %d.", event);
500501
break;
501502
}
503+
case ESP_HF_PROF_STATE_EVT:
504+
{
505+
if (ESP_HF_INIT_SUCCESS == param->prof_stat.state) {
506+
ESP_LOGI(BT_HF_TAG, "AG PROF STATE: Init Complete");
507+
} else if (ESP_HF_DEINIT_SUCCESS == param->prof_stat.state) {
508+
ESP_LOGI(BT_HF_TAG, "AG PROF STATE: Deinit Complete");
509+
} else {
510+
ESP_LOGE(BT_HF_TAG, "AG PROF STATE error: %d", param->prof_stat.state);
511+
}
512+
break;
513+
}
502514

503515
default:
504516
ESP_LOGI(BT_HF_TAG, "Unsupported HF_AG EVT: %d.", event);

0 commit comments

Comments
 (0)