Skip to content

Commit d448151

Browse files
committed
fix(i2s): fixed the pdm2pcm capability on c5 and c61
1 parent 7727de5 commit d448151

File tree

11 files changed

+42
-329
lines changed

11 files changed

+42
-329
lines changed

components/esp_driver_i2s/test_apps/i2s/main/test_i2s.c

Lines changed: 31 additions & 1 deletion
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
*/
@@ -986,3 +986,33 @@ TEST_CASE("I2S_asynchronous_read_write", "[i2s]")
986986

987987
TEST_ASSERT(received);
988988
}
989+
990+
#if SOC_I2S_SUPPORTS_PDM2PCM
991+
TEST_CASE("I2S_PDM2PCM_existence_test", "[i2s]")
992+
{
993+
i2s_chan_handle_t rx_handle;
994+
i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
995+
TEST_ESP_OK(i2s_new_channel(&rx_chan_cfg, NULL, &rx_handle));
996+
997+
i2s_pdm_rx_config_t pdm_rx_cfg = {
998+
.clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(16000),
999+
.slot_cfg = I2S_PDM_RX_SLOT_PCM_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
1000+
.gpio_cfg = {
1001+
.clk = MASTER_BCK_IO,
1002+
.din = DATA_IN_IO,
1003+
.invert_flags = {
1004+
.clk_inv = false,
1005+
},
1006+
},
1007+
};
1008+
TEST_ESP_OK(i2s_channel_init_pdm_rx_mode(rx_handle, &pdm_rx_cfg));
1009+
TEST_ESP_OK(i2s_channel_enable(rx_handle));
1010+
1011+
uint8_t *r_buf[64] = {};
1012+
size_t r_bytes = 0;
1013+
// If PDM2PCM is not supported in the hardware, it will fail to read.
1014+
TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, 64, &r_bytes, 1000));
1015+
TEST_ESP_OK(i2s_channel_disable(rx_handle));
1016+
TEST_ESP_OK(i2s_del_channel(rx_handle));
1017+
}
1018+
#endif

components/hal/esp32c5/include/hal/i2s_ll.h

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -743,7 +743,6 @@ static inline void i2s_ll_rx_enable_tdm(i2s_dev_t *hw)
743743
{
744744
hw->rx_conf.rx_pdm_en = false;
745745
hw->rx_conf.rx_tdm_en = true;
746-
hw->rx_pdm2pcm_conf.rx_pdm2pcm_en = false;
747746
}
748747

