mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-11 21:10:20 +00:00
refactor(i2s): refactor i2s examples common dependencies
Closes https://github.com/espressif/esp-idf/issues/14751 Make the common I2S dependencies as an example common component, so that to avoid slash & backslash issue on windows when use absolute include path.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# register I2S common dependencies as a component
|
||||
idf_component_register(INCLUDE_DIRS ".")
|
73
examples/peripherals/i2s/i2s_examples_common/format_wav.h
Normal file
73
examples/peripherals/i2s/i2s_examples_common/format_wav.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Header structure for WAV file with only one data chunk
|
||||
*
|
||||
* @note See this for reference: http://soundfile.sapp.org/doc/WaveFormat/
|
||||
*
|
||||
* @note Assignment to variables in this struct directly is only possible for little endian architectures
|
||||
* (including Xtensa & RISC-V)
|
||||
*/
|
||||
typedef struct {
|
||||
struct {
|
||||
char chunk_id[4]; /*!< Contains the letters "RIFF" in ASCII form */
|
||||
uint32_t chunk_size; /*!< This is the size of the rest of the chunk following this number */
|
||||
char chunk_format[4]; /*!< Contains the letters "WAVE" */
|
||||
} descriptor_chunk; /*!< Canonical WAVE format starts with the RIFF header */
|
||||
struct {
|
||||
char subchunk_id[4]; /*!< Contains the letters "fmt " */
|
||||
uint32_t subchunk_size; /*!< This is the size of the rest of the Subchunk which follows this number */
|
||||
uint16_t audio_format; /*!< PCM = 1, values other than 1 indicate some form of compression */
|
||||
uint16_t num_of_channels; /*!< Mono = 1, Stereo = 2, etc. */
|
||||
uint32_t sample_rate; /*!< 8000, 44100, etc. */
|
||||
uint32_t byte_rate; /*!< ==SampleRate * NumChannels * BitsPerSample s/ 8 */
|
||||
uint16_t block_align; /*!< ==NumChannels * BitsPerSample / 8 */
|
||||
uint16_t bits_per_sample; /*!< 8 bits = 8, 16 bits = 16, etc. */
|
||||
} fmt_chunk; /*!< The "fmt " subchunk describes the sound data's format */
|
||||
struct {
|
||||
char subchunk_id[4]; /*!< Contains the letters "data" */
|
||||
uint32_t subchunk_size; /*!< ==NumSamples * NumChannels * BitsPerSample / 8 */
|
||||
int16_t data[0]; /*!< Holds raw audio data */
|
||||
} data_chunk; /*!< The "data" subchunk contains the size of the data and the actual sound */
|
||||
} wav_header_t;
|
||||
|
||||
/**
|
||||
* @brief Default header for PCM format WAV files
|
||||
*
|
||||
*/
|
||||
#define WAV_HEADER_PCM_DEFAULT(wav_sample_size, wav_sample_bits, wav_sample_rate, wav_channel_num) { \
|
||||
.descriptor_chunk = { \
|
||||
.chunk_id = {'R', 'I', 'F', 'F'}, \
|
||||
.chunk_size = (wav_sample_size) + sizeof(wav_header_t) - 8, \
|
||||
.chunk_format = {'W', 'A', 'V', 'E'} \
|
||||
}, \
|
||||
.fmt_chunk = { \
|
||||
.subchunk_id = {'f', 'm', 't', ' '}, \
|
||||
.subchunk_size = 16, /* 16 for PCM */ \
|
||||
.audio_format = 1, /* 1 for PCM */ \
|
||||
.num_of_channels = (wav_channel_num), \
|
||||
.sample_rate = (wav_sample_rate), \
|
||||
.byte_rate = (wav_sample_bits) * (wav_sample_rate) * (wav_channel_num) / 8, \
|
||||
.block_align = (wav_sample_bits) * (wav_channel_num) / 8, \
|
||||
.bits_per_sample = (wav_sample_bits)\
|
||||
}, \
|
||||
.data_chunk = { \
|
||||
.subchunk_id = {'d', 'a', 't', 'a'}, \
|
||||
.subchunk_size = (wav_sample_size) \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define EXAMPLE_I2S_BCLK_IO1 GPIO_NUM_4 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO1 GPIO_NUM_5 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO1 GPIO_NUM_18 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO1 GPIO_NUM_19 // I2S data in io number
|
||||
// STD simplex pins
|
||||
#define EXAMPLE_I2S_BCLK_IO2 GPIO_NUM_22 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO2 GPIO_NUM_23 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO2 GPIO_NUM_25 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO2 GPIO_NUM_26 // I2S data in io number
|
||||
|
||||
#elif CONFIG_IDF_TARGET_ESP32P4
|
||||
#define EXAMPLE_I2S_BCLK_IO1 GPIO_NUM_45 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO1 GPIO_NUM_46 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO1 GPIO_NUM_47 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO1 GPIO_NUM_48 // I2S data in io number
|
||||
// PDM RX 4 line IO
|
||||
#define EXAMPLE_I2S_DIN1_IO1 GPIO_NUM_20 // I2S data in io number
|
||||
#define EXAMPLE_I2S_DIN2_IO1 GPIO_NUM_21 // I2S data in io number
|
||||
#define EXAMPLE_I2S_DIN3_IO1 GPIO_NUM_22 // I2S data in io number
|
||||
// STD/TDM simplex pins
|
||||
#define EXAMPLE_I2S_BCLK_IO2 GPIO_NUM_20 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO2 GPIO_NUM_21 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO2 GPIO_NUM_22 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO2 GPIO_NUM_23 // I2S data in io number
|
||||
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define EXAMPLE_I2S_BCLK_IO1 GPIO_NUM_2 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO1 GPIO_NUM_3 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO1 GPIO_NUM_4 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO1 GPIO_NUM_5 // I2S data in io number
|
||||
// PDM RX 4 line IO
|
||||
#define EXAMPLE_I2S_DIN1_IO1 GPIO_NUM_6 // I2S data in io number
|
||||
#define EXAMPLE_I2S_DIN2_IO1 GPIO_NUM_7 // I2S data in io number
|
||||
#define EXAMPLE_I2S_DIN3_IO1 GPIO_NUM_8 // I2S data in io number
|
||||
// STD/TDM simplex pins
|
||||
#define EXAMPLE_I2S_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO2 GPIO_NUM_7 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO2 GPIO_NUM_8 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO2 GPIO_NUM_9 // I2S data in io number
|
||||
|
||||
#else
|
||||
#define EXAMPLE_I2S_BCLK_IO1 GPIO_NUM_2 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO1 GPIO_NUM_3 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO1 GPIO_NUM_4 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO1 GPIO_NUM_5 // I2S data in io number
|
||||
|
||||
#define EXAMPLE_I2S_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number
|
||||
#define EXAMPLE_I2S_WS_IO2 GPIO_NUM_7 // I2S word select io number
|
||||
#define EXAMPLE_I2S_DOUT_IO2 GPIO_NUM_8 // I2S data out io number
|
||||
#define EXAMPLE_I2S_DIN_IO2 GPIO_NUM_9 // I2S data in io number
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user