Skip to content

Commit 7e0cb45

Browse files
committed
fix(i2s): fixed i2s_std initializer order for cpp compiler
Closes #15405
1 parent d65d2fd commit 7e0cb45

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

components/esp_driver_i2s/include/driver/i2s_pdm.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -52,6 +52,9 @@ extern "C" {
5252
.slot_mask = (mono_or_stereo == I2S_SLOT_MODE_MONO) ? \
5353
I2S_PDM_SLOT_LEFT : I2S_PDM_SLOT_BOTH, \
5454
.data_fmt = I2S_PDM_DATA_FMT_RAW, \
55+
.hp_en = false, /* No effect, only for cpp compatibility */ \
56+
.hp_cut_off_freq_hz = 35.5, /* No effect, only for cpp compatibility */ \
57+
.amplify_num = 1, /* No effect, only for cpp compatibility */ \
5558
}
5659
#else
5760
/**
@@ -270,7 +273,16 @@ esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_p
270273
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
271274
.slot_mode = mono_or_stereo, \
272275
.data_fmt = I2S_PDM_DATA_FMT_RAW, \
276+
.sd_prescale = 0, /* No effect, only for cpp compatibility */ \
277+
.sd_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
278+
.hp_scale = I2S_PDM_SIG_SCALING_DIV_2, /* No effect, only for cpp compatibility */ \
279+
.lp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
280+
.sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
273281
.line_mode = I2S_PDM_TX_ONE_LINE_CODEC, \
282+
.hp_en = false, /* No effect, only for cpp compatibility */ \
283+
.hp_cut_off_freq_hz = 35.5, /* No effect, only for cpp compatibility */ \
284+
.sd_dither = 0, /* No effect, only for cpp compatibility */ \
285+
.sd_dither2 = 1, /* No effect, only for cpp compatibility */ \
274286
}
275287

276288
/**
@@ -310,8 +322,17 @@ esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_p
310322
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO, \
311323
.slot_mode = mono_or_stereo, \
312324
.data_fmt = I2S_PDM_DATA_FMT_RAW, \
325+
.sd_prescale = 0, /* No effect, only for cpp compatibility */ \
326+
.sd_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
327+
.hp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
328+
.lp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
329+
.sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
313330
.line_mode = ((mono_or_stereo) == I2S_SLOT_MODE_MONO ? \
314331
I2S_PDM_TX_ONE_LINE_DAC : I2S_PDM_TX_TWO_LINE_DAC), \
332+
.hp_en = true, /* No effect, only for cpp compatibility */ \
333+
.hp_cut_off_freq_hz = 35.5, /* No effect, only for cpp compatibility */ \
334+
.sd_dither = 0, /* No effect, only for cpp compatibility */ \
335+
.sd_dither2 = 1, /* No effect, only for cpp compatibility */ \
315336
}
316337
#else // SOC_I2S_HW_VERSION_2
317338
/**
@@ -343,6 +364,11 @@ esp_err_t i2s_channel_reconfig_pdm_rx_gpio(i2s_chan_handle_t handle, const i2s_p
343364
.slot_mode = mono_or_stereo, \
344365
.slot_mask = I2S_PDM_SLOT_BOTH, \
345366
.data_fmt = I2S_PDM_DATA_FMT_RAW, \
367+
.sd_prescale = 0, /* No effect, only for cpp compatibility */ \
368+
.sd_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
369+
.hp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
370+
.lp_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
371+
.sinc_scale = I2S_PDM_SIG_SCALING_MUL_1, /* No effect, only for cpp compatibility */ \
346372
}
347373
#endif // SOC_I2S_HW_VERSION_2
348374

