I2S Module¶
| Since | Origin / Contributor | Maintainer | Source |
|---|---|---|---|
| 2017-04-29 | zelll | Arnim Läuger | i2s.c |
The I2S module provides access to the in-built two I2S controllers.
DAC mode configuration
DACs are only available for DAC built-in mode on I2S peripheral 0.
ADC mode configuration
Only ADC1 is available for ADC built-in mode.
i2s.mute()¶
Mute the I2S channel. The hardware buffer is instantly filled with silence.
Syntax¶
i2s.mute(i2s_num)
Parameters¶
i2s_numI2S peripheral 0 or 1
Returns¶
nil
An error is thrown in case of invalid parameters or if the i2s driver failed.
i2s.read()¶
Read data from I2S receive buffer.
Syntax¶
i2s.read(i2s_num, size[, wait_ms])
Parameters¶
i2s_numI2S peripheral 0 or 1sizeBytes to readwait_msMillisecond to wait if data is not ready. Optional, defaults to 0 (not to wait) when omitted.
Returns¶
Data read from data-in pin. If data is not ready in wait_ms millisecond, less than size bytes can be returned.
An error is thrown in case of invalid parameters or if the i2s driver failed.
i2s.start()¶
Configuration and start I2S bus.
Syntax¶
i2s.start(i2s_num, cfg, cb)
Parameters¶
i2s_numI2S peripheral 0 or 1cfgtable containing configuration data:modeI2S work mode. Optional, defaults toi2s.MODE_MASTER + i2s.MODE_TXwhen omitted.i2s.MODE_MASTERi2s.MODE_SLAVEi2s.MODE_TXi2s.MODE_RXi2s.MODE_DAC_BUILT_INi2s.MODE_ADC_BUILT_INi2s.MODE_PDM
rateaudio sample rate. Optional, defauls to 44100 when omitted.bitsbits per sample. Optional, defaults to 16 when omitted.channelchannel format of I2S stream. Optional, defaults toi2s.CHANNEL_RIGHT_LEFTwhen omitted.i2s.CHANNEL_RIGHT_LEFTi2s.CHANNEL_ALL_LEFTi2s.CHANNEL_ONLY_LEFTi2s.CHANNEL_ALL_RIGHTi2s.CHANNEL_ONLY_RIGHT
formatcommunication format. Optional, defaults toi2s.FORMAT_I2S + i2s.FORMAT_I2S_MSBwhen omitted.i2s.FORMAT_I2Si2s.FORMAT_I2S_MSBi2s.FORMAT_I2S_LSBi2s.FORMAT_PCMi2s.FORMAT_PCM_SHORTi2s.FORMAT_PCM_LONG
buffer_countnumber of dma buffers. Optional, defaults to 2 when omitted.buffer_lensize of one dma buffer. Optional, defaults to rate/100 when omitted.bck_pinclock pin, optionalws_pinWS pin, optionaldata_out_pindata output pin, optionaldata_in_pindata input pin, optionaldac_modeDAC mode configuration. Optional, defaults toi2s.DAC_CHANNEL_DISABLEwhen omitted.i2s.DAC_CHANNEL_DISABLEi2s.DAC_CHANNEL_RIGHTi2s.DAC_CHANNEL_LEFTi2s.DAC_CHANNEL_BOTH
adc1_channelADC1 channel number 0..7. Optional, defaults to off when omitted.
cbfunction called when transmit data is requested or received data is available- the function is called with parameters
i2s_numanddirdiris "tx" for TX data request. Function shall calli2s.write().diris "rx" for RX data available. Function shall calli2s.read().
- the function is called with parameters
Returns¶
nil
An error is thrown in case of invalid parameters or if the i2s driver failed.
i2s.stop()¶
Stop I2S bus.
Syntax¶
i2s.stop(i2s_num)
Parameters¶
i2s_numI2S peripheral 0 or 1
Returns¶
nil
An error is thrown in case of invalid parameters or if the i2s driver failed.
i2s.write()¶
Write to I2S transmit buffer.
Syntax¶
i2s.write(i2s_num, data)
Parameters¶
i2s_numI2S peripheral 0 or 1datastring containing I2S stream data
Returns¶
nil
An error is thrown in case of invalid parameters or if the channel failed.