• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _CS_ADP_TWS_
16 #define _CS_ADP_TWS_
17 /*chipsea_ohos proguard begin*/
18 #include "cs_proguard.h"
19 /*chipsea_ohos proguard end*/
20 
21 #include "cs_adp_type.h"
22 
23 typedef enum {
24     TWS_SLAVE = 0,
25     TWS_MASTER,
26     TWS_NOROLE,
27     TWS_NOSUPPORT,
28 }CS_ADP_TWS_ROLE;
29 
30 #ifndef RWIP_TIME_T
31 #define RWIP_TIME_T
32 typedef struct
33 {
34     /// Integer part of the time (in half-slot)
35     uint32_t hs;
36     /// Fractional part of the time (in half-us) (range: 0-624)
37     uint32_t hus;
38 } rwip_time_t;
39 
40 typedef struct
41 {
42     /// Integer part of the time (in half-slot)
43     uint32_t clk_off_hs;
44     /// Fractional part of the time (in half-us) (range: 0-624)
45     uint32_t clk_off_hus;
46 } TWS_BT_CLK_INFO_Type;
47 #endif
48 
49 typedef enum {
50     CS_IDLE = 0,
51     CS_PENDING,
52     CS_CONNECTED,
53     CS_STOP,
54     CS_START,
55     CS_CALL,
56     CS_STATE_END = 0xff,
57 }CS_TWS_STATE;
58 
59 typedef struct {
60     bt_err_type reason;
61 }Tws_Con_t;
62 
63 typedef struct {
64     bt_err_type reason;
65     CS_ADP_TWS_ROLE last_role;
66 }Tws_Disc_t;
67 
68 typedef struct {
69     U32 tws_trig_data;//redefined by AppTwsMediaDataStruct
70 }Tws_TrigNum_t;
71 
72 typedef struct {
73     U32 tws_sync_data;//redefined by AppTwsMediaDataStruct
74 }Tws_AudSync_t;
75 
76 typedef struct {
77     host_data_struct * buff;
78 }Tws_DataSend_t;
79 
80 typedef struct {
81     host_data_struct * buff;
82 }Tws_DataInd_t;
83 
84 
85 typedef struct _CS_ADP_TWS_EVENT_{
86     BT_ADDR bdaddr;
87     union {
88         Tws_Con_t conP;
89         Tws_Disc_t discP;
90         Tws_TrigNum_t trigP;
91         Tws_AudSync_t syncP;
92         Tws_DataSend_t datasendP;
93         Tws_DataInd_t dataindP;
94     }p;
95 }CS_ADP_TWS_EVENT;
96 
97 void cs_adp_tws_init(void);
98 void cs_adp_connect_tws_peer_device(BT_ADDR * bdaddr);
99 void cs_adp_disconnect_tws(BT_ADDR * bdaddr);
100 uint8_t cs_tws_get_porttype(void);
101 BOOL cs_adp_send_data(uint8_t* ptrData, uint16_t length);
102 BOOL cs_adp_check_cmp_twsaddr(BT_ADDR bdaddr);
103 CS_ADP_TWS_ROLE tws_app_get_role(void);
104 CS_ADP_TWS_ROLE tws_app_get_flash_role(void);
105 void cs_adp_update_tws_flash_role(CS_ADP_TWS_ROLE role);
106 rwip_time_t cs_adp_get_native_clk_plus_offset(void);
107 TWS_BT_CLK_INFO_Type cs_adp_get_slave_bt_offset(void);
108 void cs_adp_set_audio_sync_param(U32 synclk,U32 counternum,U32 samplerate,U32 bt_counter,U32 bt_counter_offset,U32 strb_cycle_offset);
109 void cs_adp_tws_restart(void);
110 void cs_adp_host_control_tws_sync_con(BOOL con_or_disc);
111 void cs_adp_host_m_s_switch(void);
112 void cs_adp_host_sync_stop(void);
113 
114 /************************************************
115 function: cs_adp_tws_set_scan_para
116           set ble scan param and then make scan enable,the param was set in adp layer.
117 
118           reset: 1:scan allow adv all
119                  0:scan allow adv in white list
120 *************************************************/
121 void cs_adp_tws_set_scan_para(U8 reset);
122 
123 /************************************************
124 function: cs_adp_tws_set_scan_disable
125           set ble scan disable
126 *************************************************/
127 void cs_adp_tws_set_scan_disable(void);
128 
129 /************************************************
130 function: cs_adp_tws_start_adv
131           set ble adv enable,the param was set in adp layer.
132 *************************************************/
133 void cs_adp_tws_start_adv(BT_ADDR bdaddr);
134 
135 /************************************************
136 function: cs_adp_tws_stop_adv
137           disable ble adv
138 *************************************************/
139 void cs_adp_tws_stop_adv(void);
140 /************************************************
141 function: cs_adp_tws_clear_whitelist
142           clear whitelist in fw
143 *************************************************/
144 void cs_adp_tws_clear_whitelist(void);
145 
146 #endif
147 
148