@@ -428,7 +454,7 @@ typedef struct {
428454
#if SOC_I2S_HW_VERSION_1
429455
i2s_pdm_slot_mask_t slot_mask; /*!< Slot mask to choose left or right slot */
430456
#endif
431-
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.
457+
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.
432458
* Typically, set this field to I2S_PDM_DATA_FMT_PCM when PCM2PDM filter is supported in the hardware,
433459
* so that you can write PCM format data in software, and then the hardware PCM2PDM filter will help to
434460
* convert it into PDM format on the line. Otherwise if this field is set to I2S_PDM_DATA_FMT_RAW,

components/esp_driver_i2s/include/driver/i2s_std.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ extern "C" {
215215
#define I2S_STD_CLK_DEFAULT_CONFIG(rate) { \
216216
.sample_rate_hz = rate, \
217217
.clk_src = I2S_CLK_SRC_DEFAULT, \
218-
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
219218
.ext_clk_freq_hz = 0, \
219+
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
220220
}
221221
#endif
222222

tools/test_apps/system/cxx_build_test/main/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ if(CONFIG_SOC_I2C_SUPPORTED)
77
list(APPEND srcs test_i2c_lcd.cpp)
88
endif()
99

10+
if(CONFIG_SOC_I2S_SUPPORTED)
11+
list(APPEND srcs test_i2s.cpp)
12+
endif()
13+
1014
if(CONFIG_SOC_TWAI_SUPPORTED)
1115
list(APPEND srcs test_twai.cpp)
1216
endif()
1317

1418
idf_component_register(SRCS "${srcs}"
1519
INCLUDE_DIRS "."
16-
PRIV_REQUIRES driver esp_lcd
20+
PRIV_REQUIRES driver esp_lcd esp_driver_i2s
1721
REQUIRES soc)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "soc/soc_caps.h"
7+
#include "driver/i2s_std.h"
8+
#if SOC_I2S_SUPPORTS_TDM
9+
#include "driver/i2s_tdm.h"
10+
#endif
11+
#if SOC_I2S_SUPPORTS_PDM
12+
#include "driver/i2s_pdm.h"
13+
#endif
14+
15+
/**
16+
* Check that C-style designated initializers are valid in C++ file.
17+
*/
18+
void test_i2s_initializers(void)
19+
{
20+
i2s_std_clk_config_t std_clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000);
21+
i2s_std_slot_config_t std_philips_slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO);
22+
i2s_std_slot_config_t std_msb_slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO);
23+
i2s_std_slot_config_t std_pcm_slot_cfg = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO);
24+
(void) std_clk_cfg;
25+
(void) std_philips_slot_cfg;
26+
(void) std_msb_slot_cfg;
27+
(void) std_pcm_slot_cfg;
28+
#if SOC_I2S_SUPPORTS_TDM
29+
i2s_tdm_clk_config_t tdm_clk_cfg = I2S_TDM_CLK_DEFAULT_CONFIG(16000);
30+
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);
31+
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);
32+
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);
33+
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);
34+
(void) tdm_clk_cfg;
35+
(void) tdm_philips_slot_cfg;
36+
(void) tdm_msb_slot_cfg;
37+
(void) tdm_pcm_s_slot_cfg;
38+
(void) tdm_pcm_l_slot_cfg;
39+
#endif
40+
#if SOC_I2S_SUPPORTS_PDM_RX
41+
i2s_pdm_rx_clk_config_t pdm_rx_clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(16000);
42+
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);
43+
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);
44+
(void) pdm_rx_clk_cfg;
45+
(void) pdm_rx_raw_slot_cfg;
46+
(void) pdm_rx_pcm_slot_cfg;
47+
#endif
48+
#if SOC_I2S_SUPPORTS_PDM_TX
49+
i2s_pdm_tx_clk_config_t pdm_tx_clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(16000);
50+
i2s_pdm_tx_clk_config_t pdm_tx_dac_clk_cfg = I2S_PDM_TX_CLK_DAC_DEFAULT_CONFIG(16000);
51+
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);
52+
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);
53+
(void) pdm_tx_clk_cfg;
54+
(void) pdm_tx_dac_clk_cfg;
55+
(void) pdm_tx_raw_slot_cfg;
56+
(void) pdm_tx_pcm_slot_cfg;
57+
#if SOC_I2S_HW_VERSION_2
58+
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);
59+
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);
60+
(void) pdm_tx_raw_dac_slot_cfg;
61+
(void) pdm_tx_pcm_dac_slot_cfg;
62+
#endif
63+
#endif
64+
}

0 commit comments

Comments
 (0)