749748
/**
@@ -946,80 +945,9 @@ static inline uint32_t i2s_ll_tx_get_pdm_fs(i2s_dev_t *hw)
946945
*/
947946
static inline void i2s_ll_rx_enable_pdm(i2s_dev_t *hw, bool pdm_enable)
948947
{
948+
(void)pdm_enable;
949949
hw->rx_conf.rx_pdm_en = 0;
950950
hw->rx_conf.rx_tdm_en = 1;
951-
hw->rx_pdm2pcm_conf.rx_pdm2pcm_en = pdm_enable;
952-
}
953-
954-
/**
955-
* @brief Configure RX PDM downsample
956-
*
957-
* @param hw Peripheral I2S hardware instance address.
958-
* @param dsr PDM downsample configuration parameter
959-
*/
960-
static inline void i2s_ll_rx_set_pdm_dsr(i2s_dev_t *hw, i2s_pdm_dsr_t dsr)
961-
{
962-
hw->rx_pdm2pcm_conf.rx_pdm_sinc_dsr_16_en = dsr;
963-
}
964-
965-
/**
966-
* @brief Get RX PDM downsample configuration
967-
*
968-
* @param hw Peripheral I2S hardware instance address.
969-
* @param dsr Pointer to accept PDM downsample configuration
970-
*/
971-
static inline void i2s_ll_rx_get_pdm_dsr(i2s_dev_t *hw, i2s_pdm_dsr_t *dsr)
972-
{
973-
*dsr = (i2s_pdm_dsr_t)hw->rx_pdm2pcm_conf.rx_pdm_sinc_dsr_16_en;
974-
}
975-
976-
/**
977-
* @brief Configure RX PDM amplify number
978-
* @note This is the amplification number of the digital amplifier,
979-
* which is added after the PDM to PCM conversion result and mainly used for
980-
* amplify the small PDM signal under the VAD scenario
981-
* pcm_result = pdm_input * amplify_num
982-
* pcm_result = 0 if amplify_num = 0
983-
*
984-
* @param hw Peripheral I2S hardware instance address.
985-
* @param amp_num PDM RX amplify number
986-
*/
987-
static inline void i2s_ll_rx_set_pdm_amplify_num(i2s_dev_t *hw, uint32_t amp_num)
988-
{
989-
hw->rx_pdm2pcm_conf.rx_pdm2pcm_amplify_num = amp_num;
990-
}
991-
992-
/**
993-
* @brief Set I2S RX PDM high pass filter param0
994-
*
995-
* @param hw Peripheral I2S hardware instance address.
996-
* @param param The fourth parameter of PDM RX IIR_HP filter stage 1 is (504 + I2S_RX_IIR_HP_MULT12_0[2:0])
997-
*/
998-
static inline void i2s_ll_rx_set_pdm_hp_filter_param0(i2s_dev_t *hw, uint32_t param)
999-
{
1000-
hw->rx_pdm2pcm_conf.rx_iir_hp_mult12_0 = param;
1001-
}
1002-
1003-
/**
1004-
* @brief Set I2S RX PDM high pass filter param5
1005-
*
1006-
* @param hw Peripheral I2S hardware instance address.
1007-
* @param param The fourth parameter of PDM RX IIR_HP filter stage 2 is (504 + I2S_RX_IIR_HP_MULT12_5[2:0])
1008-
*/
1009-
static inline void i2s_ll_rx_set_pdm_hp_filter_param5(i2s_dev_t *hw, uint32_t param)
1010-
{
1011-
hw->rx_pdm2pcm_conf.rx_iir_hp_mult12_5 = param;
1012-
}
1013-
1014-
/**
1015-
* @brief Enable I2S RX PDM high pass filter
1016-
*
1017-
* @param hw Peripheral I2S hardware instance address.
1018-
* @param enable Set true to enable I2S RX PDM high pass filter, set false to bypass it
1019-
*/
1020-
static inline void i2s_ll_rx_enable_pdm_hp_filter(i2s_dev_t *hw, bool enable)
1021-
{
1022-
hw->rx_pdm2pcm_conf.rx_pdm_hp_bypass = !enable;
1023951
}
1024952

