1313#else
1414#include "driver/i2s.h"
1515#endif
16+ #include "esp_private/rtc_clk.h"
1617#include "esp_codec_dev.h"
1718#include "esp_codec_dev_defaults.h"
1819#include "test_board.h"
@@ -114,7 +115,7 @@ static void ut_clr_i2s_mode(void)
114115}
115116#endif
116117
117- static int ut_i2s_init (uint8_t port , codec_i2s_pin_t * i2s_pin )
118+ static int ut_i2s_init (uint8_t port , codec_i2s_pin_t * i2s_pin , i2s_clock_src_t clk_src )
118119{
119120#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (5 , 0 , 0 )
120121 if (port >= I2S_MAX_KEEP ) {
@@ -132,6 +133,7 @@ static int ut_i2s_init(uint8_t port, codec_i2s_pin_t *i2s_pin)
132133 .din = i2s_pin ? i2s_pin -> din : TEST_BOARD_I2S_DATA_IN_PIN ,
133134 },
134135 };
136+ std_cfg .clk_cfg .clk_src = clk_src ;
135137 if (i2s_keep [port ] == NULL ) {
136138 i2s_keep [port ] = (i2s_keep_t * ) calloc (1 , sizeof (i2s_keep_t ));
137139 if (i2s_keep [port ] == NULL ) {
@@ -152,6 +154,7 @@ static int ut_i2s_init(uint8_t port, codec_i2s_pin_t *i2s_pin)
152154 },
153155 };
154156 tdm_cfg .slot_cfg .total_slot = 4 ;
157+ tdm_cfg .clk_cfg .clk_src = clk_src ;
155158#endif
156159
157160
@@ -245,12 +248,19 @@ static void codec_max_sample(uint8_t *data, int size, int *max_value, int *min_v
245248 * min_value = min ;
246249}
247250
248- TEST_CASE ( "esp codec dev test using S3 board" , "[esp_codec_dev]" )
251+ static void test_codec_dev_using_s3_board ( bool use_xtal )
249252{
253+ i2s_clock_src_t clk_src = I2S_CLK_SRC_DEFAULT ;
254+ if (use_xtal ) {
255+ #if SOC_I2S_SUPPORTS_XTAL
256+ clk_src = I2S_CLK_SRC_XTAL ;
257+ rtc_clk_cpu_set_to_default_config ();
258+ #endif
259+ }
250260 // Need install driver (i2c and i2s) firstly
251261 int ret = ut_i2c_init (0 , NULL );
252262 TEST_ESP_OK (ret );
253- ret = ut_i2s_init (0 , NULL );
263+ ret = ut_i2s_init (0 , NULL , clk_src );
254264 TEST_ESP_OK (ret );
255265 // Do initialize of related interface: data_if, ctrl_if and gpio_if
256266 audio_codec_i2s_cfg_t i2s_cfg = {
@@ -259,6 +269,9 @@ TEST_CASE("esp codec dev test using S3 board", "[esp_codec_dev]")
259269 .tx_handle = i2s_keep [0 ]-> tx_handle ,
260270#endif
261271 };
272+ if (use_xtal ) {
273+ i2s_cfg .clk_src = clk_src ;
274+ }
262275 const audio_codec_data_if_t * data_if = audio_codec_new_i2s_data (& i2s_cfg );
263276 TEST_ASSERT_NOT_NULL (data_if );
264277
@@ -359,12 +372,22 @@ TEST_CASE("esp codec dev test using S3 board", "[esp_codec_dev]")
359372 ut_i2s_deinit (0 );
360373}
361374
375+ TEST_CASE ("esp codec dev test using S3 board" , "[esp_codec_dev]" )
376+ {
377+ test_codec_dev_using_s3_board (false);
378+ }
379+
380+ TEST_CASE ("esp codec dev test using S3 board with XTAL" , "[esp_codec_dev]" )
381+ {
382+ test_codec_dev_using_s3_board (true);
383+ }
384+
362385TEST_CASE ("Record play overlap test" , "[esp_codec_dev]" )
363386{
364387 // Need install driver (i2c and i2s) firstly
365388 int ret = ut_i2c_init (0 , NULL );
366389 TEST_ESP_OK (ret );
367- ret = ut_i2s_init (0 , NULL );
390+ ret = ut_i2s_init (0 , NULL , I2S_CLK_SRC_DEFAULT );
368391 TEST_ESP_OK (ret );
369392 // Do initialize of related interface: data_if, ctrl_if and gpio_if
370393 audio_codec_i2s_cfg_t i2s_cfg = {
@@ -601,7 +624,7 @@ static void multiple_es8311_run(bool reuse_data_if)
601624 .dout = 8 ,
602625 .din = 10 ,
603626 };
604- ret = ut_i2s_init (0 , & i2s_pin );
627+ ret = ut_i2s_init (0 , & i2s_pin , I2S_CLK_SRC_DEFAULT );
605628 TEST_ESP_OK (ret );
606629 const audio_codec_data_if_t * data_if = NULL ;
607630 if (reuse_data_if ) {
@@ -723,7 +746,7 @@ TEST_CASE("Playing while recording use TDM mode", "[esp_codec_dev]")
723746 // Need install driver (i2c and i2s) firstly
724747 int ret = ut_i2c_init (0 , NULL );
725748 TEST_ESP_OK (ret );
726- ret = ut_i2s_init (0 , NULL );
749+ ret = ut_i2s_init (0 , NULL , I2S_CLK_SRC_DEFAULT );
727750 TEST_ESP_OK (ret );
728751 // Do initialize of related interface: data_if, ctrl_if and gpio_if
729752 audio_codec_i2s_cfg_t i2s_cfg = {
0 commit comments