<p>The MCUXpresso SDK provides the peripheral driver for the I2S function of FLEXCOMM module of MCUXpresso SDK devices.<br/>
<br/>
The I2S module is used to transmit or receive digital audio data. Only transmit or receive is enabled at one time in one module. <br/>
Driver currently supports one (primary) channel pair per one I2S enabled FLEXCOMM module only. <br/>
</p>
<h1><aclass="anchor"id="I2SInit"></a>
I2S Driver Initialization and Configuration</h1>
<p><aclass="el"href="a00031.html#ga5d68b2f69b625a753d498dab6758c5b9"title="Initializes the FLEXCOMM peripheral for I2S transmit functionality. ">I2S_TxInit()</a> and <aclass="el"href="a00031.html#gaa71e9b55c275d5469c1e3f723dc55213"title="Initializes the FLEXCOMM peripheral for I2S receive functionality. ">I2S_RxInit()</a> functions ungate the clock for the FLEXCOMM module, assign I2S function to FLEXCOMM module and configure audio data format and other I2S operational settings. <aclass="el"href="a00031.html#ga5d68b2f69b625a753d498dab6758c5b9"title="Initializes the FLEXCOMM peripheral for I2S transmit functionality. ">I2S_TxInit()</a> is used when I2S should transmit data, <aclass="el"href="a00031.html#gaa71e9b55c275d5469c1e3f723dc55213"title="Initializes the FLEXCOMM peripheral for I2S receive functionality. ">I2S_RxInit()</a> when it should receive data.</p>
<p><aclass="el"href="a00031.html#ga905cb886175d4a1f9ac2fbf8d2722cf6"title="Sets the I2S Tx configuration structure to default values. ">I2S_TxGetDefaultConfig()</a> and <aclass="el"href="a00031.html#ga8356de62fea66f67a9803ee89a78805a"title="Sets the I2S Rx configuration structure to default values. ">I2S_RxGetDefaultConfig()</a> functions can be used to set the module configuration structure with default values for transmit and receive function, respectively.</p>
<p><aclass="el"href="a00031.html#ga68e9243ae7345a144668c7e04f1f52ac"title="De-initializes the I2S peripheral. ">I2S_Deinit()</a> function resets the FLEXCOMM module.</p>
<p><aclass="el"href="a00031.html#ga0e630bdd0adb5a39b52e374ede7bc07f"title="Initializes handle for transfer of audio data. ">I2S_TxTransferCreateHandle()</a> function creates transactional handle for transmit in interrupt mode.</p>
<p><aclass="el"href="a00031.html#gabd8c54c9689fd89024c83bb883693c16"title="Initializes handle for reception of audio data. ">I2S_RxTransferCreateHandle()</a> function creates transactional handle for receive in interrupt mode.</p>
<p><aclass="el"href="a00032.html#gab367abb21d0180a8327c3408efa06bd8"title="Initializes handle for transfer of audio data. ">I2S_TxTransferCreateHandleDMA()</a> function creates transactional handle for transmit in DMA mode.</p>
<p><aclass="el"href="a00032.html#gabf7c9bdafbd7e7aac4b265dace33f9e6"title="Initializes handle for reception of audio data. ">I2S_RxTransferCreateHandleDMA()</a> function creates transactional handle for receive in DMA mode.</p>
<h1><aclass="anchor"id="I2STransfer"></a>
I2S Transmit Data</h1>
<p><aclass="el"href="a00031.html#ga8e341c9ce48e5be03e120ea332758048"title="Begins or queue sending of the given data. ">I2S_TxTransferNonBlocking()</a> function is used to add data buffer to transmit in interrupt mode. It also begins transmission if not transmitting yet.</p>
<p><aclass="el"href="a00031.html#ga454cba72bec3ebeecf865570ce6ed900"title="Begins or queue reception of data into given buffer. ">I2S_RxTransferNonBlocking()</a> function is used to add data buffer to receive data into in interrupt mode. It also begins reception if not receiving yet.</p>
<p><aclass="el"href="a00032.html#ga7f0ee69bcc210dc1519a99e2d9403e67"title="Begins or queue sending of the given data. ">I2S_TxTransferSendDMA()</a> function is used to add data buffer to transmit in DMA mode. It also begins transmission if not transmitting yet.</p>
<p><aclass="el"href="a00032.html#gae8c0cacf997b6d4642c6c4e26dccf5aa"title="Begins or queue reception of data into given buffer. ">I2S_RxTransferReceiveDMA()</a> function is used to add data buffer to receive data into in DMA mode. It also begins reception if not receiving yet.</p>
<p>The transfer of data will be stopped automatically when all data buffers queued using the above functions will be processed and no new data buffer is enqueued meanwhile. If the above functions are not called frequently enough, I2S stop followed by restart may keep occurring resulting in drops audio stream.</p>
<h1><aclass="anchor"id="I2SInterrupt"></a>
I2S Interrupt related functions</h1>
<p><aclass="el"href="a00031.html#ga435263725c056eccaa82eb1947e162aa"title="Enables I2S FIFO interrupts. ">I2S_EnableInterrupts()</a> function is used to enable interrupts in FIFO interrupt register. Regular use cases do not require this function to be called from application code.</p>
<p><aclass="el"href="a00031.html#gaa6f8ed52f3cd5c63b3a3716a70c77223"title="Disables I2S FIFO interrupts. ">I2S_DisableInterrupts()</a> function is used to disable interrupts in FIFO interrupt register. Regular use cases do not require this function to be called from application code.</p>
<p><aclass="el"href="a00031.html#ga2d96a8f63e454de7225a98541b6461b9"title="Returns the set of currently enabled I2S FIFO interrupts. ">I2S_GetEnabledInterrupts()</a> function returns interrupts enabled in FIFO interrupt register. Regular use cases do not require this function to be called from application code.</p>
<p><aclass="el"href="a00031.html#ga2423f95dc2c00bce6a9de6d868d1fde2"title="Invoked from interrupt handler when transmit FIFO level decreases. ">I2S_TxHandleIRQ()</a> and <aclass="el"href="a00031.html#gaeff61f8cbd780c881c593ad059f98338"title="Invoked from interrupt handler when receive FIFO level decreases. ">I2S_RxHandleIRQ()</a> functions are called from ISR which is invoked when actual FIFO level decreases to configured watermark value.</p>
<p><aclass="el"href="a00032.html#gac9f82a576dc3a2d10df9cade5ce57a42"title="Invoked from DMA interrupt handler. ">I2S_DMACallback()</a> function is called from ISR which is invoked when DMA transfer (actual descriptor) finishes.</p>
<h1><aclass="anchor"id="I2SOther"></a>
I2S Other functions</h1>
<p><aclass="el"href="a00031.html#gac109aadc23d6f31e6f8420fa3f4018fd"title="Enables I2S operation. ">I2S_Enable()</a> function enables I2S function in FLEXCOMM module. Regular use cases do not require this function to be called from application code.</p>
<p><aclass="el"href="a00031.html#ga4b393781ae83a07d4d3e99972429cfa1"title="Disables I2S operation. ">I2S_Disable()</a> function disables I2S function in FLEXCOMM module. Regular use cases do not require this function to be called from application code.</p>
<p><aclass="el"href="a00031.html#gae3d210a830859e93103931b4baf83586"title="Returns number of buffer underruns or overruns. ">I2S_TransferGetErrorCount()</a> function returns the number of FIFO underruns or overruns in interrupt mode.</p>
<p><aclass="el"href="a00031.html#ga14ef749f4300fe7b1fd38277f0ef167f"title="Returns number of bytes transferred so far. ">I2S_TransferGetCount()</a> function returns the number of bytes transferred in interrupt mode.</p>
<p><aclass="el"href="a00031.html#ga25659519f70757bf2db3831f7e807bd8"title="Aborts sending of data. ">I2S_TxTransferAbort()</a> function aborts trasmit operation in interrupt mode.</p>
<p><aclass="el"href="a00031.html#ga32eb018b43745a695ef26cec1ff73a73"title="Aborts receiving of data. ">I2S_RxTransferAbort()</a> function aborts receive operation in interrupt mode.</p>
<p><aclass="el"href="a00032.html#ga59beaf115701e7b97ffd517a83e6b611"title="Aborts transfer of data. ">I2S_TransferAbortDMA()</a> function aborts transmit or receive operation in DMA mode.</p>
<h1>I2S Functional limitations</h1>
<p>I2S can not to accurately determine when the data is sent to the end. Since program commands cannot quickly disable I2S, there will always be more clock exposure. If someone want to get accurate data, can use <aclass="el"href="a00032.html#ga59beaf115701e7b97ffd517a83e6b611"title="Aborts transfer of data. ">I2S_TransferAbortDMA()</a> api in TxCallback() to terminate sending data prematurely and ensure the accuracy of the data with delay function.</p>
<h1><aclass="anchor"id="I2SFormat"></a>
I2S Data formats</h1>
<h2><aclass="anchor"id="I2SFormatDMA"></a>
DMA mode</h2>
<p>Length of buffer for transmit or receive has to be multiply of 4 bytes. Buffer address has to be aligned to 4-bytes. Data are put into or taken from FIFO unaltered in DMA mode so buffer has to be prepared according to following information. If oneChannel is enabled, then the buffer should contain valid data only, that is to say, audio data should be put continuously in the buffer Take 8 bit data as example: </p>
<p><code>LSB</code></p>
<p><code>L07</code></p>
<p><code>L06</code></p>
<p><code>L05</code></p>
<p><code>L04</code></p>
<p><code>L03</code></p>
<p><code>L02</code></p>
<p><code>L01</code></p>
<p><code>L00</code></p>
<p><code>L07</code></p>
<p><code>L06</code></p>
<p><code>L05</code></p>
<p><code>L04</code></p>
<p><code>L03</code></p>
<p><code>L02</code></p>
<p><code>L01</code></p>
<p><code>L00</code></p>
<p><code>L07</code></p>
<p><code>L06</code></p>
<p><code>L05</code></p>
<p><code>L04</code></p>
<p><code>L03</code></p>
<p><code>L02</code></p>
<p><code>L01</code></p>
<p><code>L00</code></p>
<p><code>L07</code></p>
<p><code>L06</code></p>
<p><code>L05</code></p>
<p><code>L04</code></p>
<p><code>L03</code></p>
<p><code>L02</code></p>
<p><code>L01</code></p>
<p><code>L00</code></p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 4 and 16, every word in buffer should contain data for left and right channels.</p>
Note that for example if <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> = 7, bits on positions R07-R15 and L07-L15 are ignored (buffer "wastes space"). <br/>
</p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 17 and 24 and <aclass="el"href="a00031.html#a81806913aaa20f7a6204d215c9510fdf"title="Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit values) ...">i2s_config_t.pack48</a> = false:</p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 17 and 24 and <aclass="el"href="a00031.html#a81806913aaa20f7a6204d215c9510fdf"title="Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit values) ...">i2s_config_t.pack48</a> = true:</p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 25 and 32:</p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 5 and 8:</p>
<p>Length of buffer for transmit or receive has to be multiply of 2 bytes. Buffer address has to be aligned to 2-bytes. </p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 9 and 16:</p>
<p>Length of buffer for transmit or receive has to be multiply of 4 bytes. Buffer address has to be aligned to 4-bytes. </p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 17 and 24 and <aclass="el"href="a00031.html#a81806913aaa20f7a6204d215c9510fdf"title="Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit values) ...">i2s_config_t.pack48</a> = false(mono channel audio data is supported):</p>
<p>Length of buffer for transmit or receive has to be multiply of 6 bytes. </p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 17 and 24 and <aclass="el"href="a00031.html#a81806913aaa20f7a6204d215c9510fdf"title="Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit values) ...">i2s_config_t.pack48</a> = true:</p>
<p>Length of buffer for transmit or receive has to be multiply of 6 bytes. Buffer address has to be aligned to 4-bytes. </p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 25 and 32 and <aclass="el"href="a00031.html#a08c393f7fb7985c1469fc27eece2f444"title="true mono, false stereo ">i2s_config_t.oneChannel</a> = false:</p>
<p>Buffer for transmit or receive has to be multiply of 8 bytes. Buffer address has to be aligned to 4-bytes.</p>
<p>If <aclass="el"href="a00031.html#a7804296c524c18b636be8af8e627cc8a"title="Data length (4 - 32) ">i2s_config_t.dataLength</a> (channel bit width) is between 25 and 32 and <aclass="el"href="a00031.html#a08c393f7fb7985c1469fc27eece2f444"title="true mono, false stereo ">i2s_config_t.oneChannel</a> = true:</p>
<p>Buffer for transmit or receive has to be multiply of 4 bytes. Buffer address has to be aligned to 4-bytes.</p>
<divclass="line"><spanclass="comment">/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer finishes */</span></div>
<divclass="line"><spanclass="comment">/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer finishes */</span></div>
<divclass="line"><spanclass="comment">/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer finishes */</span></div>
<divclass="line"><spanclass="comment">/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer finishes */</span></div>