hfp_ag: send HFP AG and HCI commands independently

This commit is contained in:
Matthias Ringwald 2021-12-03 12:13:52 +01:00
parent 6d21cd94ee
commit b7802cc8b1

View File

@ -2152,9 +2152,6 @@ static void hfp_ag_run_for_context(hfp_connection_t *hfp_connection){
hfp_connection->emit_vra_enabled_after_audio_established = false;
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
}
// assert command could be sent
if (hci_can_send_command_packet_now() == 0) return;
if ((hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED) && hfp_connection->release_audio_connection){
hfp_connection->state = HFP_W4_SCO_DISCONNECTED;
@ -2162,61 +2159,65 @@ static void hfp_ag_run_for_context(hfp_connection_t *hfp_connection){
gap_disconnect(hfp_connection->sco_handle);
return;
}
// configure NBS/WBS if needed using vendor-specific HCI commands
if (hci_can_send_command_packet_now()) {
#ifdef ENABLE_CC256X_ASSISTED_HFP
// WBS Disassociate
if (hfp_connection->cc256x_send_wbs_disassociate){
hfp_connection->cc256x_send_wbs_disassociate = false;
hci_send_cmd(&hci_ti_wbs_disassociate);
return;
}
// Write Codec Config
if (hfp_connection->cc256x_send_write_codec_config){
hfp_connection->cc256x_send_write_codec_config = false;
hfp_cc256x_write_codec_config(hfp_connection);
return;
}
// WBS Associate
if (hfp_connection->cc256x_send_wbs_associate){
hfp_connection->cc256x_send_wbs_associate = false;
hci_send_cmd(&hci_ti_wbs_associate, hfp_connection->acl_handle);
return;
}
// WBS Disassociate
if (hfp_connection->cc256x_send_wbs_disassociate){
hfp_connection->cc256x_send_wbs_disassociate = false;
hci_send_cmd(&hci_ti_wbs_disassociate);
return;
}
// Write Codec Config
if (hfp_connection->cc256x_send_write_codec_config){
hfp_connection->cc256x_send_write_codec_config = false;
hfp_cc256x_write_codec_config(hfp_connection);
return;
}
// WBS Associate
if (hfp_connection->cc256x_send_wbs_associate){
hfp_connection->cc256x_send_wbs_associate = false;
hci_send_cmd(&hci_ti_wbs_associate, hfp_connection->acl_handle);
return;
}
#endif
#ifdef ENABLE_BCM_PCM_WBS
// Enable WBS
if (hfp_connection->bcm_send_enable_wbs){
hfp_connection->bcm_send_enable_wbs = false;
hci_send_cmd(&hci_bcm_enable_wbs, 1, 2);
return;
}
// Write I2S/PCM params
if (hfp_connection->bcm_send_write_i2spcm_interface_param){
hfp_connection->bcm_send_write_i2spcm_interface_param = false;
hfp_bcm_write_i2spcm_interface_param(hfp_connection);
return;
}
// Disable WBS
if (hfp_connection->bcm_send_disable_wbs){
hfp_connection->bcm_send_disable_wbs = false;
hci_send_cmd(&hci_bcm_enable_wbs, 0, 2);
return;
}
// Enable WBS
if (hfp_connection->bcm_send_enable_wbs){
hfp_connection->bcm_send_enable_wbs = false;
hci_send_cmd(&hci_bcm_enable_wbs, 1, 2);
return;
}
// Write I2S/PCM params
if (hfp_connection->bcm_send_write_i2spcm_interface_param){
hfp_connection->bcm_send_write_i2spcm_interface_param = false;
hfp_bcm_write_i2spcm_interface_param(hfp_connection);
return;
}
// Disable WBS
if (hfp_connection->bcm_send_disable_wbs){
hfp_connection->bcm_send_disable_wbs = false;
hci_send_cmd(&hci_bcm_enable_wbs, 0, 2);
return;
}
#endif
#ifdef ENABLE_RTK_PCM_WBS
// Configure CVSD vs. mSBC
if (hfp_connection->rtk_send_sco_config){
hfp_connection->rtk_send_sco_config = false;
if (hfp_connection->negotiated_codec == HFP_CODEC_MSBC){
log_info("RTK SCO: 16k + mSBC");
hci_send_cmd(&hci_rtk_configure_sco_routing, 0x81, 0x90, 0x00, 0x00, 0x1a, 0x0c, 0x00, 0x00, 0x41);
} else {
log_info("RTK SCO: 16k + CVSD");
hci_send_cmd(&hci_rtk_configure_sco_routing, 0x81, 0x90, 0x00, 0x00, 0x1a, 0x0c, 0x0c, 0x00, 0x01);
// Configure CVSD vs. mSBC
if (hfp_connection->rtk_send_sco_config){
hfp_connection->rtk_send_sco_config = false;
if (hfp_connection->negotiated_codec == HFP_CODEC_MSBC){
log_info("RTK SCO: 16k + mSBC");
hci_send_cmd(&hci_rtk_configure_sco_routing, 0x81, 0x90, 0x00, 0x00, 0x1a, 0x0c, 0x00, 0x00, 0x41);
} else {
log_info("RTK SCO: 16k + CVSD");
hci_send_cmd(&hci_rtk_configure_sco_routing, 0x81, 0x90, 0x00, 0x00, 0x1a, 0x0c, 0x0c, 0x00, 0x01);
}
return;
}
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);