fix(i2s): fixed i2s_std initializer order for cpp compiler

Closes https://github.com/espressif/esp-idf/issues/15405
This commit is contained in:
laokaiyao 2025-02-17 10:12:21 +08:00
parent d65d2fd4d1
commit 7e0cb453e8
4 changed files with 98 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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
}