2017-04-28 22:27:57 +02:00
|
|
|
# I2S Module
|
|
|
|
| Since | Origin / Contributor | Maintainer | Source |
|
|
|
|
| :----- | :-------------------- | :---------- | :------ |
|
2019-01-13 21:19:03 +01:00
|
|
|
| 2017-04-29 | zelll | [Arnim Läuger](https://github.com/devsaurus) | [i2s.c](../../components/modules/i2s.c)|
|
2017-04-28 22:27:57 +02:00
|
|
|
|
2017-04-29 19:07:46 +02:00
|
|
|
The I2S module provides access to the in-built two I2S controllers.
|
|
|
|
|
2018-10-14 18:05:48 +02:00
|
|
|
!!! note "DAC mode configuration"
|
|
|
|
DACs are only available for DAC built-in mode on I2S peripheral 0.
|
|
|
|
|
|
|
|
!!! note "ADC mode configuration"
|
|
|
|
Only ADC1 is available for ADC built-in mode.
|
|
|
|
|
2018-11-02 22:30:45 +01:00
|
|
|
|
|
|
|
## i2s.mute()
|
|
|
|
Mute the I2S channel. The hardware buffer is instantly filled with silence.
|
|
|
|
|
|
|
|
#### Syntax
|
Fix bit, bthci, can, encoder, eth, i2s docs (#3432)
* Fix bit, bthci, can, encoder, eth, i2s docs
* Fix bit, mqtt, qrcodegen, sigma-delta, sodium, time docs.
* Add object name in http.md
2021-05-19 21:02:49 +02:00
|
|
|
`i2s.mute(i2s_num)`
|
2018-11-02 22:30:45 +01:00
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
- `i2s_num` I2S 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_num` I2S peripheral 0 or 1
|
|
|
|
- `size` Bytes to read
|
|
|
|
- `wait_ms` Millisecond 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.
|
|
|
|
|
|
|
|
|
2017-04-29 19:07:46 +02:00
|
|
|
## i2s.start()
|
|
|
|
Configuration and start I2S bus.
|
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
```lua
|
2018-10-14 18:05:48 +02:00
|
|
|
i2s.start(i2s_num, cfg, cb)
|
2017-04-29 19:07:46 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Parameters
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s_num` I2S peripheral 0 or 1
|
|
|
|
- `cfg` table containing configuration data:
|
2018-10-14 18:13:00 +02:00
|
|
|
- `mode` I2S work mode. Optional, defaults to `i2s.MODE_MASTER + i2s.MODE_TX` when omitted.
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s.MODE_MASTER`
|
|
|
|
- `i2s.MODE_SLAVE`
|
|
|
|
- `i2s.MODE_TX`
|
|
|
|
- `i2s.MODE_RX`
|
|
|
|
- `i2s.MODE_DAC_BUILT_IN`
|
|
|
|
- `i2s.MODE_ADC_BUILT_IN`
|
|
|
|
- `i2s.MODE_PDM`
|
2018-10-14 18:13:00 +02:00
|
|
|
- `rate` audio sample rate. Optional, defauls to 44100 when omitted.
|
|
|
|
- `bits` bits per sample. Optional, defaults to 16 when omitted.
|
|
|
|
- `channel` channel format of I2S stream. Optional, defaults to `i2s.CHANNEL_RIGHT_LEFT` when omitted.
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s.CHANNEL_RIGHT_LEFT`
|
2018-10-14 18:13:00 +02:00
|
|
|
- `i2s.CHANNEL_ALL_LEFT`
|
|
|
|
- `i2s.CHANNEL_ONLY_LEFT`
|
|
|
|
- `i2s.CHANNEL_ALL_RIGHT`
|
|
|
|
- `i2s.CHANNEL_ONLY_RIGHT`
|
2021-07-29 05:47:45 +02:00
|
|
|
- `format` communication format. Optional, defaults to `i2s.FORMAT_I2S_STANDARD` when omitted.
|
|
|
|
- `i2s.FORMAT_I2S_STANDARD`
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s.FORMAT_I2S_MSB`
|
|
|
|
- `i2s.FORMAT_PCM_SHORT`
|
|
|
|
- `i2s.FORMAT_PCM_LONG`
|
2018-10-14 18:13:00 +02:00
|
|
|
- `buffer_count` number of dma buffers. Optional, defaults to 2 when omitted.
|
|
|
|
- `buffer_len` size of one dma buffer. Optional, defaults to rate/100 when omitted.
|
2018-10-14 18:05:48 +02:00
|
|
|
- `bck_pin` clock pin, optional
|
|
|
|
- `ws_pin` WS pin, optional
|
|
|
|
- `data_out_pin` data output pin, optional
|
|
|
|
- `data_in_pin` data input pin, optional
|
2018-10-14 18:13:00 +02:00
|
|
|
- `dac_mode` DAC mode configuration. Optional, defaults to `i2s.DAC_CHANNEL_DISABLE` when omitted.
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s.DAC_CHANNEL_DISABLE`
|
|
|
|
- `i2s.DAC_CHANNEL_RIGHT`
|
|
|
|
- `i2s.DAC_CHANNEL_LEFT`
|
|
|
|
- `i2s.DAC_CHANNEL_BOTH`
|
2018-10-14 18:13:00 +02:00
|
|
|
- `adc1_channel` ADC1 channel number 0..7. Optional, defaults to off when omitted.
|
2018-10-14 18:05:48 +02:00
|
|
|
- `cb` function called when transmit data is requested or received data is available
|
|
|
|
- the function is called with parameters `i2s_num` and `dir`
|
|
|
|
- `dir` is "tx" for TX data request. Function shall call `i2s.write()`.
|
|
|
|
- `dir` is "rx" for RX data available. Function shall call `i2s.read()`.
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
#### Returns
|
2018-10-14 18:05:48 +02:00
|
|
|
`nil`
|
|
|
|
|
2018-11-02 22:30:45 +01:00
|
|
|
An error is thrown in case of invalid parameters or if the i2s driver failed.
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
## i2s.stop()
|
2018-10-14 18:13:00 +02:00
|
|
|
Stop I2S bus.
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
`i2s.stop(i2s_num)`
|
|
|
|
|
|
|
|
#### Parameters
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s_num` I2S peripheral 0 or 1
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
#### Returns
|
2018-10-14 18:05:48 +02:00
|
|
|
`nil`
|
|
|
|
|
2018-11-02 22:30:45 +01:00
|
|
|
An error is thrown in case of invalid parameters or if the i2s driver failed.
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
## i2s.write()
|
2018-10-14 18:13:00 +02:00
|
|
|
Write to I2S transmit buffer.
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
#### Syntax
|
2018-10-14 18:05:48 +02:00
|
|
|
`i2s.write(i2s_num, data)`
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
#### Parameters
|
2018-10-14 18:05:48 +02:00
|
|
|
- `i2s_num` I2S peripheral 0 or 1
|
|
|
|
- `data` string containing I2S stream data
|
2017-04-29 19:07:46 +02:00
|
|
|
|
|
|
|
#### Returns
|
2018-10-14 18:05:48 +02:00
|
|
|
`nil`
|
|
|
|
|
|
|
|
An error is thrown in case of invalid parameters or if the channel failed.
|