@@ -259,11 +259,11 @@ void I2SClass::setInvertedPdm(bool clk){
259
259
260
260
bool I2SClass::initSTD (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
261
261
// Peripheral manager deinit previous peripheral if pin was used
262
- if (!perimanSetPinBus (_mclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
263
- if (!perimanSetPinBus (_bclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
264
- if (!perimanSetPinBus (_ws, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
262
+ if (_mclk >= 0 ) if ( !perimanSetPinBus (_mclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
263
+ if (_bclk >= 0 ) if ( !perimanSetPinBus (_bclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
264
+ if (_ws >= 0 ) if ( !perimanSetPinBus (_ws, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
265
265
if (_dout >= 0 ) if (!perimanSetPinBus (_dout, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
266
- if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
266
+ if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
267
267
268
268
// I2S configuration
269
269
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG ();
@@ -292,9 +292,9 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
292
292
}
293
293
294
294
// Peripheral manager set bus type to I2S
295
- if (!perimanSetPinBus (_mclk, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
296
- if (!perimanSetPinBus (_bclk, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
297
- if (!perimanSetPinBus (_ws, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
295
+ if (_mclk >= 0 ) if ( !perimanSetPinBus (_mclk, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
296
+ if (_bclk >= 0 ) if ( !perimanSetPinBus (_bclk, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
297
+ if (_ws >= 0 ) if ( !perimanSetPinBus (_ws, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
298
298
if (_dout >= 0 ) if (!perimanSetPinBus (_dout, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
299
299
if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_I2S_STD, (void *)(this ))){ goto err; }
300
300
@@ -307,11 +307,11 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
307
307
308
308
bool I2SClass::initTDM (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
309
309
// Peripheral manager deinit previous peripheral if pin was used
310
- if (!perimanSetPinBus (_mclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
311
- if (!perimanSetPinBus (_bclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
312
- if (!perimanSetPinBus (_ws, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
310
+ if (_mclk >= 0 ) if ( !perimanSetPinBus (_mclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
311
+ if (_bclk >= 0 ) if ( !perimanSetPinBus (_bclk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
312
+ if (_ws >= 0 ) if ( !perimanSetPinBus (_ws, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
313
313
if (_dout >= 0 ) if (!perimanSetPinBus (_dout, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
314
- if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
314
+ if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
315
315
316
316
// I2S configuration
317
317
i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG ();
@@ -340,9 +340,9 @@ bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
340
340
}
341
341
342
342
// Peripheral manager set bus type to I2S
343
- if (!perimanSetPinBus (_mclk, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
344
- if (!perimanSetPinBus (_bclk, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
345
- if (!perimanSetPinBus (_ws, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
343
+ if (_mclk >= 0 ) if ( !perimanSetPinBus (_mclk, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
344
+ if (_bclk >= 0 ) if ( !perimanSetPinBus (_bclk, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
345
+ if (_ws >= 0 ) if ( !perimanSetPinBus (_ws, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
346
346
if (_dout >= 0 ) if (!perimanSetPinBus (_dout, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
347
347
if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_I2S_TDM, (void *)(this ))){ goto err; }
348
348
@@ -355,7 +355,7 @@ bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
355
355
356
356
bool I2SClass::initPDMtx (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
357
357
// Peripheral manager deinit previous peripheral if pin was used
358
- if (!perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
358
+ if (_tx_clk >= 0 ) if ( !perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
359
359
if (_tx_dout0 >= 0 ) if (!perimanSetPinBus (_tx_dout0, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
360
360
if (_tx_dout1 >= 0 ) if (!perimanSetPinBus (_tx_dout1, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
361
361
@@ -373,7 +373,7 @@ bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
373
373
}
374
374
375
375
// Peripheral manager set bus type to I2S
376
- if (!perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
376
+ if (_tx_clk >= 0 ) if ( !perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
377
377
if (_tx_dout0 >= 0 ) if (!perimanSetPinBus (_tx_dout0, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
378
378
if (_tx_dout1 >= 0 ) if (!perimanSetPinBus (_tx_dout1, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
379
379
@@ -386,7 +386,7 @@ bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
386
386
387
387
bool I2SClass::initPDMrx (uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
388
388
// Peripheral manager deinit previous peripheral if pin was used
389
- if (!perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
389
+ if (_rx_clk >= 0 ) if ( !perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
390
390
if (_rx_din0 >= 0 ) if (!perimanSetPinBus (_rx_din0, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
391
391
if (_rx_din1 >= 0 ) if (!perimanSetPinBus (_rx_din1, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
392
392
if (_rx_din2 >= 0 ) if (!perimanSetPinBus (_rx_din2, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
@@ -406,7 +406,7 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
406
406
}
407
407
408
408
// Peripheral manager set bus type to I2S
409
- if (!perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
409
+ if (_rx_clk >= 0 ) if ( !perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
410
410
if (_rx_din0 >= 0 ) if (!perimanSetPinBus (_rx_din0, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
411
411
if (_rx_din1 >= 0 ) if (!perimanSetPinBus (_rx_din1, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
412
412
if (_rx_din2 >= 0 ) if (!perimanSetPinBus (_rx_din2, ESP32_BUS_TYPE_I2S_PDM, (void *)(this ))){ goto err; }
@@ -421,17 +421,12 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
421
421
422
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){
423
423
/* Setup I2S peripheral */
424
-
425
424
if (mode > I2S_MODE_PDM_RX){
426
425
log_e (" Invalid I2S mode selected." );
427
426
return false ;
428
427
}
429
428
_mode = mode;
430
429
431
- // i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG();
432
- // already in default config
433
- // chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
434
-
435
430
bool init = false ;
436
431
switch (_mode){
437
432
case I2S_MODE_STD:
@@ -448,7 +443,6 @@ bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_c
448
443
break ;
449
444
}
450
445
451
- // error check
452
446
if (init == false ){
453
447
log_e (" I2S initialization failed." );
454
448
return false ;
0 commit comments