31
31
}, \
32
32
}
33
33
34
+ #if SOC_I2S_SUPPORTS_TDM
34
35
#define I2S_TDM_CHAN_CFG (_sample_rate, _data_bit_width, _slot_mode, _mask ) \
35
36
{ \
36
37
.clk_cfg = I2S_TDM_CLK_DEFAULT_CONFIG (_sample_rate), \
48
49
}, \
49
50
}, \
50
51
}
51
-
52
+ #endif
53
+ #if SOC_I2S_SUPPORTS_PDM_TX
52
54
#if (SOC_I2S_PDM_MAX_TX_LINES > 1)
53
55
#define I2S_PDM_TX_CHAN_CFG (_sample_rate, _data_bit_width, _slot_mode ) \
54
56
{ \
77
79
}, \
78
80
}
79
81
#endif
82
+ #endif
80
83
84
+ #if SOC_I2S_SUPPORTS_PDM_RX
81
85
#if (SOC_I2S_PDM_MAX_RX_LINES > 1)
82
86
#define I2S_PDM_RX_CHAN_CFG (_sample_rate, _data_bit_width, _slot_mode ) \
83
87
{ \
110
114
}, \
111
115
}
112
116
#endif
117
+ #endif
113
118
114
119
#define I2S_ERROR_CHECK_RETURN (x,r ) do { last_error = (x); if (unlikely (last_error != ESP_OK)){ log_e (" ERROR: %s" , esp_err_to_name (last_error)); return (r); } } while (0 )
115
120
#define I2S_ERROR_CHECK_RETURN_FALSE (x ) I2S_ERROR_CHECK_RETURN(x,false )
@@ -192,17 +197,20 @@ I2SClass::I2SClass(){
192
197
_bclk_inv = false ;
193
198
_ws_inv = false ;
194
199
200
+ #if SOC_I2S_SUPPORTS_PDM_TX
195
201
_tx_clk = -1 ;
196
202
_tx_dout0 = -1 ;
197
203
_tx_dout1 = -1 ;
198
204
_tx_clk_inv = false ;
199
-
205
+ #endif
206
+ #if SOC_I2S_SUPPORTS_PDM_RX
200
207
_rx_clk = -1 ;
201
208
_rx_din0 = -1 ;
202
209
_rx_din1 = -1 ;
203
210
_rx_din2 = -1 ;
204
211
_rx_din3 = -1 ;
205
212
_rx_clk_inv = false ;
213
+ #endif
206
214
}
207
215
208
216
I2SClass::~I2SClass (){
@@ -233,15 +241,18 @@ void I2SClass::setInverted(bool bclk, bool ws, bool mclk){
233
241
}
234
242
235
243
// Set pins for PDM TX mode
244
+ #if SOC_I2S_SUPPORTS_PDM_TX
236
245
void I2SClass::setPinsPdmTx (int8_t clk, int8_t dout0, int8_t dout1){
237
246
_tx_clk = clk;
238
247
_tx_dout0 = dout0;
239
248
#if (SOC_I2S_PDM_MAX_TX_LINES > 1)
240
249
_tx_dout1 = dout1;
241
250
#endif
242
251
}
252
+ #endif
243
253
244
254
// Set pins for PDM RX mode
255
+ #if SOC_I2S_SUPPORTS_PDM_RX
245
256
void I2SClass::setPinsPdmRx (int8_t clk, int8_t din0, int8_t din1, int8_t din2, int8_t din3){
246
257
_rx_clk = clk;
247
258
_rx_din0 = din0;
@@ -251,11 +262,18 @@ void I2SClass::setPinsPdmRx(int8_t clk, int8_t din0, int8_t din1, int8_t din2, i
251
262
_rx_din3 = din3;
252
263
#endif
253
264
}
265
+ #endif
254
266
267
+ #if SOC_I2S_SUPPORTS_PDM_TX || SOC_I2S_SUPPORTS_PDM_RX
255
268
void I2SClass::setInvertedPdm (bool clk){
269
+ #if SOC_I2S_SUPPORTS_PDM_TX
256
270
_tx_clk_inv = clk;
271
+ #endif
272
+ #if SOC_I2S_SUPPORTS_PDM_RX
257
273
_rx_clk_inv = clk;
274
+ #endif
258
275
}
276
+ #endif
259
277
260
278
bool I2SClass::initSTD (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
261
279
// Peripheral manager deinit previous peripheral if pin was used
@@ -305,6 +323,7 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
305
323
return false ;
306
324
}
307
325
326
+ #if SOC_I2S_SUPPORTS_TDM
308
327
bool I2SClass::initTDM (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
309
328
// Peripheral manager deinit previous peripheral if pin was used
310
329
if (_mclk >= 0 ) if (!perimanSetPinBus (_mclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
@@ -352,7 +371,9 @@ bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
352
371
I2SClass::i2sDetachBus ((void *)(this ));
353
372
return false ;
354
373
}
374
+ #endif
355
375
376
+ #if SOC_I2S_SUPPORTS_PDM_TX
356
377
bool I2SClass::initPDMtx (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
357
378
// Peripheral manager deinit previous peripheral if pin was used
358
379
if (_tx_clk >= 0 ) if (!perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
@@ -383,7 +404,9 @@ bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
383
404
I2SClass::i2sDetachBus ((void *)(this ));
384
405
return false ;
385
406
}
407
+ #endif
386
408
409
+ #if SOC_I2S_SUPPORTS_PDM_RX
387
410
bool I2SClass::initPDMrx (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
388
411
// Peripheral manager deinit previous peripheral if pin was used
389
412
if (_rx_clk >= 0 ) if (!perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
@@ -418,10 +441,15 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
418
441
I2SClass::i2sDetachBus ((void *)(this ));
419
442
return false ;
420
443
}
444
+ #endif
421
445
422
- bool I2SClass::begin (i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
446
+ bool I2SClass::begin (i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch
447
+ #if SOC_I2S_SUPPORTS_TDM
448
+ , int8_t slot_mask
449
+ #endif
450
+ ){
423
451
/* Setup I2S peripheral */
424
- if (mode > I2S_MODE_PDM_RX ){
452
+ if (mode >= I2S_MODE_MAX ){
425
453
log_e (" Invalid I2S mode selected." );
426
454
return false ;
427
455
}
@@ -432,15 +460,23 @@ bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_c
432
460
case I2S_MODE_STD:
433
461
init = initSTD (rate, bits_cfg, ch);
434
462
break ;
463
+ #if SOC_I2S_SUPPORTS_TDM
435
464
case I2S_MODE_TDM:
436
465
init = initTDM (rate, bits_cfg, ch, slot_mask);
437
466
break ;
467
+ #endif
468
+ #if SOC_I2S_SUPPORTS_PDM_TX
438
469
case I2S_MODE_PDM_TX:
439
470
init = initPDMtx (rate, bits_cfg, ch);
440
471
break ;
472
+ #endif
473
+ #if SOC_I2S_SUPPORTS_PDM_RX
441
474
case I2S_MODE_PDM_RX:
442
475
init = initPDMrx (rate, bits_cfg, ch);
443
476
break ;
477
+ #endif
478
+ default :
479
+ break ;
444
480
}
445
481
446
482
if (init == false ){
@@ -469,25 +505,34 @@ bool I2SClass::end(){
469
505
470
506
// Peripheral manager deinit used pins
471
507
switch (_mode){
472
- case I2S_MODE_STD: case I2S_MODE_TDM:
508
+ case I2S_MODE_STD:
509
+ #if SOC_I2S_SUPPORTS_TDM
510
+ case I2S_MODE_TDM:
511
+ #endif
473
512
perimanSetPinBus (_mclk, ESP32_BUS_TYPE_INIT, NULL );
474
513
perimanSetPinBus (_bclk, ESP32_BUS_TYPE_INIT, NULL );
475
514
perimanSetPinBus (_ws, ESP32_BUS_TYPE_INIT, NULL );
476
515
if (_dout >= 0 ) perimanSetPinBus (_dout, ESP32_BUS_TYPE_INIT, NULL );
477
516
if (_din >= 0 ) perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL );
478
517
break ;
518
+ #if SOC_I2S_SUPPORTS_PDM_TX
479
519
case I2S_MODE_PDM_TX:
480
520
perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_INIT, NULL );
481
521
if (_tx_dout0 >= 0 ) perimanSetPinBus (_tx_dout0, ESP32_BUS_TYPE_INIT, NULL );
482
522
if (_tx_dout1 >= 0 ) perimanSetPinBus (_tx_dout1, ESP32_BUS_TYPE_INIT, NULL );
483
523
break ;
524
+ #endif
525
+ #if SOC_I2S_SUPPORTS_PDM_RX
484
526
case I2S_MODE_PDM_RX:
485
527
perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_INIT, NULL );
486
528
if (_rx_din0 >= 0 ) perimanSetPinBus (_rx_din0, ESP32_BUS_TYPE_INIT, NULL );
487
529
if (_rx_din1 >= 0 ) perimanSetPinBus (_rx_din1, ESP32_BUS_TYPE_INIT, NULL );
488
530
if (_rx_din2 >= 0 ) perimanSetPinBus (_rx_din2, ESP32_BUS_TYPE_INIT, NULL );
489
531
if (_rx_din3 >= 0 ) perimanSetPinBus (_rx_din3, ESP32_BUS_TYPE_INIT, NULL );
490
532
break ;
533
+ #endif
534
+ default :
535
+ break ;
491
536
}
492
537
return true ;
493
538
}
0 commit comments