@@ -238,6 +238,8 @@ TEST_CASE("I2S_basic_channel_allocation_reconfig_deleting_test", "[i2s]")
238238}
239239
240240static volatile bool task_run_flag ;
241+ static volatile bool read_task_success = true;
242+ static volatile bool write_task_success = true;
241243
242244#define TEST_I2S_DATA 0x78
243245
@@ -270,6 +272,7 @@ static void i2s_read_task(void *args)
270272 ret = i2s_channel_read (rx_handle , recv_buf , 2000 , & recv_size , 300 );
271273 if (ret == ESP_ERR_TIMEOUT ) {
272274 printf ("Read timeout count: %" PRIu32 "\n" , cnt ++ );
275+ read_task_success = false;
273276 }
274277 }
275278
@@ -291,6 +294,7 @@ static void i2s_write_task(void *args)
291294 ret = i2s_channel_write (tx_handle , send_buf , 2000 , & send_size , 300 );
292295 if (ret == ESP_ERR_TIMEOUT ) {
293296 printf ("Write timeout count: %" PRIu32 "\n" , cnt ++ );
297+ write_task_success = false;
294298 }
295299 }
296300
@@ -431,6 +435,7 @@ TEST_CASE("I2S_lazy_duplex_test", "[i2s]")
431435 },
432436 },
433437 };
438+ /* Part 1: test common lazy duplex mode */
434439 TEST_ESP_OK (i2s_new_channel (& chan_cfg , & tx_handle , NULL ));
435440 TEST_ESP_OK (i2s_channel_init_std_mode (tx_handle , & std_cfg ));
436441 TEST_ESP_OK (i2s_channel_enable (tx_handle ));
@@ -451,7 +456,70 @@ TEST_CASE("I2S_lazy_duplex_test", "[i2s]")
451456 xTaskCreate (i2s_read_check_task , "i2s_read_check_task" , 4096 , rx_handle , 5 , NULL );
452457 printf ("RX started\n" );
453458
454- /* Wait 3 seconds to see if any failures occur */
459+ /* Wait 1 seconds to see if any failures occur */
460+ vTaskDelay (pdMS_TO_TICKS (1000 ));
461+ printf ("Finished\n" );
462+
463+ /* Stop those three tasks */
464+ task_run_flag = false;
465+
466+ /* Wait for the three thread deleted */
467+ vTaskDelay (pdMS_TO_TICKS (1000 ));
468+
469+ /* Disable the channels, they will keep waiting until the current reading / writing finished */
470+ TEST_ESP_OK (i2s_channel_disable (tx_handle ));
471+ TEST_ESP_OK (i2s_channel_disable (rx_handle ));
472+ /* Delete the channels */
473+ TEST_ESP_OK (i2s_del_channel (tx_handle ));
474+ TEST_ESP_OK (i2s_del_channel (rx_handle ));
475+
476+ /* Part 2: Test no lazy duplex mode with port auto assignment */
477+ chan_cfg .id = I2S_NUM_AUTO ;
478+ TEST_ESP_OK (i2s_new_channel (& chan_cfg , NULL , & rx_handle ));
479+ TEST_ESP_OK (i2s_new_channel (& chan_cfg , & tx_handle , NULL ));
480+ TEST_ESP_OK (i2s_channel_init_std_mode (rx_handle , & std_cfg ));
481+
482+ /* Change the config to not constitute full-duplex */
483+ std_cfg .gpio_cfg .mclk = I2S_GPIO_UNUSED ;
484+ std_cfg .gpio_cfg .bclk = I2S_GPIO_UNUSED ;
485+ std_cfg .gpio_cfg .ws = I2S_GPIO_UNUSED ;
486+ std_cfg .gpio_cfg .dout = I2S_GPIO_UNUSED ;
487+ std_cfg .gpio_cfg .din = I2S_GPIO_UNUSED ;
488+ #if CONFIG_IDF_TARGET_ESP32S2
489+ TEST_ESP_ERR (ESP_ERR_INVALID_ARG , i2s_channel_init_std_mode (tx_handle , & std_cfg ));
490+ /* Delete the channels */
491+ TEST_ESP_OK (i2s_del_channel (tx_handle ));
492+ TEST_ESP_OK (i2s_del_channel (rx_handle ));
493+ return ;
494+ #else
495+ TEST_ESP_OK (i2s_channel_init_std_mode (tx_handle , & std_cfg ));
496+ #endif
497+
498+ #if CONFIG_IDF_TARGET_ESP32
499+ /* On ESP32, if failed to constitute full-duplex with `I2S_NUM_AUTO`,
500+ the channel will be re-assigned to the next availableport */
501+ i2s_chan_info_t chan_info ;
502+ TEST_ESP_OK (i2s_channel_get_info (rx_handle , & chan_info ));
503+ TEST_ASSERT (chan_info .id == I2S_NUM_0 );
504+ TEST_ESP_OK (i2s_channel_get_info (tx_handle , & chan_info ));
505+ TEST_ASSERT (chan_info .id == I2S_NUM_1 );
506+ #endif
507+
508+ TEST_ESP_OK (i2s_channel_enable (tx_handle ));
509+ TEST_ESP_OK (i2s_channel_enable (rx_handle ));
510+
511+ task_run_flag = true;
512+ read_task_success = true;
513+ write_task_success = true;
514+ /* writing task to keep writing */
515+ xTaskCreate (i2s_write_task , "i2s_write_task" , 4096 , tx_handle , 5 , NULL );
516+ printf ("TX started\n" );
517+ vTaskDelay (pdMS_TO_TICKS (1000 ));
518+ /* reading task to keep reading */
519+ xTaskCreate (i2s_read_task , "i2s_read_task" , 4096 , rx_handle , 5 , NULL );
520+ printf ("RX started\n" );
521+
522+ /* Wait 1 seconds to see if any failures occur */
455523 vTaskDelay (pdMS_TO_TICKS (1000 ));
456524 printf ("Finished\n" );
457525
@@ -467,6 +535,9 @@ TEST_CASE("I2S_lazy_duplex_test", "[i2s]")
467535 /* Delete the channels */
468536 TEST_ESP_OK (i2s_del_channel (tx_handle ));
469537 TEST_ESP_OK (i2s_del_channel (rx_handle ));
538+ /* Check if the reading and writing tasks are successful */
539+ TEST_ASSERT (read_task_success );
540+ TEST_ASSERT (write_task_success );
470541}
471542
472543static bool whether_contains_exapected_data (uint16_t * src , uint32_t src_len , uint32_t src_step , uint32_t start_val , uint32_t val_step )
0 commit comments