I2S.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file I2S.h
34  * @brief Inter-Integrated Circuit Sound (I2S) Bus Driver
35  *
36  * The I2S header file should be included in an application as follows:
37  * @code
38  * #include <ti/drivers/I2S.h>
39  * @endcode
40  *
41  * @anchor ti_drivers_I2S_Overview
42  * # Overview #
43  *
44  * The I2S driver facilitates the use of Inter-IC Sound (I2S), which is
45  * used to connect digital audio devices so that audio signals can be
46  * communicated between devices. The I2S driver simplifies reading and
47  * writing to any of the Multichannel Audio Serial Port (McASP) peripherals
48  * on the board with Receive and Transmit support. These include read and
49  * write characters on the McASP peripheral.
50  *
51  * I2S interfaces typically consist of 4 or 5 signals. The 5th signal is not
52  * systematically used.
53  * @li <b>Serial Clock (SCK)</b> also called Bit Clock (BCLK) or Multichannel
54  * Audio Frame Synchronization (McAFSX)
55  * @li <b>Word Select (WS)</b> also called Word Clock (WCLK), Left Right
56  * Clock (LRCLK) or Multichannel Audio Clock (McACLK)
57  * @li <b>Serial Data (SD0)</b> also called AD0, AD1, McAXR0, or possibly SDI
58  * @li <b>Serial Data (SD1)</b> also called AD1, ADI, McAXR1, or possibly SDI
59  * @li <b>Controller Clock (CCLK)</b>
60  *
61  * <hr>
62  * @anchor ti_drivers_I2S_Usage
63  * # Usage #
64  *
65  * <b>The I2S driver provides the following APIs:</b>
66  * @li I2S_init(): @copybrief I2S_init
67  * @li I2S_open(): @copybrief I2S_open
68  * @li I2S_Params_init(): @copybrief I2S_Params_init
69  * @li I2S_Transaction_init(): @copybrief I2S_Transaction_init
70  * @li I2S_setReadQueueHead(): @copybrief I2S_setReadQueueHead
71  * @li I2S_setWriteQueueHead(): @copybrief I2S_setWriteQueueHead
72  * @li I2S_startClocks(): @copybrief I2S_startClocks
73  * @li I2S_startRead(): @copybrief I2S_startRead
74  * @li I2S_startWrite(): @copybrief I2S_startWrite
75  * @li I2S_stopRead(): @copybrief I2S_stopRead
76  * @li I2S_stopWrite(): @copybrief I2S_stopWrite
77  * @li I2S_stopClocks(): @copybrief I2S_stopClocks
78  * @li I2S_close(): @copybrief I2S_close
79  *
80  * <hr>
81  * @anchor ti_drivers_I2S_Driver_Transactions
82  * ### Transactions #
83  *
84  * Data transfers are achieved through #I2S_Transaction structures. Application is
85  * responsible to maintain the transactions queues. The I2S driver completes the
86  * transactions one by one. When a transaction is over, the I2S driver takes in
87  * consideration the next transaction (if the next transaction is NULL, the I2S
88  * drivers signals this to the user).
89  * The I2S driver relies on the following fields of the #I2S_Transaction to
90  * complete it:
91  * - the buffer
92  * - the length of the buffer
93  * - a pointer on the next transaction to achieve (kept in a List_Elem structure)
94  * .
95  * The I2S driver provides the following elements (fields of the #I2S_Transaction):
96  * - the number of untransferred bytes: the driver is designed to avoid memory corruption and will
97  * not complete an incomplete transaction (meaning a transaction where the buffer size would not
98  * permit to send or receive a whole number of samples). In this case, the system considers the
99  * samples of the beginning of the buffer and read/write as much as possible samples and ignore the
100  * end of the buffer. The number of untransafered bytes is the number of bytes left at the end of
101  * the buffer)
102  * - the number of completions of the transaction. This value is basically incremented by one
103  * every time the transaction is completed.
104  *
105  * Please note that these two fields are valid only when the transaction has been completed.
106  * Consult examples to get more details on the transaction usage.
107  *
108  * The sample buffer structure and content is different between devices. Please
109  * refer to the device-specific documentation for details.
110  *
111  * <hr>
112  * @anchor ti_drivers_I2S_Driver_ProvidingData
113  * ### Providing data to the I2S driver #
114  * Application is responsible to handle the queues of transactions.
115  * Application is also responsible to provide to the driver a pointer on
116  * the first transaction to consider (considering that all the following
117  * transactions are correctly queued).
118  * #I2S_setReadQueueHead() and #I2S_setWriteQueueHead() allow the user to
119  * set the first transaction to consider. These functions should be used only
120  * when no transaction is running on the considered interface.
121  *
122  * <hr>
123  * @anchor ti_drivers_I2S_Driver_StartStopClocks
124  * ### Start and stop clocks and transactions #
125  * Clocks can be started and stopped by the application.
126  * Read and write can be started and stopped independently.
127  * To start a transfer, clocks must be running.
128  * To stop the clocks no transfer must be running.
129  * Refer to the following functions for more details:
130  * @li I2S_startClocks() @li I2S_startRead() @li I2S_startWrite()
131  * @li I2S_stopRead() @li I2S_stopWrite() @li I2S_stopClocks()
132  *
133  * @note
134  * @li In #I2S_TARGET mode, clocks must be started and stopped exactly like
135  * it is done in #I2S_CONTROLLER mode.
136  * @li If the queue of transaction is not empty, the calls to #I2S_stopRead()
137  * and #I2S_stopWrite() are blocking and potentially long.
138  *
139  * <hr>
140  * @anchor ti_drivers_I2S_Examples
141  * ## Examples #
142  *
143  * @li @ref ti_drivers_I2S_Example_PlayAndStop "Play and Stop"
144  * @li @ref ti_drivers_I2S_Example_Streaming "Streaming"
145  * @li @ref ti_drivers_I2S_Example_RepeatMode "Repeat"
146  *
147  * <hr>
148  * @anchor ti_drivers_I2S_Example_PlayAndStop
149  * ### Mode Play and Stop #
150  * The following example shows how to simultaneously receive and send out a given amount of data.
151  *
152  * <hr>
153  * @anchor ti_drivers_I2S_Example_PlayAndStop_Code
154  * @code
155  * static I2S_Handle i2sHandle;
156  *
157  * static uint16_t readBuf1[500]; // the data read will end up in this buffer
158  * static uint16_t readBuf2[500]; // the data read will end up in this buffer
159  * static uint16_t readBuf3[500]; // the data read will end up in this buffer
160  * static uint16_t writeBuf1[250] = {...some data...}; // this buffer will be sent out
161  * static uint16_t writeBuf2[250] = {...some data...}; // this buffer will be sent out
162  * static uint16_t writeBuf3[250] = {...some data...}; // this buffer will be sent out
163  *
164  * static I2S_Transaction i2sRead1;
165  * static I2S_Transaction i2sRead2;
166  * static I2S_Transaction i2sRead3;
167  * static I2S_Transaction i2sWrite1;
168  * static I2S_Transaction i2sWrite2;
169  * static I2S_Transaction i2sWrite3;
170  *
171  * List_List i2sReadList;
172  * List_List i2sWriteList;
173  *
174  * static volatile bool readStopped = (bool)true;
175  * static volatile bool writeStopped = (bool)true;
176  *
177  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
178  *
179  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
180  *
181  * // Note: Here we do not queue new transfers or set a new queue-head.
182  * // The driver will stop sending out data on its own.
183  * writeStopped = (bool)true;
184  * }
185  * }
186  *
187  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
188  *
189  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
190  *
191  * // Note: Here we do not queue new transfers or set a new queue-head.
192  * // The driver will stop receiving data on its own.
193  * readStopped = (bool)true;
194  * }
195  * }
196  *
197  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
198  *
199  * // Handle the I2S error
200  * }
201  *
202  * void *modePlayAndStopThread(void *arg0)
203  * {
204  * I2S_Params i2sParams;
205  *
206  * I2S_init();
207  *
208  * // Initialize I2S opening parameters
209  * I2S_Params_init(&i2sParams);
210  * i2sParams.fixedBufferLength = 500; // fixedBufferLength is the greatest common
211  * // divisor of all the different buffers
212  * // (here buffers' size are 500 and 1000 bytes)
213  * i2sParams.writeCallback = writeCallbackFxn ;
214  * i2sParams.readCallback = readCallbackFxn ;
215  * i2sParams.errorCallback = errCallbackFxn;
216  *
217  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
218  *
219  * // Initialize the read-transactions
220  * I2S_Transaction_init(&i2sRead1);
221  * I2S_Transaction_init(&i2sRead2);
222  * I2S_Transaction_init(&i2sRead3);
223  * i2sRead1.bufPtr = readBuf1;
224  * i2sRead2.bufPtr = readBuf2;
225  * i2sRead3.bufPtr = readBuf3;
226  * i2sRead1.bufSize = sizeof(readBuf1);
227  * i2sRead2.bufSize = sizeof(readBuf2);
228  * i2sRead3.bufSize = sizeof(readBuf3);
229  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
230  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
231  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
232  *
233  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
234  *
235  * // Initialize the write-transactions
236  * I2S_Transaction_init(&i2sWrite1);
237  * I2S_Transaction_init(&i2sWrite2);
238  * I2S_Transaction_init(&i2sWrite3);
239  * i2sWrite1.bufPtr = writeBuf1;
240  * i2sWrite2.bufPtr = writeBuf2;
241  * i2sWrite3.bufPtr = writeBuf3;
242  * i2sWrite1.bufSize = sizeof(writeBuf1);
243  * i2sWrite2.bufSize = sizeof(writeBuf2);
244  * i2sWrite3.bufSize = sizeof(writeBuf3);
245  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
246  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
247  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
248  *
249  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
250  *
251  * I2S_startClocks(i2sHandle);
252  * I2S_startWrite(i2sHandle);
253  * I2S_startRead(i2sHandle);
254  *
255  * readStopped = (bool)false;
256  * writeStopped = (bool)false;
257  *
258  * while (1) {
259  *
260  * if(readStopped && writeStopped) {
261  * I2S_stopClocks(i2sHandle);
262  * I2S_close(i2sHandle);
263  * while (1);
264  * }
265  * }
266  * }
267  * @endcode
268  *
269  * \note If you desire to put only one transaction in the queue, fixedBufferLength must be inferior to half the length
270  *(in bytes) of the buffer to transfer.
271  *
272  * <hr>
273  * @anchor ti_drivers_I2S_Example_Streaming
274  * ### Writing Data in Continuous Streaming Mode #
275  * The following example shows how to read and write data in streaming mode.
276  * A dummy treatment of the data is also done.
277  * This example is not complete (semaphore and tasks creation are not shown)
278  *
279  * <hr>
280  * @anchor ti_drivers_I2S_Example_Streaming_Code
281  * @code
282  * static I2S_Handle i2sHandle;
283  * static sem_t semDataReadyForTreatment;
284  *
285  * // These buffers will successively be written, treated and sent out
286  * static uint16_t readBuf1[500];
287  * static uint16_t readBuf2[500];
288  * static uint16_t readBuf3[500];
289  * static uint16_t readBuf4[500];
290  * static uint16_t writeBuf1[500]={0};
291  * static uint16_t writeBuf2[500]={0};
292  * static uint16_t writeBuf3[500]={0};
293  * static uint16_t writeBuf4[500]={0};
294  *
295  * // These transactions will successively be part of the
296  * // i2sReadList, the treatmentList and the i2sWriteList
297  * static I2S_Transaction i2sRead1;
298  * static I2S_Transaction i2sRead2;
299  * static I2S_Transaction i2sRead3;
300  * static I2S_Transaction i2sRead4;
301  * static I2S_Transaction i2sWrite1;
302  * static I2S_Transaction i2sWrite2;
303  * static I2S_Transaction i2sWrite3;
304  * static I2S_Transaction i2sWrite4;
305  *
306  * List_List i2sReadList;
307  * List_List treatmentList;
308  * List_List i2sWriteList;
309  *
310  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
311  *
312  * // We must remove the previous transaction (the current one is not over)
313  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
314  *
315  * if(transactionFinished != NULL){
316  * // Remove the finished transaction from the write queue
317  * List_remove(&i2sWriteList, (List_Elem*)transactionFinished);
318  *
319  * // This transaction must now feed the read queue (we do not need anymore the data of this transaction)
320  * transactionFinished->queueElement.next = NULL;
321  * List_put(&i2sReadList, (List_Elem*)transactionFinished);
322  *
323  * // We need to queue a new transaction: let's take one in the treatment queue
324  * I2S_Transaction *newTransaction = (I2S_Transaction*)List_head(&treatmentList);
325  * if(newTransaction != NULL){
326  * List_remove(&treatmentList, (List_Elem*)newTransaction);
327  * newTransaction->queueElement.next = NULL;
328  * List_put(&i2sWriteList, (List_Elem*)newTransaction);
329  * }
330  * }
331  * }
332  *
333  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
334  *
335  * // We must remove the previous transaction (the current one is not over)
336  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
337  *
338  * if(transactionFinished != NULL){
339  * // The finished transaction contains data that must be treated
340  * List_remove(&i2sReadList, (List_Elem*)transactionFinished);
341  * transactionFinished->queueElement.next = NULL;
342  * List_put(&treatmentList, (List_Elem*)transactionFinished);
343  *
344  * // Start the treatment of the data
345  * sem_post(&semDataReadyForTreatment);
346  *
347  * // We do not need to queue transaction here: writeCallbackFxn takes care of this :)
348  * }
349  * }
350  *
351  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
352  *
353  * // Handle the I2S error
354  * }
355  *
356  * void *echoExampleThread(void *arg0)
357  * {
358  * I2S_Params i2sParams;
359  *
360  * I2S_init();
361  *
362  * int retc = sem_init(&semDataReadyForTreatment, 0, 0);
363  * if (retc == -1) {
364  * while (1);
365  * }
366  *
367  * // Initialize the treatmentList (this list is initially empty)
368  * List_clearList(&treatmentList);
369  *
370  * //Initialize I2S opening parameters
371  * I2S_Params_init(&i2sParams);
372  * i2sParams.fixedBufferLength = 1000;
373  * i2sParams.writeCallback = writeCallbackFxn ;
374  * i2sParams.readCallback = readCallbackFxn ;
375  * i2sParams.errorCallback = errCallbackFxn;
376  *
377  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
378  *
379  * // Initialize the read-transactions
380  * I2S_Transaction_init(&i2sRead1);
381  * I2S_Transaction_init(&i2sRead2);
382  * I2S_Transaction_init(&i2sRead3);
383  * I2S_Transaction_init(&i2sRead4);
384  * i2sRead1.bufPtr = readBuf1;
385  * i2sRead2.bufPtr = readBuf2;
386  * i2sRead3.bufPtr = readBuf3;
387  * i2sRead4.bufPtr = readBuf4;
388  * i2sRead1.bufSize = sizeof(readBuf1);
389  * i2sRead2.bufSize = sizeof(readBuf2);
390  * i2sRead3.bufSize = sizeof(readBuf3);
391  * i2sRead4.bufSize = sizeof(readBuf4);
392  * List_clearList(&i2sReadList);
393  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
394  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
395  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
396  * List_put(&i2sReadList, (List_Elem*)&i2sRead4);
397  *
398  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
399  *
400  * // Initialize the write-transactions
401  * I2S_Transaction_init(&i2sWrite1);
402  * I2S_Transaction_init(&i2sWrite2);
403  * I2S_Transaction_init(&i2sWrite3);
404  * I2S_Transaction_init(&i2sWrite4);
405  * i2sWrite1.bufPtr = writeBuf1;
406  * i2sWrite2.bufPtr = writeBuf2;
407  * i2sWrite3.bufPtr = writeBuf3;
408  * i2sWrite4.bufPtr = writeBuf4;
409  * i2sWrite1.bufSize = sizeof(writeBuf1);
410  * i2sWrite2.bufSize = sizeof(writeBuf2);
411  * i2sWrite3.bufSize = sizeof(writeBuf3);
412  * i2sWrite4.bufSize = sizeof(writeBuf4);
413  * List_clearList(&i2sWriteList);
414  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
415  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
416  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
417  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite4);
418  *
419  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
420  *
421  * I2S_startClocks(i2sHandle);
422  * I2S_startWrite(i2sHandle);
423  * I2S_startRead(i2sHandle);
424  *
425  * while (1) {
426  * uint8_t k = 0;
427  * I2S_Transaction* lastAchievedReadTransaction = NULL;
428  *
429  * retc = sem_wait(&semDataReadyForTreatment);
430  * if (retc == -1) {
431  * while (1);
432  * }
433  *
434  * lastAchievedReadTransaction = (I2S_Transaction*) List_head(&treatmentList);
435  *
436  * if(lastAchievedReadTransaction != NULL) {
437  *
438  * // Need a critical section to be sure to have corresponding bufPtr and bufSize
439  * uintptr_t key = HwiP_disable();
440  * uint16_t *buf = lastAchievedReadTransaction->bufPtr;
441  * uint16_t bufLength = lastAchievedReadTransaction->bufSize / sizeof(uint16_t);
442  * HwiP_restore(key);
443  *
444  * // My dummy data treatment...
445  * for(k=0; k<bufLength; k++) {
446  * buf[k]--;
447  * }
448  * for(k=0; k<bufLength; k++) {
449  * buf[k]++;
450  * }
451  * }
452  * }
453  * }
454  * @endcode
455  *
456  * <hr>
457  * @anchor ti_drivers_I2S_Example_RepeatMode
458  * ### Writing Data in repeat Mode #
459  * The following example shows how to read and write data in repeat mode.
460  * The same buffers are continuously written and send out while the driver is not stopped.
461  * Here, we decide to only stop sending out after an arbitrary number of sending.
462  *
463  * <hr>
464  * @anchor ti_drivers_I2S_Example_RepeatMode_Code
465  * @code
466  * static I2S_Handle i2sHandle;
467  *
468  * // This buffer will be continuously re-written
469  * static uint16_t readBuf[500];
470  * // This data will be continuously sent out
471  * static uint16_t writeBuf[500] = {...some cool data...};
472  *
473  * static I2S_Transaction i2sRead;
474  * static I2S_Transaction i2sWrite;
475  *
476  * List_List i2sReadList;
477  * List_List i2sWriteList;
478  *
479  * static volatile bool writeFinished = (bool)false;
480  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
481  *
482  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
483  * // executed without any action from the application.
484  *
485  * // We must consider the previous transaction (ok, when you have only one transaction it's the same)
486  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
487  *
488  * if(transactionFinished != NULL){
489  * // After an arbitrary number of completion of the transaction, we will stop writting
490  * if(transactionFinished->numberOfCompletions >= 10) {
491  *
492  * // Note: You cannot use I2S_stopRead() / I2S_stopWrite() in the callback.
493  * // The execution of these functions is potentially blocking and can mess up the
494  * // system.
495  *
496  * writeFinished = (bool)true;
497  * }
498  * }
499  * }
500  *
501  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
502  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
503  * // executed without any action from the application.
504  * }
505  *
506  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
507  *
508  * // Handle the I2S error
509  * }
510  *
511  * void *modeRepeat(void *arg0)
512  * {
513  * I2S_Params i2sParams;
514  *
515  * // Initialize I2S opening parameters
516  * I2S_Params_init(&i2sParams);
517  * i2sParams.fixedBufferLength = 1000; // No problem here: the driver consider
518  * // the list as an infinite list.
519  * i2sParams.writeCallback = writeCallbackFxn ;
520  * i2sParams.readCallback = readCallbackFxn ;
521  * i2sParams.errorCallback = errCallbackFxn;
522  *
523  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
524  *
525  * // Initialize the read-transactions
526  * I2S_Transaction_init(&i2sRead);
527  * i2sRead.bufPtr = readBuf;
528  * i2sRead.bufSize = sizeof(readBuf);
529  * List_put(&i2sReadList, (List_Elem*)&i2sRead);
530  * List_tail(&i2sReadList)->next = List_head(&i2sReadList);// Read buffers are queued in a ring-list
531  * List_head(&i2sReadList)->prev = List_tail(&i2sReadList);
532  *
533  * I2S_setReadQueueHead(i2sHandle, &i2sRead);
534  *
535  * // Initialize the write-transactions
536  * I2S_Transaction_init(&i2sWrite);
537  * i2sWrite.bufPtr = writeBuf;
538  * i2sWrite.bufSize = sizeof(writeBuf);
539  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite);
540  * List_tail(&i2sWriteList)->next = List_head(&i2sWriteList); // Write buffers are queued in a ring-list
541  * List_head(&i2sWriteList)->prev = List_tail(&i2sWriteList);
542  *
543  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite);
544  *
545  * I2S_startClocks(i2sHandle);
546  * I2S_startWrite(i2sHandle);
547  * I2S_startRead(i2sHandle);
548  *
549  * while (1) {
550  *
551  * if(writeFinished){
552  * writeFinished = (bool)false;
553  * I2S_stopWrite(i2sHandle);
554  * }
555  * }
556  * }
557  * @endcode
558  *
559  * @note In the case of circular lists, there is no problem to put only
560  * one buffer in the queue.
561  *
562  * <hr>
563  * @anchor ti_drivers_I2S_Configuration
564  * # Configuration
565  *
566  * Refer to the @ref driver_configuration "Driver's Configuration" section
567  * for driver configuration information.
568  * <hr>
569  ******************************************************************************
570  */
571 
572 #ifndef ti_drivers_I2S__include
573 #define ti_drivers_I2S__include
574 
575 #include <stddef.h>
576 #include <stdbool.h>
577 #include <stdint.h>
578 
579 #include <ti/drivers/utils/List.h>
580 
581 #ifdef __cplusplus
582 extern "C" {
583 #endif
584 
598 #define I2S_ALL_TRANSACTIONS_SUCCESS (0x0001U)
599 
606 #define I2S_TRANSACTION_SUCCESS (0x0002U)
607 
614 #define I2S_TIMEOUT_ERROR (0x0100U)
615 
623 #define I2S_BUS_ERROR (0x0200U)
624 
631 #define I2S_WS_ERROR (0x0400U)
632 
640 #define I2S_PTR_READ_ERROR (0x0800U)
641 
649 #define I2S_PTR_WRITE_ERROR (0x1000U)
650 
662 typedef struct
663 {
665  void *object;
666 
668  void const *hwAttrs;
669 } I2S_Config;
670 
675 
679 typedef struct
680 {
684  void *bufPtr;
686  size_t bufSize;
694  uintptr_t arg;
696 
710 typedef void (*I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr);
711 
720 typedef void (*I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer);
721 
728 typedef void (*I2S_StopInterface)(I2S_Handle handle);
729 
740 typedef enum
741 {
742 
749 
756 typedef enum
757 {
758 
762 } I2S_Role;
763 
769 typedef enum
770 {
771 
778 
787 
796 typedef enum
797 {
805 
814 
815 } I2S_PhaseType;
816 
822 typedef enum
823 {
824 
826  I2S_SD0_INPUT = 0x01U,
827  I2S_SD0_OUTPUT = 0x02U,
829  I2S_SD1_INPUT = 0x10U,
830  I2S_SD1_OUTPUT = 0x20U
833 
856 typedef enum
857 {
858 
866 
875 
884 
892 
893  I2S_1_CHANNEL = 0x01U,
894  I2S_2_CHANNELS = 0x03U,
895  I2S_3_CHANNELS = 0x07U,
896  I2S_4_CHANNELS = 0x0FU,
897  I2S_5_CHANNELS = 0x1FU,
898  I2S_6_CHANNELS = 0x3FU,
899  I2S_7_CHANNELS = 0x7FU,
900  I2S_8_CHANNELS = 0xFFU,
904 
913 typedef struct
914 {
915 
927 
933  bool invertWS;
934 
944 
955 
959  I2S_MemoryLength memorySlotLength;
960 
966 
972 
974  uint8_t bitsPerWord;
975 
980 
985 
992  I2S_DataInterfaceUse SD0Use;
993 
1000  I2S_DataInterfaceUse SD1Use;
1001 
1009  I2S_ChannelConfig SD0Channels;
1010 
1018  I2S_ChannelConfig SD1Channels;
1019 
1023  I2S_PhaseType phaseType;
1024 
1032 
1034  uint16_t startUpDelay;
1035 
1041  uint16_t CCLKDivider;
1042 
1051 
1057 
1063 
1066 
1068  void *custom;
1069 } I2S_Params;
1070 
1076 extern const I2S_Params I2S_defaultParams;
1077 
1088 extern void I2S_close(I2S_Handle handle);
1089 
1098 extern void I2S_init(void);
1099 
1120 extern I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params);
1121 
1157 extern void I2S_Params_init(I2S_Params *params);
1158 
1176 extern void I2S_Transaction_init(I2S_Transaction *transaction);
1177 
1194 extern void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1195 
1212 extern void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1213 
1227 extern void I2S_startClocks(I2S_Handle handle);
1228 
1247 extern void I2S_stopClocks(I2S_Handle handle);
1248 
1272 extern void I2S_startRead(I2S_Handle handle);
1273 
1297 extern void I2S_startWrite(I2S_Handle handle);
1298 
1320 extern void I2S_stopRead(I2S_Handle handle);
1321 
1343 extern void I2S_stopWrite(I2S_Handle handle);
1344 
1345 #ifdef __cplusplus
1346 }
1347 #endif
1348 
1349 #endif /* ti_drivers_I2S__include */
ADC_Params params
Definition: Driver_Init.h:11
I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params)
Function to initialize a given I2S peripheral specified by the particular index value. The parameter specifies which mode the I2S will operate.
I2S_MemoryLength
I2S slot memory length setting.
Definition: I2S.h:740
Definition: I2S.h:828
void * object
Definition: I2S.h:665
Only channel 2 is activated.
Definition: I2S.h:883
Definition: I2S.h:743
size_t bytesTransferred
Definition: I2S.h:688
const I2S_Params I2S_defaultParams
Default I2S_Params structure.
Definition: I2S.h:825
bool isMSBFirst
Definition: I2S.h:943
uint8_t beforeWordPadding
Definition: I2S.h:965
Definition: I2S.h:745
void(* I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr)
The definition of a user-callback function used by the I2S driver.
Definition: I2S.h:710
Definition: I2S.h:897
Definition: I2S.h:899
Definition: I2S.h:759
void(* I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer)
The definition of a function used to set the I2S register.
Definition: I2S.h:720
size_t untransferredBytes
Definition: I2S.h:690
Definition: I2S.h:760
void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first write-transaction to consider.
I2S_DataInterfaceUse SD1Use
Definition: I2S.h:1000
uint32_t samplingFrequency
Definition: I2S.h:1050
I2S Global configuration.
Definition: I2S.h:662
I2S_DataInterfaceUse
I2S data interface configuration.
Definition: I2S.h:822
No channel activated.
Definition: I2S.h:865
I2S_PhaseType
I2S phase setting.
Definition: I2S.h:796
Definition: I2S.h:826
Definition: I2S.h:901
I2S_Role
I2S controller / target selection.
Definition: I2S.h:756
uint16_t fixedBufferLength
Definition: I2S.h:1031
Sampling on falling edges.
Definition: I2S.h:777
void I2S_init(void)
Function to initializes the I2S module.
void I2S_startClocks(I2S_Handle handle)
Start the WS, SCK and CCLK clocks.
uint16_t numberOfCompletions
Definition: I2S.h:692
bool isDMAUnused
Definition: I2S.h:954
Sampling on rising edges.
Definition: I2S.h:785
I2S_MemoryLength memorySlotLength
Definition: I2S.h:959
I2S_SamplingEdge samplingEdge
Definition: I2S.h:984
Definition: I2S.h:744
List_Elem queueElement
Definition: I2S.h:682
void I2S_startWrite(I2S_Handle handle)
Start write transactions.
I2S_Config * I2S_Handle
A handle that is returned from a I2S_open() call.
Definition: I2S.h:674
void I2S_Transaction_init(I2S_Transaction *transaction)
Initialize an I2S_Transaction struct to known state.
I2S_ChannelConfig
Channels used selection.
Definition: I2S.h:856
void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first read-transaction to consider.
I2S_SamplingEdge
I2S sampling setting.
Definition: I2S.h:769
bool invertWS
Definition: I2S.h:933
I2S_PhaseType phaseType
Definition: I2S.h:1023
Definition: I2S.h:893
uint16_t startUpDelay
Definition: I2S.h:1034
Definition: I2S.h:746
I2S_DataInterfaceUse SD0Use
Definition: I2S.h:992
void I2S_stopClocks(I2S_Handle handle)
Stops the WS, SCK and CCLK clocks.
void(* I2S_StopInterface)(I2S_Handle handle)
The definition of a function used to stop an I2S interface.
Definition: I2S.h:728
bool trueI2sFormat
Definition: I2S.h:926
I2S_Callback errorCallback
Definition: I2S.h:1065
I2S_Role moduleRole
Definition: I2S.h:979
void I2S_stopWrite(I2S_Handle handle)
Stop write transactions.
Channels 1 and 2 are activated.
Definition: I2S.h:891
I2S_ChannelConfig SD1Channels
Definition: I2S.h:1018
void I2S_stopRead(I2S_Handle handle)
Stop read transactions.
Definition: I2S.h:900
uintptr_t arg
Definition: I2S.h:694
size_t bufSize
Definition: I2S.h:686
void * custom
Definition: I2S.h:1068
void I2S_Params_init(I2S_Params *params)
Function to initialize the I2S_Params struct to its defaults.
void I2S_startRead(I2S_Handle handle)
Start read transactions.
Dual phase.
Definition: I2S.h:813
I2S_Callback writeCallback
Definition: I2S.h:1062
Definition: I2S.h:895
Definition: I2S.h:830
Definition: I2S.h:829
uint8_t bitsPerWord
Definition: I2S.h:974
Definition: I2S.h:896
Only channel 1 is activated.
Definition: I2S.h:874
I2S_Callback readCallback
Definition: I2S.h:1056
Definition: List.h:126
I2S transaction descriptor.
Definition: I2S.h:679
Definition: I2S.h:894
void const * hwAttrs
Definition: I2S.h:668
void I2S_close(I2S_Handle handle)
Function to close a given I2S peripheral specified by the I2S handle.
Single phase.
Definition: I2S.h:804
Definition: I2S.h:898
uint8_t afterWordPadding
Definition: I2S.h:971
I2S_ChannelConfig SD0Channels
Definition: I2S.h:1009
Definition: I2S.h:827
uint16_t CCLKDivider
Definition: I2S.h:1041
Linked List interface for use in drivers.
Basic I2S Parameters.
Definition: I2S.h:913
void * bufPtr
Definition: I2S.h:684
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale