1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __APP_BT_FUNC_H__ 16 #define __APP_BT_FUNC_H__ 17 18 #include "cs_adp_api.h" 19 20 21 typedef enum _bt_queue_req { 22 BT_INQUIRY_DEV = 0, 23 BT_INQUIRY_CANCEL , 24 BT_SET_SCAN_MODE , 25 BT_SET_LINK_POLICY , 26 BT_SET_SNIFF_TIMER , 27 BT_STOP_SNIFF , 28 BT_ROLE_SWITCH , 29 BT_DISCONNECT_LINK , 30 BT_DISCONNECT_LINK_ALL , 31 BT_A2DP_CONNECT , 32 BT_A2DP_DISCONNECT , 33 BT_HFP_CONNECT , 34 BT_HFP_DISCONNECT , 35 BT_HFP_SCO_CONNECT , 36 BT_HFP_SCO_DISCONNECT , 37 #if APP_SUPPORT_HSP == 1 38 BT_HSP_CONNECT , 39 BT_HSP_DISCONNECT , 40 BT_HSP_SCO_CONNECT , 41 BT_HSP_SCO_DISCONNECT , 42 #endif 43 #if APP_SUPPORT_A2DP_SOURCE == 1 44 BT_A2DP_SOURCE_CONNECT , 45 BT_A2DP_SOURCE_START , 46 BT_A2DP_SOURCE_SEND_DATA , 47 #endif 48 #if APP_SUPPORT_HFG == 1 49 BT_HFG_CONNECT , 50 #endif 51 #if APP_SUPPORT_TWS == 1 52 BT_TWS_CONNECT , 53 BT_TWS_SEND_DATA , 54 BT_TWS_SYNC_CTRL , 55 BT_TWS_MSS_CTRL , 56 BT_TWS_STOP_LOCAL_SYNC_CTRL , 57 BT_TWS_RESET , 58 BT_TWS_DISC , 59 BT_TWS_VISIBLE_REOPEN , 60 #endif 61 BT_GENERATE_KEY_COMPLETE , 62 BT_TWS_SNED_SYNC_PARAM , 63 BT_AUDIO_SEND_RESTART , 64 BT_AUDIO_SEND_MODE_REPLAY , 65 BT_KEY_MSG , 66 BT_WEARING_STATE , 67 BT_SET_LP_LEVEL , 68 #if FPGA == 0 69 BT_ERASE_FLASH , 70 #endif 71 BT_DUT_TEST , 72 BT_NO_SCAN , 73 BT_ISCAN , 74 BT_PSCAN , 75 BT_BOTH_SCAN , 76 #if APP_SUPPORT_OTA_BOX 77 BT_OTA_CONNECT , 78 BT_OTA_CONNECT_ID , 79 BT_OTA_SEND_DATA , 80 #endif 81 #if PLF_BLE_STACK && PLF_BLE_ONLY == 0 82 BLE_TIMER_NOTIFY , 83 #endif 84 }bt_queue_req; 85 86 typedef struct{ 87 U32 current_clk; 88 U32 counterNum; 89 U32 master_current_samplerate; 90 U32 current_bt_counter; 91 U32 current_bt_counter_offset; 92 U32 strb_cycle_offset; 93 }AppTwsMediaDataStruct; 94 95 typedef struct { 96 uint8_t len; 97 uint8_t maxResp; 98 }AppBtInquiryP; 99 100 typedef struct { 101 BT_ADDR bdaddr; 102 uint8_t on_off; 103 }AppA2dpP; 104 105 typedef struct { 106 uint8_t tws_sync_ctrl; 107 }AppTwsP; 108 109 typedef struct { 110 BT_ADDR bdaddr; 111 AppBtLinkPolicy policy; 112 }AppBtLinkPolicyP; 113 114 typedef struct { 115 BT_ADDR bdaddr; 116 AppBtSniffInfo sniff_info; 117 uint32_t timeout; 118 }AppBtSniffP; 119 120 typedef struct { 121 uint8_t dev_id; 122 uint32_t num; 123 }AppBtOtaP; 124 125 typedef struct _bt_msg_param { 126 union { 127 BT_ADDR bdaddr; 128 host_data_struct buff; 129 AppA2dpP a2dp_param; 130 AppBtInquiryP inquiry_param; 131 AppTwsP tws_param; 132 AppBtLinkPolicyP linkpolicy_param; 133 AppBtSniffP btsniff_param; 134 AppBtOtaP btota_param; 135 AppBtScanMode mode; 136 uint8_t dut; 137 uint8_t lp_level; 138 uint8_t audio_mode; 139 AppTwsMediaDataStruct sync_param; 140 uint32_t key; 141 uint8_t wearing_state; 142 }p; 143 } bt_msg_param; 144 145 typedef struct { 146 uint32_t msg_id; 147 bt_msg_param param; 148 } APP_BT_MSG; 149 150 int app_bt_queue_init(void); 151 152 int app_bt_role_switch(BT_ADDR* bdaddr); 153 154 int app_bt_disconnect_acl(BT_ADDR* bdaddr); 155 156 int app_bt_disconnect_all_acl(void); 157 158 int app_bt_stop_sniff(BT_ADDR* bdaddr); 159 160 int app_bt_setscanmode(AppBtScanMode mode); 161 162 int app_bt_set_linkpolicy(BT_ADDR* bdaddr, AppBtLinkPolicy policy); 163 164 int app_bt_set_sniff_timer(BT_ADDR *bdaddr, 165 AppBtSniffInfo* sniff_info, 166 TimeT Time); 167 168 int app_bt_connect_a2dp(BT_ADDR *bdaddr); 169 170 int app_bt_source_connect_a2dp(BT_ADDR *bdaddr); 171 172 int app_bt_close_a2dp(BT_ADDR *bdaddr); 173 174 int app_bt_connect_hfg(BT_ADDR *bdaddr); 175 176 int app_bt_connect_hfp(BT_ADDR *bdaddr); 177 178 int app_bt_disconnect_hfp(BT_ADDR *bdaddr); 179 180 int app_bt_hfp_connect_sco(BT_ADDR *bdaddr); 181 182 int app_bt_hfp_disconnect_sco(BT_ADDR *bdaddr); 183 184 #if APP_SUPPORT_HSP == 1 185 int app_bt_connect_hsp(BT_ADDR *bdaddr); 186 187 int app_bt_hsp_connect_sco(BT_ADDR *bdaddr); 188 189 int app_bt_hsp_disconnect_sco(BT_ADDR *bdaddr); 190 191 int app_bt_disconnect_hsp(BT_ADDR *bdaddr); 192 193 #endif 194 195 #if APP_SUPPORT_A2DP_SOURCE == 1 196 int app_bt_a2dp_start(BT_ADDR* bdaddr,uint32_t on); 197 198 int app_bt_a2dp_send_data(BT_ADDR* bdaddr); 199 200 #endif 201 #if APP_SUPPORT_TWS == 1 202 int app_bt_connect_tws(BT_ADDR* bdaddr); 203 204 int app_bt_tws_send_data(U8 *data,U16 len); 205 206 int app_bt_tws_sync_control(BOOL on); 207 208 int app_bt_tws_mss_control(void); 209 210 int app_bt_tws_stop_local_sync_control(void); 211 212 int app_bt_tws_reset(void); 213 214 int app_bt_tws_disc(void); 215 216 int app_bt_tws_visible_reopen(void); 217 #endif 218 int app_bt_send_wearing_state( uint32_t state); 219 220 int app_bt_send_key( uint32_t Key); 221 222 int app_bt_send_audio_sync_param(U32 synclk,U32 counternum,U32 samplerate,U32 bt_counter,U32 bt_counter_offset,U32 strb_cycle_offset); 223 224 int app_bt_send_bt_audio_restart(void); 225 226 int app_bt_send_bt_audio_mode_replay(uint32_t mode); 227 228 int app_bt_generate_key_complete(void); 229 230 int app_bt_set_lp_level(uint8_t level); 231 #if FPGA == 0 232 int app_bt_erased_flash(void); 233 #endif 234 int app_bt_dut_mode(void); 235 int app_bt_wr_scan_en(unsigned int scan_en,unsigned int dut); 236 int app_bt_inquiry_dev(unsigned int len,unsigned int maxResp); 237 int app_bt_inquiry_cancel(void); 238 #if APP_SUPPORT_OTA_BOX 239 int app_bt_ota_connect(BT_ADDR *bdaddr); 240 int app_bt_ota_connect_by_id(uint32_t id); 241 int app_bt_ota_send_data(uint32_t num); 242 #endif 243 #endif /* __APP_BT_FUNC_H__ */ 244 245