@@ -49,6 +49,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
49
49
bclkPin = 26 ;
50
50
wclkPin = 25 ;
51
51
doutPin = 22 ;
52
+ mclkPin = 0 ;
52
53
SetGain (1.0 );
53
54
}
54
55
@@ -61,6 +62,8 @@ AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data)
61
62
hertz = sampleRate;
62
63
bclkPin = sck;
63
64
doutPin = data;
65
+ mclkPin = 0 ;
66
+ use_mclk = false ;
64
67
SetGain (1.0 );
65
68
}
66
69
#endif
@@ -78,7 +81,7 @@ bool AudioOutputI2S::SetPinout()
78
81
79
82
i2s_pin_config_t pins = {
80
83
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
81
- .mck_io_num = 0 , // Unused
84
+ .mck_io_num = mclkPin,
82
85
#endif
83
86
.bck_io_num = bclkPin,
84
87
.ws_io_num = wclkPin,
@@ -90,6 +93,8 @@ bool AudioOutputI2S::SetPinout()
90
93
(void )bclkPin;
91
94
(void )wclkPin;
92
95
(void )doutPin;
96
+ (void )mclkPin;
97
+ (void )use_mclk;
93
98
return false ;
94
99
#endif
95
100
}
@@ -104,6 +109,22 @@ bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
104
109
105
110
return true ;
106
111
}
112
+
113
+ bool AudioOutputI2S::SetPinout (int bclk, int wclk, int dout, int mclk)
114
+ {
115
+ bclkPin = bclk;
116
+ wclkPin = wclk;
117
+ doutPin = dout;
118
+ #ifdef ESP32
119
+ mclkPin = mclk;
120
+ if (i2sOn)
121
+ return SetPinout ();
122
+ #else
123
+ (void )mclk;
124
+ #endif
125
+ return true ;
126
+ }
127
+
107
128
bool AudioOutputI2S::SetRate (int hz)
108
129
{
109
130
// TODO - have a list of allowable rates from constructor, check them
@@ -147,6 +168,17 @@ bool AudioOutputI2S::SetLsbJustified(bool lsbJustified)
147
168
return true ;
148
169
}
149
170
171
+ bool AudioOutputI2S::SetMclk (bool enabled){
172
+ (void )enabled;
173
+ #ifdef ESP32
174
+ if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
175
+ return false ; // Not allowed
176
+
177
+ use_mclk = enabled;
178
+ #endif
179
+ return true ;
180
+ }
181
+
150
182
bool AudioOutputI2S::begin (bool txDAC)
151
183
{
152
184
#ifdef ESP32
@@ -219,9 +251,9 @@ bool AudioOutputI2S::begin(bool txDAC)
219
251
.dma_buf_len = 128 ,
220
252
.use_apll = use_apll, // Use audio PLL
221
253
.tx_desc_auto_clear = true , // Silence on underflow
222
- .fixed_mclk = 0 , // Unused
254
+ .fixed_mclk = use_mclk , // Unused
223
255
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
224
- .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT , // Unused
256
+ .mclk_multiple = I2S_MCLK_MULTIPLE_256 , // Unused
225
257
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
226
258
#endif
227
259
};
0 commit comments