From 9123a41d42bfb1410e8e0039477be56e03241123 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Thu, 19 Aug 2021 13:37:12 +0100 Subject: [PATCH 01/15] Removed unused define and added mck pin definition to i2s_pin_config Changes on the pin configuration Fixed the pin setup and minor improvements --- .../main/i2s_recorder_main.c | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index afc9272e59..655ac97804 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -8,18 +8,17 @@ */ #include #include +#include +#include +#include +#include "esp_log.h" +#include "esp_err.h" +#include "esp_system.h" +#include "esp_vfs_fat.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/i2s.h" #include "driver/gpio.h" -#include "esp_system.h" -#include -#include "esp_log.h" -#include -#include -#include "esp_err.h" -#include "esp_vfs_fat.h" -#include "driver/sdspi_host.h" #include "driver/spi_common.h" #include "sdmmc_cmd.h" #include "sdkconfig.h" @@ -27,9 +26,8 @@ static const char* TAG = "pdm_rec_example"; #define AUDIO_SAMPLE_SIZE (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE * 1024) -#define SAMPLES_NUM ((CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE/100) * 2) -#define BYTE_RATE (1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * ((CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8)) -#define FLASH_RECORD_SIZE (BYTE_RATE * CONFIG_EXAMPLE_REC_TIME)) +#define BYTE_RATE 1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8) +#define FLASH_RECORD_SIZE BYTE_RATE * CONFIG_EXAMPLE_REC_TIME #define SD_MOUNT_POINT "/sdcard" #define SPI_DMA_CHAN (1) @@ -104,7 +102,7 @@ void wavHeader(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ // See this for reference: http://soundfile.sapp.org/doc/WaveFormat/ uint32_t file_size = wav_size + WAVE_HEADER_SIZE - 8; - uint32_t byte_rate = 1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8); + uint32_t byte_rate = BYTE_RATE; const char set_wav_header[] = { 'R','I','F','F', // ChunkID @@ -154,7 +152,7 @@ void record_wav(void) // Start recording while (flash_wr_size < FLASH_RECORD_SIZE) { // Read the RAW samples from the microphone - i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, AUDIO_SAMPLE_SIZE, &bytes_read, portMAX_DELAY); + i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, AUDIO_SAMPLE_SIZE, &bytes_read, 100); // Write the samples to the WAV file fwrite(i2s_readraw_buff, 1, bytes_read, f); flash_wr_size += bytes_read; @@ -179,21 +177,24 @@ void init_microphone(void) .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, - .dma_buf_count = 64, + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, + .dma_buf_count = 8, .dma_buf_len = 1024, - .use_apll = 1 + .use_apll = 1, }; - i2s_pin_config_t pin_config; - pin_config.bck_io_num = I2S_PIN_NO_CHANGE; - pin_config.ws_io_num = CONFIG_EXAMPLE_I2S_CLK_GPIO; - pin_config.data_out_num = I2S_PIN_NO_CHANGE; - pin_config.data_in_num = CONFIG_EXAMPLE_I2S_DATA_GPIO; + i2s_pin_config_t pin_config = { + .mck_io_num = I2S_PIN_NO_CHANGE, + .bck_io_num = I2S_PIN_NO_CHANGE, + .ws_io_num = CONFIG_EXAMPLE_I2S_CLK_GPIO, + .data_out_num = I2S_PIN_NO_CHANGE, + .data_in_num = CONFIG_EXAMPLE_I2S_DATA_GPIO, + }; - i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL); - i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config); - i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); + ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); + ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); + // Set the I2S clock using the sample rate divided by 2 if channel is mono + ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } void app_main(void) From 4d1e3a6ed5465cd1ba62400389467e29be2eeb56 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Wed, 25 Aug 2021 11:51:27 +0100 Subject: [PATCH 02/15] Added driver unistall function for I2S --- .../i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index 655ac97804..f7ad8e9ee8 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -178,7 +178,7 @@ void init_microphone(void) .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, - .dma_buf_count = 8, + .dma_buf_count = 16, .dma_buf_len = 1024, .use_apll = 1, }; @@ -191,9 +191,9 @@ void init_microphone(void) .data_in_num = CONFIG_EXAMPLE_I2S_DATA_GPIO, }; + // Call driver installation function before any I2S R/W operation. ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); - // Set the I2S clock using the sample rate divided by 2 if channel is mono ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } @@ -207,4 +207,6 @@ void app_main(void) ESP_LOGI(TAG, "Starting recording for %d seconds!", CONFIG_EXAMPLE_REC_TIME); // Start Recording record_wav(); + // Stop I2S driver and destroy + ESP_ERROR_CHECK( i2s_driver_uninstall(CONFIG_EXAMPLE_I2S_CH) ); } From 5e53ff825ec9f7f9c40963e804364d24c1d69908 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Wed, 25 Aug 2021 12:09:57 +0100 Subject: [PATCH 03/15] Changes on the recording function --- .../main/Kconfig.projbuild | 4 +- .../main/i2s_recorder_main.c | 58 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild index a23430d67e..9bda98a74a 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild @@ -36,13 +36,13 @@ menu "Example Configuration" help Set the I2S channel number. - config EXAMPLE_AUDIO_SAMPLE_RATE + config EXAMPLE_SAMPLE_RATE int "Audio Sample Rate" default 44100 help Set the audio sample rate frequency. Usually 16000 or 44100 Hz. - config EXAMPLE_AUDIO_BIT_SAMPLE + config EXAMPLE_BIT_SAMPLE int "Audio Bit Sample" default 16 help diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index f7ad8e9ee8..82fdf23f5d 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -25,11 +25,10 @@ static const char* TAG = "pdm_rec_example"; -#define AUDIO_SAMPLE_SIZE (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE * 1024) -#define BYTE_RATE 1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8) -#define FLASH_RECORD_SIZE BYTE_RATE * CONFIG_EXAMPLE_REC_TIME -#define SD_MOUNT_POINT "/sdcard" #define SPI_DMA_CHAN (1) +#define SD_MOUNT_POINT "/sdcard" +#define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) +#define BYTE_RATE 1 * CONFIG_EXAMPLE_SAMPLE_RATE * (CONFIG_EXAMPLE_BIT_SAMPLE / 8) // When testing SD and SPI modes, keep in mind that once the card has been // initialized in SPI mode, it can not be reinitialized in SD mode without @@ -37,7 +36,7 @@ static const char* TAG = "pdm_rec_example"; sdmmc_host_t host = SDSPI_HOST_DEFAULT(); sdmmc_card_t* card; -static int16_t i2s_readraw_buff[AUDIO_SAMPLE_SIZE]; +static int16_t i2s_readraw_buff[SAMPLE_SIZE]; size_t bytes_read; const int WAVE_HEADER_SIZE = 44; @@ -104,33 +103,35 @@ void wavHeader(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ uint32_t file_size = wav_size + WAVE_HEADER_SIZE - 8; uint32_t byte_rate = BYTE_RATE; -const char set_wav_header[] = { - 'R','I','F','F', // ChunkID - file_size, file_size >> 8, file_size >> 16, file_size >> 24, // ChunkSize - 'W','A','V','E', // Format - 'f','m','t',' ', // Subchunk1ID - 0x10, 0x00, 0x00, 0x00, // Subchunk1Size (16 for PCM) - 0x01, 0x00, // AudioFormat (1 for PCM) - 0x01, 0x00, // NumChannels (1 channel) - sample_rate, sample_rate >> 8, sample_rate >> 16, sample_rate >> 24, // SampleRate - byte_rate, byte_rate >> 8, byte_rate >> 16, byte_rate >> 24, // ByteRate - 0x02, 0x00, // BlockAlign - 0x10, 0x00, // BitsPerSample (16 bits) - 'd','a','t','a', // Subchunk2ID - wav_size, wav_size >> 8, wav_size >> 16, wav_size >> 24, // Subchunk2Size -}; + const char set_wav_header[] = { + 'R','I','F','F', // ChunkID + file_size, file_size >> 8, file_size >> 16, file_size >> 24, // ChunkSize + 'W','A','V','E', // Format + 'f','m','t',' ', // Subchunk1ID + 0x10, 0x00, 0x00, 0x00, // Subchunk1Size (16 for PCM) + 0x01, 0x00, // AudioFormat (1 for PCM) + 0x01, 0x00, // NumChannels (1 channel) + sample_rate, sample_rate >> 8, sample_rate >> 16, sample_rate >> 24, // SampleRate + byte_rate, byte_rate >> 8, byte_rate >> 16, byte_rate >> 24, // ByteRate + 0x02, 0x00, // BlockAlign + 0x10, 0x00, // BitsPerSample (16 bits) + 'd','a','t','a', // Subchunk2ID + wav_size, wav_size >> 8, wav_size >> 16, wav_size >> 24, // Subchunk2Size + }; memcpy(wav_header, set_wav_header, sizeof(set_wav_header)); } -void record_wav(void) +void record_wav(uint32_t rec_time) { // Use POSIX and C standard library functions to work with files. int flash_wr_size = 0; ESP_LOGI(TAG, "Opening file"); char wav_header_fmt[WAVE_HEADER_SIZE]; - wavHeader(wav_header_fmt, FLASH_RECORD_SIZE, CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE); + + uint32_t flash_rec_time = BYTE_RATE * rec_time; + wavHeader(wav_header_fmt, flash_rec_time, CONFIG_EXAMPLE_SAMPLE_RATE); // First check if file exists before creating a new file. struct stat st; @@ -150,9 +151,9 @@ void record_wav(void) fwrite(wav_header_fmt, 1, WAVE_HEADER_SIZE, f); // Start recording - while (flash_wr_size < FLASH_RECORD_SIZE) { + while (flash_wr_size < flash_rec_time) { // Read the RAW samples from the microphone - i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, AUDIO_SAMPLE_SIZE, &bytes_read, 100); + i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, SAMPLE_SIZE, &bytes_read, 100); // Write the samples to the WAV file fwrite(i2s_readraw_buff, 1, bytes_read, f); flash_wr_size += bytes_read; @@ -171,9 +172,11 @@ void record_wav(void) void init_microphone(void) { + + // Set the I2S configuration as PDM 16bits per sample i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM, - .sample_rate = CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE, + .sample_rate = CONFIG_EXAMPLE_SAMPLE_RATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, @@ -183,6 +186,7 @@ void init_microphone(void) .use_apll = 1, }; + // Set the pinout configuration (set using menuconfig) i2s_pin_config_t pin_config = { .mck_io_num = I2S_PIN_NO_CHANGE, .bck_io_num = I2S_PIN_NO_CHANGE, @@ -194,7 +198,7 @@ void init_microphone(void) // Call driver installation function before any I2S R/W operation. ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); - ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); + ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } void app_main(void) @@ -206,7 +210,7 @@ void app_main(void) init_microphone(); ESP_LOGI(TAG, "Starting recording for %d seconds!", CONFIG_EXAMPLE_REC_TIME); // Start Recording - record_wav(); + record_wav(CONFIG_EXAMPLE_REC_TIME); // Stop I2S driver and destroy ESP_ERROR_CHECK( i2s_driver_uninstall(CONFIG_EXAMPLE_I2S_CH) ); } From ae6e2aa687473e61c21230f1d8b613bd969b9e55 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Mon, 13 Sep 2021 10:07:19 +0100 Subject: [PATCH 04/15] Rebase and removed the sample rate division by 2 --- .../main/i2s_recorder_main.c | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index 82fdf23f5d..0a2ff65800 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -25,10 +25,11 @@ static const char* TAG = "pdm_rec_example"; -#define SPI_DMA_CHAN (1) -#define SD_MOUNT_POINT "/sdcard" -#define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) -#define BYTE_RATE 1 * CONFIG_EXAMPLE_SAMPLE_RATE * (CONFIG_EXAMPLE_BIT_SAMPLE / 8) +#define SPI_DMA_CHAN (1) +#define NUM_CHANNELS (1) // For mono recording only! +#define SD_MOUNT_POINT "/sdcard" +#define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) +#define BYTE_RATE (CONFIG_EXAMPLE_SAMPLE_RATE * (CONFIG_EXAMPLE_BIT_SAMPLE / 8)) * NUM_CHANNELS // When testing SD and SPI modes, keep in mind that once the card has been // initialized in SPI mode, it can not be reinitialized in SD mode without @@ -49,17 +50,10 @@ void mount_sdcard(void) esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = true, .max_files = 5, - .allocation_unit_size = 16 * 1024 + .allocation_unit_size = 8 * 1024 }; ESP_LOGI(TAG, "Initializing SD card"); - // Use settings defined above to initialize SD card and mount FAT filesystem. - // Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions. - // Please check its source code and implement error recovery when developing - // production applications. - - ESP_LOGI(TAG, "Using SPI peripheral"); - spi_bus_config_t bus_cfg = { .mosi_io_num = CONFIG_EXAMPLE_SPI_MOSI_GPIO, .miso_io_num = CONFIG_EXAMPLE_SPI_MISO_GPIO, @@ -84,8 +78,7 @@ void mount_sdcard(void) if (ret != ESP_OK) { if (ret == ESP_FAIL) { - ESP_LOGE(TAG, "Failed to mount filesystem. " - "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option."); + ESP_LOGE(TAG, "Failed to mount filesystem."); } else { ESP_LOGE(TAG, "Failed to initialize the card (%s). " "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret)); @@ -173,7 +166,7 @@ void record_wav(uint32_t rec_time) void init_microphone(void) { - // Set the I2S configuration as PDM 16bits per sample + // Set the I2S configuration as PDM and 16bits per sample i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM, .sample_rate = CONFIG_EXAMPLE_SAMPLE_RATE, @@ -181,7 +174,7 @@ void init_microphone(void) .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, - .dma_buf_count = 16, + .dma_buf_count = 8, .dma_buf_len = 1024, .use_apll = 1, }; @@ -198,7 +191,7 @@ void init_microphone(void) // Call driver installation function before any I2S R/W operation. ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); - ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); + ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, CONFIG_EXAMPLE_SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } void app_main(void) From e3760cf1e311d510cef1f88e6c358bc398c4972b Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Sun, 26 Sep 2021 11:37:37 +0800 Subject: [PATCH 05/15] i2s: fix the param check on PDM mode Closes https://github.com/espressif/esp-idf/issues/7604 --- components/driver/i2s.c | 4 ++-- examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/driver/i2s.c b/components/driver/i2s.c index 0eb50e4738..8fda8d7864 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -1550,10 +1550,10 @@ static esp_err_t i2s_check_cfg_validity(i2s_port_t i2s_num, i2s_hal_config_t *cf if (cfg->mode & I2S_MODE_PDM) { ESP_RETURN_ON_FALSE(i2s_num == I2S_NUM_0, ESP_ERR_INVALID_ARG, TAG, "I2S PDM mode only support on I2S0"); #if !SOC_I2S_SUPPORTS_PDM_TX - ESP_RETURN_ON_FALSE(cfg->mode & I2S_MODE_TX, ESP_ERR_INVALID_ARG, TAG, "PDM does not support TX on this chip"); + ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_TX), ESP_ERR_INVALID_ARG, TAG, "PDM does not support TX on this chip"); #endif // SOC_I2S_SUPPORTS_PDM_TX #if !SOC_I2S_SUPPORTS_PDM_RX - ESP_RETURN_ON_FALSE(cfg->mode & I2S_MODE_RX, ESP_ERR_INVALID_ARG, TAG, "PDM does not support RX on this chip"); + ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_RX), ESP_ERR_INVALID_ARG, TAG, "PDM does not support RX on this chip"); #endif // SOC_I2S_SUPPORTS_PDM_RX } #else diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md index 85b254b2df..a23531b9d0 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md @@ -80,8 +80,8 @@ I (401) I2S: APLL: Req RATE: 44100, real rate: 88199.977, BITS: 16, CLKM: 1, BCK I (431) I2S: APLL: Req RATE: 44100, real rate: 88199.977, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 22579194.000, SCLK: 2822399.250000, diva: 1, divb: 0 I (431) pdm_rec_example: Initializing SD card I (431) pdm_rec_example: Using SDMMC peripheral -I (441) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -Name: USD +I (441) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 +Name: USD Type: SDHC/SDXC Speed: 20 MHz Size: 3813MB From b7b76cbe15fbe29a6ac4e46268de25c7a2889d95 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Tue, 28 Sep 2021 12:02:07 +0800 Subject: [PATCH 06/15] i2s: fix the mono mode of PDM on esp32 --- components/hal/i2s_hal.c | 39 ++++++++++++++++++----------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/components/hal/i2s_hal.c b/components/hal/i2s_hal.c index edb2660590..c6e83cbe6c 100644 --- a/components/hal/i2s_hal.c +++ b/components/hal/i2s_hal.c @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The HAL layer for I2S (common part) @@ -104,6 +96,13 @@ void i2s_hal_tx_set_pdm_mode_default(i2s_hal_context_t *hal, uint32_t sample_rat { /* enable pdm tx mode */ i2s_ll_tx_enable_pdm(hal->dev, true); +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_tx_enable_clock(hal->dev); + i2s_ll_tx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default + i2s_ll_mclk_use_tx_clk(hal->dev); +#else + i2s_ll_tx_force_enable_fifo_mod(hal->dev, true); +#endif /* set pdm tx default presacle */ i2s_ll_tx_set_pdm_prescale(hal->dev, 0); /* set pdm tx default sacle of high pass filter */ @@ -140,6 +139,16 @@ void i2s_hal_rx_set_pdm_mode_default(i2s_hal_context_t *hal) i2s_ll_rx_enable_pdm(hal->dev, true); /* set pdm rx downsample number */ i2s_ll_rx_set_pdm_dsr(hal->dev, I2S_PDM_DSR_8S); +#if !SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_force_enable_fifo_mod(hal->dev, true); +#endif +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_enable_clock(hal->dev); + i2s_ll_rx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default + i2s_ll_mclk_use_rx_clk(hal->dev); +#else + i2s_ll_rx_force_enable_fifo_mod(hal->dev, true); +#endif } #endif // SOC_I2S_SUPPORTS_PDM_RX @@ -286,8 +295,8 @@ void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_hal_config_t *hal_cf { /* Set tx common mode */ i2s_hal_tx_set_common_mode(hal, hal_cfg); - i2s_hal_tx_set_channel_style(hal, hal_cfg); } + i2s_hal_tx_set_channel_style(hal, hal_cfg); } /* Set configurations for RX mode */ @@ -304,8 +313,8 @@ void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_hal_config_t *hal_cf { /* Set rx common mode */ i2s_hal_rx_set_common_mode(hal, hal_cfg); - i2s_hal_rx_set_channel_style(hal, hal_cfg); } + i2s_hal_rx_set_channel_style(hal, hal_cfg); } /* Set configurations for full-duplex mode */ diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 0cb7ab7e15..18e78a8599 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1670,7 +1670,6 @@ components/hal/gdma_hal.c components/hal/gpio_hal.c components/hal/i2c_hal.c components/hal/i2c_hal_iram.c -components/hal/i2s_hal.c components/hal/include/hal/adc_hal.h components/hal/include/hal/adc_types.h components/hal/include/hal/aes_hal.h From 1d7bf0f188c4b3e2ef03e797b9b6e112f77a0ea3 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Tue, 28 Sep 2021 12:04:34 +0800 Subject: [PATCH 07/15] i2s_rec_example: add support for esp32s3 --- components/hal/esp32c3/include/hal/i2s_ll.h | 38 ++++++++++++------- components/hal/esp32h2/include/hal/i2s_ll.h | 38 ++++++++++++------- components/hal/esp32s3/include/hal/i2s_ll.h | 38 ++++++++++++------- components/hal/i2s_hal.c | 36 ++++++++++++++++++ components/hal/include/hal/i2s_hal.h | 26 +++++-------- .../i2s/i2s_audio_recorder_sdcard/README.md | 18 ++++----- .../main/Kconfig.projbuild | 12 +++--- .../main/i2s_recorder_main.c | 11 +++--- tools/ci/check_copyright_ignore.txt | 4 -- 9 files changed, 140 insertions(+), 81 deletions(-) diff --git a/components/hal/esp32c3/include/hal/i2s_ll.h b/components/hal/esp32c3/include/hal/i2s_ll.h index 670db91616..0cfb05a266 100644 --- a/components/hal/esp32c3/include/hal/i2s_ll.h +++ b/components/hal/esp32c3/include/hal/i2s_ll.h @@ -1,16 +1,8 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The LL layer for I2S register operations /******************************************************************************* @@ -86,6 +78,26 @@ static inline void i2s_ll_rx_enable_clock(i2s_dev_t *hw) hw->rx_clkm_conf.rx_clk_active = 1; } +/** + * @brief Disable I2S tx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_tx_disable_clock(i2s_dev_t *hw) +{ + hw->tx_clkm_conf.tx_clk_active = 0; +} + +/** + * @brief Disable I2S rx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_rx_disable_clock(i2s_dev_t *hw) +{ + hw->rx_clkm_conf.rx_clk_active = 0; +} + /** * @brief I2S mclk use tx module clock * diff --git a/components/hal/esp32h2/include/hal/i2s_ll.h b/components/hal/esp32h2/include/hal/i2s_ll.h index e241ac2185..365362479c 100644 --- a/components/hal/esp32h2/include/hal/i2s_ll.h +++ b/components/hal/esp32h2/include/hal/i2s_ll.h @@ -1,16 +1,8 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -87,6 +79,26 @@ static inline void i2s_ll_rx_enable_clock(i2s_dev_t *hw) hw->rx_clkm_conf.rx_clk_active = 1; } +/** + * @brief Disable I2S tx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_tx_disable_clock(i2s_dev_t *hw) +{ + hw->tx_clkm_conf.tx_clk_active = 0; +} + +/** + * @brief Disable I2S rx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_rx_disable_clock(i2s_dev_t *hw) +{ + hw->rx_clkm_conf.rx_clk_active = 0; +} + /** * @brief I2S mclk use tx module clock * diff --git a/components/hal/esp32s3/include/hal/i2s_ll.h b/components/hal/esp32s3/include/hal/i2s_ll.h index 5e27b9352e..366d498746 100644 --- a/components/hal/esp32s3/include/hal/i2s_ll.h +++ b/components/hal/esp32s3/include/hal/i2s_ll.h @@ -1,16 +1,8 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The LL layer for I2S register operations /******************************************************************************* @@ -87,6 +79,26 @@ static inline void i2s_ll_rx_enable_clock(i2s_dev_t *hw) hw->rx_clkm_conf.rx_clk_active = 1; } +/** + * @brief Disable I2S tx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_tx_disable_clock(i2s_dev_t *hw) +{ + hw->tx_clkm_conf.tx_clk_active = 0; +} + +/** + * @brief Disable I2S rx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_rx_disable_clock(i2s_dev_t *hw) +{ + hw->rx_clkm_conf.rx_clk_active = 0; +} + /** * @brief I2S mclk use tx module clock * diff --git a/components/hal/i2s_hal.c b/components/hal/i2s_hal.c index c6e83cbe6c..66045c531a 100644 --- a/components/hal/i2s_hal.c +++ b/components/hal/i2s_hal.c @@ -100,6 +100,8 @@ void i2s_hal_tx_set_pdm_mode_default(i2s_hal_context_t *hal, uint32_t sample_rat i2s_ll_tx_enable_clock(hal->dev); i2s_ll_tx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default i2s_ll_mclk_use_tx_clk(hal->dev); + /* Still need to enable the first 2 TDM channel mask to get the correct number of frame */ + i2s_ll_tx_set_active_chan_mask(hal->dev, I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1); #else i2s_ll_tx_force_enable_fifo_mod(hal->dev, true); #endif @@ -146,6 +148,8 @@ void i2s_hal_rx_set_pdm_mode_default(i2s_hal_context_t *hal) i2s_ll_rx_enable_clock(hal->dev); i2s_ll_rx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default i2s_ll_mclk_use_rx_clk(hal->dev); + /* Still need to enable the first 2 TDM channel mask to get the correct number of frame */ + i2s_ll_rx_set_active_chan_mask(hal->dev, I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1); #else i2s_ll_rx_force_enable_fifo_mod(hal->dev, true); #endif @@ -327,3 +331,35 @@ void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_hal_config_t *hal_cf } } } + +void i2s_hal_start_tx(i2s_hal_context_t *hal) +{ +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_tx_enable_clock(hal->dev); +#endif + i2s_ll_tx_start(hal->dev); +} + +void i2s_hal_start_rx(i2s_hal_context_t *hal) +{ +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_enable_clock(hal->dev); +#endif + i2s_ll_rx_start(hal->dev); +} + +void i2s_hal_stop_tx(i2s_hal_context_t *hal) +{ + i2s_ll_tx_stop(hal->dev); +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_tx_disable_clock(hal->dev); +#endif +} + +void i2s_hal_stop_rx(i2s_hal_context_t *hal) +{ + i2s_ll_rx_stop(hal->dev); +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_disable_clock(hal->dev); +#endif +} diff --git a/components/hal/include/hal/i2s_hal.h b/components/hal/include/hal/i2s_hal.h index a08813db80..037970fa2b 100644 --- a/components/hal/include/hal/i2s_hal.h +++ b/components/hal/include/hal/i2s_hal.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -176,28 +168,28 @@ void i2s_hal_enable_slave_fd_mode(i2s_hal_context_t *hal); * * @param hal Context of the HAL layer */ -#define i2s_hal_start_tx(hal) i2s_ll_tx_start((hal)->dev) +void i2s_hal_start_tx(i2s_hal_context_t *hal); /** * @brief Start I2S rx * * @param hal Context of the HAL layer */ -#define i2s_hal_start_rx(hal) i2s_ll_rx_start((hal)->dev) +void i2s_hal_start_rx(i2s_hal_context_t *hal); /** * @brief Stop I2S tx * * @param hal Context of the HAL layer */ -#define i2s_hal_stop_tx(hal) i2s_ll_tx_stop((hal)->dev) +void i2s_hal_stop_tx(i2s_hal_context_t *hal); /** * @brief Stop I2S rx * * @param hal Context of the HAL layer */ -#define i2s_hal_stop_rx(hal) i2s_ll_rx_stop((hal)->dev) +void i2s_hal_stop_rx(i2s_hal_context_t *hal); /** * @brief Set the received data length to trigger `in_suc_eof` interrupt. diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md index a23531b9d0..a31daca43a 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | -| ----------------- | ----- | +| Supported Targets | ESP32 | ESP32S3 | +| ----------------- | ----- | ------- | # I2S Digital Microphone Recording Example @@ -18,7 +18,7 @@ The audio is recorded into the SDCard using WAVE file format. ### Hardware Required -* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) +* A development board with ESP32 or ESP32S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) * A USB cable for power supply and programming * A digital microphone (SPK0838HT4H PDM output was used in this example) @@ -28,17 +28,17 @@ The default GPIO configuration is the following: |Mic | GPIO | |:---------:|:------:| -| PDM Clock | GPIO22 | -| PDM Data | GPIO23 | +| PDM Clock | GPIO4 | +| PDM Data | GPIO5 | The SDCard is connected using SPI peripheral. | SPI | SDCard | GPIO | |:----:|:------:|:------:| -| MISO | DAT0 | GPIO2 | -| MOSI | CMD | GPIO15 | -| SCLK | CLK | GPIO14 | -| CS | CD | GPIO13 | +| MISO | DAT0 | GPIO17 | +| MOSI | CMD | GPIO16 | +| SCLK | CLK | GPIO18 | +| CS | CD | GPIO19 | To change the GPIO configuration, see the `Example Configuration` from the menuconfig. diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild index 9bda98a74a..74d0e40ec1 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild @@ -4,25 +4,25 @@ menu "Example Configuration" config EXAMPLE_SPI_MISO_GPIO int "SPI MISO GPIO" - default 2 + default 15 help Set the GPIO number used for MISO from SPI. config EXAMPLE_SPI_MOSI_GPIO int "SPI MOSI GPIO" - default 15 + default 14 help Set the GPIO number used for MOSI from SPI. config EXAMPLE_SPI_SCLK_GPIO int "SPI SCLK GPIO" - default 14 + default 18 help Set the GPIO number used for SCLK from SPI. config EXAMPLE_SPI_CS_GPIO int "SPI CS GPIO" - default 13 + default 19 help Set the GPIO number used for CS from SPI. @@ -50,13 +50,13 @@ menu "Example Configuration" config EXAMPLE_I2S_DATA_GPIO int "I2S Data GPIO" - default 23 + default 5 help Set the GPIO number used for transmitting/receiving data from I2S. config EXAMPLE_I2S_CLK_GPIO int "I2S Clock GPIO" - default 22 + default 4 help Set the GPIO number used for the clock line from I2S. diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index 0a2ff65800..33ca5fe985 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -25,7 +25,7 @@ static const char* TAG = "pdm_rec_example"; -#define SPI_DMA_CHAN (1) +#define SPI_DMA_CHAN SPI_DMA_CH_AUTO #define NUM_CHANNELS (1) // For mono recording only! #define SD_MOUNT_POINT "/sdcard" #define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) @@ -90,7 +90,7 @@ void mount_sdcard(void) sdmmc_card_print_info(stdout, card); } -void wavHeader(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ +void generate_wav_header(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ // See this for reference: http://soundfile.sapp.org/doc/WaveFormat/ uint32_t file_size = wav_size + WAVE_HEADER_SIZE - 8; @@ -124,7 +124,7 @@ void record_wav(uint32_t rec_time) char wav_header_fmt[WAVE_HEADER_SIZE]; uint32_t flash_rec_time = BYTE_RATE * rec_time; - wavHeader(wav_header_fmt, flash_rec_time, CONFIG_EXAMPLE_SAMPLE_RATE); + generate_wav_header(wav_header_fmt, flash_rec_time, CONFIG_EXAMPLE_SAMPLE_RATE); // First check if file exists before creating a new file. struct stat st; @@ -165,7 +165,6 @@ void record_wav(uint32_t rec_time) void init_microphone(void) { - // Set the I2S configuration as PDM and 16bits per sample i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM, @@ -175,8 +174,8 @@ void init_microphone(void) .communication_format = I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, .dma_buf_count = 8, - .dma_buf_len = 1024, - .use_apll = 1, + .dma_buf_len = 200, + .use_apll = 0, }; // Set the pinout configuration (set using menuconfig) diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 18e78a8599..65dc4a4468 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1518,7 +1518,6 @@ components/hal/esp32c3/include/hal/gpspi_flash_ll.h components/hal/esp32c3/include/hal/hmac_hal.h components/hal/esp32c3/include/hal/hmac_ll.h components/hal/esp32c3/include/hal/i2c_ll.h -components/hal/esp32c3/include/hal/i2s_ll.h components/hal/esp32c3/include/hal/interrupt_controller_ll.h components/hal/esp32c3/include/hal/ledc_ll.h components/hal/esp32c3/include/hal/memprot_ll.h @@ -1556,7 +1555,6 @@ components/hal/esp32h2/include/hal/gpspi_flash_ll.h components/hal/esp32h2/include/hal/hmac_hal.h components/hal/esp32h2/include/hal/hmac_ll.h components/hal/esp32h2/include/hal/i2c_ll.h -components/hal/esp32h2/include/hal/i2s_ll.h components/hal/esp32h2/include/hal/interrupt_controller_ll.h components/hal/esp32h2/include/hal/ledc_ll.h components/hal/esp32h2/include/hal/memprot_ll.h @@ -1635,7 +1633,6 @@ components/hal/esp32s3/include/hal/gdma_ll.h components/hal/esp32s3/include/hal/gpio_ll.h components/hal/esp32s3/include/hal/gpspi_flash_ll.h components/hal/esp32s3/include/hal/i2c_ll.h -components/hal/esp32s3/include/hal/i2s_ll.h components/hal/esp32s3/include/hal/interrupt_controller_ll.h components/hal/esp32s3/include/hal/lcd_ll.h components/hal/esp32s3/include/hal/ledc_ll.h @@ -1689,7 +1686,6 @@ components/hal/include/hal/gpio_hal.h components/hal/include/hal/gpio_types.h components/hal/include/hal/i2c_hal.h components/hal/include/hal/i2c_types.h -components/hal/include/hal/i2s_hal.h components/hal/include/hal/i2s_types.h components/hal/include/hal/interrupt_controller_hal.h components/hal/include/hal/interrupt_controller_types.h From e736c20cc98a0b0ca14929093b89587bf4cef5b5 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Thu, 19 Aug 2021 13:37:12 +0100 Subject: [PATCH 08/15] Removed unused define and added mck pin definition to i2s_pin_config Changes on the pin configuration Fixed the pin setup and minor improvements --- .../main/i2s_recorder_main.c | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index afc9272e59..655ac97804 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -8,18 +8,17 @@ */ #include #include +#include +#include +#include +#include "esp_log.h" +#include "esp_err.h" +#include "esp_system.h" +#include "esp_vfs_fat.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/i2s.h" #include "driver/gpio.h" -#include "esp_system.h" -#include -#include "esp_log.h" -#include -#include -#include "esp_err.h" -#include "esp_vfs_fat.h" -#include "driver/sdspi_host.h" #include "driver/spi_common.h" #include "sdmmc_cmd.h" #include "sdkconfig.h" @@ -27,9 +26,8 @@ static const char* TAG = "pdm_rec_example"; #define AUDIO_SAMPLE_SIZE (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE * 1024) -#define SAMPLES_NUM ((CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE/100) * 2) -#define BYTE_RATE (1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * ((CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8)) -#define FLASH_RECORD_SIZE (BYTE_RATE * CONFIG_EXAMPLE_REC_TIME)) +#define BYTE_RATE 1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8) +#define FLASH_RECORD_SIZE BYTE_RATE * CONFIG_EXAMPLE_REC_TIME #define SD_MOUNT_POINT "/sdcard" #define SPI_DMA_CHAN (1) @@ -104,7 +102,7 @@ void wavHeader(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ // See this for reference: http://soundfile.sapp.org/doc/WaveFormat/ uint32_t file_size = wav_size + WAVE_HEADER_SIZE - 8; - uint32_t byte_rate = 1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8); + uint32_t byte_rate = BYTE_RATE; const char set_wav_header[] = { 'R','I','F','F', // ChunkID @@ -154,7 +152,7 @@ void record_wav(void) // Start recording while (flash_wr_size < FLASH_RECORD_SIZE) { // Read the RAW samples from the microphone - i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, AUDIO_SAMPLE_SIZE, &bytes_read, portMAX_DELAY); + i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, AUDIO_SAMPLE_SIZE, &bytes_read, 100); // Write the samples to the WAV file fwrite(i2s_readraw_buff, 1, bytes_read, f); flash_wr_size += bytes_read; @@ -179,21 +177,24 @@ void init_microphone(void) .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, - .dma_buf_count = 64, + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, + .dma_buf_count = 8, .dma_buf_len = 1024, - .use_apll = 1 + .use_apll = 1, }; - i2s_pin_config_t pin_config; - pin_config.bck_io_num = I2S_PIN_NO_CHANGE; - pin_config.ws_io_num = CONFIG_EXAMPLE_I2S_CLK_GPIO; - pin_config.data_out_num = I2S_PIN_NO_CHANGE; - pin_config.data_in_num = CONFIG_EXAMPLE_I2S_DATA_GPIO; + i2s_pin_config_t pin_config = { + .mck_io_num = I2S_PIN_NO_CHANGE, + .bck_io_num = I2S_PIN_NO_CHANGE, + .ws_io_num = CONFIG_EXAMPLE_I2S_CLK_GPIO, + .data_out_num = I2S_PIN_NO_CHANGE, + .data_in_num = CONFIG_EXAMPLE_I2S_DATA_GPIO, + }; - i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL); - i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config); - i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); + ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); + ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); + // Set the I2S clock using the sample rate divided by 2 if channel is mono + ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } void app_main(void) From 4bd057013d589edf252d591193b961bfdc3d4fc9 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Wed, 25 Aug 2021 11:51:27 +0100 Subject: [PATCH 09/15] Added driver unistall function for I2S --- .../i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index 655ac97804..f7ad8e9ee8 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -178,7 +178,7 @@ void init_microphone(void) .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, - .dma_buf_count = 8, + .dma_buf_count = 16, .dma_buf_len = 1024, .use_apll = 1, }; @@ -191,9 +191,9 @@ void init_microphone(void) .data_in_num = CONFIG_EXAMPLE_I2S_DATA_GPIO, }; + // Call driver installation function before any I2S R/W operation. ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); - // Set the I2S clock using the sample rate divided by 2 if channel is mono ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } @@ -207,4 +207,6 @@ void app_main(void) ESP_LOGI(TAG, "Starting recording for %d seconds!", CONFIG_EXAMPLE_REC_TIME); // Start Recording record_wav(); + // Stop I2S driver and destroy + ESP_ERROR_CHECK( i2s_driver_uninstall(CONFIG_EXAMPLE_I2S_CH) ); } From 389db51f25553ea8ee4f21b84c3684a8ecd19b07 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Wed, 25 Aug 2021 12:09:57 +0100 Subject: [PATCH 10/15] Changes on the recording function --- .../main/Kconfig.projbuild | 4 +- .../main/i2s_recorder_main.c | 58 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild index a23430d67e..9bda98a74a 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild @@ -36,13 +36,13 @@ menu "Example Configuration" help Set the I2S channel number. - config EXAMPLE_AUDIO_SAMPLE_RATE + config EXAMPLE_SAMPLE_RATE int "Audio Sample Rate" default 44100 help Set the audio sample rate frequency. Usually 16000 or 44100 Hz. - config EXAMPLE_AUDIO_BIT_SAMPLE + config EXAMPLE_BIT_SAMPLE int "Audio Bit Sample" default 16 help diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index f7ad8e9ee8..82fdf23f5d 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -25,11 +25,10 @@ static const char* TAG = "pdm_rec_example"; -#define AUDIO_SAMPLE_SIZE (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE * 1024) -#define BYTE_RATE 1 * CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE * (CONFIG_EXAMPLE_AUDIO_BIT_SAMPLE / 8) -#define FLASH_RECORD_SIZE BYTE_RATE * CONFIG_EXAMPLE_REC_TIME -#define SD_MOUNT_POINT "/sdcard" #define SPI_DMA_CHAN (1) +#define SD_MOUNT_POINT "/sdcard" +#define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) +#define BYTE_RATE 1 * CONFIG_EXAMPLE_SAMPLE_RATE * (CONFIG_EXAMPLE_BIT_SAMPLE / 8) // When testing SD and SPI modes, keep in mind that once the card has been // initialized in SPI mode, it can not be reinitialized in SD mode without @@ -37,7 +36,7 @@ static const char* TAG = "pdm_rec_example"; sdmmc_host_t host = SDSPI_HOST_DEFAULT(); sdmmc_card_t* card; -static int16_t i2s_readraw_buff[AUDIO_SAMPLE_SIZE]; +static int16_t i2s_readraw_buff[SAMPLE_SIZE]; size_t bytes_read; const int WAVE_HEADER_SIZE = 44; @@ -104,33 +103,35 @@ void wavHeader(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ uint32_t file_size = wav_size + WAVE_HEADER_SIZE - 8; uint32_t byte_rate = BYTE_RATE; -const char set_wav_header[] = { - 'R','I','F','F', // ChunkID - file_size, file_size >> 8, file_size >> 16, file_size >> 24, // ChunkSize - 'W','A','V','E', // Format - 'f','m','t',' ', // Subchunk1ID - 0x10, 0x00, 0x00, 0x00, // Subchunk1Size (16 for PCM) - 0x01, 0x00, // AudioFormat (1 for PCM) - 0x01, 0x00, // NumChannels (1 channel) - sample_rate, sample_rate >> 8, sample_rate >> 16, sample_rate >> 24, // SampleRate - byte_rate, byte_rate >> 8, byte_rate >> 16, byte_rate >> 24, // ByteRate - 0x02, 0x00, // BlockAlign - 0x10, 0x00, // BitsPerSample (16 bits) - 'd','a','t','a', // Subchunk2ID - wav_size, wav_size >> 8, wav_size >> 16, wav_size >> 24, // Subchunk2Size -}; + const char set_wav_header[] = { + 'R','I','F','F', // ChunkID + file_size, file_size >> 8, file_size >> 16, file_size >> 24, // ChunkSize + 'W','A','V','E', // Format + 'f','m','t',' ', // Subchunk1ID + 0x10, 0x00, 0x00, 0x00, // Subchunk1Size (16 for PCM) + 0x01, 0x00, // AudioFormat (1 for PCM) + 0x01, 0x00, // NumChannels (1 channel) + sample_rate, sample_rate >> 8, sample_rate >> 16, sample_rate >> 24, // SampleRate + byte_rate, byte_rate >> 8, byte_rate >> 16, byte_rate >> 24, // ByteRate + 0x02, 0x00, // BlockAlign + 0x10, 0x00, // BitsPerSample (16 bits) + 'd','a','t','a', // Subchunk2ID + wav_size, wav_size >> 8, wav_size >> 16, wav_size >> 24, // Subchunk2Size + }; memcpy(wav_header, set_wav_header, sizeof(set_wav_header)); } -void record_wav(void) +void record_wav(uint32_t rec_time) { // Use POSIX and C standard library functions to work with files. int flash_wr_size = 0; ESP_LOGI(TAG, "Opening file"); char wav_header_fmt[WAVE_HEADER_SIZE]; - wavHeader(wav_header_fmt, FLASH_RECORD_SIZE, CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE); + + uint32_t flash_rec_time = BYTE_RATE * rec_time; + wavHeader(wav_header_fmt, flash_rec_time, CONFIG_EXAMPLE_SAMPLE_RATE); // First check if file exists before creating a new file. struct stat st; @@ -150,9 +151,9 @@ void record_wav(void) fwrite(wav_header_fmt, 1, WAVE_HEADER_SIZE, f); // Start recording - while (flash_wr_size < FLASH_RECORD_SIZE) { + while (flash_wr_size < flash_rec_time) { // Read the RAW samples from the microphone - i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, AUDIO_SAMPLE_SIZE, &bytes_read, 100); + i2s_read(CONFIG_EXAMPLE_I2S_CH, (char *)i2s_readraw_buff, SAMPLE_SIZE, &bytes_read, 100); // Write the samples to the WAV file fwrite(i2s_readraw_buff, 1, bytes_read, f); flash_wr_size += bytes_read; @@ -171,9 +172,11 @@ void record_wav(void) void init_microphone(void) { + + // Set the I2S configuration as PDM 16bits per sample i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM, - .sample_rate = CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE, + .sample_rate = CONFIG_EXAMPLE_SAMPLE_RATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, @@ -183,6 +186,7 @@ void init_microphone(void) .use_apll = 1, }; + // Set the pinout configuration (set using menuconfig) i2s_pin_config_t pin_config = { .mck_io_num = I2S_PIN_NO_CHANGE, .bck_io_num = I2S_PIN_NO_CHANGE, @@ -194,7 +198,7 @@ void init_microphone(void) // Call driver installation function before any I2S R/W operation. ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); - ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_AUDIO_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); + ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } void app_main(void) @@ -206,7 +210,7 @@ void app_main(void) init_microphone(); ESP_LOGI(TAG, "Starting recording for %d seconds!", CONFIG_EXAMPLE_REC_TIME); // Start Recording - record_wav(); + record_wav(CONFIG_EXAMPLE_REC_TIME); // Stop I2S driver and destroy ESP_ERROR_CHECK( i2s_driver_uninstall(CONFIG_EXAMPLE_I2S_CH) ); } From a21225d86dd626126e285b0eef6f72eedfb05105 Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Mon, 13 Sep 2021 10:07:19 +0100 Subject: [PATCH 11/15] Rebase and removed the sample rate division by 2 --- .../main/i2s_recorder_main.c | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index 82fdf23f5d..0a2ff65800 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -25,10 +25,11 @@ static const char* TAG = "pdm_rec_example"; -#define SPI_DMA_CHAN (1) -#define SD_MOUNT_POINT "/sdcard" -#define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) -#define BYTE_RATE 1 * CONFIG_EXAMPLE_SAMPLE_RATE * (CONFIG_EXAMPLE_BIT_SAMPLE / 8) +#define SPI_DMA_CHAN (1) +#define NUM_CHANNELS (1) // For mono recording only! +#define SD_MOUNT_POINT "/sdcard" +#define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) +#define BYTE_RATE (CONFIG_EXAMPLE_SAMPLE_RATE * (CONFIG_EXAMPLE_BIT_SAMPLE / 8)) * NUM_CHANNELS // When testing SD and SPI modes, keep in mind that once the card has been // initialized in SPI mode, it can not be reinitialized in SD mode without @@ -49,17 +50,10 @@ void mount_sdcard(void) esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = true, .max_files = 5, - .allocation_unit_size = 16 * 1024 + .allocation_unit_size = 8 * 1024 }; ESP_LOGI(TAG, "Initializing SD card"); - // Use settings defined above to initialize SD card and mount FAT filesystem. - // Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions. - // Please check its source code and implement error recovery when developing - // production applications. - - ESP_LOGI(TAG, "Using SPI peripheral"); - spi_bus_config_t bus_cfg = { .mosi_io_num = CONFIG_EXAMPLE_SPI_MOSI_GPIO, .miso_io_num = CONFIG_EXAMPLE_SPI_MISO_GPIO, @@ -84,8 +78,7 @@ void mount_sdcard(void) if (ret != ESP_OK) { if (ret == ESP_FAIL) { - ESP_LOGE(TAG, "Failed to mount filesystem. " - "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option."); + ESP_LOGE(TAG, "Failed to mount filesystem."); } else { ESP_LOGE(TAG, "Failed to initialize the card (%s). " "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret)); @@ -173,7 +166,7 @@ void record_wav(uint32_t rec_time) void init_microphone(void) { - // Set the I2S configuration as PDM 16bits per sample + // Set the I2S configuration as PDM and 16bits per sample i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM, .sample_rate = CONFIG_EXAMPLE_SAMPLE_RATE, @@ -181,7 +174,7 @@ void init_microphone(void) .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, - .dma_buf_count = 16, + .dma_buf_count = 8, .dma_buf_len = 1024, .use_apll = 1, }; @@ -198,7 +191,7 @@ void init_microphone(void) // Call driver installation function before any I2S R/W operation. ESP_ERROR_CHECK( i2s_driver_install(CONFIG_EXAMPLE_I2S_CH, &i2s_config, 0, NULL) ); ESP_ERROR_CHECK( i2s_set_pin(CONFIG_EXAMPLE_I2S_CH, &pin_config) ); - ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, (CONFIG_EXAMPLE_SAMPLE_RATE / 2), I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); + ESP_ERROR_CHECK( i2s_set_clk(CONFIG_EXAMPLE_I2S_CH, CONFIG_EXAMPLE_SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO) ); } void app_main(void) From 1327a563697f0b6aaf1341760f6b050f734be16d Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Sun, 26 Sep 2021 11:37:37 +0800 Subject: [PATCH 12/15] i2s: fix the param check on PDM mode Closes https://github.com/espressif/esp-idf/issues/7604 --- components/driver/i2s.c | 4 ++-- examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/driver/i2s.c b/components/driver/i2s.c index 0eb50e4738..8fda8d7864 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -1550,10 +1550,10 @@ static esp_err_t i2s_check_cfg_validity(i2s_port_t i2s_num, i2s_hal_config_t *cf if (cfg->mode & I2S_MODE_PDM) { ESP_RETURN_ON_FALSE(i2s_num == I2S_NUM_0, ESP_ERR_INVALID_ARG, TAG, "I2S PDM mode only support on I2S0"); #if !SOC_I2S_SUPPORTS_PDM_TX - ESP_RETURN_ON_FALSE(cfg->mode & I2S_MODE_TX, ESP_ERR_INVALID_ARG, TAG, "PDM does not support TX on this chip"); + ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_TX), ESP_ERR_INVALID_ARG, TAG, "PDM does not support TX on this chip"); #endif // SOC_I2S_SUPPORTS_PDM_TX #if !SOC_I2S_SUPPORTS_PDM_RX - ESP_RETURN_ON_FALSE(cfg->mode & I2S_MODE_RX, ESP_ERR_INVALID_ARG, TAG, "PDM does not support RX on this chip"); + ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_RX), ESP_ERR_INVALID_ARG, TAG, "PDM does not support RX on this chip"); #endif // SOC_I2S_SUPPORTS_PDM_RX } #else diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md index 85b254b2df..a23531b9d0 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md @@ -80,8 +80,8 @@ I (401) I2S: APLL: Req RATE: 44100, real rate: 88199.977, BITS: 16, CLKM: 1, BCK I (431) I2S: APLL: Req RATE: 44100, real rate: 88199.977, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 22579194.000, SCLK: 2822399.250000, diva: 1, divb: 0 I (431) pdm_rec_example: Initializing SD card I (431) pdm_rec_example: Using SDMMC peripheral -I (441) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -Name: USD +I (441) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 +Name: USD Type: SDHC/SDXC Speed: 20 MHz Size: 3813MB From f397379c8d722e0cf1d05ab6d54f12e07dc88024 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Tue, 28 Sep 2021 12:02:07 +0800 Subject: [PATCH 13/15] i2s: fix the mono mode of PDM on esp32 --- components/hal/i2s_hal.c | 39 ++++++++++++++++++----------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/components/hal/i2s_hal.c b/components/hal/i2s_hal.c index edb2660590..c6e83cbe6c 100644 --- a/components/hal/i2s_hal.c +++ b/components/hal/i2s_hal.c @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The HAL layer for I2S (common part) @@ -104,6 +96,13 @@ void i2s_hal_tx_set_pdm_mode_default(i2s_hal_context_t *hal, uint32_t sample_rat { /* enable pdm tx mode */ i2s_ll_tx_enable_pdm(hal->dev, true); +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_tx_enable_clock(hal->dev); + i2s_ll_tx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default + i2s_ll_mclk_use_tx_clk(hal->dev); +#else + i2s_ll_tx_force_enable_fifo_mod(hal->dev, true); +#endif /* set pdm tx default presacle */ i2s_ll_tx_set_pdm_prescale(hal->dev, 0); /* set pdm tx default sacle of high pass filter */ @@ -140,6 +139,16 @@ void i2s_hal_rx_set_pdm_mode_default(i2s_hal_context_t *hal) i2s_ll_rx_enable_pdm(hal->dev, true); /* set pdm rx downsample number */ i2s_ll_rx_set_pdm_dsr(hal->dev, I2S_PDM_DSR_8S); +#if !SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_force_enable_fifo_mod(hal->dev, true); +#endif +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_enable_clock(hal->dev); + i2s_ll_rx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default + i2s_ll_mclk_use_rx_clk(hal->dev); +#else + i2s_ll_rx_force_enable_fifo_mod(hal->dev, true); +#endif } #endif // SOC_I2S_SUPPORTS_PDM_RX @@ -286,8 +295,8 @@ void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_hal_config_t *hal_cf { /* Set tx common mode */ i2s_hal_tx_set_common_mode(hal, hal_cfg); - i2s_hal_tx_set_channel_style(hal, hal_cfg); } + i2s_hal_tx_set_channel_style(hal, hal_cfg); } /* Set configurations for RX mode */ @@ -304,8 +313,8 @@ void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_hal_config_t *hal_cf { /* Set rx common mode */ i2s_hal_rx_set_common_mode(hal, hal_cfg); - i2s_hal_rx_set_channel_style(hal, hal_cfg); } + i2s_hal_rx_set_channel_style(hal, hal_cfg); } /* Set configurations for full-duplex mode */ diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 167af07dca..14211d7990 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1669,7 +1669,6 @@ components/hal/gdma_hal.c components/hal/gpio_hal.c components/hal/i2c_hal.c components/hal/i2c_hal_iram.c -components/hal/i2s_hal.c components/hal/include/hal/adc_hal.h components/hal/include/hal/adc_types.h components/hal/include/hal/aes_hal.h From 7264c0e59a0c4f39714a4de4c33f3fd41c8c8c93 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Tue, 28 Sep 2021 12:04:34 +0800 Subject: [PATCH 14/15] i2s_rec_example: add support for esp32s3 --- components/hal/esp32c3/include/hal/i2s_ll.h | 38 ++++++++++++------- components/hal/esp32h2/include/hal/i2s_ll.h | 38 ++++++++++++------- components/hal/esp32s3/include/hal/i2s_ll.h | 38 ++++++++++++------- components/hal/i2s_hal.c | 36 ++++++++++++++++++ components/hal/include/hal/i2s_hal.h | 26 +++++-------- .../i2s/i2s_audio_recorder_sdcard/README.md | 18 ++++----- .../main/Kconfig.projbuild | 12 +++--- .../main/i2s_recorder_main.c | 11 +++--- tools/ci/check_copyright_ignore.txt | 4 -- 9 files changed, 140 insertions(+), 81 deletions(-) diff --git a/components/hal/esp32c3/include/hal/i2s_ll.h b/components/hal/esp32c3/include/hal/i2s_ll.h index 670db91616..0cfb05a266 100644 --- a/components/hal/esp32c3/include/hal/i2s_ll.h +++ b/components/hal/esp32c3/include/hal/i2s_ll.h @@ -1,16 +1,8 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The LL layer for I2S register operations /******************************************************************************* @@ -86,6 +78,26 @@ static inline void i2s_ll_rx_enable_clock(i2s_dev_t *hw) hw->rx_clkm_conf.rx_clk_active = 1; } +/** + * @brief Disable I2S tx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_tx_disable_clock(i2s_dev_t *hw) +{ + hw->tx_clkm_conf.tx_clk_active = 0; +} + +/** + * @brief Disable I2S rx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_rx_disable_clock(i2s_dev_t *hw) +{ + hw->rx_clkm_conf.rx_clk_active = 0; +} + /** * @brief I2S mclk use tx module clock * diff --git a/components/hal/esp32h2/include/hal/i2s_ll.h b/components/hal/esp32h2/include/hal/i2s_ll.h index e241ac2185..365362479c 100644 --- a/components/hal/esp32h2/include/hal/i2s_ll.h +++ b/components/hal/esp32h2/include/hal/i2s_ll.h @@ -1,16 +1,8 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -87,6 +79,26 @@ static inline void i2s_ll_rx_enable_clock(i2s_dev_t *hw) hw->rx_clkm_conf.rx_clk_active = 1; } +/** + * @brief Disable I2S tx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_tx_disable_clock(i2s_dev_t *hw) +{ + hw->tx_clkm_conf.tx_clk_active = 0; +} + +/** + * @brief Disable I2S rx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_rx_disable_clock(i2s_dev_t *hw) +{ + hw->rx_clkm_conf.rx_clk_active = 0; +} + /** * @brief I2S mclk use tx module clock * diff --git a/components/hal/esp32s3/include/hal/i2s_ll.h b/components/hal/esp32s3/include/hal/i2s_ll.h index 5e27b9352e..366d498746 100644 --- a/components/hal/esp32s3/include/hal/i2s_ll.h +++ b/components/hal/esp32s3/include/hal/i2s_ll.h @@ -1,16 +1,8 @@ -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The LL layer for I2S register operations /******************************************************************************* @@ -87,6 +79,26 @@ static inline void i2s_ll_rx_enable_clock(i2s_dev_t *hw) hw->rx_clkm_conf.rx_clk_active = 1; } +/** + * @brief Disable I2S tx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_tx_disable_clock(i2s_dev_t *hw) +{ + hw->tx_clkm_conf.tx_clk_active = 0; +} + +/** + * @brief Disable I2S rx module clock + * + * @param hw Peripheral I2S hardware instance address. + */ +static inline void i2s_ll_rx_disable_clock(i2s_dev_t *hw) +{ + hw->rx_clkm_conf.rx_clk_active = 0; +} + /** * @brief I2S mclk use tx module clock * diff --git a/components/hal/i2s_hal.c b/components/hal/i2s_hal.c index c6e83cbe6c..66045c531a 100644 --- a/components/hal/i2s_hal.c +++ b/components/hal/i2s_hal.c @@ -100,6 +100,8 @@ void i2s_hal_tx_set_pdm_mode_default(i2s_hal_context_t *hal, uint32_t sample_rat i2s_ll_tx_enable_clock(hal->dev); i2s_ll_tx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default i2s_ll_mclk_use_tx_clk(hal->dev); + /* Still need to enable the first 2 TDM channel mask to get the correct number of frame */ + i2s_ll_tx_set_active_chan_mask(hal->dev, I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1); #else i2s_ll_tx_force_enable_fifo_mod(hal->dev, true); #endif @@ -146,6 +148,8 @@ void i2s_hal_rx_set_pdm_mode_default(i2s_hal_context_t *hal) i2s_ll_rx_enable_clock(hal->dev); i2s_ll_rx_clk_set_src(hal->dev, I2S_CLK_D2CLK); // Set I2S_CLK_D2CLK as default i2s_ll_mclk_use_rx_clk(hal->dev); + /* Still need to enable the first 2 TDM channel mask to get the correct number of frame */ + i2s_ll_rx_set_active_chan_mask(hal->dev, I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1); #else i2s_ll_rx_force_enable_fifo_mod(hal->dev, true); #endif @@ -327,3 +331,35 @@ void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_hal_config_t *hal_cf } } } + +void i2s_hal_start_tx(i2s_hal_context_t *hal) +{ +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_tx_enable_clock(hal->dev); +#endif + i2s_ll_tx_start(hal->dev); +} + +void i2s_hal_start_rx(i2s_hal_context_t *hal) +{ +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_enable_clock(hal->dev); +#endif + i2s_ll_rx_start(hal->dev); +} + +void i2s_hal_stop_tx(i2s_hal_context_t *hal) +{ + i2s_ll_tx_stop(hal->dev); +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_tx_disable_clock(hal->dev); +#endif +} + +void i2s_hal_stop_rx(i2s_hal_context_t *hal) +{ + i2s_ll_rx_stop(hal->dev); +#if SOC_I2S_SUPPORTS_TDM + i2s_ll_rx_disable_clock(hal->dev); +#endif +} diff --git a/components/hal/include/hal/i2s_hal.h b/components/hal/include/hal/i2s_hal.h index a08813db80..037970fa2b 100644 --- a/components/hal/include/hal/i2s_hal.h +++ b/components/hal/include/hal/i2s_hal.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -176,28 +168,28 @@ void i2s_hal_enable_slave_fd_mode(i2s_hal_context_t *hal); * * @param hal Context of the HAL layer */ -#define i2s_hal_start_tx(hal) i2s_ll_tx_start((hal)->dev) +void i2s_hal_start_tx(i2s_hal_context_t *hal); /** * @brief Start I2S rx * * @param hal Context of the HAL layer */ -#define i2s_hal_start_rx(hal) i2s_ll_rx_start((hal)->dev) +void i2s_hal_start_rx(i2s_hal_context_t *hal); /** * @brief Stop I2S tx * * @param hal Context of the HAL layer */ -#define i2s_hal_stop_tx(hal) i2s_ll_tx_stop((hal)->dev) +void i2s_hal_stop_tx(i2s_hal_context_t *hal); /** * @brief Stop I2S rx * * @param hal Context of the HAL layer */ -#define i2s_hal_stop_rx(hal) i2s_ll_rx_stop((hal)->dev) +void i2s_hal_stop_rx(i2s_hal_context_t *hal); /** * @brief Set the received data length to trigger `in_suc_eof` interrupt. diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md index a23531b9d0..a31daca43a 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | -| ----------------- | ----- | +| Supported Targets | ESP32 | ESP32S3 | +| ----------------- | ----- | ------- | # I2S Digital Microphone Recording Example @@ -18,7 +18,7 @@ The audio is recorded into the SDCard using WAVE file format. ### Hardware Required -* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) +* A development board with ESP32 or ESP32S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) * A USB cable for power supply and programming * A digital microphone (SPK0838HT4H PDM output was used in this example) @@ -28,17 +28,17 @@ The default GPIO configuration is the following: |Mic | GPIO | |:---------:|:------:| -| PDM Clock | GPIO22 | -| PDM Data | GPIO23 | +| PDM Clock | GPIO4 | +| PDM Data | GPIO5 | The SDCard is connected using SPI peripheral. | SPI | SDCard | GPIO | |:----:|:------:|:------:| -| MISO | DAT0 | GPIO2 | -| MOSI | CMD | GPIO15 | -| SCLK | CLK | GPIO14 | -| CS | CD | GPIO13 | +| MISO | DAT0 | GPIO17 | +| MOSI | CMD | GPIO16 | +| SCLK | CLK | GPIO18 | +| CS | CD | GPIO19 | To change the GPIO configuration, see the `Example Configuration` from the menuconfig. diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild index 9bda98a74a..74d0e40ec1 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/Kconfig.projbuild @@ -4,25 +4,25 @@ menu "Example Configuration" config EXAMPLE_SPI_MISO_GPIO int "SPI MISO GPIO" - default 2 + default 15 help Set the GPIO number used for MISO from SPI. config EXAMPLE_SPI_MOSI_GPIO int "SPI MOSI GPIO" - default 15 + default 14 help Set the GPIO number used for MOSI from SPI. config EXAMPLE_SPI_SCLK_GPIO int "SPI SCLK GPIO" - default 14 + default 18 help Set the GPIO number used for SCLK from SPI. config EXAMPLE_SPI_CS_GPIO int "SPI CS GPIO" - default 13 + default 19 help Set the GPIO number used for CS from SPI. @@ -50,13 +50,13 @@ menu "Example Configuration" config EXAMPLE_I2S_DATA_GPIO int "I2S Data GPIO" - default 23 + default 5 help Set the GPIO number used for transmitting/receiving data from I2S. config EXAMPLE_I2S_CLK_GPIO int "I2S Clock GPIO" - default 22 + default 4 help Set the GPIO number used for the clock line from I2S. diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c index 0a2ff65800..33ca5fe985 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c @@ -25,7 +25,7 @@ static const char* TAG = "pdm_rec_example"; -#define SPI_DMA_CHAN (1) +#define SPI_DMA_CHAN SPI_DMA_CH_AUTO #define NUM_CHANNELS (1) // For mono recording only! #define SD_MOUNT_POINT "/sdcard" #define SAMPLE_SIZE (CONFIG_EXAMPLE_BIT_SAMPLE * 1024) @@ -90,7 +90,7 @@ void mount_sdcard(void) sdmmc_card_print_info(stdout, card); } -void wavHeader(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ +void generate_wav_header(char* wav_header, uint32_t wav_size, uint32_t sample_rate){ // See this for reference: http://soundfile.sapp.org/doc/WaveFormat/ uint32_t file_size = wav_size + WAVE_HEADER_SIZE - 8; @@ -124,7 +124,7 @@ void record_wav(uint32_t rec_time) char wav_header_fmt[WAVE_HEADER_SIZE]; uint32_t flash_rec_time = BYTE_RATE * rec_time; - wavHeader(wav_header_fmt, flash_rec_time, CONFIG_EXAMPLE_SAMPLE_RATE); + generate_wav_header(wav_header_fmt, flash_rec_time, CONFIG_EXAMPLE_SAMPLE_RATE); // First check if file exists before creating a new file. struct stat st; @@ -165,7 +165,6 @@ void record_wav(uint32_t rec_time) void init_microphone(void) { - // Set the I2S configuration as PDM and 16bits per sample i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM, @@ -175,8 +174,8 @@ void init_microphone(void) .communication_format = I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, .dma_buf_count = 8, - .dma_buf_len = 1024, - .use_apll = 1, + .dma_buf_len = 200, + .use_apll = 0, }; // Set the pinout configuration (set using menuconfig) diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 14211d7990..81e3c3ac7d 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1517,7 +1517,6 @@ components/hal/esp32c3/include/hal/gpspi_flash_ll.h components/hal/esp32c3/include/hal/hmac_hal.h components/hal/esp32c3/include/hal/hmac_ll.h components/hal/esp32c3/include/hal/i2c_ll.h -components/hal/esp32c3/include/hal/i2s_ll.h components/hal/esp32c3/include/hal/interrupt_controller_ll.h components/hal/esp32c3/include/hal/ledc_ll.h components/hal/esp32c3/include/hal/memprot_ll.h @@ -1555,7 +1554,6 @@ components/hal/esp32h2/include/hal/gpspi_flash_ll.h components/hal/esp32h2/include/hal/hmac_hal.h components/hal/esp32h2/include/hal/hmac_ll.h components/hal/esp32h2/include/hal/i2c_ll.h -components/hal/esp32h2/include/hal/i2s_ll.h components/hal/esp32h2/include/hal/interrupt_controller_ll.h components/hal/esp32h2/include/hal/ledc_ll.h components/hal/esp32h2/include/hal/memprot_ll.h @@ -1634,7 +1632,6 @@ components/hal/esp32s3/include/hal/gdma_ll.h components/hal/esp32s3/include/hal/gpio_ll.h components/hal/esp32s3/include/hal/gpspi_flash_ll.h components/hal/esp32s3/include/hal/i2c_ll.h -components/hal/esp32s3/include/hal/i2s_ll.h components/hal/esp32s3/include/hal/interrupt_controller_ll.h components/hal/esp32s3/include/hal/lcd_ll.h components/hal/esp32s3/include/hal/ledc_ll.h @@ -1688,7 +1685,6 @@ components/hal/include/hal/gpio_hal.h components/hal/include/hal/gpio_types.h components/hal/include/hal/i2c_hal.h components/hal/include/hal/i2c_types.h -components/hal/include/hal/i2s_hal.h components/hal/include/hal/i2s_types.h components/hal/include/hal/interrupt_controller_hal.h components/hal/include/hal/interrupt_controller_types.h From 5144458905a8a7a849a90bef2bccc7bd8f2ce6fb Mon Sep 17 00:00:00 2001 From: "pedro.minatel" Date: Mon, 4 Oct 2021 10:44:49 +0100 Subject: [PATCH 15/15] Fix on the readme file for the supported devices --- examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md index a31daca43a..010fc702b5 100644 --- a/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md +++ b/examples/peripherals/i2s/i2s_audio_recorder_sdcard/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32S3 | -| ----------------- | ----- | ------- | +| Supported Targets | ESP32 | ESP32-S3 | +| ----------------- | ----- | -------- | # I2S Digital Microphone Recording Example