• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 #ifndef _AUDIO_COMMON_H_
19 #define _AUDIO_COMMON_H_
20 
21 #if (BLC_AUDIO_PROFILE_EN)
22 
23 #define BltAudioWord8ArrayIsEqual(array, word) ((array)[0] == ((word)&0xFF) && (array)[1] == (((word)&0xFF00) >> 8))
24 #define BltAudioIsThisUUID2(uuid, value)       BltAudioWord8ArrayIsEqual(uuid, value)
25 
26 #define BltAudioValueSplit2Array(Array, value)                                                                        \
27     (Array)[0] = (value)&0xFF;                                                                                        \
28     (Array)[1] = ((value)&0xFF00) >> 8
29 #define BltAudioValueSplit3Array(Array, value)                                                                        \
30     (Array)[0] = (value)&0xFF;                                                                                        \
31     (Array)[1] = ((value)&0xFF00) >> 8;                                                                               \
32     (Array)[2] = ((value)&0xFF0000) >> 16
33 #define BltAudioValueSplit4Array(Array, value)                                                                        \
34     (Array)[0] = (value)&0xFF;                                                                                        \
35     (Array)[1] = ((value)&0xFF00) >> 8;                                                                               \
36     (Array)[2] = ((value)&0xFF0000) >> 16;                                                                            \
37     (Array)[3] = ((value)&0xFF000000) >> 24
38 
39 #define BltAudio2ArraySpellValue(value, Array) (value) = (((u16)(Array)[1]) << 8) | ((u16)(Array)[0])
40 #define BltAudio3ArraySpellValue(value, Array)                                                                        \
41     (value) = (((u32)(Array)[2]) << 16) | (((u32)(Array)[1]) << 8) | ((u32)(Array)[0])
42 #define BltAudio4ArraySpellValue(value, Array)                                                                        \
43     (value) = (((u32)(Array)[3]) << 24) | (((u32)(Array)[2]) << 16) | (((u32)(Array)[1]) << 8) | ((u32)(Array)[0])
44 
45 #if BLC_AUDIO_DEBUG_ENABLE
46 #define CONSOLE_DBGID_FATA  0xD1
47 #define CONSOLE_DBGID_ERROR 0xD2
48 #define CONSOLE_DBGID_INFO  0xD3
49 #define CONSOLE_DBGID_WARN  0xD4
50 #define CONSOLE_DBGID_TRACE 0xD5
51 
52 #define send_dbgmsg_fata(datalen, pData)  blt_audio_sendDbgMsg(CONSOLE_DBGID_FATA, datalen, pData)
53 #define send_dbgmsg_error(datalen, pData) blt_audio_sendDbgMsg(CONSOLE_DBGID_ERROR, datalen, pData)
54 #define send_dbgmsg_info(datalen, pData)  blt_audio_sendDbgMsg(CONSOLE_DBGID_INFO, datalen, pData)
55 #define send_dbgmsg_warn(datalen, pData)  blt_audio_sendDbgMsg(CONSOLE_DBGID_WARN, datalen, pData)
56 #define send_dbgmsg_trace(datalen, pData) blt_audio_sendDbgMsg(CONSOLE_DBGID_TRACE, datalen, pData)
57 void blt_audio_sendDbgMsg(u8 dbgId, u8 datalen, u8 *pData);
58 #endif  // BLC_AUDIO_DEBUG_ENABLE
59 
60 typedef struct {
61     u16 handle;
62     u8 uuidLen;
63     u8 dataLen;
64     u8 *pCCC;
65     u8 *pUuid;
66     u8 *pData;
67 } blt_audio_charParam_t;
68 
69 typedef struct {
70     u8 type;
71     u8 rf_len;
72     u16 l2capLen;
73     u16 chanId;
74     u8 opcode;
75     u8 handle[2];
76     u8 value[1];
77 } blt_audio_attNotify_t;
78 
79 typedef struct {
80     u8 type;
81     u8 rf_len;
82     u16 l2capLen;
83     u16 chanId;
84     u8 opcode;
85     u8 reqcode;
86     u8 handle[2];
87     u8 errcode;
88 } blt_audio_attResp_t;
89 
90 typedef struct {
91     u8 type;
92     u8 rf_len;
93     u16 l2capLen;
94     u16 chanId;
95     u8 opcode;
96     u8 value[1];
97 } blt_audio_attPkt_t;
98 
99 typedef struct {
100     u8 type;
101     u8 rf_len;
102     u16 l2capLen;
103     u16 chanId;
104     u8 opcode;
105     u8 handle[2];
106 } blt_audio_attReadReq_t;
107 
108 typedef struct {
109     u8 type;
110     u8 rf_len;
111     u16 l2capLen;
112     u16 chanId;
113     u8 opcode;
114     u8 handle[2];
115     u8 value[1];
116 } blt_audio_attWriteReq_t;
117 
blt_audio_getBitCount(u32 value)118 static inline u8 blt_audio_getBitCount(u32 value)
119 {
120     u8 count;
121 
122     count = 0;
123     while (value) {
124         count++;
125         value &= (value - 1);
126     }
127 
128     return count;
129 }
130 
131 u8 blt_audio_findNextChar(attribute_t *pServer, u8 *pOffset, blt_audio_charParam_t *pParam);
132 ble_sts_t blt_audio_pushHandleValue(u16 connHandle, u16 attHandle, u8 opcode, u8 *p, int len);
133 ble_sts_t blt_audio_pushReadRsp(u16 connHandle, u8 *p, int len);
134 ble_sts_t blt_audio_pushBlobReadRsp(u16 connHandle, u8 *p, int len);
135 ble_sts_t blt_audio_pushErrorRsp(u16 connHandle, u8 errOpcode, u16 errHandle, u8 errCode);
136 ble_sts_t blt_audio_pushWriteRsp(u16 connHandle);
137 
138 int blt_audio_sendEvent(blt_audio_handle_t *pHandle, u16 evtID, u16 dataLen, u8 *pData);
139 
140 #endif  // #if (BLC_AUDIO_PROFILE_EN)
141 
142 #endif  // _AUDIO_COMMON_H_
143