Skip to content

Commit 3eab765

Browse files
committed
Merge branch 'feat/add_profile_state_event_v5.4' into 'release/v5.4'
feat(bt/bluedroid): added events to indicate the profile states of HFP (v5.4) See merge request espressif/esp-idf!35148
2 parents 9e2decf + e8c3b64 commit 3eab765

File tree

7 files changed

+124
-20
lines changed

7 files changed

+124
-20
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: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ bt_status_t btc_hf_init(void)
316316
{
317317
int idx = 0;
318318

319+
if (hf_local_param[idx].btc_hf_cb.initialized) {
320+
esp_hf_cb_param_t param = {
321+
.prof_stat.state = ESP_HF_INIT_ALREADY,
322+
};
323+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
324+
return BT_STATUS_SUCCESS;
325+
}
326+
319327
BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients);
320328

321329
#if HFP_DYNAMIC_MEMORY == TRUE
@@ -338,8 +346,6 @@ bt_status_t btc_hf_init(void)
338346
#endif
339347
clear_phone_state();
340348
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;
343349
// set audio path
344350
#if (BT_CONTROLLER_INCLUDED == TRUE)
345351
#if BTM_SCO_HCI_INCLUDED
@@ -349,14 +355,24 @@ bt_status_t btc_hf_init(void)
349355
#endif
350356
esp_bredr_sco_datapath_set(data_path);
351357
#endif
358+
352359
return BT_STATUS_SUCCESS;
353360
}
354361

355362
void btc_hf_deinit(void)
356363
{
357364
BTC_TRACE_EVENT("%s", __FUNCTION__);
365+
366+
int idx = 0;
367+
if (!hf_local_param[idx].btc_hf_cb.initialized) {
368+
esp_hf_cb_param_t param = {
369+
.prof_stat.state = ESP_HF_DEINIT_ALREADY,
370+
};
371+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
372+
return;
373+
}
374+
358375
btc_dm_disable_service(BTA_HFP_SERVICE_ID);
359-
hf_local_param[0].btc_hf_cb.initialized = false;
360376
}
361377

362378
static void btc_hf_cb_release(void)
@@ -1268,7 +1284,13 @@ void btc_hf_cb_handler(btc_msg_t *msg)
12681284
break;
12691285
case BTA_AG_DISABLE_EVT:
12701286
{
1287+
idx = 0;
12711288
btc_hf_cb_release();
1289+
if (hf_local_param[idx].btc_hf_cb.initialized) {
1290+
param.prof_stat.state = ESP_HF_DEINIT_SUCCESS;
1291+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
1292+
}
1293+
hf_local_param[idx].btc_hf_cb.initialized = false;
12721294
break;
12731295
}
12741296
case BTA_AG_REGISTER_EVT:
@@ -1278,6 +1300,11 @@ void btc_hf_cb_handler(btc_msg_t *msg)
12781300
hf_local_param[idx].btc_hf_cb.handle = p_data->reg.hdr.handle;
12791301
BTC_TRACE_DEBUG("%s: BTA_AG_REGISTER_EVT," "hf_local_param[%d].btc_hf_cb.handle = %d",
12801302
__FUNCTION__, idx, hf_local_param[idx].btc_hf_cb.handle);
1303+
if (!hf_local_param[idx].btc_hf_cb.initialized) {
1304+
param.prof_stat.state = ESP_HF_INIT_SUCCESS;
1305+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
1306+
}
1307+
hf_local_param[idx].btc_hf_cb.initialized = true;
12811308
break;
12821309
}
12831310

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);

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -49,6 +49,7 @@ const char *c_hf_evt_str[] = {
4949
"LAST_VOICE_TAG_NUMBER_EVT", /*!< requested number from AG event */
5050
"RING_IND_EVT", /*!< ring indication event */
5151
"PKT_STAT_EVT", /*!< requested number of packet status event */
52+
"PROF_STATE_EVT", /*!< Indicate HF CLIENT init or deinit complete */
5253
};
5354

5455
// esp_hf_client_connection_state_t
@@ -229,7 +230,7 @@ static void bt_app_hf_client_incoming_cb(const uint8_t *buf, uint32_t sz)
229230
/* callback for HF_CLIENT */
230231
void bt_app_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_t *param)
231232
{
232-
if (event <= ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT) {
233+
if (event <= ESP_HF_CLIENT_PROF_STATE_EVT) {
233234
ESP_LOGI(BT_HF_TAG, "APP HFP event: %s", c_hf_evt_str[event]);
234235
} else {
235236
ESP_LOGE(BT_HF_TAG, "APP HFP invalid event %d", event);
@@ -399,6 +400,17 @@ void bt_app_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_
399400
ESP_LOGE(BT_HF_TAG, "ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT: %d", event);
400401
break;
401402
}
403+
case ESP_HF_CLIENT_PROF_STATE_EVT:
404+
{
405+
if (ESP_HF_INIT_SUCCESS == param->prof_stat.state) {
406+
ESP_LOGI(BT_HF_TAG, "HF PROF STATE: Init Complete");
407+
} else if (ESP_HF_DEINIT_SUCCESS == param->prof_stat.state) {
408+
ESP_LOGI(BT_HF_TAG, "HF PROF STATE: Deinit Complete");
409+
} else {
410+
ESP_LOGE(BT_HF_TAG, "HF PROF STATE error: %d", param->prof_stat.state);
411+
}
412+
break;
413+
}
402414
default:
403415
ESP_LOGE(BT_HF_TAG, "HF_CLIENT EVT: %d", event);
404416
break;

0 commit comments

Comments
 (0)