Skip to content

Commit f55d697

Browse files
authored
Apll (#1989)
* implement use_apll * Default mclk_multiple
1 parent 36a64fe commit f55d697

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/AudioTools/CoreAudio/AudioI2S/I2SESP32V1.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ class I2SDriverESP32V1 {
278278
clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_384;
279279
LOGI("mclk_multiple=384");
280280
} else {
281-
clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_256;
281+
// when use_appll is true, the multiple of 128 gives 256kHz
282+
clk_cfg.mclk_multiple = cfg.use_apll ? I2S_MCLK_MULTIPLE_128 : I2S_MCLK_MULTIPLE_256;
282283
LOGI("mclk_multiple=%d", clk_cfg.mclk_multiple);
283284
}
284285
}
@@ -290,20 +291,29 @@ class I2SDriverESP32V1 {
290291
soc_periph_i2s_clk_src_t getClockSource(I2SConfigESP32V1 &cfg){
291292
soc_periph_i2s_clk_src_t result = I2S_CLK_SRC_DEFAULT;
292293
// use mclk pin as input in slave mode if supported
293-
if (cfg.pin_mck != -1) {
294-
if (!cfg.is_master) {
294+
if (cfg.pin_mck != -1 && !cfg.is_master) {
295295
#if SOC_I2S_HW_VERSION_2
296296
LOGI("pin_mclk is input");
297297
result = I2S_CLK_SRC_EXTERNAL;
298+
return result;
298299
#else
299300
LOGE("pin_mclk as input not supported");
300301
#endif
301-
}
302302
}
303303

304+
// select APLL clock if possible
305+
if (cfg.use_apll) {
306+
// select clock source
307+
#if SOC_I2S_SUPPORTS_APLL
308+
result = I2S_CLK_SRC_APLL;
309+
LOGI("clk_src is I2S_CLK_SRC_APLL");
310+
#elif SOC_I2S_SUPPORTS_PLL_F160M
311+
result = I2S_CLK_SRC_PLL_160M;
312+
LOGI("clk_src is I2S_CLK_SRC_PLL_160M");
313+
#endif
314+
}
304315

305316
return result;
306-
307317
}
308318

309319
bool changeSampleRate(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,

src/AudioToolsConfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ typedef WiFiClient WiFiClientSecure;
273273
# if !defined(ARDUINO)
274274
# define USE_IDF_LOGGER
275275
# endif
276+
# if !defined(I2S_USE_APLL)
277+
# define I2S_USE_APLL false
278+
# endif
276279
#endif
277280

278281
// ----- Regular ESP32 -----
@@ -311,7 +314,6 @@ typedef WiFiClient WiFiClientSecure;
311314
#define PIN_I2S_DATA_IN 32
312315
#define PIN_I2S_DATA_OUT 22
313316
#define PIN_I2S_MCK -1
314-
#define I2S_USE_APLL true
315317
// Default Setting: The mute pin can be switched actovated by setting it to a gpio (e.g 23). Or you could drive the LED by assigning LED_BUILTIN
316318
#define PIN_I2S_MUTE -1
317319
#define SOFT_MUTE_VALUE 0
@@ -379,7 +381,6 @@ typedef uint32_t eps32_i2s_sample_rate_type;
379381
#define PIN_I2S_WS 7
380382
#define PIN_I2S_DATA_OUT 8
381383
#define PIN_I2S_DATA_IN 9
382-
#define I2S_USE_APLL true
383384
// Default Setting: The mute pin can be switched actovated by setting it to a gpio (e.g 5). Or you could drive the LED by assigning LED_BUILTIN
384385
#define PIN_I2S_MUTE -1
385386
#define SOFT_MUTE_VALUE 0
@@ -435,7 +436,6 @@ typedef uint32_t eps32_i2s_sample_rate_type;
435436
#define PIN_I2S_WS 7
436437
#define PIN_I2S_DATA_OUT 8
437438
#define PIN_I2S_DATA_IN 9
438-
#define I2S_USE_APLL true
439439
// Default Setting: The mute pin can be switched actovated by setting it to a gpio (e.g 5). Or you could drive the LED by assigning LED_BUILTIN
440440
#define PIN_I2S_MUTE -1
441441
#define SOFT_MUTE_VALUE 0

0 commit comments

Comments
 (0)