Explorar el Código

RTP clear audio implemented from ESP32

Joey hace 3 horas
commit
8269ea80a4

+ 2 - 0
.clangd

@@ -0,0 +1,2 @@
+CompileFlags:
+    Remove: [-f*, -m*]

+ 16 - 0
.cproject

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="org.eclipse.cdt.core.default.config.758724571">
+			<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.758724571" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
+				<externalSettings/>
+				<extensions/>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.pathentry">
+		<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+</cproject>

+ 2 - 0
.gitattributes

@@ -0,0 +1,2 @@
+*.wav filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text

+ 37 - 0
.gitignore

@@ -0,0 +1,37 @@
+# PlatformIO build and dependency state
+.pio/
+.pioenvs/
+.piolibdeps/
+libdeps/
+
+# PlatformIO / editor-generated configuration
+.vscode/*
+!.vscode/extensions.json
+.idea/
+.clangd/
+
+# ESP-IDF generated configuration and managed component sources
+sdkconfig
+sdkconfig.old
+sdkconfig.*
+!sdkconfig.defaults
+!sdkconfig.defaults.*
+managed_components/
+components/
+compile_commands.json
+
+# Generated firmware and linker artifacts
+*.bin
+*.elf
+*.map
+
+# Local tooling, caches, and packaged deliverables
+work/
+outputs/
+.cache/
+__pycache__/
+*.py[cod]
+
+# Host operating-system files
+.DS_Store
+Thumbs.db

+ 20 - 0
.project

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>esp_sr_02_Modified</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.core.cBuilder</name>
+			<triggers>clean,full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.cmake.core.cmakeNature</nature>
+	</natures>
+</projectDescription>

+ 4 - 0
CMakeLists.txt

@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.5)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(esp_sr_02)

+ 97 - 0
dependencies.lock

@@ -0,0 +1,97 @@
+dependencies:
+  espressif/cjson:
+    component_hash: e788323270d90738662d66fffa910bfe1fba019bba087f01557e70c40485b469
+    dependencies:
+    - name: idf
+      require: private
+      version: '>=5.0'
+    source:
+      registry_url: https://components.espressif.com/
+      type: service
+    version: 1.7.19~2
+  espressif/dl_fft:
+    component_hash: a955ca29581de2177ddf25759273bd83f082b3c805e735fe6ee105858643989b
+    dependencies:
+    - name: idf
+      require: private
+      version: '>=5.0'
+    source:
+      registry_url: https://components.espressif.com/
+      type: service
+    version: 0.6.0
+  espressif/esp-dsp:
+    component_hash: 12e44db246517a627bc0fe2b255b8335410c0215c98bfba2df5a8e3edea839ef
+    dependencies:
+    - name: idf
+      require: private
+      version: '>=4.2'
+    source:
+      registry_url: https://components.espressif.com/
+      type: service
+    version: 1.8.0
+  espressif/esp-sr:
+    dependencies: []
+    source:
+      path: C:\Users\doop3\OneDrive\Documents\espidfprojects\SIP_test2_1\SIP_test2\components\espressif__esp-sr
+      type: local
+    version: 2.4.6
+  espressif/esp_codec_dev:
+    component_hash: 8a58569aed3c6e8d858da5419eba4d54ee905d7709cdbe01c42101c1ed0c5319
+    dependencies:
+    - name: idf
+      require: private
+      version: '>=4.0'
+    source:
+      registry_url: https://components.espressif.com/
+      type: service
+    version: 1.6.1
+  espressif/esp_io_expander:
+    component_hash: 7b7f91270172e46ca4597e3874f48d8412e280e8c295559f5922ec38656e3e5f
+    dependencies:
+    - name: idf
+      require: private
+      version: '>=4.4.2'
+    source:
+      registry_url: https://components.espressif.com
+      type: service
+    version: 1.2.1
+  espressif/esp_io_expander_tca95xx_16bit:
+    component_hash: a9608ba5753ae2a72e79fccd376fc4283343c0306d23505fbf8a46fafdbde2a2
+    dependencies:
+    - name: espressif/esp_io_expander
+      registry_url: https://components.espressif.com
+      require: public
+      version: ^1.2.0
+    - name: idf
+      require: private
+      version: '>=5.2'
+    source:
+      registry_url: https://components.espressif.com/
+      type: service
+    version: 2.0.2
+  espressif/led_strip:
+    component_hash: 28621486f77229aaf81c71f5e15d6fbf36c2949cf11094e07090593e659e7639
+    dependencies:
+    - name: idf
+      require: private
+      version: '>=5.0'
+    source:
+      registry_url: https://components.espressif.com/
+      type: service
+    version: 3.0.3
+  idf:
+    source:
+      type: idf
+    version: 5.3.5
+direct_dependencies:
+- espressif/cjson
+- espressif/dl_fft
+- espressif/esp-dsp
+- espressif/esp-sr
+- espressif/esp_codec_dev
+- espressif/esp_io_expander_tca95xx_16bit
+- espressif/led_strip
+- idf
+manifest_hash: 2e8c992a35dd97ed7aa093a6dede2214b63671f1dbf36fba70a42539f89df49a
+target: esp32s3
+version: 2.0.0

+ 16 - 0
main/.cproject

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="org.eclipse.cdt.core.default.config.81865998">
+			<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.81865998" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
+				<externalSettings/>
+				<extensions/>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.pathentry">
+		<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+</cproject>

+ 20 - 0
main/.project

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>main</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.core.cBuilder</name>
+			<triggers>clean,full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.cmake.core.cmakeNature</nature>
+	</natures>
+</projectDescription>

+ 23 - 0
main/CMakeLists.txt

@@ -0,0 +1,23 @@
+
+set(SOURCES
+    "./main.c" 
+    "./hardeware_driver/bsp_board.c"
+    "./tca9555_driver/tca9555_driver.c"
+    "./sip/sip.c"
+
+)
+
+set(INCLUDE_DIRS 
+    "."
+    "./hardeware_driver"
+    "./tca9555_driver"
+    "./sip"
+)
+
+
+idf_component_register(
+    SRCS ${SOURCES}
+    INCLUDE_DIRS ${INCLUDE_DIRS}
+    REQUIRES mbedtls esp_driver_gpio esp_driver_i2s openthread
+    PRIV_REQUIRES esp_wifi fatfs nvs_flash
+)

+ 0 - 0
main/Kconfig.projbuild


+ 885 - 0
main/hardeware_driver/bsp_board.c

@@ -0,0 +1,885 @@
+#include "bsp_board.h"
+
+#include <stdbool.h>
+#include "esp_err.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/semphr.h"
+#include "freertos/task.h"
+#include "string.h"
+#include "driver/gpio.h"
+#include "esp_err.h"
+#include "esp_log.h"
+#include "esp_rom_sys.h"
+#include "esp_check.h"
+#include "esp_vfs_fat.h"
+#include "sdmmc_cmd.h"
+#include "driver/i2s_std.h"
+#include "driver/i2s_types.h"
+#include "driver/i2s_pdm.h"
+#include "driver/i2s_tdm.h"
+
+#include <sys/unistd.h>
+#include <sys/stat.h>
+#include "dirent.h"
+#include "driver/sdmmc_host.h"
+#include <errno.h>
+
+#if ((SOC_SDMMC_HOST_SUPPORTED) && (FUNC_SDMMC_EN))
+#include "driver/sdmmc_host.h"
+#endif /* ((SOC_SDMMC_HOST_SUPPORTED) && (FUNC_SDMMC_EN)) */
+
+
+#define ADC_I2S_CHANNEL 2
+#define ADC_BITS_PER_SAMPLE 32
+
+static sdmmc_card_t *card;
+static const char *TAG = "board";
+static int s_play_sample_rate = 16000;
+static int s_play_channel_format = 1;
+static int s_bits_per_chan = 16;
+
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+static i2s_chan_handle_t            tx_handle = NULL;        // I2S tx channel handler
+static i2s_chan_handle_t            rx_handle = NULL;        // I2S rx channel handler
+#endif
+static audio_codec_data_if_t *record_data_if  = NULL;
+static audio_codec_ctrl_if_t *record_ctrl_if  = NULL;
+static audio_codec_if_t *record_codec_if      = NULL;
+static esp_codec_dev_handle_t record_dev      = NULL;
+
+static audio_codec_data_if_t *play_data_if    = NULL;
+static audio_codec_ctrl_if_t *play_ctrl_if    = NULL;
+static audio_codec_gpio_if_t *play_gpio_if    = NULL;
+static audio_codec_if_t *play_codec_if        = NULL;
+static esp_codec_dev_handle_t play_dev        = NULL;
+static i2c_master_bus_handle_t i2c_bus_handle = NULL;
+static uint32_t SDCard_Size  = 0;
+static bool s_volume_buttons_task_started = false;
+
+int mic_level = 0;
+esp_codec_dev_handle_t esp_ret_play_dev(void)
+{
+    return play_dev;
+}
+
+i2c_master_bus_handle_t esp_ret_i2c_handle(void)
+{
+    return i2c_bus_handle;
+}
+
+static esp_err_t i2c_master_init(void)
+{
+    const i2c_master_bus_config_t bus_config = {
+        .i2c_port = I2C_NUM,
+        .sda_io_num = GPIO_I2C_SDA,
+        .scl_io_num = GPIO_I2C_SCL,
+        .clk_source = I2C_CLK_SRC_DEFAULT,
+    };
+
+    esp_err_t ret = i2c_new_master_bus(&bus_config, &i2c_bus_handle);
+    if (ret != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to initialize I2C bus: %s", esp_err_to_name(ret));
+        return ret;
+    }
+
+    ESP_LOGI(TAG, "I2C bus initialized successfully");
+    return ESP_OK;  // 返回 ESP_OK 表示成功
+}
+
+
+esp_err_t bsp_codec_adc_init(int sample_rate)
+{    ESP_LOGI(TAG,"ADC INIT START");
+    esp_err_t ret_val = ESP_OK;
+
+    audio_codec_i2s_cfg_t i2s_cfg = {
+        .port = I2S_NUM_1,
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+        .rx_handle = rx_handle,
+        .tx_handle = NULL,
+#endif
+    };
+
+    record_data_if = audio_codec_new_i2s_data(&i2s_cfg);
+
+    if(record_data_if == NULL)
+{
+    ESP_LOGE(TAG,"record_data_if creation failed");
+    return ESP_FAIL;
+}
+
+
+    audio_codec_i2c_cfg_t i2c_cfg = {
+        .addr = ES7210_CODEC_DEFAULT_ADDR,
+        .bus_handle = i2c_bus_handle
+    };
+
+
+    record_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
+
+
+    es7210_codec_cfg_t es7210_cfg = {
+        .ctrl_if = record_ctrl_if,
+        .mic_selected =
+            ES7210_SEL_MIC1 |
+            ES7210_SEL_MIC2 |
+            ES7210_SEL_MIC3 |
+            ES7210_SEL_MIC4,
+    };
+
+
+    record_codec_if = es7210_codec_new(&es7210_cfg);
+
+    ESP_LOGI(TAG,"ES7210 IF=%p", record_codec_if);
+
+
+    esp_codec_dev_cfg_t dev_cfg = {
+        .codec_if = record_codec_if,
+        .data_if = record_data_if,
+        .dev_type = ESP_CODEC_DEV_TYPE_IN,
+    };
+
+
+    record_dev = esp_codec_dev_new(&dev_cfg);
+
+
+    if(record_dev == NULL)
+    {
+        ESP_LOGE(TAG,"Failed creating ADC codec");
+        return ESP_FAIL;
+    }
+
+
+    esp_codec_dev_sample_info_t fs = {
+        .sample_rate = sample_rate,
+        .channel = 2,
+        .bits_per_sample = 16,
+    };
+
+
+    ret_val = esp_codec_dev_open(record_dev, &fs);
+
+
+    if(ret_val != ESP_OK)
+    {
+        ESP_LOGE(TAG,
+                 "Codec open failed %s",
+                 esp_err_to_name(ret_val));
+        return ret_val;
+    }
+
+
+    esp_codec_dev_set_in_channel_gain(
+        record_dev,
+        ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0),
+        RECORD_VOLUME);
+
+    esp_codec_dev_set_in_channel_gain(
+        record_dev,
+        ESP_CODEC_DEV_MAKE_CHANNEL_MASK(1),
+        RECORD_VOLUME);
+
+
+    return ret_val;
+}
+
+esp_err_t bsp_codec_dac_init(int sample_rate, int channel_format, int bits_per_chan)
+{
+    esp_err_t ret_val = ESP_OK;
+
+    // Do initialize of related interface: data_if, ctrl_if and gpio_if
+    audio_codec_i2s_cfg_t i2s_cfg = {
+        .port = I2S_NUM_1,
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+        .rx_handle = NULL,
+        .tx_handle = tx_handle,
+#endif
+    };
+    play_data_if = audio_codec_new_i2s_data(&i2s_cfg);
+
+    audio_codec_i2c_cfg_t i2c_cfg = {.addr = ES8311_CODEC_DEFAULT_ADDR,.bus_handle = i2c_bus_handle};
+    play_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
+    play_gpio_if = audio_codec_new_gpio();
+    // New output codec interface
+    es8311_codec_cfg_t es8311_cfg = {
+        .codec_mode = ESP_CODEC_DEV_WORK_MODE_DAC,
+        .ctrl_if = play_ctrl_if,
+        .gpio_if = play_gpio_if,
+        .pa_pin = GPIO_PWR_CTRL,
+        .use_mclk = false,
+    };
+    play_codec_if = es8311_codec_new(&es8311_cfg);
+    // New output codec device
+    esp_codec_dev_cfg_t dev_cfg = {
+        .codec_if = play_codec_if,
+        .data_if = play_data_if,
+        .dev_type = ESP_CODEC_DEV_TYPE_OUT,
+    };
+    play_dev = esp_codec_dev_new(&dev_cfg);
+
+    esp_codec_dev_sample_info_t fs = {
+        .bits_per_sample = bits_per_chan,
+        .sample_rate = sample_rate,
+        .channel = channel_format,
+    };
+    esp_codec_dev_set_out_vol(play_dev, PLAYER_VOLUME);
+    esp_codec_dev_open(play_dev, &fs);
+
+    return ret_val;
+}
+
+static esp_err_t bsp_codec_adc_deinit()
+{
+    esp_err_t ret_val = ESP_OK;
+
+    if (record_dev) {
+        esp_codec_dev_close(record_dev);
+        esp_codec_dev_delete(record_dev);
+        record_dev = NULL;
+    }
+
+    // Delete codec interface
+    if (record_codec_if) {
+        audio_codec_delete_codec_if(record_codec_if);
+        record_codec_if = NULL;
+    }
+    
+    // Delete codec control interface
+    if (record_ctrl_if) {
+        audio_codec_delete_ctrl_if(record_ctrl_if);
+        record_ctrl_if = NULL;
+    }
+    
+    // Delete codec data interface
+    if (record_data_if) {
+        audio_codec_delete_data_if(record_data_if);
+        record_data_if = NULL;
+    }
+
+    return ret_val;
+}
+
+static esp_err_t bsp_codec_dac_deinit()
+{
+    esp_err_t ret_val = ESP_OK;
+
+    if (play_dev) {
+        esp_codec_dev_close(play_dev);
+        esp_codec_dev_delete(play_dev);
+        play_dev = NULL;
+    }
+
+    // Delete codec interface
+    if (play_codec_if) {
+        audio_codec_delete_codec_if(play_codec_if);
+        play_codec_if = NULL;
+    }
+    
+    // Delete codec control interface
+    if (play_ctrl_if) {
+        audio_codec_delete_ctrl_if(play_ctrl_if);
+        play_ctrl_if = NULL;
+    }
+    
+    if (play_gpio_if) {
+        audio_codec_delete_gpio_if(play_gpio_if);
+        play_gpio_if = NULL;
+    }
+    
+    // Delete codec data interface
+    if (play_data_if) {
+        audio_codec_delete_data_if(play_data_if);
+        play_data_if = NULL;
+    }
+
+    return ret_val;
+}
+
+esp_err_t esp_audio_set_play_vol(int volume)
+{
+    if (!play_dev) {
+        ESP_LOGE(TAG, "DAC codec init fail");
+        return ESP_FAIL;
+    }
+    esp_codec_dev_set_out_vol(play_dev, volume);
+    return ESP_OK;
+}
+
+esp_err_t esp_audio_get_play_vol(int *volume)
+{
+    if (!play_dev) {
+        ESP_LOGE(TAG, "DAC codec init fail");
+        return ESP_FAIL;
+    }
+    esp_codec_dev_get_out_vol(play_dev, volume);
+    return ESP_OK;
+}
+
+// static esp_err_t bsp_i2s_init(i2s_port_t i2s_num, uint32_t sample_rate, i2s_channel_fmt_t channel_format, i2s_bits_per_chan_t bits_per_chan)
+static esp_err_t bsp_i2s_init(int i2s_num, uint32_t sample_rate, int channel_format, int bits_per_chan)
+{
+    esp_err_t ret_val = ESP_OK;
+
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+    i2s_slot_mode_t channel_fmt = I2S_SLOT_MODE_STEREO;
+    if (channel_format == 1) {
+        channel_fmt = I2S_SLOT_MODE_MONO;
+    } else if (channel_format == 2) {
+        channel_fmt = I2S_SLOT_MODE_STEREO;
+    } else {
+        ESP_LOGE(TAG, "Unable to configure channel_format %d", channel_format);
+        channel_format = 1;
+        channel_fmt = I2S_SLOT_MODE_MONO;
+    }
+
+    if (bits_per_chan != 16 && bits_per_chan != 32) {
+        ESP_LOGE(TAG, "Unable to configure bits_per_chan %d", bits_per_chan);
+        bits_per_chan = 32;
+    }
+
+    i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(i2s_num, I2S_ROLE_MASTER);
+    ret_val |= i2s_new_channel(&chan_cfg, &tx_handle, &rx_handle);
+    i2s_std_config_t std_cfg = I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan);
+    ret_val |= i2s_channel_init_std_mode(tx_handle, &std_cfg);
+    ret_val |= i2s_channel_init_std_mode(rx_handle, &std_cfg);
+    ret_val |= i2s_channel_enable(tx_handle);
+    ret_val |= i2s_channel_enable(rx_handle);
+#else
+    i2s_channel_fmt_t channel_fmt = I2S_CHANNEL_FMT_RIGHT_LEFT;
+    if (channel_format == 1) {
+        channel_fmt = I2S_CHANNEL_FMT_ONLY_LEFT;
+    } else if (channel_format == 2) {
+        channel_fmt = I2S_CHANNEL_FMT_RIGHT_LEFT;
+    } else {
+        ESP_LOGE(TAG, "Unable to configure channel_format %d", channel_format);
+        channel_format = 1;
+        channel_fmt = I2S_CHANNEL_FMT_ONLY_LEFT;
+    }
+
+    if (bits_per_chan != 16 && bits_per_chan != 32) {
+        ESP_LOGE(TAG, "Unable to configure bits_per_chan %d", bits_per_chan);
+        bits_per_chan = 16;
+    }
+
+    i2s_config_t i2s_config = I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan);
+
+    i2s_pin_config_t pin_config = {
+        .bck_io_num = GPIO_I2S_SCLK,
+        .ws_io_num = GPIO_I2S_LRCK,
+        .data_out_num = GPIO_I2S_DOUT,
+        .data_in_num = GPIO_I2S_SDIN,
+        .mck_io_num = GPIO_I2S_MCLK,
+    };
+
+    ret_val |= i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
+    ret_val |= i2s_set_pin(i2s_num, &pin_config);
+#endif
+
+    return ret_val;
+}
+
+static esp_err_t bsp_i2s_deinit(int i2s_num)
+{
+    esp_err_t ret_val = ESP_OK;
+
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+    if (i2s_num == I2S_NUM_1 && rx_handle) {
+        ret_val |= i2s_channel_disable(rx_handle);
+        ret_val |= i2s_del_channel(rx_handle);
+        rx_handle = NULL;
+    } else if (i2s_num == I2S_NUM_0  && tx_handle) {
+        ret_val |= i2s_channel_disable(tx_handle);
+        ret_val |= i2s_del_channel(tx_handle);
+        tx_handle = NULL;
+    }
+#else
+    ret_val |= i2s_stop(i2s_num);
+    ret_val |= i2s_driver_uninstall(i2s_num);
+#endif
+
+    return ret_val;
+}
+
+static esp_err_t bsp_codec_init(
+        int adc_sample_rate,
+        int dac_sample_rate,
+        int dac_channel_format,
+        int dac_bits_per_chan)
+{
+    //ESP_LOGE(TAG, "bsp_codec_adc_init START");
+    esp_err_t ret;
+
+    ret = bsp_codec_adc_init(adc_sample_rate);
+
+    if(ret != ESP_OK)
+    {
+        ESP_LOGE(TAG,"ADC init failed: %s",
+                 esp_err_to_name(ret));
+        return ret;
+    }
+
+
+    ret = bsp_codec_dac_init(
+            dac_sample_rate,
+            dac_channel_format,
+            dac_bits_per_chan);
+
+
+    if(ret != ESP_OK)
+    {
+        ESP_LOGE(TAG,"DAC init failed: %s",
+                 esp_err_to_name(ret));
+    }
+
+
+    return ret;
+}
+
+static esp_err_t bsp_codec_deinit()
+{
+    esp_err_t ret_val = ESP_OK;
+
+    ret_val |= bsp_codec_adc_deinit();
+    ret_val |= bsp_codec_dac_deinit();
+    return ret_val;
+}
+
+esp_err_t esp_audio_play(const int16_t* data, int length, uint32_t ticks_to_wait)
+{
+    size_t bytes_write = 0;
+    esp_err_t ret = ESP_OK;
+    if (!play_dev) {
+        return ESP_FAIL;
+    }
+
+    int out_length= length;
+    int audio_time = 1;
+    audio_time *= (16000 / s_play_sample_rate);
+    audio_time *= (2 / s_play_channel_format);
+
+    int *data_out = NULL;
+    if (s_bits_per_chan != 32) {
+        out_length = length * 2;
+        data_out = malloc(out_length);
+        for (int i = 0; i < length / sizeof(int16_t); i++) {
+            int ret = data[i];
+            data_out[i] = ret << 16;
+        }
+    }
+
+    int *data_out_1 = NULL;
+    if (s_play_channel_format != 2 || s_play_sample_rate != 16000) {
+        out_length *= audio_time;
+        data_out_1 = malloc(out_length);
+        int *tmp_data = NULL;
+        if (data_out != NULL) {
+            tmp_data = data_out;
+        } else {
+            tmp_data = (int *)data;
+        }
+
+        for (int i = 0; i < out_length / (audio_time * sizeof(int)); i++) {
+            for (int j = 0; j < audio_time; j++) {
+                data_out_1[audio_time * i + j] = tmp_data[i];
+            }
+        }
+        if (data_out != NULL) {
+            free(data_out);
+            data_out = NULL;
+        }
+    }
+
+    if (data_out != NULL) {
+        ret = esp_codec_dev_write(play_dev, (void *)data_out, out_length);
+        free(data_out);
+    } else if (data_out_1 != NULL) {
+        ret = esp_codec_dev_write(play_dev, (void *)data_out_1, out_length);
+        free(data_out_1);
+    } else {
+        ret = esp_codec_dev_write(play_dev, (void *)data, length);
+    }
+
+    return ret;
+}
+int get_mic_level (void) {
+
+    return mic_level;
+}
+esp_err_t esp_get_feed_data(
+        bool is_get_raw_channel,
+        int16_t *buffer,
+        int buffer_len)
+{
+
+    ESP_LOGE(TAG, "NEW esp_get_feed_data CALLED");
+
+    if(record_dev == NULL)
+    {
+        ESP_LOGE(TAG,"record_dev NULL");
+        return ESP_ERR_INVALID_STATE;
+    }
+
+
+    ESP_LOGI(TAG,
+             "read buffer=%p size=%d",
+             buffer,
+             buffer_len);
+
+
+    esp_err_t ret;
+
+    ret = esp_codec_dev_read(
+            record_dev,
+            buffer,
+            buffer_len);
+
+
+    ESP_LOGI(TAG,
+             "codec read ret=%s",
+             esp_err_to_name(ret));
+
+
+    if(ret != ESP_OK)
+    {
+        return ret;
+    }
+
+
+    // Check microphone data
+    int64_t sum = 0;
+
+    for(int i=0;i<buffer_len/sizeof(int16_t);i++)
+    {
+        sum += abs(buffer[i]);
+    }
+
+
+    ESP_LOGI(TAG,
+             "MIC level=%lld",
+             sum/(buffer_len/sizeof(int16_t)));
+
+
+    return ESP_OK;
+}
+
+
+int esp_get_feed_channel(void)
+{
+    return ADC_I2S_CHANNEL;
+}
+
+char* esp_get_input_format(void)
+{
+    return "RM";
+}
+
+static void bsp_volume_buttons_task(void *arg)
+{
+    int last_key1 = 1;
+    int last_key3 = 1;
+
+    while (1) {
+        int key1 = gpio_get_level(GPIO_KEY1_PIN);
+        int key3 = gpio_get_level(GPIO_KEY3_PIN);
+
+        if (key1 == 0 && last_key1 != 0) {
+            int current_vol = 0;
+            if (esp_audio_get_play_vol(&current_vol) == ESP_OK) {
+                current_vol += VOLUME_STEP;
+                if (current_vol > VOLUME_MAX_LEVEL) {
+                    current_vol = VOLUME_MAX_LEVEL;
+                }
+                if (esp_audio_set_play_vol(current_vol) == ESP_OK) {
+                    ESP_LOGI(TAG, "Volume up -> %d", current_vol);
+                }
+            }
+        }
+
+        if (key3 == 0 && last_key3 != 0) {
+            int current_vol = 0;
+            if (esp_audio_get_play_vol(&current_vol) == ESP_OK) {
+                current_vol -= VOLUME_STEP;
+                if (current_vol < VOLUME_MIN_LEVEL) {
+                    current_vol = VOLUME_MIN_LEVEL;
+                }
+                if (esp_audio_set_play_vol(current_vol) == ESP_OK) {
+                    ESP_LOGI(TAG, "Volume down -> %d", current_vol);
+                }
+            }
+        }
+
+        last_key1 = key1;
+        last_key3 = key3;
+        vTaskDelay(pdMS_TO_TICKS(VOLUME_BUTTON_POLL_MS));
+    }
+}
+
+static esp_err_t bsp_volume_buttons_init(void)
+{
+    if (s_volume_buttons_task_started) {
+        return ESP_OK;
+    }
+
+    gpio_config_t io_conf = {
+        .pin_bit_mask = (1ULL << GPIO_KEY1_PIN) | (1ULL << GPIO_KEY3_PIN),
+        .mode = GPIO_MODE_INPUT,
+        .pull_up_en = GPIO_PULLUP_ENABLE,
+        .pull_down_en = GPIO_PULLDOWN_DISABLE,
+        .intr_type = GPIO_INTR_DISABLE,
+    };
+
+    esp_err_t ret = gpio_config(&io_conf);
+    if (ret != ESP_OK) {
+        return ret;
+    }
+
+    BaseType_t task_created = xTaskCreate(bsp_volume_buttons_task, "vol_btns", 4096, NULL, 5, NULL);
+    if (task_created != pdPASS) {
+        return ESP_FAIL;
+    }
+
+    s_volume_buttons_task_started = true;
+    return ESP_OK;
+}
+
+esp_err_t esp_board_init(uint32_t sample_rate, int channel_format, int bits_per_chan)
+{
+    /*!< Initialize I2C bus, used for audio codec*/
+
+    i2c_master_init();
+    s_play_sample_rate = sample_rate;
+
+    if (channel_format != 2 && channel_format != 1) {
+        ESP_LOGE(TAG, "Unable to configure channel_format");
+        channel_format = 2;
+    }
+    s_play_channel_format = channel_format;
+
+    if (bits_per_chan != 32 && bits_per_chan != 16) {
+        ESP_LOGE(TAG, "Unable to configure bits_per_chan");
+        bits_per_chan = 32;
+    }
+    s_bits_per_chan = bits_per_chan;
+
+    bsp_i2s_init(I2S_NUM_1, 16000, 2, 16);
+    // Because record and play use the same i2s.
+esp_err_t codec_ret;
+
+codec_ret = bsp_codec_init(16000,16000,2,16);
+
+if(codec_ret != ESP_OK)
+{
+    ESP_LOGE(TAG,
+             "bsp_codec_init failed: %s",
+             esp_err_to_name(codec_ret));
+}
+else
+{
+    ESP_LOGI(TAG,"bsp_codec_init OK");
+}
+    /* Initialize PA */
+     /*gpio_config_t  io_conf;
+     memset(&io_conf, 0, sizeof(io_conf));
+     io_conf.intr_type = GPIO_INTR_DISABLE;
+     io_conf.mode = GPIO_MODE_OUTPUT;
+     io_conf.pin_bit_mask = ((1ULL << GPIO_PWR_CTRL));
+     io_conf.pull_down_en = 0;
+     io_conf.pull_up_en = 0;
+     gpio_config(&io_conf);
+     */
+    gpio_set_level(GPIO_PWR_CTRL, 1);
+
+    esp_err_t button_ret = bsp_volume_buttons_init();
+    if (button_ret != ESP_OK) {
+        ESP_LOGW(TAG, "Failed to initialize volume buttons: %s", esp_err_to_name(button_ret));
+    }
+
+    return ESP_OK;
+}
+
+esp_err_t esp_sdcard_init(char *mount_point, size_t max_files)
+{
+    if (NULL != card) {
+        return ESP_ERR_INVALID_STATE;
+    }
+
+    /* Check if SD crad is supported */
+    if (!FUNC_SDMMC_EN && !FUNC_SDSPI_EN) {
+        ESP_LOGE(TAG, "SDMMC and SDSPI not supported on this board!");
+        return ESP_ERR_NOT_SUPPORTED;
+    }
+
+    esp_err_t ret_val = ESP_OK;
+
+    /**
+     * @brief Options for mounting the filesystem.
+     *   If format_if_mount_failed is set to true, SD card will be partitioned and
+     *   formatted in case when mounting fails.
+     *
+     */
+    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
+        .format_if_mount_failed = false,
+        .max_files = max_files,
+        .allocation_unit_size = 16 * 1024
+    };
+
+    /**
+     * @brief 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.
+     *
+     */
+    sdmmc_host_t host =
+#if FUNC_SDMMC_EN
+        SDMMC_HOST_DEFAULT();
+#else
+        SDSPI_HOST_DEFAULT();
+    spi_bus_config_t bus_cfg = {
+        .mosi_io_num = GPIO_SDSPI_MOSI,
+        .miso_io_num = GPIO_SDSPI_MISO,
+        .sclk_io_num = GPIO_SDSPI_SCLK,
+        .quadwp_io_num = GPIO_NUM_NC,
+        .quadhd_io_num = GPIO_NUM_NC,
+        .max_transfer_sz = 4000,
+    };
+    ret_val = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH_AUTO);
+    if (ret_val != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to initialize bus.");
+        return ret_val;
+    }
+#endif
+
+    /**
+     * @brief This initializes the slot without card detect (CD) and write protect (WP) signals.
+     *   Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
+     *
+     */
+#if FUNC_SDMMC_EN
+    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
+#else
+    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
+#endif
+
+#if FUNC_SDMMC_EN
+    /* Config SD data width. 0, 4 or 8. Currently for SD card, 8 bit is not supported. */
+    slot_config.width = SDMMC_BUS_WIDTH;
+
+    /**
+     * @brief On chips where the GPIOs used for SD card can be configured, set them in
+     *   the slot_config structure.
+     *
+     */
+#if SOC_SDMMC_USE_GPIO_MATRIX
+    slot_config.clk = GPIO_SDMMC_CLK;
+    slot_config.cmd = GPIO_SDMMC_CMD;
+    slot_config.d0 = GPIO_SDMMC_D0;
+    slot_config.d1 = GPIO_SDMMC_D1;
+    slot_config.d2 = GPIO_SDMMC_D2;
+    slot_config.d3 = GPIO_SDMMC_D3;
+#endif
+    slot_config.cd = GPIO_SDMMC_DET;
+    slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
+#else
+    slot_config.gpio_cs = GPIO_SDSPI_CS;
+    slot_config.host_id = host.slot;
+#endif
+    /**
+     * @brief Enable internal pullups on enabled pins. The internal pullups
+     *   are insufficient however, please make sure 10k external pullups are
+     *   connected on the bus. This is for debug / example purpose only.
+     */
+
+    /* get FAT filesystem on SD card registered in VFS. */
+    ret_val =
+#if FUNC_SDMMC_EN
+        esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
+#else
+        esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
+#endif
+
+    /* Check for SDMMC mount result. */
+    if (ret_val != ESP_OK) {
+        if (ret_val == 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.");
+        } 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_val));
+        }
+        return ret_val;
+    }
+
+    /* Card has been initialized, print its properties. */
+    sdmmc_card_print_info(stdout, card);
+    SDCard_Size = ((uint64_t) card->csd.capacity) * card->csd.sector_size / (1024 * 1024);
+    return ret_val;
+}
+
+esp_err_t esp_sdcard_deinit(char *mount_point)
+{
+    if (NULL == mount_point) {
+        return ESP_ERR_INVALID_STATE;
+    }
+
+    /* Unmount an SD card from the FAT filesystem and release resources acquired */
+    esp_err_t ret_val = esp_vfs_fat_sdcard_unmount(mount_point, card);
+
+    /* Make SD/MMC card information structure pointer NULL */
+    card = NULL;
+
+    return ret_val;
+}
+
+#define MOUNT_POINT "/sdcard"
+
+static const char *SD_TAG = "SD";
+
+
+
+uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][MAX_FILE_NAME_SIZE], uint16_t maxFiles)    
+{
+    DIR *dir = opendir(directory);  
+    if (dir == NULL) {
+        ESP_LOGE(SD_TAG, "Path: <%s> does not exist", directory); 
+        return 0;  
+    }
+
+    uint16_t fileCount = 0;  
+    struct dirent *entry;   
+
+    while ((entry = readdir(dir)) != NULL && fileCount < maxFiles) {
+
+        if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+            continue;
+        }
+
+        const char *dot = strrchr(entry->d_name, '.');  
+        if (dot != NULL && dot != entry->d_name) { 
+
+            if (strcasecmp(dot, fileExtension) == 0) {  
+                strncpy(File_Name[fileCount], entry->d_name, MAX_FILE_NAME_SIZE - 1);
+                File_Name[fileCount][MAX_FILE_NAME_SIZE - 1] = '\0';  
+
+                char filePath[MAX_PATH_SIZE];
+                snprintf(filePath, MAX_PATH_SIZE, "%s/%s", directory, entry->d_name);
+
+                printf("File found: %s\r\n", filePath); 
+                fileCount++;  
+            }
+        }
+        else{
+           
+            // printf("No extension found for file: %s\r\n", entry->d_name);
+        }
+    }
+
+    closedir(dir);  
+
+    if (fileCount > 0) {
+        ESP_LOGI(SD_TAG, "Retrieved %d files with extension '%s'", fileCount, fileExtension);  
+    } else {
+        ESP_LOGW(SD_TAG, "No files with extension '%s' found in directory: %s", fileExtension, directory); 
+    }
+
+    return fileCount; 
+}

