2022-08-15 04:20:27 -05:00
|
|
|
/***************************************************************************
|
2023-02-01 14:52:54 -06:00
|
|
|
*
|
|
|
|
*Copyright 2015-2019 BES.
|
|
|
|
*All rights reserved. All unpublished rights reserved.
|
|
|
|
*
|
|
|
|
*No part of this work may be used or reproduced in any form or by any
|
|
|
|
*means, or stored in a database or retrieval system, without prior written
|
|
|
|
*permission of BES.
|
|
|
|
*
|
|
|
|
*Use of this work is governed by a license granted by BES.
|
|
|
|
*This work contains confidential and proprietary information of
|
|
|
|
*BES. which is protected by copyright, trade secret,
|
|
|
|
*trademark and other intellectual property rights.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
/*****************************header include********************************/
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "app_tws_if.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "app.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "app_ai_if.h"
|
|
|
|
#include "app_ai_manager_api.h"
|
|
|
|
#include "app_ai_tws.h"
|
|
|
|
#include "app_bt.h"
|
|
|
|
#include "app_bt_func.h"
|
|
|
|
#include "app_bt_stream.h"
|
|
|
|
#include "app_dip.h"
|
|
|
|
#include "app_ibrt_ui.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "app_sec.h"
|
|
|
|
#include "app_tws_ctrl_thread.h"
|
|
|
|
#include "app_tws_ibrt_cmd_handler.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "besbt.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "btapp.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "cmsis.h"
|
|
|
|
#include "hal_trace.h"
|
|
|
|
#include "me_api.h"
|
|
|
|
#include "nvrecord_ble.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "nvrecord_env.h"
|
|
|
|
#include "nvrecord_extension.h"
|
|
|
|
#include "tgt_hardware.h"
|
|
|
|
#ifdef __THIRDPARTY
|
|
|
|
#include "app_thirdparty.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IBRT
|
|
|
|
#include "app_ibrt_customif_cmd.h"
|
|
|
|
#include "app_ibrt_customif_ui.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "app_ibrt_if.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BLE_ENABLE
|
|
|
|
#include "app_ble_include.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OTA_ENABLED
|
|
|
|
#include "ota_common.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BISTO_ENABLED
|
|
|
|
#include "gsound_custom.h"
|
|
|
|
#include "gsound_custom_tws.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
|
|
|
#include "ai_thread.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IBRT_OTA
|
|
|
|
#include "ota_control.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IS_MULTI_AI_ENABLED
|
|
|
|
#include "ai_manager.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GFPS_ENABLED
|
|
|
|
#include "app_gfps.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "nvrecord_fp_account_key.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GMA_VOICE__
|
|
|
|
#include "app_gma_ota.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************************private macro defination***************************/
|
|
|
|
|
|
|
|
/************************private struct defination****************************/
|
|
|
|
|
|
|
|
/**********************private function declearation************************/
|
|
|
|
|
|
|
|
/************************private variable defination************************/
|
|
|
|
static TWS_ENV_T twsEnv;
|
|
|
|
static TWS_SYNC_DATA_T twsSyncBuf;
|
|
|
|
|
|
|
|
osMutexId twsSyncBufMutexId = NULL;
|
|
|
|
osMutexDef(twsSyncBufMutex);
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#define POST_ROLESWITCH_STATE_STAYING_MS 15000
|
2022-08-15 04:20:27 -05:00
|
|
|
osTimerId app_post_roleswitch_handling_timer_id = NULL;
|
|
|
|
static int app_post_roleswitch_handling_timer_handler(void const *param);
|
2023-02-01 14:52:54 -06:00
|
|
|
osTimerDef(APP_POST_ROLESWITCH_HANDLING_TIMER,
|
|
|
|
(void (*)(void const *))
|
|
|
|
app_post_roleswitch_handling_timer_handler); // define timers
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
/****************************function defination****************************/
|
|
|
|
extern int hfp_volume_get(enum BT_DEVICE_ID_T id);
|
|
|
|
extern int a2dp_volume_get(enum BT_DEVICE_ID_T id);
|
2023-02-01 14:52:54 -06:00
|
|
|
static const char *tws_sync_user2str(TWS_SYNC_USER_E user) {
|
|
|
|
const char *str = NULL;
|
|
|
|
#define CASES(user) \
|
|
|
|
case user: \
|
|
|
|
str = "[" #user "]"; \
|
|
|
|
break
|
|
|
|
|
|
|
|
switch (user) {
|
|
|
|
CASES(TWS_SYNC_USER_BLE_INFO);
|
|
|
|
CASES(TWS_SYNC_USER_OTA);
|
|
|
|
CASES(TWS_SYNC_USER_AI_CONNECTION);
|
|
|
|
CASES(TWS_SYNC_USER_GFPS_INFO);
|
|
|
|
CASES(TWS_SYNC_USER_AI_INFO);
|
|
|
|
CASES(TWS_SYNC_USER_AI_MANAGER);
|
|
|
|
CASES(TWS_SYNC_USER_DIP);
|
|
|
|
|
|
|
|
default:
|
|
|
|
str = "[INVALID]";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void app_tws_if_init(void) {
|
|
|
|
// reset the environment
|
|
|
|
memset(&twsEnv, 0, sizeof(twsEnv));
|
|
|
|
memset(&twsSyncBuf, 0, TWS_SYNC_BUF_SIZE);
|
|
|
|
|
|
|
|
// init the tws sync buffer mutex
|
|
|
|
if (NULL == twsSyncBufMutexId) {
|
|
|
|
twsSyncBufMutexId = osMutexCreate(osMutex(twsSyncBufMutex));
|
|
|
|
}
|
|
|
|
|
|
|
|
// register all users
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef BLE_ENABLE
|
2023-02-01 14:52:54 -06:00
|
|
|
// init ble tws interface
|
|
|
|
app_ble_mode_tws_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OTA_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
ota_common_tws_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BISTO_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
// init gsound tws interface
|
|
|
|
app_ai_tws_gsound_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GFPS_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
app_gfps_tws_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ai_tws_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IS_MULTI_AI_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
ai_manager_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BTIF_DIP_DEVICE
|
2023-02-01 14:52:54 -06:00
|
|
|
app_dip_sync_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_role_switch_started_handler(void) {
|
|
|
|
TRACE(1, "[%s]+++", __func__);
|
|
|
|
if (NULL == app_post_roleswitch_handling_timer_id) {
|
|
|
|
app_post_roleswitch_handling_timer_id = osTimerCreate(
|
|
|
|
osTimer(APP_POST_ROLESWITCH_HANDLING_TIMER), osTimerOnce, NULL);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
osTimerStop(app_post_roleswitch_handling_timer_id);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
app_bt_active_mode_clear(ACTIVE_MODE_KEEPER_ROLE_SWITCH,
|
|
|
|
UPDATE_ACTIVE_MODE_FOR_ALL_LINKS);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static int app_post_roleswitch_handling_timer_handler(void const *param) {
|
|
|
|
app_bt_start_custom_function_in_bt_thread(ACTIVE_MODE_KEEPER_ROLE_SWITCH,
|
|
|
|
UPDATE_ACTIVE_MODE_FOR_ALL_LINKS,
|
|
|
|
(uint32_t)app_bt_active_mode_clear);
|
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static void app_tws_if_post_roleswitch_handler(void) {
|
|
|
|
if (NULL == app_post_roleswitch_handling_timer_id) {
|
|
|
|
app_post_roleswitch_handling_timer_id = osTimerCreate(
|
|
|
|
osTimer(APP_POST_ROLESWITCH_HANDLING_TIMER), osTimerOnce, NULL);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
osTimerStart(app_post_roleswitch_handling_timer_id,
|
|
|
|
POST_ROLESWITCH_STATE_STAYING_MS);
|
|
|
|
// keep bt link in active mode right after role switch
|
|
|
|
app_bt_active_mode_set(ACTIVE_MODE_KEEPER_ROLE_SWITCH,
|
|
|
|
UPDATE_ACTIVE_MODE_FOR_ALL_LINKS);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_tws_role_switch_complete_handler(uint8_t newRole) {
|
|
|
|
TRACE(2, "[%s]+++ role %d", __func__, newRole);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef BISTO_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
gsound_on_system_role_switch_done(newRole);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// update BLE info saved in flash after role switch complete
|
|
|
|
nv_record_tws_exchange_ble_info();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef BLE_USE_RPA
|
2023-02-01 14:52:54 -06:00
|
|
|
appm_refresh_ble_irk();
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
btif_me_set_ble_bd_address(bt_get_ble_local_address());
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ai_tws_role_switch_complete();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BLE_ENABLE
|
2023-02-01 14:52:54 -06:00
|
|
|
ble_callback_evnet_t event;
|
|
|
|
event.evt_type = BLE_CALLBACK_RS_COMPLETE;
|
|
|
|
event.p.rs_complete_handled.newRole = newRole;
|
|
|
|
app_ble_core_global_callback_event(&event, NULL);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
app_tws_if_post_roleswitch_handler();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef IBRT_OTA
|
2023-02-01 14:52:54 -06:00
|
|
|
ota_control_send_role_switch_complete();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_register_sync_user(uint8_t id, TWS_SYNC_USER_T *user) {
|
|
|
|
memcpy(&twsEnv.syncUser[id], user, sizeof(TWS_SYNC_USER_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_deregister_sync_user(uint8_t id) {
|
|
|
|
memset(&twsEnv.syncUser[id], 0, sizeof(TWS_SYNC_USER_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_sync_info(TWS_SYNC_USER_E id) {
|
|
|
|
TRACE(1, "[%s]+++", __func__);
|
|
|
|
TRACE(1, "user:%s", tws_sync_user2str(id));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
osMutexWait(twsSyncBufMutexId, osWaitForever);
|
|
|
|
if (twsEnv.syncUser[id].sync_info_prepare_handler) {
|
|
|
|
uint16_t length = 0;
|
|
|
|
twsEnv.syncUser[id].sync_info_prepare_handler(twsSyncBuf.info, &length);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (length) {
|
|
|
|
twsSyncBuf.userId = id;
|
|
|
|
length++;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
tws_ctrl_send_cmd(APP_TWS_CMD_SHARE_COMMON_INFO, (uint8_t *)&twsSyncBuf,
|
|
|
|
length);
|
|
|
|
} else {
|
|
|
|
TRACE(0, "no info to sync");
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
2023-02-01 14:52:54 -06:00
|
|
|
} else {
|
|
|
|
TRACE(0, "prepare handler is null pointer");
|
|
|
|
}
|
|
|
|
osMutexRelease(twsSyncBufMutexId);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_sync_info_received_handler(uint16_t rsp_seq, uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]+++", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TWS_SYNC_DATA_T *pInfo = (TWS_SYNC_DATA_T *)p_buff;
|
|
|
|
TRACE(1, "user:%s", tws_sync_user2str(pInfo->userId));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// handle received data
|
|
|
|
if (twsEnv.syncUser[pInfo->userId].sync_info_received_handler) {
|
|
|
|
twsEnv.syncUser[pInfo->userId].sync_info_received_handler(pInfo->info,
|
|
|
|
(length - 1));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// send response to peer device
|
|
|
|
uint16_t len = 0;
|
|
|
|
osMutexWait(twsSyncBufMutexId, osWaitForever);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (twsEnv.syncUser[pInfo->userId].sync_info_prepare_rsp_handler) {
|
|
|
|
twsEnv.syncUser[pInfo->userId].sync_info_prepare_rsp_handler(
|
|
|
|
twsSyncBuf.info, &len);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
twsSyncBuf.userId = pInfo->userId;
|
|
|
|
len++;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
tws_ctrl_send_rsp(APP_TWS_CMD_SHARE_COMMON_INFO, rsp_seq,
|
|
|
|
(uint8_t *)&twsSyncBuf, len);
|
|
|
|
osMutexRelease(twsSyncBufMutexId);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_sync_info_rsp_received_handler(uint16_t rsp_seq,
|
|
|
|
uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]+++", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TWS_SYNC_DATA_T *pInfo = (TWS_SYNC_DATA_T *)p_buff;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// handle received data
|
|
|
|
if (twsEnv.syncUser[pInfo->userId].sync_info_rsp_received_handler) {
|
|
|
|
twsEnv.syncUser[pInfo->userId].sync_info_rsp_received_handler(pInfo->info,
|
|
|
|
(length - 1));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_sync_info_rsp_timeout_handler(uint16_t rsp_seq, uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]+++", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TWS_SYNC_DATA_T *pInfo = (TWS_SYNC_DATA_T *)p_buff;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (twsEnv.syncUser[pInfo->userId].sync_info_rsp_timeout_handler) {
|
|
|
|
twsEnv.syncUser[pInfo->userId].sync_info_rsp_timeout_handler(pInfo->info,
|
|
|
|
(length - 1));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_tws_role_updated_handler(uint8_t newRole) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef BLE_ENABLE
|
2023-02-01 14:52:54 -06:00
|
|
|
ble_callback_evnet_t event;
|
|
|
|
event.evt_type = BLE_CALLBACK_ROLE_UPDATE;
|
|
|
|
event.p.role_update_handled.newRole = newRole;
|
|
|
|
app_ble_core_global_callback_event(&event, NULL);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(BISTO_ENABLED) && defined(IBRT)
|
2023-02-01 14:52:54 -06:00
|
|
|
gsound_on_tws_role_updated(newRole);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_tws_connected_sync_info(void) {
|
|
|
|
TRACE(2, "[%s]+++ role %d", __func__, app_tws_ibrt_role_get_callback(NULL));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (IBRT_MASTER == app_tws_ibrt_role_get_callback(NULL)) {
|
|
|
|
// inform peer to update the common info
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_BLE_INFO);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_OTA);
|
|
|
|
// app_tws_if_sync_info(TWS_SYNC_USER_AI_CONNECTION);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_GFPS_INFO);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_AI_INFO);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_AI_MANAGER);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_DIP);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef GFPS_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
if (!app_tws_ibrt_mobile_link_connected()) {
|
|
|
|
app_enter_fastpairing_mode();
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
2023-02-01 14:52:54 -06:00
|
|
|
#endif
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "[%s]---", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_tws_connected_handler(void) {
|
|
|
|
TRACE(1, "twsif_tws_connected, role %d",
|
|
|
|
app_tws_ibrt_role_get_callback(NULL));
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_tws_disconnected_handler(void) {
|
|
|
|
TRACE(0, "twsif_tws_disconnected.");
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
if (IBRT_SLAVE == app_tws_ibrt_role_get_callback(NULL)) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef BISTO_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
gsound_set_ble_connect_state(GSOUND_CHANNEL_AUDIO, false);
|
|
|
|
gsound_set_ble_connect_state(GSOUND_CHANNEL_CONTROL, false);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __GMA_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_gma_ota_exception_reboot(); // shuailong
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_mobile_connected_handler(uint8_t *addr) {
|
|
|
|
TRACE(0, "twsif_mobile_connected");
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
if (IBRT_MASTER == app_tws_ibrt_role_get_callback(NULL))
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
// inform peer to update the common info
|
|
|
|
// app_tws_if_sync_info(TWS_SYNC_USER_AI_CONNECTION);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_GFPS_INFO);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_mobile_disconnected_handler(uint8_t *addr) {
|
|
|
|
TRACE(0, "twsif_mobile_disconnected");
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ibrt_connected_handler(void) {
|
|
|
|
TRACE(0, "twsif_ibrt_connected");
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
if (IBRT_MASTER == app_tws_ibrt_role_get_callback(NULL))
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
// inform peer to update the common info
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_AI_INFO);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_AI_MANAGER);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ibrt_disconnected_handler(void) {
|
|
|
|
TRACE(0, "twsif_ibrt_disconnected");
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ble_connected_handler(void) {
|
|
|
|
TRACE(0, "twsif_ble_connected");
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
if (IBRT_MASTER == app_tws_ibrt_role_get_callback(NULL))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// inform peer to update the common info
|
|
|
|
// app_tws_if_sync_info(TWS_SYNC_USER_BLE_INFO);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_OTA);
|
|
|
|
// app_tws_if_sync_info(TWS_SYNC_USER_AI_CONNECTION);
|
|
|
|
app_tws_if_sync_info(TWS_SYNC_USER_GFPS_INFO);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ble_disconnected_handler(void) {
|
|
|
|
TRACE(0, "twsif_ble_disconnected");
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
if (IBRT_MASTER == app_tws_ibrt_role_get_callback(NULL))
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
// inform peer to update the common info
|
|
|
|
// app_tws_if_sync_info(TWS_SYNC_USER_AI_CONNECTION);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_trigger_role_switch(void) {
|
|
|
|
if (false == app_ibrt_ui_can_tws_switch()) {
|
|
|
|
TRACE(1, "%s can't switch", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ibrt_customif_ui_tws_switch();
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_handle_click(void) {
|
|
|
|
TRACE(1, "%s", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(BISTO_ENABLED) || defined(__AI_VOICE__)
|
2023-02-01 14:52:54 -06:00
|
|
|
app_tws_if_trigger_role_switch();
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
bt_key_handle_func_click();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_send_cmd_to_peer(uint8_t *p_buff, uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
tws_ctrl_send_cmd(APP_TWS_CMD_AI_SEND_CMD_TO_PEER, p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_rev_peer_cmd_hanlder(uint16_t rsp_seq, uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ai_tws_rev_peer_cmd_hanlder(rsp_seq, p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_send_cmd_with_rsp_to_peer(uint8_t *p_buff, uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
tws_ctrl_send_cmd(APP_TWS_CMD_AI_SEND_CMD_TO_PEER_WITH_RSP, p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_send_cmd_rsp_to_peer(uint8_t *p_buff, uint16_t rsp_seq,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
tws_ctrl_send_rsp(APP_TWS_CMD_AI_SEND_CMD_TO_PEER_WITH_RSP, rsp_seq, p_buff,
|
|
|
|
length);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_rev_peer_cmd_with_rsp_hanlder(uint16_t rsp_seq,
|
|
|
|
uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ai_tws_rev_peer_cmd_with_rsp_hanlder(rsp_seq, p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_rev_cmd_rsp_from_peer_hanlder(uint16_t rsp_seq,
|
|
|
|
uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
|
|
|
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ai_tws_rev_cmd_rsp_from_peer_hanlder(rsp_seq, p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_ai_rev_cmd_rsp_timeout_hanlder(uint16_t rsp_seq,
|
|
|
|
uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
TRACE(1, "[%s]", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
app_ai_tws_rev_cmd_rsp_timeout_hanlder(rsp_seq, p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_master_prepare_rs(uint8_t *p_buff, uint16_t length) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef BLE_ENABLE
|
2023-02-01 14:52:54 -06:00
|
|
|
ble_callback_evnet_t event;
|
|
|
|
event.evt_type = BLE_CALLBACK_RS_START;
|
|
|
|
app_ble_core_global_callback_event(&event, NULL);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef BISTO_ENABLED
|
2023-02-01 14:52:54 -06:00
|
|
|
if (*p_buff == AI_SPEC_GSOUND) {
|
|
|
|
gsound_tws_update_roleswitch_initiator(IBRT_SLAVE);
|
|
|
|
gsound_tws_request_roleswitch();
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
if (*p_buff != AI_SPEC_GSOUND) {
|
|
|
|
app_ai_tws_master_role_switch_prepare();
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_if_slave_continue_rs(uint8_t *p_buff, uint16_t length) {
|
|
|
|
TRACE(2, "%s len %d", __func__, length);
|
|
|
|
DUMP8("%x ", p_buff, length);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __AI_VOICE__
|
2023-02-01 14:52:54 -06:00
|
|
|
if (*p_buff != AI_SPEC_GSOUND) {
|
|
|
|
app_ai_tws_role_switch_prepare_done();
|
|
|
|
} else
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
app_ibrt_if_tws_switch_prepare_done_in_bt_thread(IBRT_ROLE_SWITCH_USER_AI,
|
|
|
|
(uint32_t)*p_buff);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(GFPS_ENABLED) && defined(IBRT)
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_ibrt_share_fastpair_info(uint8_t *p_buff, uint16_t length) {
|
|
|
|
app_ibrt_send_cmd_without_rsp(APP_TWS_CMD_SHARE_FASTPAIR_INFO, p_buff,
|
|
|
|
length);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_send_fastpair_info_to_slave(void) {
|
|
|
|
TRACE(0, "Send fastpair info to secondary device.");
|
|
|
|
NV_FP_ACCOUNT_KEY_RECORD_T *pFpData = nv_record_get_fp_data_structure_info();
|
|
|
|
app_ibrt_share_fastpair_info((uint8_t *)pFpData,
|
|
|
|
sizeof(NV_FP_ACCOUNT_KEY_RECORD_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_ibrt_shared_fastpair_info_received_handler(uint16_t rsp_seq,
|
|
|
|
uint8_t *p_buff,
|
|
|
|
uint16_t length) {
|
|
|
|
NV_FP_ACCOUNT_KEY_RECORD_T *pFpData = (NV_FP_ACCOUNT_KEY_RECORD_T *)p_buff;
|
|
|
|
nv_record_update_fp_data_structure(pFpData);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IBRT
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_is_master_mode(void) {
|
|
|
|
return (IBRT_MASTER == app_tws_ibrt_role_get_callback(NULL)) ? true : false;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_is_slave_mode(void) {
|
|
|
|
return (IBRT_SLAVE == app_tws_ibrt_role_get_callback(NULL)) ? true : false;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_is_freeman_mode(void) {
|
|
|
|
return (IBRT_UNKNOW == app_tws_ibrt_role_get_callback(NULL)) ? true : false;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_nv_is_master_role(void) {
|
|
|
|
TRACE(1, "[ZYH]%s -> %d", __func__, app_tws_ibrt_nv_role_get_callback(NULL));
|
|
|
|
return (IBRT_MASTER == app_tws_ibrt_nv_role_get_callback(NULL)) ? true
|
|
|
|
: false;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_ibrt_sync_volume_info(void) {
|
|
|
|
if (app_tws_ibrt_tws_link_connected()) {
|
|
|
|
ibrt_volume_info_t ibrt_volume_req;
|
|
|
|
ibrt_volume_req.a2dp_volume = a2dp_volume_get(BT_DEVICE_ID_1);
|
|
|
|
ibrt_volume_req.hfp_volume = hfp_volume_get(BT_DEVICE_ID_1);
|
|
|
|
tws_ctrl_send_cmd(APP_TWS_CMD_SYNC_VOLUME_INFO, (uint8_t *)&ibrt_volume_req,
|
|
|
|
sizeof(ibrt_volume_req));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static APP_TWS_SIDE_T app_tws_side = EAR_SIDE_UNKNOWN;
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_set_side(APP_TWS_SIDE_T side) {
|
|
|
|
ASSERT((EAR_SIDE_LEFT == side) || (EAR_SIDE_RIGHT == side),
|
|
|
|
"Error: setting invalid side");
|
|
|
|
TRACE(1, "Set TWS side to %d", side);
|
|
|
|
app_tws_side = side;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_is_left_side(void) { return (app_tws_side == EAR_SIDE_LEFT); }
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_is_right_side(void) { return (app_tws_side == EAR_SIDE_RIGHT); }
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool app_tws_is_unknown_side(void) {
|
|
|
|
return (app_tws_side == EAR_SIDE_UNKNOWN);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2022-12-28 04:29:29 -06:00
|
|
|
// void app_tws_set_side_from_addr(uint8_t *addr)
|
|
|
|
// {
|
|
|
|
// ASSERT(addr, "Error: address invalid");
|
|
|
|
// if (addr[0] & 0x1) {
|
|
|
|
// app_tws_set_side(EAR_SIDE_RIGHT);
|
|
|
|
// TRACE(0, "Right earbud");
|
|
|
|
// } else {
|
|
|
|
// app_tws_set_side(EAR_SIDE_LEFT);
|
|
|
|
// TRACE(0, "Left earbud");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void app_tws_set_side_from_gpio(void) {
|
|
|
|
if (tgt_tws_get_channel_is_right()) {
|
|
|
|
app_tws_set_side(EAR_SIDE_RIGHT);
|
|
|
|
} else {
|
|
|
|
app_tws_set_side(EAR_SIDE_LEFT);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|