1025953
/**

components/hal/esp32c61/include/hal/i2s_ll.h

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -941,88 +941,13 @@ static inline uint32_t i2s_ll_tx_get_pdm_fs(i2s_dev_t *hw)
941941
* @brief Enable RX PDM mode.
942942
*
943943
* @param hw Peripheral I2S hardware instance address.
944-
* @param pdm2pcm Set true to RX enable PDM mode
944+
* @param pdm2pcm Set true to RX enable PDM mode (ignored)
945945
*/
946946
static inline void i2s_ll_rx_enable_pdm(i2s_dev_t *hw, bool pdm2pcm)
947947
{
948+
(void)pdm2pcm;
948949
hw->rx_conf.rx_pdm_en = 0;
949950
hw->rx_conf.rx_tdm_en = 1;
950-
hw->rx_pdm2pcm_conf.rx_pdm2pcm_en = pdm2pcm;
951-
}
952-
953-
/**
954-
* @brief Configure RX PDM downsample
955-
*
956-
* @param hw Peripheral I2S hardware instance address.
957-
* @param dsr PDM downsample configuration parameter
958-
*/
959-
static inline void i2s_ll_rx_set_pdm_dsr(i2s_dev_t *hw, i2s_pdm_dsr_t dsr)
960-
{
961-
hw->rx_pdm2pcm_conf.rx_pdm_sinc_dsr_16_en = dsr;
962-
}
963-
964-
/**
965-
* @brief Get RX PDM downsample configuration
966-
*
967-
* @param hw Peripheral I2S hardware instance address.
968-
* @param dsr Pointer to accept PDM downsample configuration
969-
*/
970-
static inline void i2s_ll_rx_get_pdm_dsr(i2s_dev_t *hw, i2s_pdm_dsr_t *dsr)
971-
{
972-
*dsr = (i2s_pdm_dsr_t)hw->rx_pdm2pcm_conf.rx_pdm_sinc_dsr_16_en;
973-
}
974-
975-
/**
976-
* @brief Configure RX PDM amplify number
977-
* @note This is the amplification number of the digital amplifier,
978-
* which is added after the PDM to PCM conversion result and mainly used for
979-
* amplify the small PDM signal under the VAD scenario
980-
* pcm_result = pdm_input * amplify_num
981-
* pcm_result = 0 if amplify_num = 0
982-
*
983-
* @param hw Peripheral I2S hardware instance address.
984-
* @param amp_num PDM RX amplify number
985-
*/
986-
static inline void i2s_ll_rx_set_pdm_amplify_num(i2s_dev_t *hw, uint32_t amp_num)
987-
{
988-
hw->rx_pdm2pcm_conf.rx_pdm2pcm_amplify_num = amp_num;
989-
}
990-
991-
/**
992-
* @brief Set I2S RX PDM high pass filter param0 (only for compatibility)
993-
*
994-
* @param hw Peripheral I2S hardware instance address.
995-
* @param param no effect
996-
*/
997-
static inline void i2s_ll_rx_set_pdm_hp_filter_param0(i2s_dev_t *hw, uint32_t param)
998-
{
999-
// Can't configure HP filter param on this target
1000-
(void) hw;
1001-
(void) param;
1002-
}
1003-
1004-
/**
1005-
* @brief Set I2S RX PDM high pass filter param5 (only for compatibility)
1006-
*
1007-
* @param hw Peripheral I2S hardware instance address.
1008-
* @param param no effect
1009-
*/
1010-
static inline void i2s_ll_rx_set_pdm_hp_filter_param5(i2s_dev_t *hw, uint32_t param)
1011-
{
1012-
// Can't configure HP filter param on this target
1013-
(void) hw;
1014-
(void) param;
1015-
}
1016-
1017-
/**
1018-
* @brief Enable I2S RX PDM high pass filter
1019-
*
1020-
* @param hw Peripheral I2S hardware instance address.
1021-
* @param enable Set true to enable I2S RX PDM high pass filter, set false to bypass it
1022-
*/
1023-
static inline void i2s_ll_rx_enable_pdm_hp_filter(i2s_dev_t *hw, bool enable)
1024-
{
1025-
hw->rx_pdm2pcm_conf.rx_pdm_hp_bypass = !enable;
1026951
}
1027952

