@@ -64,6 +64,7 @@ typedef struct i2s_state {
64
64
// Callback function should be defined as 'void ICACHE_RAM_ATTR function_name()',
65
65
// and be placed in IRAM for faster execution. Avoid long computational tasks in this
66
66
// function, use it to set flags and process later.
67
+ bool driveClocks;
67
68
} i2s_state_t ;
68
69
69
70
// RX = I2S receive (i.e. microphone), TX = I2S transmit (i.e. DAC)
@@ -493,6 +494,10 @@ float i2s_get_real_rate(){
493
494
}
494
495
495
496
bool i2s_rxtx_begin (bool enableRx, bool enableTx) {
497
+ return i2s_rxtxdrive_begin (enableRx, enableTx, true , true );
498
+ }
499
+
500
+ bool i2s_rxtxdrive_begin (bool enableRx, bool enableTx, bool driveRxClocks, bool driveTxClocks) {
496
501
if (tx || rx) {
497
502
i2s_end (); // Stop and free any ongoing stuff
498
503
}
@@ -503,22 +508,28 @@ bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
503
508
// Nothing to clean up yet
504
509
return false ; // OOM Error!
505
510
}
506
- pinMode (I2SO_WS, FUNCTION_1) ;
511
+ tx-> driveClocks = driveTxClocks ;
507
512
pinMode (I2SO_DATA, FUNCTION_1);
508
- pinMode (I2SO_BCK, FUNCTION_1);
513
+ if (driveTxClocks) {
514
+ pinMode (I2SO_WS, FUNCTION_1);
515
+ pinMode (I2SO_BCK, FUNCTION_1);
516
+ }
509
517
}
510
518
if (enableRx) {
511
519
rx = (i2s_state_t *)calloc (1 , sizeof (*rx));
512
520
if (!rx) {
513
521
i2s_end (); // Clean up any TX or pin changes
514
522
return false ; // OOM error!
515
523
}
516
- pinMode (I2SI_WS, OUTPUT);
517
- pinMode (I2SI_BCK, OUTPUT);
524
+ rx->driveClocks = driveRxClocks;
518
525
pinMode (I2SI_DATA, INPUT);
526
+ if (driveRxClocks) {
527
+ pinMode (I2SI_WS, OUTPUT);
528
+ pinMode (I2SI_BCK, OUTPUT);
529
+ PIN_FUNC_SELECT (PERIPHS_IO_MUX_MTCK_U, FUNC_I2SI_BCK);
530
+ PIN_FUNC_SELECT (PERIPHS_IO_MUX_MTMS_U, FUNC_I2SI_WS);
531
+ }
519
532
PIN_FUNC_SELECT (PERIPHS_IO_MUX_MTDI_U, FUNC_I2SI_DATA);
520
- PIN_FUNC_SELECT (PERIPHS_IO_MUX_MTCK_U, FUNC_I2SI_BCK);
521
- PIN_FUNC_SELECT (PERIPHS_IO_MUX_MTMS_U, FUNC_I2SI_WS);
522
533
}
523
534
524
535
if (!i2s_slc_begin ()) {
@@ -579,15 +590,19 @@ void i2s_end() {
579
590
580
591
if (tx) {
581
592
pinMode (I2SO_DATA, INPUT);
582
- pinMode (I2SO_BCK, INPUT);
583
- pinMode (I2SO_WS, INPUT);
593
+ if (tx->driveClocks ) {
594
+ pinMode (I2SO_BCK, INPUT);
595
+ pinMode (I2SO_WS, INPUT);
596
+ }
584
597
free (tx);
585
598
tx = NULL ;
586
599
}
587
600
if (rx) {
588
601
pinMode (I2SI_DATA, INPUT);
589
- pinMode (I2SI_BCK, INPUT);
590
- pinMode (I2SI_WS, INPUT);
602
+ if (rx->driveClocks ) {
603
+ pinMode (I2SI_BCK, INPUT);
604
+ pinMode (I2SI_WS, INPUT);
605
+ }
591
606
free (rx);
592
607
rx = NULL ;
593
608
}
0 commit comments