mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
i2s_rec_example: add support for esp32s3
This commit is contained in:
parent
b7b76cbe15
commit
1d7bf0f188
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user