1028953
/**

components/soc/esp32c5/include/soc/Kconfig.soc_caps.in

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,14 +719,6 @@ config SOC_I2S_SUPPORTS_PDM_RX
719719
bool
720720
default y
721721

722-
config SOC_I2S_SUPPORTS_PDM2PCM
723-
bool
724-
default y
725-
726-
config SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER
727-
bool
728-
default y
729-
730722
config SOC_I2S_SUPPORTS_TX_SYNC_CNT
731723
bool
732724
default y

components/soc/esp32c5/include/soc/soc_caps.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@
296296
#define SOC_I2S_SUPPORTS_PDM_TX (1) // Support to output raw PDM format data
297297
#define SOC_I2S_SUPPORTS_PCM2PDM (1) // Support to write PCM format but output PDM format data with the help of PCM to PDM filter
298298
#define SOC_I2S_SUPPORTS_PDM_RX (1) // Support to input raw PDM format data
299-
#define SOC_I2S_SUPPORTS_PDM2PCM (1) // Support to input PDM format but read PCM format data with the help of PDM to PCM filter
300-
#define SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER (1)
301299
#define SOC_I2S_SUPPORTS_TX_SYNC_CNT (1)
302300
#define SOC_I2S_PDM_MAX_TX_LINES (2)
303301
#define SOC_I2S_PDM_MAX_RX_LINES (1U)

components/soc/esp32c5/register/soc/i2s_reg.h

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -836,56 +836,6 @@ extern "C" {
836836
#define I2S_TX_IIR_HP_MULT12_0_V 0x00000007U
837837
#define I2S_TX_IIR_HP_MULT12_0_S 23
838838

839-
/** I2S_RX_PDM2PCM_CONF_REG register
840-
* I2S RX configure register
841-
*/
842-
#define I2S_RX_PDM2PCM_CONF_REG(i) (REG_I2S_BASE(i) + 0x4c)
843-
/** I2S_RX_PDM2PCM_EN : R/W; bitpos: [19]; default: 0;
844-
* 1: Enable PDM2PCM RX mode. 0: DIsable.
845-
*/
846-
#define I2S_RX_PDM2PCM_EN (BIT(19))
847-
#define I2S_RX_PDM2PCM_EN_M (I2S_RX_PDM2PCM_EN_V << I2S_RX_PDM2PCM_EN_S)
848-
#define I2S_RX_PDM2PCM_EN_V 0x00000001U
849-
#define I2S_RX_PDM2PCM_EN_S 19
850-
/** I2S_RX_PDM_SINC_DSR_16_EN : R/W; bitpos: [20]; default: 0;
851-
* Configure the down sampling rate of PDM RX filter group1 module. 1: The down
852-
* sampling rate is 128. 0: down sampling rate is 64.
853-
*/
854-
#define I2S_RX_PDM_SINC_DSR_16_EN (BIT(20))
855-
#define I2S_RX_PDM_SINC_DSR_16_EN_M (I2S_RX_PDM_SINC_DSR_16_EN_V << I2S_RX_PDM_SINC_DSR_16_EN_S)
856-
#define I2S_RX_PDM_SINC_DSR_16_EN_V 0x00000001U
857-
#define I2S_RX_PDM_SINC_DSR_16_EN_S 20
858-
/** I2S_RX_PDM2PCM_AMPLIFY_NUM : R/W; bitpos: [24:21]; default: 1;
859-
* Configure PDM RX amplify number.
860-
*/
861-
#define I2S_RX_PDM2PCM_AMPLIFY_NUM 0x0000000FU
862-
#define I2S_RX_PDM2PCM_AMPLIFY_NUM_M (I2S_RX_PDM2PCM_AMPLIFY_NUM_V << I2S_RX_PDM2PCM_AMPLIFY_NUM_S)
863-
#define I2S_RX_PDM2PCM_AMPLIFY_NUM_V 0x0000000FU
864-
#define I2S_RX_PDM2PCM_AMPLIFY_NUM_S 21
865-
/** I2S_RX_PDM_HP_BYPASS : R/W; bitpos: [25]; default: 0;
866-
* I2S PDM RX bypass hp filter or not.
867-
*/
868-
#define I2S_RX_PDM_HP_BYPASS (BIT(25))
869-
#define I2S_RX_PDM_HP_BYPASS_M (I2S_RX_PDM_HP_BYPASS_V << I2S_RX_PDM_HP_BYPASS_S)
870-
#define I2S_RX_PDM_HP_BYPASS_V 0x00000001U
871-
#define I2S_RX_PDM_HP_BYPASS_S 25
872-
/** I2S_RX_IIR_HP_MULT12_5 : R/W; bitpos: [28:26]; default: 6;
873-
* The fourth parameter of PDM RX IIR_HP filter stage 2 is (504 +
874-
* LP_I2S_RX_IIR_HP_MULT12_5[2:0])
875-
*/
876-
#define I2S_RX_IIR_HP_MULT12_5 0x00000007U
877-
#define I2S_RX_IIR_HP_MULT12_5_M (I2S_RX_IIR_HP_MULT12_5_V << I2S_RX_IIR_HP_MULT12_5_S)
878-
#define I2S_RX_IIR_HP_MULT12_5_V 0x00000007U
879-
#define I2S_RX_IIR_HP_MULT12_5_S 26
880-
/** I2S_RX_IIR_HP_MULT12_0 : R/W; bitpos: [31:29]; default: 7;
881-
* The fourth parameter of PDM RX IIR_HP filter stage 1 is (504 +
882-
* LP_I2S_RX_IIR_HP_MULT12_0[2:0])
883-
*/
884-
#define I2S_RX_IIR_HP_MULT12_0 0x00000007U
885-
#define I2S_RX_IIR_HP_MULT12_0_M (I2S_RX_IIR_HP_MULT12_0_V << I2S_RX_IIR_HP_MULT12_0_S)
886-
#define I2S_RX_IIR_HP_MULT12_0_V 0x00000007U
887-
#define I2S_RX_IIR_HP_MULT12_0_S 29
888-
889839
/** I2S_RX_TDM_CTRL_REG register
890840
* I2S TX TDM mode control register
891841
*/

