Components/arch_driver/src/include/driver/i2s.h
Go to the documentation of this file.
1 
26 #pragma once
27 
28 #include <stdint.h>
29 #include <stddef.h>
30 #include <esp_attr.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
51 typedef union {
52  uint32_t u32;
53  struct {
54  int16_t left;
55  int16_t right;
56  };
57 } i2s_sample_t;
58 
62 typedef enum {
67 
71 typedef enum {
75 
79 typedef enum {
84 
88 typedef enum {
95 
99 typedef enum {
103 } i2s_mode_t;
104 
108 typedef enum {
114 
119 typedef void (*i2s_callback_t)(void* param, i2s_event_type_t event);
120 
124 typedef struct {
129  uint16_t dma_buf_len;
130  uint8_t dma_buf_count;
134 
138 typedef struct {
141  unsigned sample_rate;
143  bool auto_start;
145  void* param;
146  uint8_t bits_mod;
147 } i2s_config_t;
148 
155 bool i2s_driver_install(const i2s_config_t* config);
156 
161 
168 bool i2s_start();
169 
175 bool i2s_stop();
176 
180 bool i2s_set_sample_rates(uint32_t rate);
181 
185 bool i2s_set_dividers(uint8_t bck_div, uint8_t mclk_div);
186 
191 
195 typedef struct {
196  union {
197  void* buffer;
199  };
200  size_t size;
201  // debugging
202  uint16_t buf;
203  uint16_t pos;
205 
209 typedef unsigned TickType_t;
210 
220 bool IRAM_ATTR i2s_dma_read(i2s_buffer_info_t* info, size_t max_bytes);
221 
231 bool IRAM_ATTR i2s_dma_write(i2s_buffer_info_t* info, size_t max_bytes);
232 
241 size_t i2s_write(const void* src, size_t size, TickType_t ticks_to_wait);
242 
250 size_t i2s_read(void* dest, size_t size, TickType_t ticks_to_wait);
251 
257 
261 typedef enum {
263  I2S_PIN_WS_OUT = 0x02,
265  I2S_PIN_BC_IN = 0x10,
266  I2S_PIN_WS_IN = 0x20,
268 } i2s_pin_t;
269 
270 typedef uint8_t i2s_pin_set_t;
271 
283 
285 
290 typedef struct {
291  uint16_t size;
292  uint16_t used;
294 
301 
308 
312 //unsigned i2s_rx_available();
313 
316 #ifdef __cplusplus
317 }
318 #endif
i2s_comm_format_t
I2S communication standard format.
Definition: Components/arch_driver/src/include/driver/i2s.h:79
bool i2s_set_dividers(uint8_t bck_div, uint8_t mclk_div)
bool i2s_dma_read(i2s_buffer_info_t *info, size_t max_bytes)
Fetch a DMA buffer containing received data (zero-copy)
void i2s_set_pins(i2s_pin_set_t pins, bool enable)
Configure I2S pins.
i2s_event_type_t
I2S event types.
Definition: Components/arch_driver/src/include/driver/i2s.h:108
i2s_channel_fmt_t
I2S channel format type.
Definition: Components/arch_driver/src/include/driver/i2s.h:88
bool i2s_set_sample_rates(uint32_t rate)
bool i2s_start()
Start I2S driver.
bool i2s_dma_write(i2s_buffer_info_t *info, size_t max_bytes)
Fetch a DMA buffer for direct writing (zero-copy)
i2s_bits_per_sample_t
I2S bit width per sample.
Definition: Components/arch_driver/src/include/driver/i2s.h:62
bool i2s_stat_tx(i2s_buffer_stat_t *stat)
Obtain state information for TX buffers.
unsigned TickType_t
Defines the wait interval (presently milliseconds)
Definition: Components/arch_driver/src/include/driver/i2s.h:209
void i2s_driver_uninstall()
Uninstall I2S driver.
size_t i2s_write(const void *src, size_t size, TickType_t ticks_to_wait)
writes a buffer of frames into the DMA memory, returns the amount of frames written.
void(* i2s_callback_t)(void *param, i2s_event_type_t event)
Callback function type.
Definition: Components/arch_driver/src/include/driver/i2s.h:119
uint8_t i2s_pin_set_t
Definition: Components/arch_driver/src/include/driver/i2s.h:270
bool i2s_stat_rx(i2s_buffer_stat_t *stat)
Obtain state information for RX buffers.
size_t i2s_read(void *dest, size_t size, TickType_t ticks_to_wait)
Reads a block of received data.
i2s_mode_t
I2S Mode, default is I2S_MODE_MASTER.
Definition: Components/arch_driver/src/include/driver/i2s.h:99
bool i2s_zero_dma_buffer()
Zero the contents of the TX DMA buffer.
float i2s_get_real_rate()
bool i2s_enable_loopback(bool enable)
bool i2s_stop()
Stop I2S driver.
i2s_channel_t
I2S channel.
Definition: Components/arch_driver/src/include/driver/i2s.h:71
bool i2s_driver_install(const i2s_config_t *config)
Install and start I2S driver.
i2s_pin_t
I2S pin enable for i2s_set_pin.
Definition: Components/arch_driver/src/include/driver/i2s.h:261
@ I2S_COMM_FORMAT_I2S_MSB
I2S format MSB.
Definition: Components/arch_driver/src/include/driver/i2s.h:81
@ I2S_COMM_FORMAT_I2S
I2S communication format I2S.
Definition: Components/arch_driver/src/include/driver/i2s.h:80
@ I2S_COMM_FORMAT_I2S_LSB
I2S format LSB.
Definition: Components/arch_driver/src/include/driver/i2s.h:82
@ I2S_EVENT_DMA_ERROR
Definition: Components/arch_driver/src/include/driver/i2s.h:109
@ I2S_EVENT_TX_DONE
Definition: Components/arch_driver/src/include/driver/i2s.h:110
@ I2S_EVENT_RX_DONE
Definition: Components/arch_driver/src/include/driver/i2s.h:111
@ I2S_EVENT_MAX
Definition: Components/arch_driver/src/include/driver/i2s.h:112
@ I2S_CHANNEL_FMT_ONLY_RIGHT
Definition: Components/arch_driver/src/include/driver/i2s.h:92
@ I2S_CHANNEL_FMT_RIGHT_LEFT
Definition: Components/arch_driver/src/include/driver/i2s.h:89
@ I2S_CHANNEL_FMT_ALL_RIGHT
Definition: Components/arch_driver/src/include/driver/i2s.h:90
@ I2S_CHANNEL_FMT_ONLY_LEFT
Definition: Components/arch_driver/src/include/driver/i2s.h:93
@ I2S_CHANNEL_FMT_ALL_LEFT
Definition: Components/arch_driver/src/include/driver/i2s.h:91
@ I2S_BITS_PER_SAMPLE_16BIT
I2S bits per sample: 16-bits.
Definition: Components/arch_driver/src/include/driver/i2s.h:64
@ I2S_BITS_PER_SAMPLE_8BIT
I2S bits per sample: 8-bits.
Definition: Components/arch_driver/src/include/driver/i2s.h:63
@ I2S_BITS_PER_SAMPLE_24BIT
I2S bits per sample: 24-bits.
Definition: Components/arch_driver/src/include/driver/i2s.h:65
@ I2S_MODE_DISABLED
Definition: Components/arch_driver/src/include/driver/i2s.h:100
@ I2S_MODE_MASTER
Definition: Components/arch_driver/src/include/driver/i2s.h:101
@ I2S_MODE_SLAVE
Definition: Components/arch_driver/src/include/driver/i2s.h:102
@ I2S_CHANNEL_MONO
I2S 1 channel (mono)
Definition: Components/arch_driver/src/include/driver/i2s.h:72
@ I2S_CHANNEL_STEREO
I2S 2 channel (stereo)
Definition: Components/arch_driver/src/include/driver/i2s.h:73
@ I2S_PIN_BC_IN
GPIO 13 / RXD2 / D7.
Definition: Components/arch_driver/src/include/driver/i2s.h:265
@ I2S_PIN_BCK_OUT
GPIO 15 / TXD2 / D8.
Definition: Components/arch_driver/src/include/driver/i2s.h:262
@ I2S_PIN_WS_IN
GPIO 14 / D5.
Definition: Components/arch_driver/src/include/driver/i2s.h:266
@ I2S_PIN_WS_OUT
GPIO 2 / TXD1 / D4.
Definition: Components/arch_driver/src/include/driver/i2s.h:263
@ I2S_PIN_DATA_OUT
GPIO 3 / RXD0 / D9.
Definition: Components/arch_driver/src/include/driver/i2s.h:264
@ I2S_PIN_DATA_IN
GPIO 12 / D6.
Definition: Components/arch_driver/src/include/driver/i2s.h:267
void enable(Handler &commandHandler, HardwareSerial &serial)
Defines a buffer with available content.
Definition: Components/arch_driver/src/include/driver/i2s.h:195
void * buffer
Definition: Components/arch_driver/src/include/driver/i2s.h:197
uint16_t pos
Definition: Components/arch_driver/src/include/driver/i2s.h:203
i2s_sample_t * samples
Definition: Components/arch_driver/src/include/driver/i2s.h:198
uint16_t buf
Definition: Components/arch_driver/src/include/driver/i2s.h:202
size_t size
Available space (TX) or data (RX) in bytes.
Definition: Components/arch_driver/src/include/driver/i2s.h:200
Contains I2S buffer status information.
Definition: Components/arch_driver/src/include/driver/i2s.h:290
uint16_t size
Definition: Components/arch_driver/src/include/driver/i2s.h:291
uint16_t used
Definition: Components/arch_driver/src/include/driver/i2s.h:292
I2S configuration parameters.
Definition: Components/arch_driver/src/include/driver/i2s.h:138
void * param
Callback parameter.
Definition: Components/arch_driver/src/include/driver/i2s.h:145
bool auto_start
Start immediately on successful initialisation.
Definition: Components/arch_driver/src/include/driver/i2s.h:143
uint8_t bits_mod
Evaluate what this does (4 bits)
Definition: Components/arch_driver/src/include/driver/i2s.h:146
unsigned sample_rate
I2S sample rate.
Definition: Components/arch_driver/src/include/driver/i2s.h:141
i2s_module_config_t tx
TX module configuration.
Definition: Components/arch_driver/src/include/driver/i2s.h:139
i2s_module_config_t rx
RX module configuration.
Definition: Components/arch_driver/src/include/driver/i2s.h:140
i2s_callback_t callback
Callback handler.
Definition: Components/arch_driver/src/include/driver/i2s.h:144
bool tx_desc_auto_clear
I2S auto clear tx descriptor if there is underflow condition (Mutes output)
Definition: Components/arch_driver/src/include/driver/i2s.h:142
I2S module configuration (TX or RX)
Definition: Components/arch_driver/src/include/driver/i2s.h:124
uint16_t dma_buf_len
I2S DMA Buffer Length (in samples)
Definition: Components/arch_driver/src/include/driver/i2s.h:129
i2s_comm_format_t communication_format
I2S communication format.
Definition: Components/arch_driver/src/include/driver/i2s.h:128
i2s_bits_per_sample_t bits_per_sample
I2S bits per sample.
Definition: Components/arch_driver/src/include/driver/i2s.h:126
uint8_t dma_buf_count
I2S DMA Buffer Count.
Definition: Components/arch_driver/src/include/driver/i2s.h:130
uint8_t callback_threshold
Definition: Components/arch_driver/src/include/driver/i2s.h:131
i2s_channel_fmt_t channel_format
I2S channel format.
Definition: Components/arch_driver/src/include/driver/i2s.h:127
i2s_mode_t mode
I2S work mode (combination of i2s_mode_t)
Definition: Components/arch_driver/src/include/driver/i2s.h:125
I2S sample.
Definition: Components/arch_driver/src/include/driver/i2s.h:51
int16_t left
Definition: Components/arch_driver/src/include/driver/i2s.h:54
uint32_t u32
Definition: Components/arch_driver/src/include/driver/i2s.h:52
int16_t right
Definition: Components/arch_driver/src/include/driver/i2s.h:55