|
|
@@ -25,11 +25,17 @@
|
|
|
#include "math.h"
|
|
|
#include "esp_rom_gpio.h"
|
|
|
#include "soc/i2s_periph.h"
|
|
|
-#include "driver/i2s_controller.h"
|
|
|
+#include "driver/i2s_std.h"
|
|
|
+#if SOC_I2S_SUPPORTS_PDM
|
|
|
+#include "driver/i2s_pdm.h"
|
|
|
+#endif
|
|
|
+#if SOC_I2S_SUPPORTS_TDM
|
|
|
+#include "driver/i2s_tdm.h"
|
|
|
+#endif
|
|
|
#include "hal/i2s_hal.h"
|
|
|
#include "esp_private/i2s_platform.h"
|
|
|
#if SOC_PCNT_SUPPORTED
|
|
|
-#include "driver/pcnt.h"
|
|
|
+#include "driver/pulse_cnt.h"
|
|
|
#include "soc/pcnt_periph.h"
|
|
|
#endif
|
|
|
|
|
|
@@ -38,12 +44,12 @@
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
#define MASTER_MCK_IO 0
|
|
|
-#define MASTER_BCK_IO 15
|
|
|
-#define MASTER_WS_IO 25
|
|
|
-#define SLAVE_BCK_IO 19
|
|
|
-#define SLAVE_WS_IO 26
|
|
|
-#define DATA_IN_IO 21
|
|
|
-#define DATA_OUT_IO 22
|
|
|
+#define MASTER_BCK_IO 4
|
|
|
+#define MASTER_WS_IO 5
|
|
|
+#define SLAVE_BCK_IO 21
|
|
|
+#define SLAVE_WS_IO 22
|
|
|
+#define DATA_IN_IO 19
|
|
|
+#define DATA_OUT_IO 18
|
|
|
#define ADC1_CHANNEL_4_IO 32
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
|
|
#define MASTER_MCK_IO 0
|
|
|
@@ -81,7 +87,7 @@
|
|
|
.ws = MASTER_WS_IO, \
|
|
|
.dout = DATA_OUT_IO, \
|
|
|
.din = DATA_IN_IO \
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
#define I2S_TEST_SLAVE_DEFAULT_PIN { \
|
|
|
.mclk = -1, \
|
|
|
@@ -89,10 +95,10 @@
|
|
|
.ws = SLAVE_WS_IO, \
|
|
|
.dout = DATA_OUT_IO, \
|
|
|
.din = DATA_IN_IO \
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// This empty function is used to force the compiler link this file
|
|
|
-void test_app_include_i2s_controller(void)
|
|
|
+void test_app_include_i2s(void)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
@@ -192,35 +198,37 @@ finish:
|
|
|
// To check if the software logic of I2S driver is correct
|
|
|
TEST_CASE("I2S basic driver apply, delete test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t i2s_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
|
|
|
i2s_chan_handle_t tx_handle;
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &i2s_pin);
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO);
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
+ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
|
|
|
+ i2s_std_config_t std_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
|
|
|
/* TX channel basic test */
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, &tx_handle, NULL));
|
|
|
|
|
|
- TEST_ESP_OK(i2s_init_channel(tx_handle, &clk_cfg, &slot_cfg));
|
|
|
- slot_cfg.data_bit_width = I2S_DATA_BIT_WIDTH_32BIT;
|
|
|
- TEST_ESP_OK(i2s_set_slot(tx_handle, &slot_cfg));
|
|
|
- clk_cfg.sample_rate = 44100;
|
|
|
- TEST_ESP_OK(i2s_set_clock(tx_handle, &clk_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_cfg));
|
|
|
+ std_cfg.slot_cfg.data_bit_width = I2S_DATA_BIT_WIDTH_32BIT;
|
|
|
+ TEST_ESP_OK(i2s_reconfig_std_slot(tx_handle, &std_cfg.slot_cfg));
|
|
|
+ std_cfg.clk_cfg.sample_rate_hz = 44100;
|
|
|
+ TEST_ESP_OK(i2s_reconfig_std_clock(tx_handle, &std_cfg.clk_cfg));
|
|
|
TEST_ESP_OK(i2s_start_channel(tx_handle));
|
|
|
TEST_ESP_OK(i2s_del_channel(tx_handle));
|
|
|
|
|
|
/* Duplex channel basic test */
|
|
|
chan_cfg.id = I2S_NUM_0; // Specify port id to I2S port 0
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, &tx_handle, &rx_handle));
|
|
|
- TEST_ESP_OK(i2s_init_channel(tx_handle, &clk_cfg, &slot_cfg));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
TEST_ESP_OK(i2s_del_channel(tx_handle));
|
|
|
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
|
|
|
|
|
- /* Repeat to check if a same port can be applied again */
|
|
|
+ /* Repeat to check if a same port can be allocated again */
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, NULL, &rx_handle));
|
|
|
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
|
|
|
|
|
@@ -235,15 +243,20 @@ TEST_CASE("I2S basic driver apply, delete test", "[i2s]")
|
|
|
|
|
|
TEST_CASE("I2S memory leak test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t i2s_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
-
|
|
|
i2s_chan_handle_t tx_handle;
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &i2s_pin);
|
|
|
+ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
|
|
|
+ i2s_std_config_t std_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
|
|
|
/* The first operation will always take some memory */
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, &tx_handle, &rx_handle));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
TEST_ESP_OK(i2s_del_channel(tx_handle));
|
|
|
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
|
|
|
|
|
@@ -251,6 +264,8 @@ TEST_CASE("I2S memory leak test", "[i2s]")
|
|
|
printf("\r\nHeap size before: %d\n", memory_left);
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, &tx_handle, &rx_handle));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
TEST_ESP_OK(i2s_del_channel(tx_handle));
|
|
|
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
|
|
TEST_ASSERT(memory_left == esp_get_free_heap_size());
|
|
|
@@ -260,18 +275,18 @@ TEST_CASE("I2S memory leak test", "[i2s]")
|
|
|
|
|
|
TEST_CASE("I2S loopback test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t i2s_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
-
|
|
|
i2s_chan_handle_t tx_handle;
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &i2s_pin);
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO);
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
- chan_cfg.id = I2S_NUM_0;
|
|
|
+ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
|
|
+ i2s_std_config_t std_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, &tx_handle, &rx_handle));
|
|
|
- TEST_ESP_OK(i2s_init_channel(tx_handle, &clk_cfg, &slot_cfg));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
i2s_test_io_config(I2S_TEST_MODE_LOOPBACK);
|
|
|
|
|
|
TEST_ESP_OK(i2s_start_channel(tx_handle));
|
|
|
@@ -286,23 +301,28 @@ TEST_CASE("I2S loopback test", "[i2s]")
|
|
|
#if SOC_I2S_NUM > 1
|
|
|
TEST_CASE("I2S master write slave read test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t mst_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
- i2s_gpio_config_t slv_pin = I2S_TEST_SLAVE_DEFAULT_PIN;
|
|
|
-
|
|
|
i2s_chan_handle_t tx_handle;
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t mst_chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &mst_pin);
|
|
|
- mst_chan_cfg.id = I2S_NUM_0;
|
|
|
- i2s_chan_config_t slv_chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_SLAVE, I2S_COMM_MODE_STD, &slv_pin);
|
|
|
- slv_chan_cfg.id = I2S_NUM_1;
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO);
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
+ i2s_chan_config_t mst_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
|
|
+ i2s_chan_config_t slv_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_1, I2S_ROLE_SLAVE);
|
|
|
+
|
|
|
+ i2s_std_config_t std_mst_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
+
|
|
|
+ i2s_std_config_t std_slv_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_SLAVE_DEFAULT_PIN,
|
|
|
+ };
|
|
|
|
|
|
TEST_ESP_OK(i2s_new_channel(&mst_chan_cfg, &tx_handle, NULL));
|
|
|
TEST_ESP_OK(i2s_new_channel(&slv_chan_cfg, NULL, &rx_handle));
|
|
|
- TEST_ESP_OK(i2s_init_channel(tx_handle, &clk_cfg, &slot_cfg));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_mst_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_slv_cfg));
|
|
|
i2s_test_io_config(I2S_TEST_MODE_MASTER_TO_SLAVE);
|
|
|
|
|
|
TEST_ESP_OK(i2s_start_channel(tx_handle));
|
|
|
@@ -316,23 +336,27 @@ TEST_CASE("I2S master write slave read test", "[i2s]")
|
|
|
|
|
|
TEST_CASE("I2S master read slave write test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t mst_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
- i2s_gpio_config_t slv_pin = I2S_TEST_SLAVE_DEFAULT_PIN;
|
|
|
-
|
|
|
i2s_chan_handle_t tx_handle;
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t mst_chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &mst_pin);
|
|
|
- mst_chan_cfg.id = I2S_NUM_0;
|
|
|
- i2s_chan_config_t slv_chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_SLAVE, I2S_COMM_MODE_STD, &slv_pin);
|
|
|
- slv_chan_cfg.id = I2S_NUM_1;
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO);
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
+ i2s_chan_config_t mst_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
|
|
+ i2s_chan_config_t slv_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_1, I2S_ROLE_SLAVE);
|
|
|
+ i2s_std_config_t std_mst_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
+
|
|
|
+ i2s_std_config_t std_slv_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_SLAVE_DEFAULT_PIN,
|
|
|
+ };
|
|
|
|
|
|
TEST_ESP_OK(i2s_new_channel(&mst_chan_cfg, NULL, &rx_handle));
|
|
|
TEST_ESP_OK(i2s_new_channel(&slv_chan_cfg, &tx_handle, NULL));
|
|
|
- TEST_ESP_OK(i2s_init_channel(tx_handle, &clk_cfg, &slot_cfg));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(tx_handle, &std_slv_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_mst_cfg));
|
|
|
i2s_test_io_config(I2S_TEST_MODE_SLAVE_TO_MASTER);
|
|
|
|
|
|
TEST_ESP_OK(i2s_start_channel(tx_handle));
|
|
|
@@ -348,26 +372,28 @@ TEST_CASE("I2S master read slave write test", "[i2s]")
|
|
|
/*------------------------------ Clock Test --------------------------------*/
|
|
|
#if SOC_PCNT_SUPPORTED
|
|
|
#define TEST_I2S_PERIOD_MS 100
|
|
|
-static void i2s_test_common_sample_rate(i2s_chan_handle_t rx_chan, i2s_clk_config_t* clk_cfg)
|
|
|
+static void i2s_test_common_sample_rate(i2s_chan_handle_t rx_chan, i2s_std_clk_config_t* clk_cfg)
|
|
|
{
|
|
|
TEST_ASSERT_NOT_NULL(rx_chan);
|
|
|
TEST_ASSERT_NOT_NULL(clk_cfg);
|
|
|
|
|
|
/* Prepare configuration for the PCNT unit */
|
|
|
- pcnt_config_t pcnt_cfg = {
|
|
|
- // Set PCNT input signal and control GPIOs
|
|
|
- .pulse_gpio_num = MASTER_WS_IO,
|
|
|
- .ctrl_gpio_num = -1,
|
|
|
- .channel = PCNT_CHANNEL_0,
|
|
|
- .unit = PCNT_UNIT_0,
|
|
|
- .pos_mode = PCNT_COUNT_INC, // Count up on the positive edge
|
|
|
- .neg_mode = PCNT_COUNT_DIS, // Keep the counter value on the negative edge
|
|
|
- .lctrl_mode = PCNT_MODE_KEEP,
|
|
|
- .hctrl_mode = PCNT_MODE_KEEP,
|
|
|
- .counter_h_lim = (int16_t)0x7fff,
|
|
|
- .counter_l_lim = (int16_t)0x8000,
|
|
|
+ pcnt_unit_handle_t pcnt_unit = NULL;
|
|
|
+ pcnt_channel_handle_t pcnt_chan = NULL;
|
|
|
+
|
|
|
+ pcnt_unit_config_t unit_config = {
|
|
|
+ .high_limit = (int16_t)0x7fff,
|
|
|
+ .low_limit = (int16_t)0x8000,
|
|
|
+ };
|
|
|
+ pcnt_chan_config_t chan_config = {
|
|
|
+ .edge_gpio_num = MASTER_WS_IO,
|
|
|
+ .level_gpio_num = -1,
|
|
|
};
|
|
|
- TEST_ESP_OK(pcnt_unit_config(&pcnt_cfg));
|
|
|
+ TEST_ESP_OK(pcnt_new_unit(&unit_config, &pcnt_unit));
|
|
|
+ TEST_ESP_OK(pcnt_unit_set_glitch_filter(pcnt_unit, NULL));
|
|
|
+ TEST_ESP_OK(pcnt_new_channel(pcnt_unit, &chan_config, &pcnt_chan));
|
|
|
+ TEST_ESP_OK(pcnt_channel_set_edge_action(pcnt_chan, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_HOLD));
|
|
|
+ TEST_ESP_OK(pcnt_channel_set_level_action(pcnt_chan, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_KEEP));
|
|
|
|
|
|
// Reconfig GPIO signal
|
|
|
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[MASTER_WS_IO], PIN_FUNC_GPIO);
|
|
|
@@ -375,26 +401,23 @@ static void i2s_test_common_sample_rate(i2s_chan_handle_t rx_chan, i2s_clk_confi
|
|
|
esp_rom_gpio_connect_out_signal(MASTER_WS_IO, i2s_periph_signal[0].m_rx_ws_sig, 0, 0);
|
|
|
esp_rom_gpio_connect_in_signal(MASTER_WS_IO, pcnt_periph_signals.groups[0].units[0].channels[0].pulse_sig, 0);
|
|
|
|
|
|
- // pcnt_set_filter_value(PCNT_UNIT_0, 10);
|
|
|
- pcnt_filter_disable(PCNT_UNIT_0);
|
|
|
-
|
|
|
// Test common sample rate
|
|
|
uint32_t test_freq[15] = {8000, 11025, 12000, 16000, 22050, 24000,
|
|
|
32000, 44100, 48000, 64000, 88200, 96000,
|
|
|
128000, 144000, 196000};
|
|
|
- int16_t real_pulse = 0;
|
|
|
+ int real_pulse = 0;
|
|
|
for (int i = 0; i < 15; i++) {
|
|
|
- int16_t expt_pulse = (int16_t)((float)test_freq[i] * (TEST_I2S_PERIOD_MS / 1000.0));
|
|
|
- clk_cfg->sample_rate = test_freq[i];
|
|
|
- TEST_ESP_OK(i2s_set_clock(rx_chan, clk_cfg));
|
|
|
+ int expt_pulse = (int)((float)test_freq[i] * (TEST_I2S_PERIOD_MS / 1000.0));
|
|
|
+ clk_cfg->sample_rate_hz = test_freq[i];
|
|
|
+ TEST_ESP_OK(i2s_reconfig_std_clock(rx_chan, clk_cfg));
|
|
|
TEST_ESP_OK(i2s_start_channel(rx_chan));
|
|
|
vTaskDelay(1); // Waiting for hardware totally started
|
|
|
// pcnt will count the pulse number on WS signal in 100ms
|
|
|
- TEST_ESP_OK(pcnt_counter_clear(PCNT_UNIT_0));
|
|
|
- TEST_ESP_OK(pcnt_counter_resume(PCNT_UNIT_0));
|
|
|
+ TEST_ESP_OK(pcnt_unit_clear_count(pcnt_unit));
|
|
|
+ TEST_ESP_OK(pcnt_unit_start(pcnt_unit));
|
|
|
vTaskDelay(pdMS_TO_TICKS(TEST_I2S_PERIOD_MS));
|
|
|
- TEST_ESP_OK(pcnt_counter_pause(PCNT_UNIT_0));
|
|
|
- TEST_ESP_OK(pcnt_get_counter_value(PCNT_UNIT_0, &real_pulse));
|
|
|
+ TEST_ESP_OK(pcnt_unit_stop(pcnt_unit));
|
|
|
+ TEST_ESP_OK(pcnt_unit_get_count(pcnt_unit, &real_pulse));
|
|
|
printf("[%d Hz] %d pulses, expected %d, err %d\n", test_freq[i], real_pulse, expt_pulse, real_pulse - expt_pulse);
|
|
|
TEST_ESP_OK(i2s_stop_channel(rx_chan));
|
|
|
// Check if the error between real pulse number and expected pulse number is within 1%
|
|
|
@@ -404,39 +427,39 @@ static void i2s_test_common_sample_rate(i2s_chan_handle_t rx_chan, i2s_clk_confi
|
|
|
|
|
|
TEST_CASE("I2S D2CLK clock test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t i2s_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
-
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &i2s_pin);
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO);
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
- chan_cfg.id = I2S_NUM_0;
|
|
|
+ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
|
|
+ i2s_std_config_t std_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, NULL, &rx_handle));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
|
|
|
- i2s_test_common_sample_rate(rx_handle, (i2s_clk_config_t *)&clk_cfg);
|
|
|
+ i2s_test_common_sample_rate(rx_handle, &std_cfg.clk_cfg);
|
|
|
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
|
|
}
|
|
|
|
|
|
#if SOC_I2S_SUPPORTS_APLL
|
|
|
TEST_CASE("I2S APLL clock test", "[i2s]")
|
|
|
{
|
|
|
- i2s_gpio_config_t i2s_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
-
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &i2s_pin);
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO);
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
- chan_cfg.id = I2S_NUM_0;
|
|
|
- clk_cfg.clk_src = I2S_CLK_APLL;
|
|
|
+ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
|
|
|
+ i2s_std_config_t std_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(SAMPLE_BITS, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
+ std_cfg.clk_cfg.clk_src = I2S_CLK_APLL;
|
|
|
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, NULL, &rx_handle));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
|
|
|
- i2s_test_common_sample_rate(rx_handle, (i2s_clk_config_t *)&clk_cfg);
|
|
|
+ i2s_test_common_sample_rate(rx_handle, &std_cfg.clk_cfg);
|
|
|
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
|
|
}
|
|
|
#endif // SOC_I2S_SUPPORTS_APLL
|
|
|
@@ -467,17 +490,19 @@ TEST_CASE("I2S package lost test", "[i2s]")
|
|
|
* 2. dma_desc_num > polling_cycle / interrupt_interval = cell(2.818) = 3
|
|
|
* 3. recv_buffer_size > dma_desc_num * dma_buffer_size = 3 * 4092 = 12276 bytes */
|
|
|
#define TEST_RECV_BUF_LEN 12276
|
|
|
- i2s_gpio_config_t i2s_pin = I2S_TEST_MASTER_DEFAULT_PIN;
|
|
|
i2s_chan_handle_t rx_handle;
|
|
|
|
|
|
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_CONFIG(I2S_ROLE_MASTER, I2S_COMM_MODE_STD, &i2s_pin);
|
|
|
- i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIP_SLOT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_STEREO);
|
|
|
- slot_cfg.dma_desc_num = 3;
|
|
|
- slot_cfg.dma_frame_num = 511;
|
|
|
- i2s_std_clk_config_t clk_cfg = I2S_STD_CLK_CONFIG(SAMPLE_RATE);
|
|
|
+ i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
|
|
|
+ chan_cfg.dma_desc_num = 3;
|
|
|
+ chan_cfg.dma_frame_num = 511;
|
|
|
+ i2s_std_config_t std_cfg = {
|
|
|
+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
|
|
+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_STEREO),
|
|
|
+ .gpio_cfg = I2S_TEST_MASTER_DEFAULT_PIN,
|
|
|
+ };
|
|
|
|
|
|
TEST_ESP_OK(i2s_new_channel(&chan_cfg, NULL, &rx_handle));
|
|
|
- TEST_ESP_OK(i2s_init_channel(rx_handle, &clk_cfg, &slot_cfg));
|
|
|
+ TEST_ESP_OK(i2s_init_std_channel(rx_handle, &std_cfg));
|
|
|
|
|
|
TaskHandle_t h_monitor_task;
|
|
|
xTaskCreate(i2s_event_monitor, "event monitor task", 4096, &rx_handle, 5, &h_monitor_task);
|
|
|
@@ -489,8 +514,9 @@ TEST_CASE("I2S package lost test", "[i2s]")
|
|
|
int i;
|
|
|
for (i = 0; i < test_num; i++) {
|
|
|
printf("Testing %d Hz sample rate\n", test_freq[i]);
|
|
|
- clk_cfg.sample_rate = test_freq[i];
|
|
|
- TEST_ESP_OK(i2s_set_clock(rx_handle, &clk_cfg));
|
|
|
+ std_cfg.clk_cfg.sample_rate_hz = test_freq[i];
|
|
|
+ std_cfg.clk_cfg.sample_rate_hz = test_freq[i];
|
|
|
+ TEST_ESP_OK(i2s_reconfig_std_clock(rx_handle, &std_cfg.clk_cfg));
|
|
|
TEST_ESP_OK(i2s_start_channel(rx_handle));
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
TEST_ESP_OK(i2s_read_channel(rx_handle, (void *)data, TEST_RECV_BUF_LEN, &bytes_read, portMAX_DELAY));
|