diff --git a/components/bt_hfp/CMakeLists.txt b/components/bt_hfp/CMakeLists.txt index 6471ac8..13b4856 100644 --- a/components/bt_hfp/CMakeLists.txt +++ b/components/bt_hfp/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( SRCS "bt_hfp.c" INCLUDE_DIRS "include" - REQUIRES bt + REQUIRES bt audio_router ) diff --git a/components/bt_hfp/bt_hfp.c b/components/bt_hfp/bt_hfp.c index 60ad159..d3fabd7 100644 --- a/components/bt_hfp/bt_hfp.c +++ b/components/bt_hfp/bt_hfp.c @@ -20,6 +20,7 @@ #include "esp_bt_device.h" #include "esp_gap_bt_api.h" #include "esp_hf_client_api.h" +#include "audio_router.h" #define TAG "bt_hfp" @@ -35,6 +36,18 @@ static void emit(bt_hfp_event_t ev, const char *number, bool msbc) } } +/* ---- Callbacks data SCO : pont PCM BT <-> audio_router ---- */ +static void sco_incoming_cb(const uint8_t *buf, uint32_t len) +{ + audio_router_sco_feed_playback(buf, len); + esp_hf_client_outgoing_data_ready(); +} + +static uint32_t sco_outgoing_cb(uint8_t *buf, uint32_t len) +{ + return audio_router_sco_take_capture(buf, len); +} + /* ---- GAP callback : appairage / authentification / SSP ---- */ static void gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) { @@ -133,6 +146,7 @@ static void hf_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_t *para ESP_HF_CLIENT_AUDIO_STATE_CONNECTED_MSBC); ESP_LOGI(TAG, "audio SCO connecte (%s)", msbc ? "mSBC 16k" : "CVSD 8k"); emit(BT_HFP_EV_AUDIO_CONNECTED, NULL, msbc); + esp_hf_client_register_data_callback(sco_incoming_cb, sco_outgoing_cb); } else if (param->audio_stat.state == ESP_HF_CLIENT_AUDIO_STATE_DISCONNECTED) { ESP_LOGI(TAG, "audio SCO deconnecte"); emit(BT_HFP_EV_AUDIO_DISCONNECTED, NULL, false);