+ 210 - 0
main/hardeware_driver/bsp_board.h

@@ -0,0 +1,210 @@
+#pragma once
+
+#include "driver/gpio.h"
+#include "driver/i2s_std.h"
+#include "driver/i2s_tdm.h"
+#include "driver/i2c_master.h"
+
+#include "soc/soc_caps.h"
+#include "esp_idf_version.h"
+
+#include "esp_codec_dev.h"
+#include "esp_codec_dev_defaults.h"
+#include "esp_codec_dev_os.h"
+#include "sdkconfig.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAX_FILE_NAME_SIZE 100  // Define maximum file name size
+#define MAX_PATH_SIZE 512      // Define a larger size for the full path
+
+/**
+ * @brief ESP32-S3-CAM-OVxxxx I2C GPIO defineation
+ * 
+ */
+#define I2C_NUM         (0)
+#define GPIO_I2C_SCL    (GPIO_NUM_10)
+#define GPIO_I2C_SDA    (GPIO_NUM_11)
+
+/**
+ * @brief ESP32-S3-CAM-OVxxxx SDMMC GPIO defination
+ * 
+ * @note Only avaliable when PMOD connected
+ */
+#define FUNC_SDMMC_EN   (1)
+#define SDMMC_BUS_WIDTH (1)
+#define GPIO_SDMMC_CLK  (GPIO_NUM_40)
+#define GPIO_SDMMC_CMD  (GPIO_NUM_42)
+#define GPIO_SDMMC_D0   (GPIO_NUM_41)
+#define GPIO_SDMMC_D1   (GPIO_NUM_NC)
+#define GPIO_SDMMC_D2   (GPIO_NUM_NC)
+#define GPIO_SDMMC_D3   (GPIO_NUM_NC)
+#define GPIO_SDMMC_DET  (GPIO_NUM_NC)
+
+/**
+ * @brief ESP32-S3-CAM-OVxxxx SDSPI GPIO definationv
+ * 
+ */
+#define FUNC_SDSPI_EN       (0)
+#define SDSPI_HOST          (SPI2_HOST)
+#define GPIO_SDSPI_CS       (GPIO_NUM_NC)
+#define GPIO_SDSPI_SCLK     (GPIO_NUM_NC)
+#define GPIO_SDSPI_MISO     (GPIO_NUM_NC)
+#define GPIO_SDSPI_MOSI     (GPIO_NUM_NC)
+
+/**
+ * @brief ESP32-S3-CAM-OVxxxx I2S GPIO defination
+ * 
+ */
+#define FUNC_I2S_EN         (1)
+#define GPIO_I2S_LRCK       (GPIO_NUM_14)
+#define GPIO_I2S_MCLK       (GPIO_NUM_12)
+#define GPIO_I2S_SCLK       (GPIO_NUM_13)
+#define GPIO_I2S_SDIN       (GPIO_NUM_15)
+#define GPIO_I2S_DOUT       (GPIO_NUM_16)
+
+/**
+ * @brief ESP32-S3-CAM-OVxxxx I2S GPIO defination
+ * 
+ */
+#define FUNC_I2S0_EN         (0)
+#define GPIO_I2S0_LRCK       (GPIO_NUM_NC)
+#define GPIO_I2S0_MCLK       (GPIO_NUM_NC)
+#define GPIO_I2S0_SCLK       (GPIO_NUM_NC)
+#define GPIO_I2S0_SDIN       (GPIO_NUM_NC)
+#define GPIO_I2S0_DOUT       (GPIO_NUM_NC)
+
+/**
+ * @brief record configurations
+ *
+ */
+#define RECORD_VOLUME   (30.0)
+
+/**
+ * @brief player configurations
+ *
+ */
+#define PLAYER_VOLUME   (60)
+
+/**
+ * @brief ESP32-S3-HMI-DevKit power control IO
+ * 
+ * @note Some power control pins might not be listed yet
+ * 
+ */
+//#define FUNC_PWR_CTRL       (1)
+#define GPIO_PWR_CTRL       (-1)
+#define GPIO_PWR_ON_LEVEL   (1)
+
+/* Waveshare ESP32-S3 audio board button mapping */
+#define GPIO_KEY1_PIN       (GPIO_NUM_0)
+#define GPIO_KEY3_PIN       (GPIO_NUM_18)
+#define VOLUME_BUTTON_POLL_MS (50)
+#define VOLUME_STEP         (2)
+#define VOLUME_MIN_LEVEL    (0)
+#define VOLUME_MAX_LEVEL    (100)
+
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
+
+#define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
+        .clk_cfg  = I2S_STD_CLK_DEFAULT_CONFIG(16000), \
+        .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(32, I2S_SLOT_MODE_STEREO), \
+        .gpio_cfg = { \
+            .mclk = GPIO_I2S_MCLK, \
+            .bclk = GPIO_I2S_SCLK, \
+            .ws   = GPIO_I2S_LRCK, \
+            .dout = GPIO_I2S_DOUT, \
+            .din  = GPIO_I2S_SDIN, \
+        }, \
+    }
+
+#else
+
+#define I2S_CONFIG_DEFAULT(sample_rate, channel_fmt, bits_per_chan) { \
+    .mode                   = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX, \
+    .sample_rate            = 16000, \
+    .bits_per_sample        = I2S_BITS_PER_SAMPLE_32BIT, \
+    .channel_format         = I2S_CHANNEL_FMT_RIGHT_LEFT, \
+    .communication_format   = I2S_COMM_FORMAT_STAND_I2S, \
+    .intr_alloc_flags       = ESP_INTR_FLAG_LEVEL1, \
+    .dma_buf_count          = 6, \
+    .dma_buf_len            = 160, \
+    .use_apll               = false, \
+    .tx_desc_auto_clear     = true, \
+    .fixed_mclk             = 0, \
+    .mclk_multiple          = I2S_MCLK_MULTIPLE_DEFAULT, \
+    .bits_per_chan          = I2S_BITS_PER_CHAN_32BIT, \
+}
+
+#endif
+
+
+/* LCD settings */
+#define EXAMPLE_LCD_SPI_NUM         (SPI3_HOST)
+#define EXAMPLE_LCD_PIXEL_CLK_HZ    (80 * 1000 * 1000)
+#define EXAMPLE_LCD_CMD_BITS        (8)
+#define EXAMPLE_LCD_PARAM_BITS      (8)
+#define EXAMPLE_LCD_BITS_PER_PIXEL  (16)
+#define EXAMPLE_LCD_DRAW_BUFF_DOUBLE (1)
+#define EXAMPLE_LCD_DRAW_BUFF_HEIGHT (50)
+#define EXAMPLE_LCD_BL_ON_LEVEL     (1)
+#define Backlight_MAX           100   
+#define DEFAULT_BACKLIGHT       80 
+
+/* LCD pins */
+#define EXAMPLE_LCD_GPIO_SCLK       (GPIO_NUM_5)
+#define EXAMPLE_LCD_GPIO_MOSI       (GPIO_NUM_1)
+#define EXAMPLE_LCD_GPIO_RST        (GPIO_NUM_NC)
+#define EXAMPLE_LCD_GPIO_DC         (GPIO_NUM_3)
+#define EXAMPLE_LCD_GPIO_CS         (GPIO_NUM_6)
+#define EXAMPLE_LCD_GPIO_BL         (GPIO_NUM_NC)
+
+/* LCD touch pins */
+#define EXAMPLE_TOUCH_GPIO_RST      (GPIO_NUM_NC)
+
+#ifdef CONFIG_WAVESHARE_1_47INCH_TOUCH_LCD
+#define EXAMPLE_LCD_H_RES   (172)
+#define EXAMPLE_LCD_V_RES   (320)
+#define EXAMPLE_TOUCH_GPIO_INT      (GPIO_NUM_9)
+#elif defined(CONFIG_WAVESHARE_2INCH_TOUCH_LCD)
+#define EXAMPLE_LCD_H_RES   (240)
+#define EXAMPLE_LCD_V_RES   (320)
+#define EXAMPLE_TOUCH_GPIO_INT      (GPIO_NUM_9)
+#elif defined(CONFIG_WAVESHARE_2_8INCH_TOUCH_LCD)
+#define EXAMPLE_LCD_H_RES   (240)
+#define EXAMPLE_LCD_V_RES   (320)
+#define EXAMPLE_TOUCH_GPIO_INT      (GPIO_NUM_NC)
+#elif defined(CONFIG_WAVESHARE_3_5INCH_TOUCH_LCD)
+#define EXAMPLE_LCD_H_RES   (320)
+#define EXAMPLE_LCD_V_RES   (480)
+#define EXAMPLE_TOUCH_GPIO_INT      (GPIO_NUM_9)
+#endif
+
+// GPIO assignment
+#define LED_STRIP_GPIO_PIN  38
+#define LED_STRIP_LED_COUNT 7
+
+
+esp_err_t esp_board_init(uint32_t sample_rate, int channel_format, int bits_per_chan);
+
+esp_err_t esp_sdcard_init(char *mount_point, size_t max_files);
+esp_err_t esp_sdcard_deinit(char *mount_point);
+
+esp_err_t esp_audio_play(const int16_t* data, int length, uint32_t ticks_to_wait);
+
+esp_err_t esp_get_feed_data(bool is_get_raw_channel, int16_t *buffer, int buffer_len);
+int esp_get_feed_channel(void);
+char* esp_get_input_format(void);
+esp_err_t esp_audio_set_play_vol(int volume);
+esp_err_t esp_audio_get_play_vol(int *volume);
+
+i2c_master_bus_handle_t esp_ret_i2c_handle(void);
+esp_codec_dev_handle_t esp_ret_play_dev();
+uint32_t Get_SD_Size(void);
+uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File_Name[][MAX_FILE_NAME_SIZE], uint16_t maxFiles) ;
+
+#ifdef __cplusplus
+}
+#endif

