| 
									
										
										
										
											2021-05-24 01:06:17 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-12-02 20:24:19 +08:00
										 |  |  |  * SPDX-License-Identifier: Unlicense OR CC0-1.0 | 
					
						
							| 
									
										
										
										
											2021-05-24 01:06:17 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * I2S test environment UT_T1_I2S: | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |  * We use internal signals instead of external wiring, but please keep the following IO connections, or connect nothing to prevent the signal from being disturbed. | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |  * connect GPIO15 and GPIO19, GPIO25(ESP32)/GPIO17(ESP32-S2) and GPIO26, GPIO21 and GPIO22(ESP32)/GPIO20(ESP32-S2) | 
					
						
							|  |  |  |  * Please do not connect GPIO32(ESP32) any pull-up resistors externally, it will be used to test i2s adc function. | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-26 17:03:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include "freertos/FreeRTOS.h"
 | 
					
						
							|  |  |  | #include "freertos/task.h"
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  | #include "freertos/queue.h"
 | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | #include "driver/gpio.h"
 | 
					
						
							| 
									
										
										
										
											2021-03-16 10:55:05 +08:00
										 |  |  | #include "hal/gpio_hal.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | #include "unity.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | #include "math.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-19 12:00:58 +08:00
										 |  |  | #include "esp_rom_gpio.h"
 | 
					
						
							| 
									
										
										
										
											2021-11-26 17:03:47 +08:00
										 |  |  | #if SOC_I2S_SUPPORTED
 | 
					
						
							|  |  |  | #include "driver/i2s.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define SAMPLE_RATE     (36000)
 | 
					
						
							|  |  |  | #define SAMPLE_BITS     (16)
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if CONFIG_IDF_TARGET_ESP32
 | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | #define MASTER_BCK_IO 15
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | #define MASTER_WS_IO 25
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | #define SLAVE_BCK_IO 19
 | 
					
						
							|  |  |  | #define SLAVE_WS_IO 26
 | 
					
						
							|  |  |  | #define DATA_IN_IO 21
 | 
					
						
							|  |  |  | #define DATA_OUT_IO 22
 | 
					
						
							| 
									
										
										
										
											2019-12-20 14:57:34 +08:00
										 |  |  | #define ADC1_CHANNEL_4_IO 32
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | #define I2S0_DATA_OUT_IDX   I2S0O_DATA_OUT23_IDX
 | 
					
						
							|  |  |  | #define I2S0_DATA_IN_IDX   I2S0I_DATA_IN15_IDX
 | 
					
						
							|  |  |  | #define I2S1_DATA_OUT_IDX   I2S1O_DATA_OUT23_IDX
 | 
					
						
							|  |  |  | #define I2S1_DATA_IN_IDX   I2S1I_DATA_IN15_IDX
 | 
					
						
							| 
									
										
										
										
											2020-01-17 11:47:08 +08:00
										 |  |  | #elif CONFIG_IDF_TARGET_ESP32S2
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | #define MASTER_BCK_IO 15
 | 
					
						
							| 
									
										
										
										
											2019-11-21 21:58:18 +05:30
										 |  |  | #define MASTER_WS_IO 28
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | #define SLAVE_BCK_IO 19
 | 
					
						
							|  |  |  | #define SLAVE_WS_IO 26
 | 
					
						
							|  |  |  | #define DATA_IN_IO 21
 | 
					
						
							| 
									
										
										
										
											2019-11-21 21:58:18 +05:30
										 |  |  | #define DATA_OUT_IO 20
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | #define I2S0_DATA_OUT_IDX   I2S0O_DATA_OUT23_IDX
 | 
					
						
							|  |  |  | #define I2S0_DATA_IN_IDX   I2S0I_DATA_IN15_IDX
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32C3
 | 
					
						
							|  |  |  | // TODO: change pins
 | 
					
						
							|  |  |  | #define MASTER_BCK_IO 4
 | 
					
						
							|  |  |  | #define MASTER_WS_IO 5
 | 
					
						
							|  |  |  | #define SLAVE_BCK_IO 14
 | 
					
						
							|  |  |  | #define SLAVE_WS_IO 15
 | 
					
						
							|  |  |  | #define DATA_IN_IO 19
 | 
					
						
							|  |  |  | #define DATA_OUT_IO 18
 | 
					
						
							|  |  |  | #define I2S0_DATA_OUT_IDX   I2SO_SD_OUT_IDX
 | 
					
						
							|  |  |  | #define I2S0_DATA_IN_IDX   I2SI_SD_IN_IDX
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32S3
 | 
					
						
							|  |  |  | #define MASTER_BCK_IO 4
 | 
					
						
							|  |  |  | #define MASTER_WS_IO 5
 | 
					
						
							|  |  |  | #define SLAVE_BCK_IO 14
 | 
					
						
							|  |  |  | #define SLAVE_WS_IO 15
 | 
					
						
							|  |  |  | #define DATA_IN_IO 19
 | 
					
						
							|  |  |  | #define DATA_OUT_IO 18
 | 
					
						
							|  |  |  | #define I2S0_DATA_OUT_IDX   I2S0O_SD_OUT_IDX
 | 
					
						
							|  |  |  | #define I2S0_DATA_IN_IDX   I2S0I_SD_IN_IDX
 | 
					
						
							|  |  |  | #define I2S1_DATA_OUT_IDX   I2S1O_SD_OUT_IDX
 | 
					
						
							|  |  |  | #define I2S1_DATA_IN_IDX   I2S1I_SD_IN_IDX
 | 
					
						
							| 
									
										
										
										
											2019-11-21 21:58:18 +05:30
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | #define PERCENT_DIFF 0.0001
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | #define I2S_TEST_MODE_SLAVE_TO_MAXTER 0
 | 
					
						
							|  |  |  | #define I2S_TEST_MODE_MASTER_TO_SLAVE 1
 | 
					
						
							|  |  |  | #define I2S_TEST_MODE_LOOPBACK        2
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | // mode: 0, master rx, slave tx. mode: 1, master tx, slave rx. mode: 2, master tx rx loopback
 | 
					
						
							|  |  |  | // Since ESP32-S2 has only one I2S, only loop back test can be tested.
 | 
					
						
							|  |  |  | static void i2s_test_io_config(int mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Connect internal signals using IO matrix.
 | 
					
						
							| 
									
										
										
										
											2021-03-16 10:55:05 +08:00
										 |  |  |     gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[MASTER_BCK_IO], PIN_FUNC_GPIO); | 
					
						
							|  |  |  |     gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[MASTER_WS_IO], PIN_FUNC_GPIO); | 
					
						
							|  |  |  |     gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[DATA_OUT_IO], PIN_FUNC_GPIO); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     gpio_set_direction(MASTER_BCK_IO, GPIO_MODE_INPUT_OUTPUT); | 
					
						
							|  |  |  |     gpio_set_direction(MASTER_WS_IO, GPIO_MODE_INPUT_OUTPUT); | 
					
						
							|  |  |  |     gpio_set_direction(DATA_OUT_IO, GPIO_MODE_INPUT_OUTPUT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (mode) { | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | #if SOC_I2S_NUM > 1
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     case I2S_TEST_MODE_SLAVE_TO_MAXTER: { | 
					
						
							|  |  |  |         esp_rom_gpio_connect_out_signal(MASTER_BCK_IO, I2S0I_BCK_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(MASTER_BCK_IO, I2S1O_BCK_IN_IDX, 0); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         esp_rom_gpio_connect_out_signal(MASTER_WS_IO, I2S0I_WS_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(MASTER_WS_IO, I2S1O_WS_IN_IDX, 0); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         esp_rom_gpio_connect_out_signal(DATA_OUT_IO, I2S1_DATA_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(DATA_OUT_IO, I2S0_DATA_IN_IDX, 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     case I2S_TEST_MODE_MASTER_TO_SLAVE: { | 
					
						
							|  |  |  |         esp_rom_gpio_connect_out_signal(MASTER_BCK_IO, I2S0O_BCK_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(MASTER_BCK_IO, I2S1I_BCK_IN_IDX, 0); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         esp_rom_gpio_connect_out_signal(MASTER_WS_IO, I2S0O_WS_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(MASTER_WS_IO, I2S1I_WS_IN_IDX, 0); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         esp_rom_gpio_connect_out_signal(DATA_OUT_IO, I2S0_DATA_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(DATA_OUT_IO, I2S1_DATA_IN_IDX, 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     case I2S_TEST_MODE_LOOPBACK: { | 
					
						
							|  |  |  |         esp_rom_gpio_connect_out_signal(DATA_OUT_IO, I2S0_DATA_OUT_IDX, 0, 0); | 
					
						
							|  |  |  |         esp_rom_gpio_connect_in_signal(DATA_OUT_IO, I2S0_DATA_IN_IDX, 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     default: { | 
					
						
							|  |  |  |         TEST_FAIL_MESSAGE("error: mode not supported"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * i2s initialize test | 
					
						
							|  |  |  |  * 1. i2s_driver_install | 
					
						
							|  |  |  |  * 2. i2s_set_pin | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | TEST_CASE("I2S basic driver install, uninstall, set pin test", "[i2s]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // dac, adc  i2s
 | 
					
						
							|  |  |  |     i2s_config_t  i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_TX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 60, | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // normal  i2s
 | 
					
						
							|  |  |  |     i2s_pin_config_t pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = DATA_OUT_IO, | 
					
						
							|  |  |  |         .data_in_num = -1 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |     QueueHandle_t evt_que; | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &i2s_config, 16, &evt_que)); | 
					
						
							|  |  |  |     TEST_ASSERT(evt_que); | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &pin_config)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_uninstall(I2S_NUM_0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //error param test
 | 
					
						
							|  |  |  |     TEST_ASSERT(i2s_driver_install(I2S_NUM_MAX, &i2s_config, 0, NULL) == ESP_ERR_INVALID_ARG); | 
					
						
							|  |  |  |     TEST_ASSERT(i2s_driver_install(I2S_NUM_0, NULL, 0, NULL) == ESP_ERR_INVALID_ARG); | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |     i2s_config.dma_desc_num = 1; | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |     TEST_ASSERT(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL) == ESP_ERR_INVALID_ARG); | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |     i2s_config.dma_desc_num = 129; | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |     TEST_ASSERT(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL) == ESP_ERR_INVALID_ARG); | 
					
						
							| 
									
										
										
										
											2021-08-04 16:47:56 +08:00
										 |  |  |     TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, i2s_driver_uninstall(I2S_NUM_0)); | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | TEST_CASE("I2S Loopback test(master tx and rx)", "[i2s]") | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     // master driver installed and send data
 | 
					
						
							|  |  |  |     i2s_config_t master_i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t master_pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							|  |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = DATA_OUT_IO, | 
					
						
							|  |  |  |         .data_in_num = DATA_IN_IO | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &master_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &master_pin_config)); | 
					
						
							|  |  |  |     i2s_test_io_config(I2S_TEST_MODE_LOOPBACK); | 
					
						
							|  |  |  |     printf("\r\nheap size: %d\n", esp_get_free_heap_size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint8_t *data_wr = (uint8_t *)malloc(sizeof(uint8_t) * 400); | 
					
						
							|  |  |  |     size_t i2s_bytes_write = 0; | 
					
						
							|  |  |  |     size_t bytes_read = 0; | 
					
						
							|  |  |  |     int length = 0; | 
					
						
							|  |  |  |     uint8_t *i2s_read_buff = (uint8_t *)malloc(sizeof(uint8_t) * 10000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < 100; i++) { | 
					
						
							|  |  |  |         data_wr[i] = i + 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     int flag = 0; // break loop flag
 | 
					
						
							|  |  |  |     int end_position = 0; | 
					
						
							|  |  |  |     // write data to slave
 | 
					
						
							|  |  |  |     i2s_write(I2S_NUM_0, data_wr, sizeof(uint8_t) * 400, &i2s_bytes_write, 1000 / portTICK_PERIOD_MS); | 
					
						
							|  |  |  |     while (!flag) { | 
					
						
							|  |  |  |         if (length >= 10000 - 500) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         i2s_read(I2S_NUM_0, i2s_read_buff + length, sizeof(uint8_t) * 500, &bytes_read, 1000 / portMAX_DELAY); | 
					
						
							|  |  |  |         if (bytes_read > 0) { | 
					
						
							|  |  |  |             for (int i = length; i < length + bytes_read; i++) { | 
					
						
							|  |  |  |                 if (i2s_read_buff[i] == 100) { | 
					
						
							|  |  |  |                     flag = 1; | 
					
						
							|  |  |  |                     end_position = i; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         length = length + bytes_read; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // test the read data right or not
 | 
					
						
							|  |  |  |     for (int i = end_position - 99; i <= end_position; i++) { | 
					
						
							|  |  |  |         TEST_ASSERT_EQUAL_UINT8((i - end_position + 100), *(i2s_read_buff + i)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     free(data_wr); | 
					
						
							|  |  |  |     free(i2s_read_buff); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  | TEST_CASE("I2S TDM Loopback test(master tx and rx)", "[i2s]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // master driver installed and send data
 | 
					
						
							|  |  |  |     i2s_config_t master_i2s_config = { | 
					
						
							|  |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_MULTIPLE, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							|  |  |  |         .total_chan = 4, | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1 | I2S_TDM_ACTIVE_CH2 | I2S_TDM_ACTIVE_CH3, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							|  |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t master_pin_config = { | 
					
						
							|  |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = DATA_OUT_IO, | 
					
						
							|  |  |  |         .data_in_num = DATA_IN_IO | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &master_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &master_pin_config)); | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |     i2s_test_io_config(I2S_TEST_MODE_LOOPBACK); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     printf("\r\nheap size: %d\n", esp_get_free_heap_size()); | 
					
						
							| 
									
										
										
										
											2019-11-21 21:58:18 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint8_t *data_wr = (uint8_t *)malloc(sizeof(uint8_t) * 400); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     size_t i2s_bytes_write = 0; | 
					
						
							|  |  |  |     size_t bytes_read = 0; | 
					
						
							|  |  |  |     int length = 0; | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint8_t *i2s_read_buff = (uint8_t *)malloc(sizeof(uint8_t) * 10000); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = 0; i < 100; i++) { | 
					
						
							|  |  |  |         data_wr[i] = i + 1; | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     int flag = 0; // break loop flag
 | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     int end_position = 0; | 
					
						
							|  |  |  |     // write data to slave
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     i2s_write(I2S_NUM_0, data_wr, sizeof(uint8_t) * 400, &i2s_bytes_write, 1000 / portTICK_PERIOD_MS); | 
					
						
							|  |  |  |     while (!flag) { | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |         if (length >= 10000 - 500) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         i2s_read(I2S_NUM_0, i2s_read_buff + length, sizeof(uint8_t) * 500, &bytes_read, 1000 / portMAX_DELAY); | 
					
						
							|  |  |  |         if (bytes_read > 0) { | 
					
						
							|  |  |  |             for (int i = length; i < length + bytes_read; i++) { | 
					
						
							|  |  |  |                 if (i2s_read_buff[i] == 100) { | 
					
						
							|  |  |  |                     flag = 1; | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |                     end_position = i; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         length = length + bytes_read; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |     // test the read data right or not
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = end_position - 99; i <= end_position; i++) { | 
					
						
							|  |  |  |         TEST_ASSERT_EQUAL_UINT8((i - end_position + 100), *(i2s_read_buff + i)); | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     free(data_wr); | 
					
						
							|  |  |  |     free(i2s_read_buff); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 18:49:44 +08:00
										 |  |  | #if SOC_I2S_NUM > 1
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | /* ESP32S2 and ESP32C3 has only single I2S port and hence following test cases are not applicable */ | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | TEST_CASE("I2S write and read test(master tx and slave rx)", "[i2s]") | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     // master driver installed and send data
 | 
					
						
							|  |  |  |     i2s_config_t master_i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_TX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t master_pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = DATA_OUT_IO, | 
					
						
							|  |  |  |         .data_in_num = -1 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &master_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &master_pin_config)); | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |     i2s_test_io_config(I2S_TEST_MODE_MASTER_TO_SLAVE); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     printf("\r\nheap size: %d\n", esp_get_free_heap_size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     i2s_config_t slave_i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_SLAVE | I2S_MODE_RX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t slave_pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |         .bck_io_num = SLAVE_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = SLAVE_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = -1, | 
					
						
							|  |  |  |         .data_in_num = DATA_IN_IO, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     // slave driver installed and receive data
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_1, &slave_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_1, &slave_pin_config)); | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |     i2s_test_io_config(I2S_TEST_MODE_MASTER_TO_SLAVE); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     printf("\r\nheap size: %d\n", esp_get_free_heap_size()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint8_t *data_wr = (uint8_t *)malloc(sizeof(uint8_t) * 400); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     size_t i2s_bytes_write = 0; | 
					
						
							|  |  |  |     size_t bytes_read = 0; | 
					
						
							|  |  |  |     int length = 0; | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint8_t *i2s_read_buff = (uint8_t *)malloc(sizeof(uint8_t) * 10000); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = 0; i < 100; i++) { | 
					
						
							|  |  |  |         data_wr[i] = i + 1; | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     int flag = 0; // break loop flag
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     int end_position = 0; | 
					
						
							|  |  |  |     // write data to slave
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     i2s_write(I2S_NUM_0, data_wr, sizeof(uint8_t) * 400, &i2s_bytes_write, 1000 / portTICK_PERIOD_MS); | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |     printf("write data size: %d\n", i2s_bytes_write); | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     while (!flag) { | 
					
						
							|  |  |  |         i2s_read(I2S_NUM_1, i2s_read_buff + length, sizeof(uint8_t) * 500, &bytes_read, 1000 / portTICK_PERIOD_MS); | 
					
						
							|  |  |  |         if (bytes_read > 0) { | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |             printf("read data size: %d\n", bytes_read); | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |             for (int i = length; i < length + bytes_read; i++) { | 
					
						
							|  |  |  |                 if (i2s_read_buff[i] == 100) { | 
					
						
							|  |  |  |                     flag = 1; | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |                     end_position = i; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         length = length + bytes_read; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // test the readed data right or not
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = end_position - 99; i <= end_position; i++) { | 
					
						
							|  |  |  |         TEST_ASSERT_EQUAL_UINT8((i - end_position + 100), *(i2s_read_buff + i)); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     free(data_wr); | 
					
						
							|  |  |  |     free(i2s_read_buff); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  | TEST_CASE("I2S write and read test(master rx and slave tx)", "[i2s]") | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     // master driver installed and send data
 | 
					
						
							|  |  |  |     i2s_config_t master_i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_RX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |         .use_apll = 1, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t master_pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = -1, | 
					
						
							|  |  |  |         .data_in_num = DATA_IN_IO, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &master_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &master_pin_config)); | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |     i2s_test_io_config(I2S_TEST_MODE_SLAVE_TO_MAXTER); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     printf("\r\nheap size: %d\n", esp_get_free_heap_size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     i2s_config_t slave_i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_SLAVE | I2S_MODE_TX,                                  // Only RX
 | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,                           //2-channels
 | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  |         .use_apll = 1, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t slave_pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |         .bck_io_num = SLAVE_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = SLAVE_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = DATA_OUT_IO, | 
					
						
							|  |  |  |         .data_in_num = -1 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     // slave driver installed and receive data
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_1, &slave_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_1, &slave_pin_config)); | 
					
						
							| 
									
										
										
										
											2020-02-20 16:00:48 +08:00
										 |  |  |     i2s_test_io_config(I2S_TEST_MODE_SLAVE_TO_MAXTER); | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     printf("\r\nheap size: %d\n", esp_get_free_heap_size()); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint8_t *data_wr = (uint8_t *)malloc(sizeof(uint8_t) * 400); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     size_t i2s_bytes_write = 0; | 
					
						
							|  |  |  |     size_t bytes_read = 0; | 
					
						
							|  |  |  |     int length = 0; | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint8_t *i2s_read_buff = (uint8_t *)malloc(sizeof(uint8_t) * 10000); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = 0; i < 100; i++) { | 
					
						
							|  |  |  |         data_wr[i] = i + 1; | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     // slave write data to master
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     i2s_write(I2S_NUM_1, data_wr, sizeof(uint8_t) * 400, &i2s_bytes_write, 1000 / portTICK_PERIOD_MS); | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |     printf("write data size: %d\n", i2s_bytes_write); | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     int flag = 0; // break loop flag
 | 
					
						
							| 
									
										
										
										
											2021-08-18 10:52:16 +08:00
										 |  |  |     volatile int end_position = 0; | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     // write data to slave
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     while (!flag) { | 
					
						
							|  |  |  |         TEST_ESP_OK(i2s_read(I2S_NUM_0, i2s_read_buff + length, 10000 - length, &bytes_read, 1000 / portTICK_PERIOD_MS)); | 
					
						
							|  |  |  |         if (bytes_read > 0) { | 
					
						
							| 
									
										
										
										
											2021-08-18 10:52:16 +08:00
										 |  |  |             printf("read data size: %d\n", bytes_read); | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |             for (int i = length; i < length + bytes_read; i++) { | 
					
						
							|  |  |  |                 if (i2s_read_buff[i] == 100) { | 
					
						
							|  |  |  |                     flag = 1; | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |                     end_position = i; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         length = length + bytes_read; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // test the readed data right or not
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = end_position - 99; i <= end_position; i++) { | 
					
						
							|  |  |  |         TEST_ASSERT_EQUAL_UINT8((i - end_position + 100), *(i2s_read_buff + i)); | 
					
						
							| 
									
										
										
										
											2019-08-06 17:59:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     free(data_wr); | 
					
						
							|  |  |  |     free(i2s_read_buff); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_1); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-09 15:20:41 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("I2S memory leaking test", "[i2s]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     i2s_config_t master_i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_RX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 100, | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  |     i2s_pin_config_t master_pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = -1, | 
					
						
							|  |  |  |         .data_in_num = DATA_IN_IO | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &master_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &master_pin_config)); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  |     int initial_size = esp_get_free_heap_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = 0; i < 100; i++) { | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &master_i2s_config, 0, NULL)); | 
					
						
							|  |  |  |         TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &master_pin_config)); | 
					
						
							|  |  |  |         i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  |         TEST_ASSERT(initial_size == esp_get_free_heap_size()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     vTaskDelay(100 / portTICK_PERIOD_MS); | 
					
						
							|  |  |  |     TEST_ASSERT(initial_size == esp_get_free_heap_size()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_APLL
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *   The I2S APLL clock variation test used to test the difference between the different sample rates, different bits per sample | 
					
						
							|  |  |  |  *   and the APLL clock generate for it. The TEST_CASE passes PERCENT_DIFF variation from the provided sample rate in APLL generated clock | 
					
						
							|  |  |  |  *   The percentage difference calculated as (mod((obtained clock rate - desired clock rate)/(desired clock rate))) * 100. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | TEST_CASE("I2S APLL clock variation test", "[i2s]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     i2s_pin_config_t pin_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:53:44 +08:00
										 |  |  |         .mck_io_num = -1, | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         .bck_io_num = MASTER_BCK_IO, | 
					
						
							|  |  |  |         .ws_io_num = MASTER_WS_IO, | 
					
						
							|  |  |  |         .data_out_num = DATA_OUT_IO, | 
					
						
							|  |  |  |         .data_in_num = -1 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     i2s_config_t i2s_config = { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_TX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 60, | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |         .use_apll = true, | 
					
						
							|  |  |  |         .intr_alloc_flags = 0, | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_TDM
 | 
					
						
							|  |  |  |         .chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1, | 
					
						
							|  |  |  |         .total_chan = 2, | 
					
						
							|  |  |  |         .left_align = false, | 
					
						
							|  |  |  |         .big_edin = false, | 
					
						
							|  |  |  |         .bit_order_msb = false, | 
					
						
							|  |  |  |         .skip_msk = false | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &pin_config)); | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_uninstall(I2S_NUM_0)); | 
					
						
							|  |  |  |     int initial_size = esp_get_free_heap_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint32_t sample_rate_arr[8] = { 10675, 11025, 16000, 22050, 32000, 44100, 48000, 96000 }; | 
					
						
							|  |  |  |     int bits_per_sample_arr[3] = { 16, 24, 32 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     for (int i = 0; i < (sizeof(sample_rate_arr) / sizeof(sample_rate_arr[0])); i++) { | 
					
						
							|  |  |  |         for (int j = 0; j < (sizeof(bits_per_sample_arr) / sizeof(bits_per_sample_arr[0])); j++) { | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |             i2s_config.sample_rate = sample_rate_arr[i]; | 
					
						
							|  |  |  |             i2s_config.bits_per_sample = bits_per_sample_arr[j]; | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |             TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL)); | 
					
						
							|  |  |  |             TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, &pin_config)); | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |             TEST_ASSERT((fabs((i2s_get_clk(I2S_NUM_0) - sample_rate_arr[i])) / (sample_rate_arr[i])) * 100 < PERCENT_DIFF); | 
					
						
							| 
									
										
										
										
											2019-08-27 17:36:53 +08:00
										 |  |  |             TEST_ESP_OK(i2s_driver_uninstall(I2S_NUM_0)); | 
					
						
							|  |  |  |             TEST_ASSERT(initial_size == esp_get_free_heap_size()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vTaskDelay(100 / portTICK_PERIOD_MS); | 
					
						
							|  |  |  |     TEST_ASSERT(initial_size == esp_get_free_heap_size()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-07 21:09:52 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-08-20 12:22:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-18 10:52:16 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_ADC
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | /* Only ESP32 need I2S adc/dac test */ | 
					
						
							|  |  |  | TEST_CASE("I2S adc test", "[i2s]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // init I2S ADC
 | 
					
						
							|  |  |  |     i2s_config_t i2s_config = { | 
					
						
							|  |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN, | 
					
						
							|  |  |  |         .sample_rate =  SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .intr_alloc_flags = 0, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 2, | 
					
						
							|  |  |  |         .dma_frame_num = 1024, | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |     // install and start I2S driver
 | 
					
						
							|  |  |  |     i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); | 
					
						
							|  |  |  |     // init ADC pad
 | 
					
						
							|  |  |  |     i2s_set_adc_mode(ADC_UNIT_1, ADC1_CHANNEL_4); | 
					
						
							|  |  |  |     // enable adc sampling, ADC_WIDTH_BIT_12, ADC_ATTEN_DB_11 hard-coded in adc_i2s_mode_init
 | 
					
						
							|  |  |  |     i2s_adc_enable(I2S_NUM_0); | 
					
						
							|  |  |  |     // init read buffer
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |     uint16_t *i2sReadBuffer = (uint16_t *)calloc(1024, sizeof(uint16_t)); | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |     size_t bytesRead; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int loop = 0; loop < 10; loop++) { | 
					
						
							|  |  |  |         for (int level = 0; level <= 1; level++) { | 
					
						
							|  |  |  |             if (level == 0) { | 
					
						
							|  |  |  |                 gpio_set_pull_mode(ADC1_CHANNEL_4_IO, GPIO_PULLDOWN_ONLY); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 gpio_set_pull_mode(ADC1_CHANNEL_4_IO, GPIO_PULLUP_ONLY); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             vTaskDelay(200 / portTICK_RATE_MS); | 
					
						
							|  |  |  |             // read data from adc, will block until buffer is full
 | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |             i2s_read(I2S_NUM_0, (void *)i2sReadBuffer, 1024 * sizeof(uint16_t), &bytesRead, portMAX_DELAY); | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // calc average
 | 
					
						
							|  |  |  |             int64_t adcSumValue = 0; | 
					
						
							|  |  |  |             for (size_t i = 0; i < 1024; i++) { | 
					
						
							|  |  |  |                 adcSumValue += i2sReadBuffer[i] & 0xfff; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             int adcAvgValue = adcSumValue / 1024; | 
					
						
							|  |  |  |             printf("adc average val: %d\n", adcAvgValue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (level == 0) { | 
					
						
							|  |  |  |                 if (adcAvgValue > 100) { | 
					
						
							|  |  |  |                     i2s_adc_disable(I2S_NUM_0); | 
					
						
							|  |  |  |                     free(i2sReadBuffer); | 
					
						
							|  |  |  |                     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  |                     TEST_ASSERT_LESS_THAN(100, adcAvgValue); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 if (adcAvgValue < 4000) { | 
					
						
							|  |  |  |                     i2s_adc_disable(I2S_NUM_0); | 
					
						
							|  |  |  |                     free(i2sReadBuffer); | 
					
						
							|  |  |  |                     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  |                     TEST_ASSERT_GREATER_THAN(4000, adcAvgValue); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     i2s_adc_disable(I2S_NUM_0); | 
					
						
							|  |  |  |     free(i2sReadBuffer); | 
					
						
							|  |  |  |     i2s_driver_uninstall(I2S_NUM_0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-08-18 10:52:16 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-18 10:52:16 +08:00
										 |  |  | #if SOC_I2S_SUPPORTS_DAC
 | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  | TEST_CASE("I2S dac test", "[i2s]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // dac, adc  i2s
 | 
					
						
							|  |  |  |     i2s_config_t  i2s_config = { | 
					
						
							|  |  |  |         .mode = I2S_MODE_MASTER | I2S_MODE_TX, | 
					
						
							|  |  |  |         .sample_rate = SAMPLE_RATE, | 
					
						
							|  |  |  |         .bits_per_sample = SAMPLE_BITS, | 
					
						
							|  |  |  |         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, | 
					
						
							|  |  |  |         .communication_format = I2S_COMM_FORMAT_STAND_I2S, | 
					
						
							| 
									
										
										
										
											2021-11-24 13:21:13 +08:00
										 |  |  |         .dma_desc_num = 6, | 
					
						
							|  |  |  |         .dma_frame_num = 60, | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |         .use_apll = 0, | 
					
						
							| 
									
										
										
										
											2021-07-20 21:03:52 +08:00
										 |  |  |         .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, | 
					
						
							| 
									
										
										
										
											2021-06-15 15:43:03 +08:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //install and start i2s driver
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL)); | 
					
						
							|  |  |  |     //for internal DAC, this will enable both of the internal channels
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_set_pin(I2S_NUM_0, NULL)); | 
					
						
							|  |  |  |     //stop & destroy i2s driver
 | 
					
						
							|  |  |  |     TEST_ESP_OK(i2s_driver_uninstall(I2S_NUM_0)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-20 12:22:36 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-11-26 17:03:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif //SOC_I2S_SUPPORTED
 |