From e3a705f5df5ae7baae46ed1a4601736c94398419 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 15 Aug 2023 17:12:11 +0200 Subject: [PATCH] hfp: send start/stop audio for ENABLE_NXP_PCM_WBS --- src/classic/hfp.c | 15 ++++++++++++++- src/classic/hfp.h | 4 ++++ src/classic/hfp_ag.c | 14 ++++++++++++++ src/classic/hfp_hf.c | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/classic/hfp.c b/src/classic/hfp.c index f3879e7aa..94c235806 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -645,6 +645,11 @@ static hfp_connection_t * hfp_create_connection(bd_addr_t bd_addr, hfp_role_t lo hfp_connection->local_role = local_role; log_info("Create HFP context %p: role %u, addr %s", hfp_connection, local_role, bd_addr_to_str(bd_addr)); +#ifdef ENABLE_NXP_PCM_WBS + hfp_connection->nxp_start_audio_handle = HCI_CON_HANDLE_INVALID; + hfp_connection->nxp_stop_audio_handle = HCI_CON_HANDLE_INVALID; +#endif + return hfp_connection; } @@ -967,7 +972,11 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet hfp_emit_sco_connection_established(hfp_connection, status, hfp_connection->negotiated_codec, rx_packet_length, tx_packet_length); - break; + +#ifdef ENABLE_NXP_PCM_WBS + hfp_connection->nxp_start_audio_handle = hfp_connection->sco_handle; +#endif + break; } case HCI_EVENT_DISCONNECTION_COMPLETE: @@ -982,6 +991,10 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet #ifdef ENABLE_BCM_PCM_WBS hfp_connection->bcm_send_disable_wbs = true; #endif +#ifdef ENABLE_NXP_PCM_WBS + hfp_connection->nxp_stop_audio_handle = hfp_connection->sco_handle; +#endif + if (hfp_connection->sco_handle == handle){ hfp_connection->sco_handle = HCI_CON_HANDLE_INVALID; hfp_connection->release_audio_connection = 0; diff --git a/src/classic/hfp.h b/src/classic/hfp.h index 825c1e82c..65df55ba6 100644 --- a/src/classic/hfp.h +++ b/src/classic/hfp.h @@ -744,6 +744,10 @@ typedef struct hfp_connection { #ifdef ENABLE_RTK_PCM_WBS bool rtk_send_sco_config; #endif +#ifdef ENABLE_NXP_PCM_WBS + hci_con_handle_t nxp_start_audio_handle; + hci_con_handle_t nxp_stop_audio_handle; +#endif } hfp_connection_t; /** diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index 3d0445c36..d9a629bed 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -2284,6 +2284,20 @@ static void hfp_ag_run_for_context(hfp_connection_t *hfp_connection){ } return; } +#endif +#ifdef ENABLE_NXP_PCM_WBS + if (hfp_connection->nxp_start_audio_handle != HCI_CON_HANDLE_INVALID){ + hci_con_handle_t sco_handle = hfp_connection->nxp_start_audio_handle; + hfp_connection->sco_handle = HCI_CON_HANDLE_INVALID; + hci_send_cmd(&hci_nxp_host_pcm_i2s_audio_config, 0, 0, sco_handle, 0); + return; + } + if (hfp_connection->nxp_stop_audio_handle != HCI_CON_HANDLE_INVALID){ + hci_con_handle_t sco_handle = hfp_connection->nxp_stop_audio_handle; + hfp_connection->sco_handle = HCI_CON_HANDLE_INVALID; + hci_send_cmd(&hci_nxp_host_pcm_i2s_audio_config, 0, 0, sco_handle, 0); + return; + } #endif } diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 6fe1d7901..1babb217d 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -819,6 +819,20 @@ static void hfp_hf_run_for_context(hfp_connection_t * hfp_connection){ return; } #endif +#ifdef ENABLE_NXP_PCM_WBS + if (hfp_connection->nxp_start_audio_handle != HCI_CON_HANDLE_INVALID){ + hci_con_handle_t sco_handle = hfp_connection->nxp_start_audio_handle; + hfp_connection->sco_handle = HCI_CON_HANDLE_INVALID; + hci_send_cmd(&hci_nxp_host_pcm_i2s_audio_config, 0, 0, sco_handle, 0); + return; + } + if (hfp_connection->nxp_stop_audio_handle != HCI_CON_HANDLE_INVALID){ + hci_con_handle_t sco_handle = hfp_connection->nxp_stop_audio_handle; + hfp_connection->sco_handle = HCI_CON_HANDLE_INVALID; + hci_send_cmd(&hci_nxp_host_pcm_i2s_audio_config, 0, 0, sco_handle, 0); + return; + } +#endif #if defined (ENABLE_CC256X_ASSISTED_HFP) || defined (ENABLE_BCM_PCM_WBS) if (hfp_connection->state == HFP_W4_WBS_SHUTDOWN){ hfp_finalize_connection_context(hfp_connection);