1
6
7
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
56
57
61
68
69
72
73
74
75
76
77
78
79
80
87
88
89
90
93
94
95
96
97
98
99
100
102
103
104
107
117
118
121
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
314
315
316
317
318
322
323
324
325
326
327
328
329
330
331
332
337
338
339
340
343
344
345
346
347
348
349
350
351
353
354
355
358
370
371
374
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/* ... */
/* ... */
#pragma once
#include "hal/i2s_types.h"
#include "hal/gpio_types.h"
#include "driver/i2s_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#if SOC_I2S_SUPPORTS_PDM_RX
#if SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER
/* ... */
#define I2S_PDM_RX_SLOT_DEFAULT_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \
I2S_PDM_SLOT_LEFT : I2S_PDM_SLOT_BOTH, \
.hp_en = true, \
.hp_cut_off_freq_hz = 35.5, \
.amplify_num = 1, \
}{...}
/* ... */#else
/* ... */
#define I2S_PDM_RX_SLOT_DEFAULT_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \
I2S_PDM_SLOT_LEFT : I2S_PDM_SLOT_BOTH, \
}{...}
/* ... */#endif
/* ... */
#define I2S_PDM_RX_CLK_DEFAULT_CONFIG(rate) { \
.sample_rate_hz = rate, \
.clk_src = I2S_CLK_SRC_DEFAULT, \
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
.dn_sample_mode = I2S_PDM_DSR_8S, \
.bclk_div = 8, \
}{...}
/* ... */
typedef struct {
i2s_data_bit_width_t data_bit_width;
i2s_slot_bit_width_t slot_bit_width;
i2s_slot_mode_t slot_mode;
i2s_pdm_slot_mask_t slot_mask;
#if SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER
bool hp_en;
float hp_cut_off_freq_hz;
uint32_t amplify_num;
/* ... */
/* ... */#endif
}{ ... } i2s_pdm_rx_slot_config_t;
/* ... */
typedef struct {
uint32_t sample_rate_hz;
i2s_clock_src_t clk_src;
i2s_mclk_multiple_t mclk_multiple;
i2s_pdm_dsr_t dn_sample_mode;
uint32_t bclk_div;
/* ... */
}{ ... } i2s_pdm_rx_clk_config_t;
/* ... */
typedef struct {
gpio_num_t clk;
union {
gpio_num_t din;
gpio_num_t dins[SOC_I2S_PDM_MAX_RX_LINES];
}{ ... };
struct {
uint32_t clk_inv: 1;
}{ ... } invert_flags;
}{ ... } i2s_pdm_rx_gpio_config_t;
/* ... */
typedef struct {
i2s_pdm_rx_clk_config_t clk_cfg;
i2s_pdm_rx_slot_config_t slot_cfg;
i2s_pdm_rx_gpio_config_t gpio_cfg;
}{ ... } i2s_pdm_rx_config_t;
/* ... */
esp_err_t i2s_channel_init_pdm_rx_mode(i2s_chan_handle_t handle, const i2s_pdm_rx_config_t *pdm_rx_cfg);
/* ... */
esp_err_t i2s_channel_reconfig_pdm_rx_clock(i2s_chan_handle_t handle, const i2s_pdm_rx_clk_config_t *clk_cfg);
/* ... */
esp_err_t i2s_channel_reconfig_pdm_rx_slot(i2s_chan_handle_t handle, const i2s_pdm_rx_slot_config_t *slot_cfg);
/* ... */
esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_pdm_rx_gpio_config_t *gpio_cfg);
/* ... */
#endif
#if SOC_I2S_SUPPORTS_PDM_TX
#if SOC_I2S_HW_VERSION_2
/* ... */
#define I2S_PDM_TX_SLOT_DEFAULT_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.sd_prescale = 0, \
.sd_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.hp_scale = I2S_PDM_SIG_SCALING_DIV_2, \
.lp_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.line_mode = I2S_PDM_TX_ONE_LINE_CODEC, \
.hp_en = true, \
.hp_cut_off_freq_hz = 35.5, \
.sd_dither = 0, \
.sd_dither2 = 1, \
}{...}
/* ... */
#define I2S_PDM_TX_SLOT_DAC_DEFAULT_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.sd_prescale = 0, \
.sd_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.hp_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.lp_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.line_mode = ((mono_or_stereo) == I2S_SLOT_MODE_MONO ? \
I2S_PDM_TX_ONE_LINE_DAC : I2S_PDM_TX_TWO_LINE_DAC), \
.hp_en = true, \
.hp_cut_off_freq_hz = 35.5, \
.sd_dither = 0, \
.sd_dither2 = 1, \
}{...}
/* ... */#else
/* ... */
#define I2S_PDM_TX_SLOT_DEFAULT_CONFIG(bits_per_sample, mono_or_stereo) { \
.data_bit_width = bits_per_sample, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
.slot_mode = mono_or_stereo, \
.slot_mask = I2S_PDM_SLOT_BOTH, \
.sd_prescale = 0, \
.sd_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.hp_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.lp_scale = I2S_PDM_SIG_SCALING_MUL_1, \
.sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, \
}{...}
/* ... */#endif
/* ... */
#define I2S_PDM_TX_CLK_DEFAULT_CONFIG(rate) { \
.sample_rate_hz = rate, \
.clk_src = I2S_CLK_SRC_DEFAULT, \
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
.up_sample_fp = 960, \
.up_sample_fs = 480, \
.bclk_div = 8, \
}{...}
/* ... */
#define I2S_PDM_TX_CLK_DAC_DEFAULT_CONFIG(rate) { \
.sample_rate_hz = rate, \
.clk_src = I2S_CLK_SRC_DEFAULT, \
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
.up_sample_fp = 960, \
.up_sample_fs = (rate) / 100, \
.bclk_div = 13, \
}{...}
/* ... */
/* ... */
typedef struct {
i2s_data_bit_width_t data_bit_width;
i2s_slot_bit_width_t slot_bit_width;
i2s_slot_mode_t slot_mode;
/* ... */
#if SOC_I2S_HW_VERSION_1
i2s_pdm_slot_mask_t slot_mask;
#endif
uint32_t sd_prescale;
i2s_pdm_sig_scale_t sd_scale;
i2s_pdm_sig_scale_t hp_scale;
i2s_pdm_sig_scale_t lp_scale;
i2s_pdm_sig_scale_t sinc_scale;
#if SOC_I2S_HW_VERSION_2
i2s_pdm_tx_line_mode_t line_mode;
bool hp_en;
float hp_cut_off_freq_hz;
uint32_t sd_dither;
uint32_t sd_dither2; /* ... */
#endif
}{ ... } i2s_pdm_tx_slot_config_t;
/* ... */
typedef struct {
uint32_t sample_rate_hz;
i2s_clock_src_t clk_src;
i2s_mclk_multiple_t mclk_multiple;
uint32_t up_sample_fp;
uint32_t up_sample_fs;
uint32_t bclk_div;
/* ... */
}{ ... } i2s_pdm_tx_clk_config_t;
/* ... */
typedef struct {
gpio_num_t clk;
gpio_num_t dout;
#if SOC_I2S_PDM_MAX_TX_LINES > 1
gpio_num_t dout2;
/* ... */
/* ... */#endif
struct {
uint32_t clk_inv: 1;
}{ ... } invert_flags;
}{ ... } i2s_pdm_tx_gpio_config_t;
/* ... */
typedef struct {
i2s_pdm_tx_clk_config_t clk_cfg;
i2s_pdm_tx_slot_config_t slot_cfg;
i2s_pdm_tx_gpio_config_t gpio_cfg;
}{ ... } i2s_pdm_tx_config_t;
/* ... */
esp_err_t i2s_channel_init_pdm_tx_mode(i2s_chan_handle_t handle, const i2s_pdm_tx_config_t *pdm_tx_cfg);
/* ... */
esp_err_t i2s_channel_reconfig_pdm_tx_clock(i2s_chan_handle_t handle, const i2s_pdm_tx_clk_config_t *clk_cfg);
/* ... */
esp_err_t i2s_channel_reconfig_pdm_tx_slot(i2s_chan_handle_t handle, const i2s_pdm_tx_slot_config_t *slot_cfg);
/* ... */
esp_err_t i2s_channel_reconfig_pdm_tx_gpio(i2s_chan_handle_t handle, const i2s_pdm_tx_gpio_config_t *gpio_cfg);
/* ... */
#endif
#ifdef __cplusplus
}{...}
#endif