feat(i2s): support to select PDM data format
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "i2s_pdm_example.h"
|
||||
#include "i2s_example_pins.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define EXAMPLE_PDM_RX_CLK_IO EXAMPLE_I2S_BCLK_IO1 // I2S PDM RX clock io number
|
||||
#define EXAMPLE_PDM_RX_DIN_IO EXAMPLE_I2S_DIN_IO1 // I2S PDM RX data in io number
|
||||
@@ -24,10 +25,21 @@
|
||||
#define EXAMPLE_PDM_RX_DIN3_IO EXAMPLE_I2S_DIN3_IO1 // I2S PDM RX data line3 in io number
|
||||
#endif
|
||||
|
||||
#define EXAMPLE_PDM_RX_FREQ_HZ 16000 // I2S PDM RX frequency
|
||||
#if SOC_I2S_SUPPORTS_PDM2PCM
|
||||
#define EXAMPLE_PDM_RX_FREQ_HZ 16000 // I2S PDM RX frequency in PCM format
|
||||
#else
|
||||
#define EXAMPLE_PDM_RX_FREQ_HZ 2048000 // I2S PDM RX over sample frequency in raw PDM format
|
||||
#endif
|
||||
|
||||
static const char *TAG = "i2s_pdm_rx";
|
||||
|
||||
static i2s_chan_handle_t i2s_example_init_pdm_rx(void)
|
||||
{
|
||||
#if SOC_I2S_SUPPORTS_PDM2PCM
|
||||
ESP_LOGI(TAG, "I2S PDM RX example (receiving data in PCM format)");
|
||||
#else
|
||||
ESP_LOGI(TAG, "I2S PDM RX example (receiving data in raw PDM format)");
|
||||
#endif // SOC_I2S_SUPPORTS_PDM2PCM
|
||||
i2s_chan_handle_t rx_chan; // I2S rx channel handler
|
||||
/* Setp 1: Determine the I2S channel configuration and allocate RX channel only
|
||||
* The default configuration can be generated by the helper macro,
|
||||
@@ -42,7 +54,12 @@ static i2s_chan_handle_t i2s_example_init_pdm_rx(void)
|
||||
i2s_pdm_rx_config_t pdm_rx_cfg = {
|
||||
.clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(EXAMPLE_PDM_RX_FREQ_HZ),
|
||||
/* The data bit-width of PDM mode is fixed to 16 */
|
||||
.slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
|
||||
#if SOC_I2S_SUPPORTS_PDM2PCM
|
||||
.slot_cfg = I2S_PDM_RX_SLOT_PCM_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
|
||||
#else
|
||||
// For the target that not support PDM-to-PCM format, we can only receive RAW PDM data format
|
||||
.slot_cfg = I2S_PDM_RX_SLOT_RAW_FMT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
|
||||
#endif // SOC_I2S_SUPPORTS_PDM2PCM
|
||||
.gpio_cfg = {
|
||||
.clk = EXAMPLE_PDM_RX_CLK_IO,
|
||||
#if SOC_I2S_PDM_MAX_RX_LINES == 4
|
||||
|
||||
Reference in New Issue
Block a user