• 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 __APP_BT_H__
16 #define __APP_BT_H__
17 #include "al_rtos.h"
18 #include "cs_adp_api.h"
19 #include "app_media.h"
20 #include "app_bt_queue.h"
21 #include "co_message.h"
22 #include "app_media_mgr.h"
23 #include "co_main.h"
24 #if PLF_LED_MODULE
25 #include "led.h"
26 #endif
27 #if PLF_KEY_MODULE
28 #include "key.h"
29 #endif
30 #if PLF_LS_MODULE
31 #include "light_sensor.h"
32 #endif
33 #if APP_SUPPORT_HFG && PLF_USB_BT
34 #include "usb_bt.h"
35 #include "usb_bt_dongle.h"
36 #endif
37 #if PLF_BT_OTA
38 #include "app_ota_box.h"
39 #endif
40 
41 #define APP_RECONNECT_INCREASE_TIME 3000    //increase reconnect times when reconnect timer run sometimes
42 #define APP_RECONNECT_TIME 3000             //base reconnect timer times
43 #define APP_RECONNECT_NUM  3                //max reconnect num for reconnect timer ,30 is total 3 min. (APP_RECONNECT_INCREASE_TIME*(N-1)+APP_RECONNECT_INCREASE_TIME*(N+1))
44 
45 typedef enum {
46     RECONNECT_IDLE,
47     RECONNECT_POWERON,
48     RECONNECT_AFTER_DISC,
49 }app_reconnect_mode;
50 
51 
52 typedef enum {
53     CONNECT_IDLE,
54     CONNECTED,
55     DISCONNECTED,
56 }app_connect_status;
57 
58 typedef enum{
59     BT_CLOSED,
60     BT_CLOSE_PENDING,
61     BT_ACTIVE_PENDING,
62     BT_ACTIVED,
63     BT_SCAN,
64     BT_INQUIRY_PENDNG,
65     BT_CONNECTED,
66 }app_bt_state_t;
67 
68 typedef enum {
69     KEY_HFP = 0,
70     KEY_HSP,
71     KEY_AVRCP,
72     KEY_HID,
73     KEY_SPP,
74     KEY_TWS,
75     KEY_MAX_MODULE
76 }cs_bt_key_module;
77 
78 typedef struct{
79     app_reconnect_mode reconnect_mode;
80     uint8_t connect_retry_cnt;
81 #if PLF_AON_SUPPORT
82     co_timer * connect_timer_handle;
83     co_timer_callback connect_timer_cb;
84     void * cb_param;
85 #else
86     TimerHandle_t connect_timer_handle;
87     TimerCallbackFunction_t connect_timer_cb;
88 #endif
89 }app_reconnect_struct;
90 
91 typedef struct{
92     app_connect_status hfp_connect;
93     app_connect_status hsp_connect;
94     app_connect_status a2dp_connect;
95     bool all_connected;
96 }app_profile_connect;
97 
98 typedef struct {
99     app_reconnect_struct reconnect;
100     app_profile_connect profile;
101     BT_ADDR remotedev_addr;
102 }app_connect_manager;
103 
104 typedef BOOL (*app_bt_key_handle_cb)(uint32_t key);
105 
106 typedef struct {
107     cs_bt_key_module module;
108     app_bt_key_handle_cb callback;
109 }app_bt_key_handler;
110 
111 
112 extern app_connect_manager *app_con_ptr[LINK_MAX];
113 
114 app_connect_manager *app_bt_get_unused_con_ptr(void);
115 
116 app_connect_manager *app_bt_get_con_ptr_by_addr(BT_ADDR * bdaddr);
117 
118 void app_bt_set_scan_mode(AppBtScanMode mode);
119 
120 /*************************************************************/
121 /*   @func :  app_bt_open_cs_vender_adv                     */
122 /*   @brief:  only used for two cs device connection process*/
123 /*            used by CS Vendor-Defined BLE ADV and SCAN.   */
124 /*************************************************************/
125 void app_bt_open_cs_vender_adv(void);
126 
127 void app_bt_start_pd_timer(void);
128 
129 void app_bt_init(void);
130 
131 void app_bt_connect_init(void);
132 
133 void app_bt_connect(void);
134 
135 #if PLF_AON_SUPPORT
136 void app_bt_connect_timer(void *cb_param);
137 
138 void app_bt_start_reconnect(co_timer **timer, void *cb_param, uint32_t t);
139 #else
140 void app_bt_connect_timer( TimerHandle_t xTimer );
141 
142 void app_bt_start_reconnect( TimerHandle_t xTimer ,uint32_t t);
143 #endif
144 
145 void app_bt_disconnect_all(void);
146 
147 void app_bt_report_connect_internal_audio(app_connect_manager * app_bt_con);
148 
149 void app_bt_wearing_state_hanlde(uint32_t state);
150 
151 BOOL app_bt_key_handle(uint32_t key);
152 #if APP_SUPPORT_HID == 1
153 BOOL app_hid_key_handle(uint32_t key);
154 
155 void app_hid_msg_handle(CS_EVENT *event);
156 #endif
157 
158 void app_console_command_add(void);
159 
160 void app_bt_volume_absolute_mute(void);
161 
162 void app_bt_local_volume_handle(uint8_t mode, uint8_t volume);
163 
164 #endif /* CSBT_H */
165