diff --git a/.gitignore b/.gitignore index e9ca8d694..105f9fa7f 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ coverage.info coverage_report/ .vscode +examples/rtc-aigc-embedded-demo/ diff --git a/components/audio_board/CMakeLists.txt b/components/audio_board/CMakeLists.txt index 82bba4c80..48746a228 100644 --- a/components/audio_board/CMakeLists.txt +++ b/components/audio_board/CMakeLists.txt @@ -161,4 +161,22 @@ set(COMPONENT_SRCS ) endif() +if(CONFIG_DFROBOT_ESP32S3_AI_CAM) +message(STATUS "Current board name is " DFROBOT_ESP32S3_AI_CAM) +list(APPEND COMPONENT_ADD_INCLUDEDIRS ./dfrobot_esp32_s3_ai_cam) +set(COMPONENT_SRCS +./dfrobot_esp32_s3_ai_cam/board.c +./dfrobot_esp32_s3_ai_cam/board_pins_config.c +) +endif() + +if(CONFIG_UNIHIKER_K10) +message(STATUS "Current board name is " UNIHIKER_K10) +list(APPEND COMPONENT_ADD_INCLUDEDIRS ./unihiker_k10) +set(COMPONENT_SRCS +./unihiker_k10/board.c +./unihiker_k10/board_pins_config.c +) +endif() + register_component() diff --git a/components/audio_board/Kconfig.projbuild b/components/audio_board/Kconfig.projbuild index ba68fb09a..50ab8f44c 100644 --- a/components/audio_board/Kconfig.projbuild +++ b/components/audio_board/Kconfig.projbuild @@ -41,7 +41,10 @@ config ESP32_P4_FUNCTION_EV_BOARD bool "ESP32-P4-FUNCTION-EV-BOARD" config ESP32_P4_FUNCTION_EV_SUB_BOARD bool "ESP32-P4-FUNCTION-EV-SUB-BOARD" - +config DFROBOT_ESP32S3_AI_CAM + bool "DFROBOT-ESP32S3-AI-CAM" +config UNIHIKER_K10 + bool "UNIHIKER-K10" endchoice choice ESP32_KORVO_DU1906_DAC diff --git a/components/audio_board/component.mk b/components/audio_board/component.mk index 61cf50f35..a31b0e9d7 100644 --- a/components/audio_board/component.mk +++ b/components/audio_board/component.mk @@ -50,4 +50,14 @@ endif ifdef CONFIG_ESP32_C3_LYRA_V2_BOARD COMPONENT_ADD_INCLUDEDIRS += ./esp32_c3_lyra COMPONENT_SRCDIRS += ./esp32_c3_lyra +endif + +ifdef CONFIG_DFROBOT_ESP32S3_AI_CAM +COMPONENT_ADD_INCLUDEDIRS += ./dfrobot_esp32_s3_ai_cam +COMPONENT_SRCDIRS += ./dfrobot_esp32_s3_ai_cam +endif + +ifdef CONFIG_UNIHIKER_K10 +COMPONENT_ADD_INCLUDEDIRS += ./unihiker_k10 +COMPONENT_SRCDIRS += ./unihiker_k10 endif \ No newline at end of file diff --git a/components/audio_board/dfrobot_esp32_s3_ai_cam/board.c b/components/audio_board/dfrobot_esp32_s3_ai_cam/board.c new file mode 100644 index 000000000..6a26d98c9 --- /dev/null +++ b/components/audio_board/dfrobot_esp32_s3_ai_cam/board.c @@ -0,0 +1,88 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2025 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "esp_log.h" +#include "board.h" +#include "audio_mem.h" +#include "periph_sdcard.h" + +static const char *TAG = "AUDIO_BOARD"; + +static audio_board_handle_t board_handle = 0; + +audio_board_handle_t audio_board_init(void) +{ + if (board_handle) { + ESP_LOGW(TAG, "The board has already been initialized!"); + return board_handle; + } + board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); + AUDIO_MEM_CHECK(TAG, board_handle, return NULL); + return board_handle; +} + +esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) +{ + if (mode != SD_MODE_SPI) { + ESP_LOGE(TAG, "Current board only support SPI SD mode!"); + return ESP_FAIL; + } + periph_sdcard_cfg_t sdcard_cfg = { + .root = "/sdcard", + .card_detect_pin = get_sdcard_intr_gpio(), + .mode = mode + }; + esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg); + esp_err_t ret = esp_periph_start(set, sdcard_handle); + int retry_time = 5; + bool mount_flag = false; + while (retry_time--) { + if (periph_sdcard_is_mounted(sdcard_handle)) { + mount_flag = true; + break; + } else { + vTaskDelay(500 / portTICK_PERIOD_MS); + } + } + if (mount_flag == false) { + ESP_LOGE(TAG, "Sdcard mount failed"); + return ESP_FAIL; + } + return ret; +} + +audio_board_handle_t audio_board_get_handle(void) +{ + return board_handle; +} + +esp_err_t audio_board_deinit(audio_board_handle_t audio_board) +{ + esp_err_t ret = ESP_OK; + ret |= audio_hal_deinit(audio_board->audio_hal); + ret |= audio_hal_deinit(audio_board->adc_hal); + audio_free(audio_board); + board_handle = NULL; + return ret; +} diff --git a/components/audio_board/dfrobot_esp32_s3_ai_cam/board.h b/components/audio_board/dfrobot_esp32_s3_ai_cam/board.h new file mode 100644 index 000000000..f8923ab59 --- /dev/null +++ b/components/audio_board/dfrobot_esp32_s3_ai_cam/board.h @@ -0,0 +1,87 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2025 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef _AUDIO_BOARD_H_ +#define _AUDIO_BOARD_H_ + +#include "audio_hal.h" +#include "board_def.h" +#include "board_pins_config.h" +#include "esp_peripherals.h" +#include "periph_sdcard.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Audio board handle + */ +struct audio_board_handle { + audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ + audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */ +}; + +typedef struct audio_board_handle *audio_board_handle_t; + +/** + * @brief Initialize audio board + * + * @return The audio board handle + */ +audio_board_handle_t audio_board_init(void); + +/** + * @brief Initialize sdcard peripheral + * + * @param set The handle of esp_periph_set_handle_t + * + * @return + * - ESP_OK, success + * - Others, fail + */ +esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); + +/** + * @brief Query audio_board_handle + * + * @return The audio board handle + */ +audio_board_handle_t audio_board_get_handle(void); + +/** + * @brief Uninitialize the audio board + * + * @param audio_board The handle of audio board + * + * @return 0 success, + * others fail + */ +esp_err_t audio_board_deinit(audio_board_handle_t audio_board); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/audio_board/dfrobot_esp32_s3_ai_cam/board_def.h b/components/audio_board/dfrobot_esp32_s3_ai_cam/board_def.h new file mode 100644 index 000000000..fd74f2314 --- /dev/null +++ b/components/audio_board/dfrobot_esp32_s3_ai_cam/board_def.h @@ -0,0 +1,105 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2025 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef _AUDIO_BOARD_DEFINITION_H_ +#define _AUDIO_BOARD_DEFINITION_H_ + +/** + * @brief SDCARD Function Definition + */ +#define FUNC_SDCARD_EN (1) +#define SDCARD_OPEN_FILE_NUM_MAX (5) +#define SDCARD_INTR_GPIO GPIO_NUM_NC +#define SDCARD_PWR_CTRL GPIO_NUM_NC + +#define ESP_SD_PIN_CLK GPIO_NUM_12 +#define ESP_SD_PIN_CMD GPIO_NUM_11 +#define ESP_SD_PIN_D0 GPIO_NUM_13 +#define ESP_SD_PIN_D1 GPIO_NUM_NC +#define ESP_SD_PIN_D2 GPIO_NUM_NC +#define ESP_SD_PIN_D3 GPIO_NUM_10 +#define ESP_SD_PIN_D4 GPIO_NUM_NC +#define ESP_SD_PIN_D5 GPIO_NUM_NC +#define ESP_SD_PIN_D6 GPIO_NUM_NC +#define ESP_SD_PIN_D7 GPIO_NUM_NC +#define ESP_SD_PIN_CD GPIO_NUM_NC +#define ESP_SD_PIN_WP GPIO_NUM_NC + + +/** + * @brief Camera Function Definition + */ +#define FUNC_CAMERA_EN (1) +#define CAM_PIN_PWDN GPIO_NUM_NC +#define CAM_PIN_RESET GPIO_NUM_NC +#define CAM_PIN_XCLK GPIO_NUM_40 +#define CAM_PIN_SIOD GPIO_NUM_17 +#define CAM_PIN_SIOC GPIO_NUM_18 + +#define CAM_PIN_D7 GPIO_NUM_39 +#define CAM_PIN_D6 GPIO_NUM_41 +#define CAM_PIN_D5 GPIO_NUM_42 +#define CAM_PIN_D4 GPIO_NUM_12 +#define CAM_PIN_D3 GPIO_NUM_3 +#define CAM_PIN_D2 GPIO_NUM_14 +#define CAM_PIN_D1 GPIO_NUM_47 +#define CAM_PIN_D0 GPIO_NUM_13 +#define CAM_PIN_VSYNC GPIO_NUM_21 +#define CAM_PIN_HREF GPIO_NUM_38 +#define CAM_PIN_PCLK GPIO_NUM_11 + +/** + * @brief Audio Codec Chip Function Definition + */ +#define FUNC_AUDIO_CODEC_EN (0) +#define HEADPHONE_DETECT (-1) +#define PA_ENABLE_GPIO GPIO_NUM_NC +#define CODEC_ADC_I2S_PORT ((i2s_port_t)0) +#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)I2S_BITS_PER_SAMPLE_32BIT) +#define CODEC_ADC_SAMPLE_RATE (48000) +#define RECORD_HARDWARE_AEC (false) +#define BOARD_PA_GAIN (0) /* Power amplifier gain defined by board (dB) */ + + + +/** + * @brief ADC input data format + */ +#define AUDIO_ADC_INPUT_CH_FORMAT "N" + +#define AUDIO_CODEC_DEFAULT_CONFIG(){ \ + .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ + .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ + .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ + .i2s_iface = { \ + .mode = AUDIO_HAL_MODE_SLAVE, \ + .fmt = AUDIO_HAL_I2S_NORMAL, \ + .samples = AUDIO_HAL_48K_SAMPLES, \ + .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ + }, \ +}; + + + +#endif diff --git a/components/audio_board/dfrobot_esp32_s3_ai_cam/board_pins_config.c b/components/audio_board/dfrobot_esp32_s3_ai_cam/board_pins_config.c new file mode 100644 index 000000000..767f065ba --- /dev/null +++ b/components/audio_board/dfrobot_esp32_s3_ai_cam/board_pins_config.c @@ -0,0 +1,107 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2025 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "esp_log.h" +#include "driver/gpio.h" +#include +#include "board.h" +#include "audio_error.h" +#include "audio_mem.h" +#include "soc/soc_caps.h" + +static const char *TAG = "DFROBOT_ESP32S3_AI_CAM"; + +esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) +{ + AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); + if (port == I2C_NUM_0 || port == I2C_NUM_1) { + i2c_config->sda_io_num = GPIO_NUM_8; + i2c_config->scl_io_num = GPIO_NUM_9; + } else { + i2c_config->sda_io_num = -1; + i2c_config->scl_io_num = -1; + ESP_LOGE(TAG, "i2c port %d is not supported", port); + return ESP_FAIL; + } + return ESP_OK; +} + +esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config) +{ + AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); + if (port == 0) { + i2s_config->bck_io_num = GPIO_NUM_38; + i2s_config->ws_io_num = -1; + i2s_config->data_out_num = -1; + i2s_config->data_in_num = GPIO_NUM_39; + i2s_config->mck_io_num = -1; + } else if (port == 1) { + i2s_config->bck_io_num = GPIO_NUM_45; + i2s_config->ws_io_num = GPIO_NUM_46; + i2s_config->data_out_num = GPIO_NUM_42; + i2s_config->data_in_num = -1; + i2s_config->mck_io_num = -1; + } else { + memset(i2s_config, -1, sizeof(board_i2s_pin_t)); + ESP_LOGE(TAG, "i2s port %d is not supported", port); + return ESP_FAIL; + } + + return ESP_OK; +} + +esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) +{ + AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); + AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); + + spi_config->mosi_io_num = GPIO_NUM_11; + spi_config->miso_io_num = GPIO_NUM_13; + spi_config->sclk_io_num = GPIO_NUM_12; + spi_config->quadwp_io_num = -1; + spi_config->quadhd_io_num = -1; + + spi_device_interface_config->spics_io_num = -1; + + ESP_LOGW(TAG, "SPI interface is not supported"); + return ESP_OK; +} + +// sdcard + +int8_t get_sdcard_intr_gpio(void) +{ + return SDCARD_INTR_GPIO; +} + +int8_t get_sdcard_open_file_num_max(void) +{ + return SDCARD_OPEN_FILE_NUM_MAX; +} + +int8_t get_sdcard_power_ctrl_gpio(void) +{ + return SDCARD_PWR_CTRL; +} + diff --git a/components/audio_board/unihiker_k10/board.c b/components/audio_board/unihiker_k10/board.c new file mode 100644 index 000000000..91000e7d4 --- /dev/null +++ b/components/audio_board/unihiker_k10/board.c @@ -0,0 +1,69 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2022 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "esp_log.h" +#include "board.h" +#include "audio_mem.h" + +static const char *TAG = "AUDIO_BOARD"; + +static audio_board_handle_t board_handle = 0; + +audio_board_handle_t audio_board_init(void) +{ + if (board_handle) { + ESP_LOGW(TAG, "The board has already been initialized!"); + return board_handle; + } + es7243e_adc_set_addr(0x23); + board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); + AUDIO_MEM_CHECK(TAG, board_handle, return NULL); + //board_handle->audio_hal = audio_board_codec_init(); + board_handle->adc_hal = audio_board_adc_init(); + return board_handle; +} + +audio_hal_handle_t audio_board_adc_init(void) +{ + audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); + audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE; + audio_hal_handle_t adc_hal = NULL; + adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243E_DEFAULT_HANDLE); + AUDIO_NULL_CHECK(TAG, adc_hal, return NULL); + return adc_hal; +} + +audio_board_handle_t audio_board_get_handle(void) +{ + return board_handle; +} + +esp_err_t audio_board_deinit(audio_board_handle_t audio_board) +{ + esp_err_t ret = ESP_OK; + ret |= audio_hal_deinit(audio_board->adc_hal); + audio_free(audio_board); + board_handle = NULL; + return ret; +} diff --git a/components/audio_board/unihiker_k10/board.h b/components/audio_board/unihiker_k10/board.h new file mode 100644 index 000000000..9ab44a3aa --- /dev/null +++ b/components/audio_board/unihiker_k10/board.h @@ -0,0 +1,92 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2022 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef _AUDIO_BOARD_H_ +#define _AUDIO_BOARD_H_ + +#include "audio_hal.h" +#include "board_def.h" +#include "board_pins_config.h" +#include "esp_peripherals.h" +#include "display_service.h" +#include "periph_sdcard.h" +#include "periph_lcd.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Audio board handle + */ +struct audio_board_handle { + audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ + audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */ +}; + +typedef struct audio_board_handle *audio_board_handle_t; + +/** + * @brief Initialize audio board + * + * @return The audio board handle + */ +audio_board_handle_t audio_board_init(void); + +/** + * @brief Initialize codec chip + * + * @return The audio hal handle + */ +audio_hal_handle_t audio_board_codec_init(void); + +/** + * @brief Initialize adc + * + * @return The adc hal handle + */ +audio_hal_handle_t audio_board_adc_init(void); + +/** + * @brief Query audio_board_handle + * + * @return The audio board handle + */ +audio_board_handle_t audio_board_get_handle(void); + +/** + * @brief Uninitialize the audio board + * + * @param audio_board The handle of audio board + * + * @return 0 success, + * others fail + */ +esp_err_t audio_board_deinit(audio_board_handle_t audio_board); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/audio_board/unihiker_k10/board_def.h b/components/audio_board/unihiker_k10/board_def.h new file mode 100644 index 000000000..22c968cbf --- /dev/null +++ b/components/audio_board/unihiker_k10/board_def.h @@ -0,0 +1,77 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2025 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef _AUDIO_BOARD_DEFINITION_H_ +#define _AUDIO_BOARD_DEFINITION_H_ + +#define FUNC_SDCARD_EN (0) +#define SDCARD_OPEN_FILE_NUM_MAX 5 +#define SDCARD_INTR_GPIO -1 +#define SDCARD_PWR_CTRL -1 +#define ESP_SD_PIN_CLK GPIO_NUM_13 +#define ESP_SD_PIN_CMD GPIO_NUM_11 +#define ESP_SD_PIN_D0 GPIO_NUM_14 +#define ESP_SD_PIN_D1 -1 +#define ESP_SD_PIN_D2 -1 +#define ESP_SD_PIN_D3 -1 +#define ESP_SD_PIN_D4 -1 +#define ESP_SD_PIN_D5 -1 +#define ESP_SD_PIN_D6 -1 +#define ESP_SD_PIN_D7 -1 +#define ESP_SD_PIN_CD -1 +#define ESP_SD_PIN_WP -1 + +/** + * @brief Audio Codec Chip Function Definition + */ +#define FUNC_AUDIO_CODEC_EN (1) +#define CODEC_ADC_I2S_PORT ((i2s_port_t)0) +#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)16) /* 32bit */ +#define CODEC_ADC_SAMPLE_RATE (16000) +#define RECORD_HARDWARE_AEC (false) +#define BOARD_PA_GAIN (0) /* Power amplifier gain defined by board (dB) */ +#define PA_ENABLE_GPIO -1 +#define HEADPHONE_DETECT -1 + +/** + * @brief ADC input data format + */ +#define AUDIO_ADC_INPUT_CH_FORMAT "MR" + +extern audio_hal_func_t AUDIO_CODEC_ES7243E_DEFAULT_HANDLE; +extern esp_err_t es7243e_adc_set_addr(int addr); + +#define AUDIO_CODEC_DEFAULT_CONFIG(){ \ + .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ + .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ + .codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE, \ + .i2s_iface = { \ + .mode = AUDIO_HAL_MODE_SLAVE, \ + .fmt = AUDIO_HAL_I2S_NORMAL, \ + .samples = AUDIO_HAL_16K_SAMPLES, \ + .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ + }, \ +}; + +#endif diff --git a/components/audio_board/unihiker_k10/board_pins_config.c b/components/audio_board/unihiker_k10/board_pins_config.c new file mode 100644 index 000000000..2abccd727 --- /dev/null +++ b/components/audio_board/unihiker_k10/board_pins_config.c @@ -0,0 +1,108 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2022 + * + * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "esp_log.h" +#include "driver/gpio.h" +#include +#include "board.h" +#include "audio_error.h" +#include "audio_mem.h" +#include "soc/soc_caps.h" + +static const char *TAG = "UNIHIKER_K10"; + +esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) +{ + AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); + if (port == I2C_NUM_0 || port == I2C_NUM_1) { + i2c_config->sda_io_num = GPIO_NUM_47; + i2c_config->scl_io_num = GPIO_NUM_48; + } else { + i2c_config->sda_io_num = -1; + i2c_config->scl_io_num = -1; + ESP_LOGE(TAG, "i2c port %d is not supported", port); + return ESP_FAIL; + } + return ESP_OK; +} + +esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config) +{ + AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); + if (port == 0) { + i2s_config->bck_io_num = GPIO_NUM_0; + i2s_config->ws_io_num = GPIO_NUM_38; + i2s_config->data_out_num = GPIO_NUM_45; + i2s_config->data_in_num = GPIO_NUM_39; + i2s_config->mck_io_num = GPIO_NUM_3; + } else if (port == 1) { + i2s_config->bck_io_num = -1; + i2s_config->ws_io_num = -1; + i2s_config->data_out_num = -1; + i2s_config->data_in_num = -1; + i2s_config->mck_io_num = -1; + } else { + memset(i2s_config, -1, sizeof(board_i2s_pin_t)); + ESP_LOGE(TAG, "i2s port %d is not supported", port); + return ESP_FAIL; + } + + return ESP_OK; +} + +esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) +{ + AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); + AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); + + spi_config->mosi_io_num = -1; + spi_config->miso_io_num = -1; + spi_config->sclk_io_num = -1; + spi_config->quadwp_io_num = -1; + spi_config->quadhd_io_num = -1; + + spi_device_interface_config->spics_io_num = -1; + + ESP_LOGW(TAG, "SPI interface is not supported"); + return ESP_OK; +} + + +// input-output pins + +int8_t get_headphone_detect_gpio(void) +{ + return HEADPHONE_DETECT; +} + +int8_t get_pa_enable_gpio(void) +{ + return -1; +} + +int8_t get_es7243_mclk_gpio(void) +{ + return GPIO_NUM_3; +} +