]> granicus.if.org Git - esp-idf/commitdiff
BT HFP: Add AT+NREC=0 command for disabling AG echo cancellation.
authornif <nif@nifomorph.com>
Thu, 20 Jun 2019 10:01:02 +0000 (12:01 +0200)
committerbot <bot@espressif.com>
Mon, 2 Sep 2019 09:28:38 +0000 (09:28 +0000)
components/bt/host/bluedroid/api/esp_hf_client_api.c
components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h
components/bt/host/bluedroid/btc/profile/std/hf_client/btc_hf_client.c
components/bt/host/bluedroid/btc/profile/std/include/btc_hf_client.h

index 7db990206a7fae12f6b272780d96587786cf1282..c0a6cbe8008258b49ea1ed694c60b50359655731 100644 (file)
@@ -432,6 +432,22 @@ esp_err_t esp_hf_client_request_last_voice_tag_number(void)
     return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
 }
 
+esp_err_t esp_hf_client_send_nrec(void)
+{
+    if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+        return ESP_ERR_INVALID_STATE;
+    }
+
+    btc_msg_t msg;
+    msg.sig = BTC_SIG_API_CALL;
+    msg.pid = BTC_PID_HF_CLIENT;
+    msg.act = BTC_HF_CLIENT_SEND_NREC_EVT;
+
+    /* Switch to BTC context */
+    bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
+    return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
+}
+
 esp_err_t esp_hf_client_register_data_callback(esp_hf_client_incoming_data_cb_t recv,
                                                esp_hf_client_outgoing_data_cb_t send)
 {
index 8e3dc956b7c8c8bb3a2c0327b17c4714ce5b230f..d82308b2cffe5e77673eab6b5750d067515e737a 100644 (file)
@@ -578,6 +578,20 @@ esp_err_t esp_hf_client_send_dtmf(char code);
  */
 esp_err_t esp_hf_client_request_last_voice_tag_number(void);
 
+/**
+ *
+ * @brief           Disable echo cancellation and noise reduction in the AG (use AT+NREC=0 command)
+ *                  As a precondition to use this API, Service Level Connection shall exist with AG
+ *
+ * @return
+ *                  - ESP_OK: NREC=0 request is sent to lower layer
+ *                  - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
+ *                  - ESP_FAIL: others
+ *
+ */
+esp_err_t esp_hf_client_send_nrec(void);
+
+
 /**
  * @brief           Register HFP client data output function; the callback is only used in
  *                  the case that Voice Over HCI is enabled.
index d3ccd669977e01eacbe28749dd67357707d875c1..64fb8e2bac793a1b53d64bb6e6c9be78a9d976d6 100644 (file)
@@ -630,6 +630,27 @@ static bt_status_t btc_hf_client_request_last_voice_tag_number(void)
     return BT_STATUS_UNSUPPORTED;
 }
 
+/*******************************************************************************
+**
+** Function         btc_hf_client_send_nrec
+**
+** Description      Request AG to disable echo cancellation & noise reduction
+**
+** Returns          bt_status_t
+**
+*******************************************************************************/
+static bt_status_t btc_hf_client_send_nrec(void)
+{
+    CHECK_HF_CLIENT_SLC_CONNECTED();
+
+    if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_ECNR)
+    {
+        BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_NREC, 0, 0, NULL);
+        return BT_STATUS_SUCCESS;
+    }
+    return BT_STATUS_UNSUPPORTED;
+}
+
 /*******************************************************************************
 **
 ** Function         bte_hf_client_evt
@@ -1073,6 +1094,9 @@ void btc_hf_client_call_handler(btc_msg_t *msg)
     case BTC_HF_CLIENT_REGISTER_DATA_CALLBACK_EVT:
         btc_hf_client_reg_data_cb(arg->reg_data_cb.recv, arg->reg_data_cb.send);
         break;
+    case BTC_HF_CLIENT_SEND_NREC_EVT:
+        btc_hf_client_send_nrec();
+        break;
     default:
         BTC_TRACE_WARNING("%s : unhandled event: %d\n", __FUNCTION__, msg->act);
     }
index 04226e72a259f7bbda347711e5eedf9e69ca5883..e3befc9f4a2228a3e9501bf16750183a3e775e53 100644 (file)
@@ -57,6 +57,7 @@ typedef enum {
     BTC_HF_CLIENT_SEND_DTMF_EVT,
     BTC_HF_CLIENT_REQUEST_LAST_VOICE_TAG_NUMBER_EVT,
     BTC_HF_CLIENT_REGISTER_DATA_CALLBACK_EVT,
+    BTC_HF_CLIENT_SEND_NREC_EVT,
 } btc_hf_client_act_t;
 
 /* btc_hf_client_args_t */