blob: 2f19362c1d1bb486ba6f7170cef716c53707f8c8 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
2 * @file drvs_i2s.h
3 * @brief Public APIs of i2s drivers
4 *
5 * Copyright (C) 2017 Sanechips Technology Co., Ltd.
6 * @author Xinqiang Xu <xu.xinqiang@sanechips.com.cn>
7 * @ingroup si_cp_drv_id
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#ifndef _HAL_I2S_H
16#define _HAL_I2S_H
17
18/*******************************************************************************
19 * Include header files *
20 ******************************************************************************/
21#include "drvs_general.h"
22#include "drvs_io_voice.h"
23
24/*******************************************************************************
25 * Macro definitions *
26 ******************************************************************************/
27
28/*******************************************************************************
29 * Type definitions *
30 ******************************************************************************/
31/* i2s index */
32typedef enum {
33 I2S_1 = 0,
34 I2S_2 = 1,
35
36 MAX_I2S_ID
37} T_ZDrvI2S_Id;
38
39typedef enum {
40 I2S_TX = 0,
41 I2S_RX = 1
42} T_ZDrvI2S_TransDirection;
43
44typedef enum {
45 I2S_NORMAL_MODE,
46 I2S_LOOPBACK_MODE,
47
48 MAX_TEST_MODE
49} T_ZDrvI2S_TestMode;
50
51typedef enum {
52 PCM_NORMAL_MODE,
53 PCM_TEAK_MODE,
54
55 MAX_PCM_MODE
56} T_ZDrvI2S_PcmMode;
57
58typedef enum {
59 PCM_LSB_FIRST,
60 PCM_MSB_FIRST,
61
62 MAX_PCM_FIRSTBIT
63} T_ZDrvI2S_PcmFirstBitSel;
64
65typedef enum {
66 PCM_1TIME_SLOT = 0x00,
67 PCM_2TIME_SLOT = 0x01,
68 PCM_4TIME_SLOT = 0x03,
69 PCM_8TIME_SLOT = 0x07,
70 PCM_16TIME_SLOT = 0x0f,
71
72 MAX_PCM_SLOTNUM
73} T_ZDrvI2S_PcmSlotNum;
74
75/* i2s operation mode */
76typedef enum {
77 I2S_DATA_16BIT = 0x0f,
78 I2S_DATA_17BIT = 0x10,
79 I2S_DATA_18BIT = 0x11,
80 I2S_DATA_19BIT = 0x12,
81 I2S_DATA_20BIT = 0x13,
82 I2S_DATA_21BIT = 0x14,
83 I2S_DATA_22BIT = 0x15,
84 I2S_DATA_23BIT = 0x16,
85 I2S_DATA_24BIT = 0x17,
86 I2S_DATA_25BIT = 0x18,
87 I2S_DATA_26BIT = 0x19,
88 I2S_DATA_27BIT = 0x1a,
89 I2S_DATA_28BIT = 0x1b,
90 I2S_DATA_29BIT = 0x1c,
91 I2S_DATA_30BIT = 0x1d,
92 I2S_DATA_31BIT = 0x1e,
93 I2S_DATA_32BIT = 0x1f,
94
95 MAX_I2S_DATA_FMT
96} T_ZDrvI2S_DataFmt;
97
98typedef enum {
99 I2S_TS_16CYCLE = 0x0f,
100 I2S_TS_17CYCLE = 0x10,
101 I2S_TS_18CYCLE = 0x11,
102 I2S_TS_19CYCLE = 0x12,
103 I2S_TS_20CYCLE = 0x13,
104 I2S_TS_21CYCLE = 0x14,
105 I2S_TS_22CYCLE = 0x15,
106 I2S_TS_23CYCLE = 0x16,
107 I2S_TS_24CYCLE = 0x17,
108 I2S_TS_25CYCLE = 0x18,
109 I2S_TS_26CYCLE = 0x19,
110 I2S_TS_27CYCLE = 0x1a,
111 I2S_TS_28CYCLE = 0x1b,
112 I2S_TS_29CYCLE = 0x1c,
113 I2S_TS_30CYCLE = 0x1d,
114 I2S_TS_31CYCLE = 0x1e,
115 I2S_TS_32CYCLE = 0x1f,
116
117 MAX_I2S_TS_WIDTH
118} T_ZDrvI2S_TsWidth;
119
120#if 1//defined _USE_EVB2963
121/*i2s track select*/
122typedef enum {
123 DOUBLE_TRACK = 0x00,
124 LEFT_TRACK = 0x01,
125 RIGHT_TRACK = 0x02,
126
127 MAX_I2S_TRACK_FMT
128} T_ZDrvI2S_TrackFmt;
129
130/*i2s clock source in master mode*/
131typedef enum {
132 PCLK_DIVIDE = 0x00,
133 I2S_SCLK_DIVIDE = 0x01,
134 EQUAL_TO_SCLK = 0x02,
135
136 MAX_I2S_CLK_SOURCE
137} T_ZDrvI2S_ClkSource;
138
139/*i2s clock mode*/
140typedef enum {
141 TRANS_POSITIVE_NEGATIVE = 0,
142 TRANS_NEGATIVE_POSITIVE ,
143
144 MAX_EDGE_SELECT
145} T_ZDrvI2S_ClkEdgeSel;
146
147#endif
148
149typedef VOID (*T_ZDrvI2S_AUD_PLAY_CB)(VOID);
150
151/* i2s configuration */
152
153/*i2s clock mode*/
154typedef enum {
155 I2S_TIME_MODE = 0,
156 PCM_TIME_MODE ,
157
158 MAX_I2S_TIME_MODE
159} T_ZDrvI2S_ClkMode;
160
161typedef enum {
162 PCM_FSYNC_LENGTH_1CLK,
163 PCM_FSYNC_LENGTH_2CLK,
164 PCM_FSYNC_LENGTH_3CLK,
165 PCM_FSYNC_LENGTH_4CLK,
166 PCM_FSYNC_LENGTH_5CLK,
167 PCM_FSYNC_LENGTH_6CLK,
168 PCM_FSYNC_LENGTH_7CLK,
169 PCM_FSYNC_LENGTH_8CLK,
170
171 MAX_PCM_FSYNC
172} T_ZDrvI2S_PcmFsyncLen;
173
174typedef enum {
175 FIRST_DATA_ALIGN_TO_FIRST_CYCLE,
176 FIRST_DATA_ALIGN_TO_SECOND_CYCLE,
177
178 MAX_7510_DATA_ALIGN_MODE
179} T_ZDrvI2S_DataAlignMode;
180
181typedef enum {
182 TIMING_I2S_MONO_RIGHT = 0,
183 TIMING_I2S_MONO_LEFT,
184 TIMING_I2S_ST_2CHN_1LANE,
185 TIMING_I2S_ST_4CHN_2LANE,
186 TIMING_I2S_ST_6CHN_3LANE,
187 TIMING_I2S_ST_8CHN_4LANE,
188 TIMING_TDM_1CHN_1LANE_1TS,
189 TIMING_TDM_2CHN_1LANE_2TS,
190
191 MAX_TMING_SELECT
192} T_ZDrvI2S_TimingType;
193
194/**
195 * @brief describe the i2s device timing config info
196 * @param tTimingTp tTimingTp
197 * @param tTimingSel tTimingSel
198 * @param tChnNum tChnNum
199 * @param tLaneNum tLaneNum
200 * @param tTsCfg tTsCfg
201 */
202typedef struct {
203 T_ZDrvI2S_TimingType tTimingTp;
204 T_ZDrvI2S_ClkMode tTimingSel;
205 UINT8 tChnNum;
206 UINT8 tLaneNum;
207 UINT8 tTsCfg;
208
209} T_ZDrvI2S_TimingCfg;
210
211typedef enum {
212 PCM_LONG_FSYNC,
213 PCM_SHORT_FSYNC,
214 MAX_PCM_LS_FSYNC
215} T_ZDrvI2S_PcmFsync;
216
217typedef enum {
218 TDM_TEAK_EXTRA_CYCLE,
219 TDM_NO_EXTRA_CYCLE,
220 MAX_TDM_EXTRA_CYCLE
221} T_ZDrvI2S_TdmExtCycle;
222
223typedef enum {
224 DATA_ALIGN_STD_I2S,
225 DATA_ALIGN_MSB_JUSTIF,
226 DATA_ALIGN_LSB_JUSTIF,
227 DATA_ALIGN_NORMAL,
228 MAX_DATA_ALIGN_MODE
229} T_ZDrvI2S_TransMode;
230
231typedef enum {
232 REF_CLK26M,
233 REF_CLK104M,
234 REF_CLK122M88,
235
236 REF_CLK_MAX
237} T_I2s_RefClkForI2s;
238
239/**
240 * @brief describe the i2s device config info
241 * @param bMaster TRUE: master mode; FALSE: slave mode
242 * @param tDataFmt T_ZDrvI2S_DataFmt
243 * @param tTsWidth T_ZDrvI2S_TsWidth
244 * @param sample_rate sample rate of auido file
245 * @param tClkMode the clk mode of i2s
246 * @param tTansmit_edge the clk edge select
247 * @param tTrackFmt tTrackFmt
248 * @param tTestMode tTestMode
249 * @param tDataAlignMode tDataAlignMode
250 * @param tPcmMode; tPcmMode
251 * @param tPcmFirstBit tPcmFirstBit
252 * @param tPcmFsynLen tPcmFsynLen
253 * @param tPcmSlotNum tPcmSlotNum
254 * @param tTimingType tTimingType
255 * @param tPcmFsync tPcmFsync
256 * @param tTdmExtCycle only exit in the 7520
257 * @param tTransMode tTransMode
258 * @param refclk refclk
259 */
260typedef struct {
261 BOOL bMaster;
262 T_ZDrvI2S_DataFmt tDataFmt;
263 T_ZDrvI2S_TsWidth tTsWidth;
264 UINT32 sample_rate;
265 T_ZDrvI2S_ClkMode tClkMode;
266 T_ZDrvI2S_ClkEdgeSel tTansmit_edge;
267 T_ZDrvI2S_TrackFmt tTrackFmt;
268 T_ZDrvI2S_TestMode tTestMode;
269 T_ZDrvI2S_DataAlignMode tDataAlignMode;
270 T_ZDrvI2S_PcmMode tPcmMode;
271 T_ZDrvI2S_PcmFirstBitSel tPcmFirstBit;
272 T_ZDrvI2S_PcmFsyncLen tPcmFsynLen;
273 T_ZDrvI2S_PcmSlotNum tPcmSlotNum;
274
275 T_ZDrvI2S_TimingType tTimingType;
276 T_ZDrvI2S_PcmFsync tPcmFsync;
277 T_ZDrvI2S_TdmExtCycle tTdmExtCycle;
278 T_ZDrvI2S_TransMode tTransMode;
279 T_I2s_RefClkForI2s refclk;
280
281} T_ZDrvI2S_Cfg;
282
283typedef enum {
284 I2S_IDLE,
285 I2S_OPEN,
286 I2S_PLAY_INUSE,
287 I2S_RECORD_INUSE,
288 I2S_BOTH_INUSE,
289
290 MAX_I2S_STATUS
291}T_I2s_Status;
292
293/**
294 * @brief describe the codec agc Parameter
295 * @param channel audio channel
296 * @param buffersize buffer size
297 * @param p_cb the callback of audio play
298 */
299typedef struct {
300 T_ZDrvAudio_Channel channel;
301 UINT32 buffersize;
302 T_ZDrvI2S_AUD_PLAY_CB p_cb;
303} T_ZDrvI2s_Params;
304
305typedef enum {
306 TRANS_CPU_MODE,
307 TRANS_INT_MODE,
308 TRANS_DMA_MODE,
309
310 MAX_TRANS_FUNC
311}T_ZDrvI2s_TransMode;
312
313/*******************************************************************************
314 * Global variable declarations *
315 ******************************************************************************/
316
317
318/*******************************************************************************
319 * Global function declarations *
320 ******************************************************************************/
321
322/**
323* @brief open i2s device.
324*
325* @param tId i2s selete struct
326* @param i2sTransMode T_ZDrvI2s_TransMode
327*
328* @return 0-DRV_SUCCESS, other-error
329*/
330SINT32 zDrvI2S_Open(T_ZDrvI2S_Id tId, T_ZDrvI2s_TransMode i2sTransMode);
331
332/**
333* @brief reset i2s device.
334*
335* @param tId i2s select i2s0 or i2s1
336*
337* @return 0-DRV_SUCCESS, other-error
338*/
339SINT32 zDrvI2S_Reset(T_ZDrvI2S_Id tId);
340
341/**
342* @brief close i2s device.
343*
344* @param tId i2s selete struct
345*
346* @return 0-DRV_SUCCESS, other-error
347*/
348SINT32 zDrvI2S_Close(T_ZDrvI2S_Id tId);
349
350/**
351* @brief i2s write stop ,use to stop playing or recording.
352*
353* @param tId i2s index select i2s0 or i2s1
354*
355* @return 0-DRV_SUCCESS, other-error
356*/
357SINT32 zDrvI2S_Write_Stop(T_ZDrvI2S_Id tId);
358
359/**
360* @brief i2s read stop ,use to stop playing or recording.
361*
362* @param tId i2s select i2s0 or i2s1
363*
364* @return 0-DRV_SUCCESS, other-error
365*/
366SINT32 zDrvI2S_Read_Stop(T_ZDrvI2S_Id tId);
367
368/**
369* @brief This function is used to read data by i2s.
370*
371* @param tId i2s select i2s0 or i2s1
372* @param pBuf one buffer is how many bytes
373* @param uiLen buffer length
374*
375* @return 0-DRV_SUCCESS, other-error
376*/
377SINT32 zDrvI2S_Read(T_ZDrvI2S_Id tId, UINT8 **pBuf, UINT32 *uiLen);
378
379/**
380* @brief i2s trans data to fifo from ram while playing.
381*
382* @param tId i2s selete struct
383* @param pBuf one buffer is how many bytes
384* @param uiLen buffer length
385*
386* @return 0-DRV_SUCCESS, other-error
387*/
388SINT32 zDrvI2S_Write(T_ZDrvI2S_Id tId, const UINT8 *pBuf, UINT32 uiLen);
389
390/**
391* @brief i2s write start .
392*
393* @param tId i2s selete struct
394* @param params pointer to struct T_ZDrvI2s_Params
395* @param ptCfg pointer to struct T_ZDrvI2S_Cfg
396* @return 0-DRV_SUCCESS, other-error
397*/
398SINT32 zDrvI2S_Write_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);
399
400/**
401* @brief i2s read start.
402*
403* @param tId i2s selete struct
404* @param params pointer to T_ZDrvI2s_Params
405* @param ptCfg pointer to T_ZDrvI2S_Cfg
406* @return 0-DRV_SUCCESS, other-error
407*/
408SINT32 zDrvI2S_Read_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);
409
410/**
411* @brief start to trans data,use in playing.
412*
413* @param tId i2s selete struct
414* @param params T_ZDrvI2s_Params
415* @param ptCfg config param
416* @return 0-DRV_SUCCESS, other-error
417*/
418SINT32 zDrvI2S_Vousb_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);
419
420/**
421* @brief i2s get buffer ,get buffer to write playing data.
422*
423* @param tId i2s select i2s0 or i2s1
424* @param pBuf playing data buffer
425* @param uiLen buffer length
426* @return 0-DRV_SUCCESS, other-error
427*/
428SINT32 zDrvI2S_GetBuf(T_ZDrvI2S_Id tId, UINT8 **pBuf, UINT32 *uiLen);
429
430/**
431* @brief i2s free buffer ,get buffer to write playing data.
432*
433* @param tId i2s select i2s0 or i2s1
434* @param pBuf data buffer
435* @return 0-DRV_SUCCESS, other-error
436*/
437SINT32 zDrvI2S_GetRemained(T_ZDrvI2S_Id tId, UINT32 *len);
438
439/**
440* @brief i2s free buffer ,get buffer to write playing data.
441*
442* @param tId i2s select i2s0 or i2s1
443* @param pBuf data buffer
444* @return 0-DRV_SUCCESS, other-error
445*/
446SINT32 zDrvI2S_FreeBuf(T_ZDrvI2S_Id tId, UINT8 *pBuf);
447
448/**
449* @brief pause while playing.
450*
451* @param tId i2s select i2s0 or i2s1
452* @return 0-DRV_SUCCESS, other-error
453*/
454VOID zDrvI2S_Pause(T_ZDrvI2S_Id tId);
455
456/**
457* @brief resume playing if pause.
458*
459* @param tId i2s select i2s0 or i2s1
460* @return 0-DRV_SUCCESS, other-error
461*/
462VOID zDrvI2S_Resume(T_ZDrvI2S_Id tId);
463
464/**
465* @brief Release the rx semaphore before stop.
466*
467* @param tId i2s select i2s0 or i2s1
468* @return 0-DRV_SUCCESS, other-error
469*/
470VOID zDrvI2s_RxRlsSemaBeforeStop(T_ZDrvI2S_Id tId);
471
472/**
473* @brief Release the tx semaphore before stop.
474*
475* @param tId i2s select i2s0 or i2s1
476* @return 0-DRV_SUCCESS, other-error
477*/
478VOID zDrvI2s_TxRlsSemaBeforeStop(T_ZDrvI2S_Id tId);
479
480/**
481* @brief get i2s status.
482*
483* @param tId i2s select i2s0 or i2s1
484* @return 0-DRV_SUCCESS, other-error
485*/
486T_I2s_Status zDrvI2s_GetI2sStatus(T_ZDrvI2S_Id tId);
487
488#endif /* #ifndef _HAL_I2S_H */
489