@@ -143,7 +143,7 @@ class I2SDriverESP32V1 {
143
143
i2s_chan_handle_t &tx_chan,
144
144
i2s_chan_handle_t &rx_chan, int txPin,
145
145
int rxPin) = 0;
146
-
146
+
147
147
virtual i2s_chan_config_t getChannelConfig (I2SConfigESP32V1 &cfg) = 0;
148
148
// changes the sample rate
149
149
virtual bool changeSampleRate (I2SConfigESP32V1 &cfg,
@@ -152,10 +152,9 @@ class I2SDriverESP32V1 {
152
152
return false ;
153
153
}
154
154
155
- protected:
155
+ protected:
156
156
// / 24 bits are stored in a 32 bit integer
157
- int get_bits_eff (int bits) { return ( bits == 24 )? 32 : bits; }
158
-
157
+ int get_bits_eff (int bits) { return (bits == 24 ) ? 32 : bits; }
159
158
};
160
159
161
160
struct DriverI2S : public DriverCommon {
@@ -269,23 +268,56 @@ class I2SDriverESP32V1 {
269
268
I2S_STD_CLK_DEFAULT_CONFIG ((uint32_t )cfg.sample_rate );
270
269
if (cfg.mclk_multiple > 0 ) {
271
270
clk_cfg.mclk_multiple = (i2s_mclk_multiple_t )cfg.mclk_multiple ;
271
+ LOGI (" mclk_multiple=%d" , clk_cfg.mclk_multiple );
272
272
} else {
273
273
if (cfg.bits_per_sample == 24 ) {
274
274
// mclk_multiple' should be the multiple of 3 while using 24-bit
275
275
clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_384;
276
276
LOGI (" mclk_multiple=384" );
277
+ } else {
278
+ LOGI (" mclk_multiple=%d" , clk_cfg.mclk_multiple );
277
279
}
278
280
}
279
281
280
- if (cfg.pin_mck != -1 && !cfg.is_master ){
282
+ // determine clock source
283
+ clk_cfg.clk_src = getClockSource (cfg);
284
+
285
+ return clk_cfg;
286
+ }
287
+
288
+ // / select clock source dependent on is_master and use_apll
289
+ soc_periph_i2s_clk_src_t getClockSource (I2SConfigESP32V1 &cfg){
290
+ soc_periph_i2s_clk_src_t result = I2S_CLK_SRC_DEFAULT;
291
+ // use mclk pin as input in slave mode if supported
292
+ bool is_pin_mck_input = false ;
293
+ if (cfg.pin_mck != -1 ) {
294
+ if (!cfg.is_master ) {
281
295
#if SOC_I2S_HW_VERSION_2
282
- LOGI (" clk_src=I2S_CLK_SRC_EXTERNAL" );
283
- clk_cfg.clk_src = I2S_CLK_SRC_EXTERNAL;
296
+ LOGI (" pin_mclk is input" );
297
+ result = I2S_CLK_SRC_EXTERNAL;
298
+ is_pin_mck_input = true ;
284
299
#else
285
- LOGE (" clk_src=I2S_CLK_SRC_EXTERNAL not supported" );
300
+ LOGE (" pin_mclk as input not supported" );
286
301
#endif
302
+ }
303
+
304
+ if (!is_pin_mck_input) {
305
+ // select clock source
306
+ #if SOC_I2S_SUPPORTS_APLL
307
+ if (cfg.use_apll ) {
308
+ result = I2S_CLK_SRC_APLL;
309
+ LOGI (" clk_src is I2S_CLK_SRC_APLL" );
310
+ }
311
+ #elif SOC_I2S_SUPPORTS_PLL_F160M
312
+ if (cfg.use_apll ) {
313
+ result = I2S_CLK_SRC_PLL_160M;
314
+ LOGI (" clk_src is I2S_CLK_SRC_PLL_160M" );
315
+ }
316
+ #endif
317
+ }
287
318
}
288
- return clk_cfg;
319
+ return result;
320
+
289
321
}
290
322
291
323
bool changeSampleRate (I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
0 commit comments