• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., 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 AUDIO_DEF_H
16 #define AUDIO_DEF_H
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <stdint.h>
23 
24 #define CODEC_FREQ_24M                      24000000
25 #define CODEC_FREQ_26M                      26000000
26 #define CODEC_FREQ_24P576M                  24576000
27 #define CODEC_FREQ_22P5792M                 22579200
28 
29 #define CODEC_FREQ_48K_SERIES               CODEC_FREQ_24P576M
30 #define CODEC_FREQ_44_1K_SERIES             CODEC_FREQ_22P5792M
31 
32 #if 0
33 #elif defined(CHIP_BEST3001) || defined(CHIP_BEST3003) || defined(CHIP_BEST3005)
34 
35 #define CODEC_FREQ_CRYSTAL                  CODEC_FREQ_24M
36 
37 #define CODEC_PLL_DIV                       36
38 #define CODEC_CMU_DIV                       9
39 #ifdef CHIP_BEST3001
40 #define CODEC_PLAYBACK_BIT_DEPTH            20
41 #else
42 #define CODEC_PLAYBACK_BIT_DEPTH            24
43 #endif
44 
45 #elif defined(CHIP_BEST1305) || \
46     defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
47     defined(CHIP_BEST1501) || defined(CHIP_BEST1600) || \
48     defined(CHIP_BEST2300) || defined(CHIP_BEST2300A) || \
49     defined(CHIP_BEST2300P) || defined(CHIP_BEST1501SIMU) || defined(CHIP_BEST1600SIMU)
50 
51 #if defined(CHIP_BEST1501) || defined(CHIP_BEST1501SIMU) || defined(CHIP_BEST1600SIMU)
52 #define CODEC_FREQ_CRYSTAL                  CODEC_FREQ_24M
53 #endif
54 
55 #define CODEC_FREQ_EXTRA_DIV                2
56 
57 #define CODEC_PLL_DIV                       16
58 #define CODEC_CMU_DIV                       8
59 #define CODEC_PLAYBACK_BIT_DEPTH            24
60 
61 #elif defined(CHIP_BEST1000)
62 
63 #if defined(__AUDIO_DIV_10___)
64 #define CODEC_PLL_DIV                       10
65 #elif defined(__AUDIO_DIV_9___)
66 #define CODEC_PLL_DIV                       9
67 #else
68 #define CODEC_PLL_DIV                       8
69 #endif
70 #define CODEC_CMU_DIV                       CODEC_PLL_DIV
71 #define CODEC_PLAYBACK_BIT_DEPTH            18
72 
73 #elif defined(CHIP_BEST2000) || defined(CHIP_BEST2001) || defined(CHIP_BEST2002)
74 
75 #define CODEC_PLL_DIV                       32
76 #define CODEC_CMU_DIV                       8
77 #define CODEC_PLAYBACK_BIT_DEPTH            20
78 
79 #elif defined(CHIP_BEST2003)
80 
81 #define CODEC_PLL_DIV                       156
82 #define CODEC_CMU_DIV                       13
83 #define CODEC_PLAYBACK_BIT_DEPTH            20
84 
85 #else
86 
87 #error "Please update audio definitions"
88 
89 #endif
90 
91 #ifndef CODEC_FREQ_CRYSTAL
92 #define CODEC_FREQ_CRYSTAL                  CODEC_FREQ_26M
93 #endif
94 #ifndef CODEC_FREQ_EXTRA_DIV
95 #define CODEC_FREQ_EXTRA_DIV                1
96 #endif
97 
98 #define CODEC_TX_PA_GAIN_DEFAULT            -1
99 
100 enum AUD_STREAM_USE_DEVICE_T{
101     AUD_STREAM_USE_DEVICE_NULL = 0,
102     AUD_STREAM_USE_EXT_CODEC,
103     AUD_STREAM_USE_I2S0_MASTER,
104     AUD_STREAM_USE_I2S0_SLAVE,
105     AUD_STREAM_USE_I2S1_MASTER,
106     AUD_STREAM_USE_I2S1_SLAVE,
107     AUD_STREAM_USE_TDM0_MASTER,
108     AUD_STREAM_USE_TDM0_SLAVE,
109     AUD_STREAM_USE_TDM1_MASTER,
110     AUD_STREAM_USE_TDM1_SLAVE,
111     AUD_STREAM_USE_INT_CODEC,
112     AUD_STREAM_USE_INT_CODEC2,
113     AUD_STREAM_USE_INT_SPDIF,
114     AUD_STREAM_USE_BT_PCM,
115     AUD_STREAM_USE_DPD_RX,
116     AUD_STREAM_USE_MC,
117 };
118 
119 enum AUD_SAMPRATE_T {
120     AUD_SAMPRATE_NULL = 0,
121     AUD_SAMPRATE_7350 = 7350,
122     AUD_SAMPRATE_8000 = 8000,
123     AUD_SAMPRATE_8463 = 8463,       // 26M / 512 / 6
124     AUD_SAMPRATE_14700 = 14700,
125     AUD_SAMPRATE_16000 = 16000,
126     AUD_SAMPRATE_16927 = 16927,     // 26M / 512 / 3
127     AUD_SAMPRATE_22050 = 22050,
128     AUD_SAMPRATE_24000 = 24000,
129     AUD_SAMPRATE_32000 = 32000,
130     AUD_SAMPRATE_44100 = 44100,
131     AUD_SAMPRATE_48000 = 48000,
132     AUD_SAMPRATE_50781 = 50781,     // 26M / 512
133     AUD_SAMPRATE_64000 = 64000,
134     AUD_SAMPRATE_88200 = 88200,
135     AUD_SAMPRATE_96000 = 96000,
136     AUD_SAMPRATE_101562 = 101562,   // 26M / 256
137     AUD_SAMPRATE_128000 = 128000,
138     AUD_SAMPRATE_176400 = 176400,
139     AUD_SAMPRATE_192000 = 192000,
140     AUD_SAMPRATE_203125 = 203125,   // 26M / 128
141     AUD_SAMPRATE_256000 = 256000,
142     AUD_SAMPRATE_352800 = 352800,
143     AUD_SAMPRATE_384000 = 384000,
144     AUD_SAMPRATE_406250 = 406250,   // 26M / 64
145     AUD_SAMPRATE_705600 = 705600,
146     AUD_SAMPRATE_768000 = 768000,
147     AUD_SAMPRATE_812500 = 812500,   // 26M / 32
148     // NOTE: DIV must be a multiple of 32
149 };
150 
151 enum AUD_CHANNEL_NUM_T {
152     AUD_CHANNEL_NUM_NULL = 0,
153     AUD_CHANNEL_NUM_1 = 1,
154     AUD_CHANNEL_NUM_2 = 2,
155     AUD_CHANNEL_NUM_3 = 3,
156     AUD_CHANNEL_NUM_4 = 4,
157     AUD_CHANNEL_NUM_5 = 5,
158     AUD_CHANNEL_NUM_6 = 6,
159     AUD_CHANNEL_NUM_7 = 7,
160     AUD_CHANNEL_NUM_8 = 8,
161 };
162 
163 // For preprocess check
164 #define AUD_CHANNEL_MAP_CH0                 (1 << 0)
165 #define AUD_CHANNEL_MAP_CH1                 (1 << 1)
166 #define AUD_CHANNEL_MAP_CH2                 (1 << 2)
167 #define AUD_CHANNEL_MAP_CH3                 (1 << 3)
168 #define AUD_CHANNEL_MAP_CH4                 (1 << 4)
169 #define AUD_CHANNEL_MAP_CH5                 (1 << 5)
170 #define AUD_CHANNEL_MAP_CH6                 (1 << 6)
171 #define AUD_CHANNEL_MAP_CH7                 (1 << 7)
172 #define AUD_CHANNEL_MAP_DIGMIC_CH0          (1 << 8)
173 #define AUD_CHANNEL_MAP_DIGMIC_CH1          (1 << 9)
174 #define AUD_CHANNEL_MAP_DIGMIC_CH2          (1 << 10)
175 #define AUD_CHANNEL_MAP_DIGMIC_CH3          (1 << 11)
176 #define AUD_CHANNEL_MAP_DIGMIC_CH4          (1 << 12)
177 #define AUD_CHANNEL_MAP_DIGMIC_CH5          (1 << 13)
178 #define AUD_CHANNEL_MAP_DIGMIC_CH6          (1 << 14)
179 #define AUD_CHANNEL_MAP_DIGMIC_CH7          (1 << 15)
180 #define AUD_CHANNEL_MAP_ECMIC_CH0           (1 << 16)
181 #define AUD_CHANNEL_MAP_ECMIC_CH1           (1 << 17)
182 
183 #define AUD_CHANNEL_MAP_ANA_ALL             (0x000000FF)
184 #define AUD_CHANNEL_MAP_DIGMIC_ALL          (0x0000FF00)
185 #define AUD_CHANNEL_MAP_NORMAL_ALL          (0x0000FFFF)
186 #define AUD_CHANNEL_MAP_ALL                 (0x0003FFFF)
187 
188 enum AUD_CHANNEL_MAP_T {
189     AUD_CHANNEL_MAP_END = AUD_CHANNEL_MAP_ECMIC_CH1,
190 };
191 
192 enum AUD_VMIC_MAP_T {
193     AUD_VMIC_MAP_VMIC1 = (AUD_CHANNEL_MAP_END << 1),
194     AUD_VMIC_MAP_VMIC2 = (AUD_CHANNEL_MAP_END << 2),
195     AUD_VMIC_MAP_VMIC3 = (AUD_CHANNEL_MAP_END << 3),
196     AUD_VMIC_MAP_VMIC4 = (AUD_CHANNEL_MAP_END << 4),
197     AUD_VMIC_MAP_VMIC5 = (AUD_CHANNEL_MAP_END << 5),
198 };
199 
200 enum AUD_BITS_T {
201     AUD_BITS_NULL = 0,
202     AUD_BITS_8 = 8,
203     AUD_BITS_12 = 12,
204     AUD_BITS_16 = 16,
205     AUD_BITS_20 = 20,
206     AUD_BITS_24 = 24,
207     AUD_BITS_32 = 32,
208 };
209 
210 enum AUD_DATA_ALIGN_T {
211     AUD_DATA_ALIGN_I2S = 0,
212     AUD_DATA_ALIGN_LEFT_JUSTIFIED,
213     AUD_DATA_ALIGN_RIGHT_JUSTIFIED,
214 };
215 
216 enum AUD_FS_FIRST_EDGE_T {
217     AUD_FS_FIRST_EDGE_NEG = 0,  // I2S mode
218     AUD_FS_FIRST_EDGE_POS,      // TDM mode (likely)
219 };
220 
221 enum AUD_STREAM_ID_T {
222     AUD_STREAM_ID_0 = 0,
223     AUD_STREAM_ID_1,
224     AUD_STREAM_ID_2,
225     AUD_STREAM_ID_3,
226 
227     AUD_STREAM_ID_NUM,
228 };
229 
230 enum AUD_STREAM_T {
231     AUD_STREAM_PLAYBACK = 0,
232     AUD_STREAM_CAPTURE,
233 
234     AUD_STREAM_NUM,
235 };
236 
237 // TODO: Need rename
238 enum AUD_IO_PATH_T {
239     AUD_IO_PATH_NULL = 0,
240 
241     // Input path
242     AUD_INPUT_PATH_MAINMIC,
243     AUD_INPUT_PATH_VOICE_DEV,
244     AUD_INPUT_PATH_VADMIC,
245     AUD_INPUT_PATH_ASRMIC,
246     AUD_INPUT_PATH_LINEIN,
247     AUD_INPUT_PATH_NTMIC,
248     AUD_INPUT_PATH_USBAUDIO,
249     AUD_INPUT_PATH_ANC_ASSIST,
250     AUD_INPUT_PATH_HEARING,
251 
252     // Output path
253     AUD_OUTPUT_PATH_SPEAKER,
254 };
255 
256 struct AUD_IO_PATH_CFG_T {
257     enum AUD_IO_PATH_T io_path;
258     unsigned int cfg;
259 };
260 
261 #define ANC_TYPE_NUM    (8)
262 enum ANC_TYPE_T {
263     ANC_NOTYPE          = 0,
264     ANC_FEEDFORWARD     = (1 << 0),
265     ANC_FEEDBACK        = (1 << 1),
266     ANC_TALKTHRU        = (1 << 2),
267     ANC_MUSICCANCLE     = (1 << 3),
268     ANC_SPKCALIB        = (1 << 4),
269     ANC_DEHOWLING       = (1 << 5),
270     PSAP_FEEDFORWARD    = (1 << 6),
271 };
272 
273 struct CODEC_DAC_VOL_T {
274     signed char tx_pa_gain      :6;
275     unsigned char sdm_gain      :2;
276     signed char sdac_volume;
277 };
278 
279 typedef signed char CODEC_ADC_VOL_T;
280 
281 enum TGT_VOLUME_LEVEL_T {
282     TGT_VOLUME_LEVEL_MUTE = 0,
283     TGT_VOLUME_LEVEL_1,
284     TGT_VOLUME_LEVEL_2,
285     TGT_VOLUME_LEVEL_3,
286     TGT_VOLUME_LEVEL_4,
287     TGT_VOLUME_LEVEL_5,
288     TGT_VOLUME_LEVEL_6,
289     TGT_VOLUME_LEVEL_7,
290     TGT_VOLUME_LEVEL_8,
291     TGT_VOLUME_LEVEL_9,
292     TGT_VOLUME_LEVEL_10,
293     TGT_VOLUME_LEVEL_11,
294     TGT_VOLUME_LEVEL_12,
295     TGT_VOLUME_LEVEL_13,
296     TGT_VOLUME_LEVEL_14,
297     TGT_VOLUME_LEVEL_15,
298     TGT_VOLUME_LEVEL_MAX,
299 
300     TGT_VOLUME_LEVEL_QTY
301 };
302 
303 enum TGT_ADC_VOL_LEVEL_T {
304     TGT_ADC_VOL_LEVEL_0 = 0,
305     TGT_ADC_VOL_LEVEL_1,
306     TGT_ADC_VOL_LEVEL_2,
307     TGT_ADC_VOL_LEVEL_3,
308     TGT_ADC_VOL_LEVEL_4,
309     TGT_ADC_VOL_LEVEL_5,
310     TGT_ADC_VOL_LEVEL_6,
311     TGT_ADC_VOL_LEVEL_7,
312     TGT_ADC_VOL_LEVEL_8,
313     TGT_ADC_VOL_LEVEL_9,
314     TGT_ADC_VOL_LEVEL_10,
315     TGT_ADC_VOL_LEVEL_11,
316     TGT_ADC_VOL_LEVEL_12,
317     TGT_ADC_VOL_LEVEL_13,
318     TGT_ADC_VOL_LEVEL_14,
319     TGT_ADC_VOL_LEVEL_15,
320 
321     TGT_ADC_VOL_LEVEL_QTY
322 };
323 
324 typedef void (*AUD_VAD_CALLBACK)(int found);
325 
326 enum AUD_VAD_TYPE_T {
327     AUD_VAD_TYPE_NONE = 0,
328     AUD_VAD_TYPE_MIX,
329     AUD_VAD_TYPE_DIG,
330     AUD_VAD_TYPE_ANA,
331 
332     AUD_VAD_TYPE_NUM,
333 };
334 
335 #define VAD_DEF_MIC_FRAME_LEN       0x50    // 16K sample rate
336 #define VAD_DEF_STH         0x10
337 #define VAD_DEF_MVAD        0x7
338 #define VAD_DEF_PSD_TH0     0x0
339 #define VAD_DEF_PSD_TH1     0x07ffffff
340 #define VAD_DEF_UDC         0x1//0xa
341 #define VAD_DEF_UPRE        0x4
342 #define VAD_DEF_DIG_MODE    0x1
343 #define VAD_DEF_PRE_GAIN    0x4
344 #define VAD_DEF_DC_BYPASS   0x0
345 #define VAD_DEF_FRAME_TH0   0x32
346 #define VAD_DEF_FRAME_TH1   0x1f4
347 #define VAD_DEF_FRAME_TH2   0x1388
348 #define VAD_DEF_RANGE0      0xf
349 #define VAD_DEF_RANGE1      0x32
350 #define VAD_DEF_RANGE2      0x96
351 #define VAD_DEF_RANGE3      0x12c
352 
353 struct AUD_VAD_SIMP_CFG_T {
354     enum AUD_VAD_TYPE_T type;
355     enum AUD_SAMPRATE_T sample_rate;
356     enum AUD_BITS_T bits;
357     AUD_VAD_CALLBACK handler;
358     uint8_t adc_gain;
359     uint8_t frame_len;
360     uint8_t frame_thresh;
361     uint8_t sound_thresh;
362 };
363 
364 struct AUD_VAD_CONFIG_T {
365     enum AUD_VAD_TYPE_T type;
366     enum AUD_SAMPRATE_T sample_rate;
367     enum AUD_BITS_T bits;
368     AUD_VAD_CALLBACK handler;
369 
370     uint8_t udc;
371     uint8_t upre;
372     uint8_t frame_len;
373     uint8_t mvad;
374 
375     uint8_t dig_mode;
376     uint8_t pre_gain;
377     uint8_t sth;
378     uint8_t dc_bypass;
379 
380     uint8_t ds_bypass;
381     uint8_t pre_bypass;
382     uint8_t adc_gain;
383 
384     uint16_t range[4];
385 
386     uint32_t frame_th[3];
387     uint32_t psd_th[2];
388 };
389 
390 struct CODEC_VAD_BUF_INFO_T {
391     uint32_t base_addr;
392     uint32_t buf_size;
393     uint32_t data_count;
394     uint32_t addr_count;
395 };
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /* AUDIO_DEF_H */
402