+ 5 - 0
main/idf_component.yml

@@ -0,0 +1,5 @@
+dependencies:
+  espressif/esp-sr: ^2.1.5
+  espressif/esp_io_expander_tca95xx_16bit: ^2.0.1
+  espressif/esp_codec_dev: ^1.5.1
+  espressif/led_strip: ^3.0.3

+ 54 - 0
main/main.c

@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+#include "esp_wifi.h"
+#include "esp_event.h"
+#include "esp_log.h"
+#include "nvs_flash.h"
+
+#include "lwip/sockets.h"
+
+#include <stdbool.h>
+#include "esp_rom_md5.h"
+#include "sip/sip.h"
+
+#include "bsp_board.h"
+
+static const char *TAG = "APP";
+
+void app_main(void)
+{
+    ESP_LOGI(TAG, "Starting SIP client...");
+
+    esp_err_t ret;
+
+    ret = esp_board_init(16000, 2, 32);
+
+    if(ret != ESP_OK)
+    {
+        ESP_LOGE(TAG,
+                 "Audio board init failed: %s",
+                 esp_err_to_name(ret));
+        return;
+    }
+
+
+    wifi_init();
+
+    while (!wifi_ready) {
+        vTaskDelay(pdMS_TO_TICKS(500));
+    }
+
+
+    xTaskCreate(
+        sip_register_task,
+        "sip_register",
+        24576,
+        NULL,
+        5,
+        NULL);
+}

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1030 - 0
main/sip/sip.c


