diff --git a/components/esp_driver_i2s/include/driver/i2s_pdm.h b/components/esp_driver_i2s/include/driver/i2s_pdm.h index b986c74b3a..09f97ad7d4 100644 --- a/components/esp_driver_i2s/include/driver/i2s_pdm.h +++ b/components/esp_driver_i2s/include/driver/i2s_pdm.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -52,6 +52,9 @@ extern "C" { .slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \ I2S_PDM_SLOT_LEFT : I2S_PDM_SLOT_BOTH, \ .data_fmt = I2S_PDM_DATA_FMT_RAW, \ + .hp_en = false, /* No effect, only for cpp compatibility */ \ + .hp_cut_off_freq_hz = 35.5, /* No effect, only for cpp compatibility */ \ + .amplify_num = 1, /* No effect, only for cpp compatibility */ \ } #else /** @@ -270,7 +273,16 @@ esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_p .slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \ .slot_mode = mono_or_stereo, \ .data_fmt = I2S_PDM_DATA_FMT_RAW, \ + .sd_prescale = 0, /* No effect, only for cpp compatibility */ \ + .sd_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .hp_scale = I2S_PDM_SIG_SCALING_DIV_2, /* No effect, only for cpp compatibility */ \ + .lp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ .line_mode = I2S_PDM_TX_ONE_LINE_CODEC, \ + .hp_en = false, /* No effect, only for cpp compatibility */ \ + .hp_cut_off_freq_hz = 35.5, /* No effect, only for cpp compatibility */ \ + .sd_dither = 0, /* No effect, only for cpp compatibility */ \ + .sd_dither2 = 1, /* No effect, only for cpp compatibility */ \ } /** @@ -310,8 +322,17 @@ esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_p .slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \ .slot_mode = mono_or_stereo, \ .data_fmt = I2S_PDM_DATA_FMT_RAW, \ + .sd_prescale = 0, /* No effect, only for cpp compatibility */ \ + .sd_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .hp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .lp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ .line_mode = ((mono_or_stereo) == I2S_SLOT_MODE_MONO ? \ I2S_PDM_TX_ONE_LINE_DAC : I2S_PDM_TX_TWO_LINE_DAC), \ + .hp_en = true, /* No effect, only for cpp compatibility */ \ + .hp_cut_off_freq_hz = 35.5, /* No effect, only for cpp compatibility */ \ + .sd_dither = 0, /* No effect, only for cpp compatibility */ \ + .sd_dither2 = 1, /* No effect, only for cpp compatibility */ \ } #else // SOC_I2S_HW_VERSION_2 /** @@ -343,6 +364,11 @@ esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_p .slot_mode = mono_or_stereo, \ .slot_mask = I2S_PDM_SLOT_BOTH, \ .data_fmt = I2S_PDM_DATA_FMT_RAW, \ + .sd_prescale = 0, /* No effect, only for cpp compatibility */ \ + .sd_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .hp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .lp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ + .sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \ } #endif // SOC_I2S_HW_VERSION_2 @@ -428,7 +454,7 @@ typedef struct { #if SOC_I2S_HW_VERSION_1 i2s_pdm_slot_mask_t slot_mask; /*!< Slot mask to choose left or right slot */ #endif - i2s_pdm_data_fmt_t data_fmt; /*!< The data format of PDM TX mode. It determines what kind of data format is written in software. + i2s_pdm_data_fmt_t data_fmt; /*!< The data format of PDM TX mode. It determines what kind of data format is written in software. * Typically, set this field to I2S_PDM_DATA_FMT_PCM when PCM2PDM filter is supported in the hardware, * so that you can write PCM format data in software, and then the hardware PCM2PDM filter will help to * convert it into PDM format on the line. Otherwise if this field is set to I2S_PDM_DATA_FMT_RAW, diff --git a/components/esp_driver_i2s/include/driver/i2s_std.h b/components/esp_driver_i2s/include/driver/i2s_std.h index 85cb06ab0b..038ff2825a 100644 --- a/components/esp_driver_i2s/include/driver/i2s_std.h +++ b/components/esp_driver_i2s/include/driver/i2s_std.h @@ -215,8 +215,8 @@ extern "C" { #define I2S_STD_CLK_DEFAULT_CONFIG(rate) { \ .sample_rate_hz = rate, \ .clk_src = I2S_CLK_SRC_DEFAULT, \ - .mclk_multiple = I2S_MCLK_MULTIPLE_256, \ .ext_clk_freq_hz = 0, \ + .mclk_multiple = I2S_MCLK_MULTIPLE_256, \ } #endif diff --git a/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt index be4e711a2b..06e770b6de 100644 --- a/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt +++ b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt @@ -7,11 +7,15 @@ if(CONFIG_SOC_I2C_SUPPORTED) list(APPEND srcs test_i2c_lcd.cpp) endif() +if(CONFIG_SOC_I2S_SUPPORTED) + list(APPEND srcs test_i2s.cpp) +endif() + if(CONFIG_SOC_TWAI_SUPPORTED) list(APPEND srcs test_twai.cpp) endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "." - PRIV_REQUIRES driver esp_lcd + PRIV_REQUIRES driver esp_lcd esp_driver_i2s REQUIRES soc) diff --git a/tools/test_apps/system/cxx_build_test/main/test_i2s.cpp b/tools/test_apps/system/cxx_build_test/main/test_i2s.cpp new file mode 100644 index 0000000000..5682293eb8 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/test_i2s.cpp @@ -0,0 +1,64 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "soc/soc_caps.h" +#include "driver/i2s_std.h" +#if SOC_I2S_SUPPORTS_TDM +#include "driver/i2s_tdm.h" +#endif +#if SOC_I2S_SUPPORTS_PDM +#include "driver/i2s_pdm.h" +#endif + +/** + * Check that C-style designated initializers are valid in C++ file. + */ +void test_i2s_initializers(void) +{ + i2s_std_clk_config_t std_clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000); + i2s_std_slot_config_t std_philips_slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + i2s_std_slot_config_t std_msb_slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + i2s_std_slot_config_t std_pcm_slot_cfg = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + (void) std_clk_cfg; + (void) std_philips_slot_cfg; + (void) std_msb_slot_cfg; + (void) std_pcm_slot_cfg; +#if SOC_I2S_SUPPORTS_TDM + i2s_tdm_clk_config_t tdm_clk_cfg = I2S_TDM_CLK_DEFAULT_CONFIG(16000); + i2s_tdm_slot_config_t tdm_philips_slot_cfg = I2S_TDM_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, (i2s_tdm_slot_mask_t)0x03); + i2s_tdm_slot_config_t tdm_msb_slot_cfg = I2S_TDM_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, (i2s_tdm_slot_mask_t)0x03); + i2s_tdm_slot_config_t tdm_pcm_s_slot_cfg = I2S_TDM_PCM_SHORT_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, (i2s_tdm_slot_mask_t)0x03); + i2s_tdm_slot_config_t tdm_pcm_l_slot_cfg = I2S_TDM_PCM_LONG_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, (i2s_tdm_slot_mask_t)0x03); + (void) tdm_clk_cfg; + (void) tdm_philips_slot_cfg; + (void) tdm_msb_slot_cfg; + (void) tdm_pcm_s_slot_cfg; + (void) tdm_pcm_l_slot_cfg; +#endif +#if SOC_I2S_SUPPORTS_PDM_RX + i2s_pdm_rx_clk_config_t pdm_rx_clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(16000); + i2s_pdm_rx_slot_config_t pdm_rx_raw_slot_cfg = I2S_PDM_RX_SLOT_RAW_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + i2s_pdm_rx_slot_config_t pdm_rx_pcm_slot_cfg = I2S_PDM_RX_SLOT_PCM_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + (void) pdm_rx_clk_cfg; + (void) pdm_rx_raw_slot_cfg; + (void) pdm_rx_pcm_slot_cfg; +#endif +#if SOC_I2S_SUPPORTS_PDM_TX + i2s_pdm_tx_clk_config_t pdm_tx_clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(16000); + i2s_pdm_tx_clk_config_t pdm_tx_dac_clk_cfg = I2S_PDM_TX_CLK_DAC_DEFAULT_CONFIG(16000); + i2s_pdm_tx_slot_config_t pdm_tx_raw_slot_cfg = I2S_PDM_TX_SLOT_RAW_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + i2s_pdm_tx_slot_config_t pdm_tx_pcm_slot_cfg = I2S_PDM_TX_SLOT_PCM_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + (void) pdm_tx_clk_cfg; + (void) pdm_tx_dac_clk_cfg; + (void) pdm_tx_raw_slot_cfg; + (void) pdm_tx_pcm_slot_cfg; +#if SOC_I2S_HW_VERSION_2 + i2s_pdm_tx_slot_config_t pdm_tx_raw_dac_slot_cfg = I2S_PDM_TX_SLOT_RAW_FMT_DAC_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + i2s_pdm_tx_slot_config_t pdm_tx_pcm_dac_slot_cfg = I2S_PDM_TX_SLOT_PCM_FMT_DAC_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); + (void) pdm_tx_raw_dac_slot_cfg; + (void) pdm_tx_pcm_dac_slot_cfg; +#endif +#endif +}