components/soc/esp32c5/register/soc/i2s_struct.h

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -295,43 +295,6 @@ typedef union {
295295
uint32_t val;
296296
} i2s_rx_recomb_dma_chn_reg_t;
297297

298-
/** Type of rx_pdm2pcm_conf register
299-
* I2S RX configure register
300-
*/
301-
typedef union {
302-
struct {
303-
uint32_t reserved_0:19;
304-
/** rx_pdm2pcm_en : R/W; bitpos: [19]; default: 0;
305-
* 1: Enable PDM2PCM RX mode. 0: DIsable.
306-
*/
307-
uint32_t rx_pdm2pcm_en:1;
308-
/** rx_pdm_sinc_dsr_16_en : R/W; bitpos: [20]; default: 0;
309-
* Configure the down sampling rate of PDM RX filter group1 module. 1: The down
310-
* sampling rate is 128. 0: down sampling rate is 64.
311-
*/
312-
uint32_t rx_pdm_sinc_dsr_16_en:1;
313-
/** rx_pdm2pcm_amplify_num : R/W; bitpos: [24:21]; default: 1;
314-
* Configure PDM RX amplify number.
315-
*/
316-
uint32_t rx_pdm2pcm_amplify_num:4;
317-
/** rx_pdm_hp_bypass : R/W; bitpos: [25]; default: 0;
318-
* I2S PDM RX bypass hp filter or not.
319-
*/
320-
uint32_t rx_pdm_hp_bypass:1;
321-
/** rx_iir_hp_mult12_5 : R/W; bitpos: [28:26]; default: 6;
322-
* The fourth parameter of PDM RX IIR_HP filter stage 2 is (504 +
323-
* LP_I2S_RX_IIR_HP_MULT12_5[2:0])
324-
*/
325-
uint32_t rx_iir_hp_mult12_5:3;
326-
/** rx_iir_hp_mult12_0 : R/W; bitpos: [31:29]; default: 7;
327-
* The fourth parameter of PDM RX IIR_HP filter stage 1 is (504 +
328-
* LP_I2S_RX_IIR_HP_MULT12_0[2:0])
329-
*/
330-
uint32_t rx_iir_hp_mult12_0:3;
331-
};
332-
uint32_t val;
333-
} i2s_rx_pdm2pcm_conf_reg_t;
334-
335298
/** Type of rx_tdm_ctrl register
336299
* I2S TX TDM mode control register
337300
*/
@@ -1038,7 +1001,7 @@ typedef struct {
10381001
volatile i2s_rx_recomb_dma_chn_reg_t rx_recomb_dma_ch[4];
10391002
volatile i2s_tx_pcm2pdm_conf_reg_t tx_pcm2pdm_conf;
10401003
volatile i2s_tx_pcm2pdm_conf1_reg_t tx_pcm2pdm_conf1;
1041-
volatile i2s_rx_pdm2pcm_conf_reg_t rx_pdm2pcm_conf;
1004+
uint32_t reserved_048;
10421005
volatile i2s_rx_tdm_ctrl_reg_t rx_tdm_ctrl;
10431006
volatile i2s_tx_tdm_ctrl_reg_t tx_tdm_ctrl;
10441007
volatile i2s_rx_timing_reg_t rx_timing;

components/soc/esp32c61/include/soc/Kconfig.soc_caps.in

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,6 @@ config SOC_I2S_SUPPORTS_PDM_RX
595595
bool
596596
default y
597597

598-
config SOC_I2S_SUPPORTS_PDM2PCM
599-
bool
600-
default y
601-
602-
config SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER
603-
bool
604-
default y
605-
606598
config SOC_I2S_SUPPORTS_TX_SYNC_CNT
607599
bool
608600
default y

0 commit comments

Comments
 (0)