+ 26 - 0
main/sip/sip.h

@@ -0,0 +1,26 @@
+#ifndef SIP_H
+#define SIP_H
+
+#include <stdbool.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern volatile bool wifi_ready;
+
+void wifi_init(void);
+void sip_compute_response(const char *username,
+                          const char *realm,
+                          const char *password,
+                          const char *nonce,
+                          const char *uri,
+                          char *out_response);
+void sip_register_task(void *pvParameters);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SIP_H */

+ 50 - 0
main/tca9555_driver/tca9555_driver.c

@@ -0,0 +1,50 @@
+#include "tca9555_driver.h"
+#include "esp_log.h"
+#include "bsp_board.h"
+
+
+esp_io_expander_handle_t io_expander = NULL;
+
+
+void tca9555_driver_init(void)
+{
+
+    i2c_master_bus_handle_t i2c_bus = esp_ret_i2c_handle();
+    esp_err_t ret = esp_io_expander_new_i2c_tca95xx_16bit(i2c_bus, ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_000, &io_expander);
+
+   /* Test output level function */
+   ret = esp_io_expander_set_dir(io_expander, (IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1 | IO_EXPANDER_PIN_NUM_5 | IO_EXPANDER_PIN_NUM_6 | IO_EXPANDER_PIN_NUM_8), IO_EXPANDER_OUTPUT);
+   if(ret != ESP_OK){
+    printf("EXIO Mode setting failure!!\r\n");
+   }
+   
+   ret = esp_io_expander_set_dir(io_expander, (IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_9 | IO_EXPANDER_PIN_NUM_10 | IO_EXPANDER_PIN_NUM_11), IO_EXPANDER_INPUT);   
+   if(ret != ESP_OK){
+    printf("EXIO Mode setting failure!!\r\n");
+   }
+}
+
+
+/********************************************************** Set the EXIO output status **********************************************************/  
+void Set_EXIO(uint32_t Pin,uint8_t State)                  // Sets the level state of the Pin without affecting the other pins(PIN:1~8)
+{
+    esp_err_t ret;
+    ret = esp_io_expander_set_level(io_expander, Pin, State);      
+    if(ret != ESP_OK){
+        printf("EXIO level setting failure!!\r\n");
+    }
+
+}
+/********************************************************** Read EXIO status **********************************************************/       
+bool Read_EXIO(uint32_t Pin)                            // Read the level of the TCA9555PWR Pin
+{
+    
+    esp_err_t ret;
+    uint32_t input_level_mask = 0;            
+    ret = esp_io_expander_get_level(io_expander, Pin, &input_level_mask);      
+    if(ret != ESP_OK){
+        printf("EXIO level reading failure!!\r\n");
+    }          
+    bool bitStatus = input_level_mask & Pin;                             
+    return bitStatus;                                                              
+}

+ 19 - 0
main/tca9555_driver/tca9555_driver.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include "freertos/FreeRTOS.h"
+#include "esp_io_expander_tca95xx_16bit.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern esp_io_expander_handle_t io_expander;
+void tca9555_driver_init(void);
+void Set_EXIO(uint32_t Pin,uint8_t State);    
+bool Read_EXIO(uint32_t Pin);
+
+
+
+#ifdef __cplusplus
+}
+#endif

+ 6 - 0
partitions.csv

@@ -0,0 +1,6 @@
+# Name,     Type, SubType, Offset,   Size, Flags
+# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap,,,,
+nvs,        data,   nvs,      0x9000,       0x6000,
+factory,    0,      0,        0x10000,      3M,
+flash_test, data,   fat,      ,             528K,
+model,      data,   spiffs,   ,             5900K,

+ 4 - 0
sdkconfig.defaults

@@ -0,0 +1,4 @@
+CONFIG_PARTITION_TABLE_CUSTOM=y
+CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
+CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
+CONFIG_PARTITION_TABLE_OFFSET=0x8000