diff --git a/components/audio_board/CMakeLists.txt b/components/audio_board/CMakeLists.txt index 9541885..438ffcd 100644 --- a/components/audio_board/CMakeLists.txt +++ b/components/audio_board/CMakeLists.txt @@ -24,6 +24,15 @@ set(COMPONENT_SRCS ) endif() +if (CONFIG_ESP_AI_THINKER_ES8388_BOARD) +message(STATUS "Current board name is " CONFIG_ESP_AI_THINKER_ES8388_BOARD) +list(APPEND COMPONENT_ADD_INCLUDEDIRS ./ai_thinker_es8388) +set(COMPONENT_SRCS +./ai_thinker_es8388/board.c +./ai_thinker_es8388/board_pins_config.c +) +endif() + if (CONFIG_ESP_LYRAT_MINI_V1_1_BOARD) message(STATUS "Current board name is " CONFIG_ESP_LYRAT_MINI_V1_1_BOARD) diff --git a/components/audio_board/Kconfig.projbuild b/components/audio_board/Kconfig.projbuild index b401cb1..050309a 100644 --- a/components/audio_board/Kconfig.projbuild +++ b/components/audio_board/Kconfig.projbuild @@ -21,6 +21,8 @@ config ESP32_KORVO_DU1906_BOARD bool "ESP32_KORVO_DU1906" config ESP32_S2_KALUGA_1_V1_2_BOARD bool "ESP32-S2-Kaluga-1 v1.2" +config ESP_AI_THINKER_ES8388_BOARD + bool "ESP-AI-Thinker-ES8388 v2.2" endchoice diff --git a/components/audio_board/ai_thinker_es8388/board.c b/components/audio_board/ai_thinker_es8388/board.c new file mode 100644 index 0000000..e59adc0 --- /dev/null +++ b/components/audio_board/ai_thinker_es8388/board.c @@ -0,0 +1,155 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2019 + * + * 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 "board.h" +#include "audio_mem.h" +#include "esp_log.h" + +//#include "periph_sdcard.h" +//#include "led_indicator.h" +//#include "periph_touch.h" +//#include "periph_button.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); + board_handle->audio_hal = audio_board_codec_init (); + + return board_handle; +} + +audio_hal_handle_t +audio_board_codec_init (void) +{ + audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG (); + audio_hal_handle_t codec_hal + = audio_hal_init (&audio_codec_cfg, &AUDIO_CODEC_ES8388_DEFAULT_HANDLE); + AUDIO_NULL_CHECK (TAG, codec_hal, return NULL); + return codec_hal; +} + +/* +display_service_handle_t audio_board_led_init(void) +{ + led_indicator_handle_t led = +led_indicator_init((gpio_num_t)get_green_led_gpio()); display_service_config_t +display = { .based_cfg = { .task_stack = 0, .task_prio = 0, .task_core = 0, + .task_func = NULL, + .service_start = NULL, + .service_stop = NULL, + .service_destroy = NULL, + .service_ioctl = led_indicator_pattern, + .service_name = "DISPLAY_serv", + .user_data = NULL, + }, + .instance = led, + }; + + return display_service_create(&display); +} + +esp_err_t audio_board_key_init(esp_periph_set_handle_t set) +{ + periph_button_cfg_t btn_cfg = { + .gpio_mask = (1ULL << get_input_rec_id()) | (1ULL << +get_input_mode_id()), //REC BTN & MODE BTN + }; + esp_periph_handle_t button_handle = periph_button_init(&btn_cfg); + AUDIO_NULL_CHECK(TAG, button_handle, return ESP_ERR_ADF_MEMORY_LACK); + esp_err_t ret = ESP_OK; + ret = esp_periph_start(set, button_handle); + if (ret != ESP_OK) { + return ret; + } + periph_touch_cfg_t touch_cfg = { + .touch_mask = TOUCH_PAD_SEL4 | TOUCH_PAD_SEL7 | TOUCH_PAD_SEL8 | +TOUCH_PAD_SEL9, .tap_threshold_percent = 70, + }; + esp_periph_handle_t touch_periph = periph_touch_init(&touch_cfg); + AUDIO_NULL_CHECK(TAG, touch_periph, return ESP_ERR_ADF_MEMORY_LACK); + ret = esp_periph_start(set, touch_periph); + return ret; +} + +esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, +periph_sdcard_mode_t mode) +{ + if (mode >= SD_MODE_MAX) { + ESP_LOGE(TAG, "PLease select the correct sd mode!, current mode is %d", +mode); return ESP_FAIL; + } + periph_sdcard_cfg_t sdcard_cfg = { + .root = "/sdcard", + .card_detect_pin = get_sdcard_intr_gpio(), // GPIO_NUM_34 + .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); + audio_free (audio_board); + board_handle = NULL; + return ret; +} diff --git a/components/audio_board/ai_thinker_es8388/board.h b/components/audio_board/ai_thinker_es8388/board.h new file mode 100644 index 0000000..0dca37c --- /dev/null +++ b/components/audio_board/ai_thinker_es8388/board.h @@ -0,0 +1,117 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2019 + * + * 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" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @brief Audio board handle + */ + struct audio_board_handle + { + audio_hal_handle_t audio_hal; /*!< audio 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 led peripheral and display service + // * + // * @return The audio display service handle + // */ + // display_service_handle_t audio_board_led_init(void); + // + ///** + // * @brief Initialize key peripheral + // * + // * @param set The handle of esp_periph_set_handle_t + // * + // * @return + // * - ESP_OK, success + // * - Others, fail + // */ + // esp_err_t audio_board_key_init(esp_periph_set_handle_t set); + // + ///** + // * @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/ai_thinker_es8388/board_def.h b/components/audio_board/ai_thinker_es8388/board_def.h new file mode 100644 index 0000000..2161188 --- /dev/null +++ b/components/audio_board/ai_thinker_es8388/board_def.h @@ -0,0 +1,98 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2019 + * + * 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_ + +#include "driver/touch_pad.h" + +#define SDCARD_OPEN_FILE_NUM_MAX 5 +#define SDCARD_INTR_GPIO GPIO_NUM_34 + +#define BUTTON_REC_ID GPIO_NUM_36 +#define BUTTON_MODE_ID GPIO_NUM_39 +#define BUTTON_SET_ID TOUCH_PAD_NUM9 +#define BUTTON_PLAY_ID TOUCH_PAD_NUM8 +#define BUTTON_VOLUP_ID TOUCH_PAD_NUM7 +#define BUTTON_VOLDOWN_ID TOUCH_PAD_NUM4 + +#define AUXIN_DETECT_GPIO GPIO_NUM_12 +#define HEADPHONE_DETECT GPIO_NUM_19 +#define PA_ENABLE_GPIO GPIO_NUM_21 + +#define GREEN_LED_GPIO GPIO_NUM_22 + +extern audio_hal_func_t AUDIO_CODEC_ES8388_DEFAULT_HANDLE; + +#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, \ + }, \ +}; + +#define INPUT_KEY_NUM 6 + +#define INPUT_KEY_DEFAULT_INFO() \ + { \ + { \ + .type = PERIPH_ID_BUTTON, \ + .user_id = INPUT_KEY_USER_ID_REC, \ + .act_id = BUTTON_REC_ID, \ + }, \ + { \ + .type = PERIPH_ID_BUTTON, \ + .user_id = INPUT_KEY_USER_ID_MODE, \ + .act_id = BUTTON_MODE_ID, \ + }, \ + { \ + .type = PERIPH_ID_TOUCH, \ + .user_id = INPUT_KEY_USER_ID_SET, \ + .act_id = BUTTON_SET_ID, \ + }, \ + { \ + .type = PERIPH_ID_TOUCH, \ + .user_id = INPUT_KEY_USER_ID_PLAY, \ + .act_id = BUTTON_PLAY_ID, \ + }, \ + { \ + .type = PERIPH_ID_TOUCH, \ + .user_id = INPUT_KEY_USER_ID_VOLUP, \ + .act_id = BUTTON_VOLUP_ID, \ + }, \ + { \ + .type = PERIPH_ID_TOUCH, .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ + .act_id = BUTTON_VOLDOWN_ID, \ + } \ + } + +#endif diff --git a/components/audio_board/ai_thinker_es8388/board_pins_config.c b/components/audio_board/ai_thinker_es8388/board_pins_config.c new file mode 100644 index 0000000..55b2c23 --- /dev/null +++ b/components/audio_board/ai_thinker_es8388/board_pins_config.c @@ -0,0 +1,228 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2019 + * + * 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 "audio_error.h" +#include "audio_mem.h" +#include "board.h" +#include "driver/gpio.h" +#include "esp_log.h" +#include + +static const char *TAG = "AI_THINKER_ES8388"; + +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_33; + i2c_config->scl_io_num = GPIO_NUM_32; + } + 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 (i2s_port_t port, i2s_pin_config_t *i2s_config) +{ + AUDIO_NULL_CHECK (TAG, i2s_config, return ESP_FAIL); + if (port == I2S_NUM_0 || port == I2S_NUM_1) + { + i2s_config->bck_io_num = GPIO_NUM_27; + i2s_config->ws_io_num = GPIO_NUM_25; + i2s_config->data_out_num = GPIO_NUM_26; + i2s_config->data_in_num = GPIO_NUM_35; + } + else + { + memset (i2s_config, -1, sizeof (i2s_pin_config_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; +} + +esp_err_t +i2s_mclk_gpio_select (i2s_port_t i2s_num, gpio_num_t gpio_num) +{ + if (i2s_num >= I2S_NUM_MAX) + { + ESP_LOGE (TAG, "Does not support i2s number(%d)", i2s_num); + return ESP_ERR_INVALID_ARG; + } + if (gpio_num != GPIO_NUM_0 && gpio_num != GPIO_NUM_1 + && gpio_num != GPIO_NUM_3) + { + ESP_LOGE (TAG, "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num); + return ESP_ERR_INVALID_ARG; + } + ESP_LOGI (TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); + if (i2s_num == I2S_NUM_0) + { + if (gpio_num == GPIO_NUM_0) + { + PIN_FUNC_SELECT (PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); + WRITE_PERI_REG (PIN_CTRL, 0xFFF0); + } + else if (gpio_num == GPIO_NUM_1) + { + PIN_FUNC_SELECT (PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); + WRITE_PERI_REG (PIN_CTRL, 0xF0F0); + } + else + { + PIN_FUNC_SELECT (PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); + WRITE_PERI_REG (PIN_CTRL, 0xFF00); + } + } + else if (i2s_num == I2S_NUM_1) + { + if (gpio_num == GPIO_NUM_0) + { + PIN_FUNC_SELECT (PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); + WRITE_PERI_REG (PIN_CTRL, 0xFFFF); + } + else if (gpio_num == GPIO_NUM_1) + { + PIN_FUNC_SELECT (PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); + WRITE_PERI_REG (PIN_CTRL, 0xF0FF); + } + else + { + PIN_FUNC_SELECT (PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); + WRITE_PERI_REG (PIN_CTRL, 0xFF0F); + } + } + 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; +} + +// input-output pins + +int8_t +get_auxin_detect_gpio (void) +{ + return AUXIN_DETECT_GPIO; +} + +int8_t +get_headphone_detect_gpio (void) +{ + return HEADPHONE_DETECT; +} + +int8_t +get_pa_enable_gpio (void) +{ + return PA_ENABLE_GPIO; +} + +// button pins + +int8_t +get_input_rec_id (void) +{ + return BUTTON_REC_ID; +} + +int8_t +get_input_mode_id (void) +{ + return BUTTON_MODE_ID; +} + +// touch pins + +int8_t +get_input_set_id (void) +{ + return BUTTON_SET_ID; +} + +int8_t +get_input_play_id (void) +{ + return BUTTON_PLAY_ID; +} + +int8_t +get_input_volup_id (void) +{ + return BUTTON_VOLUP_ID; +} + +int8_t +get_input_voldown_id (void) +{ + return BUTTON_VOLDOWN_ID; +} + +// led pins + +int8_t +get_green_led_gpio (void) +{ + return GREEN_LED_GPIO; +} diff --git a/components/audio_board/component.mk b/components/audio_board/component.mk index 35766bc..dc97d1b 100644 --- a/components/audio_board/component.mk +++ b/components/audio_board/component.mk @@ -41,3 +41,8 @@ ifdef CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD COMPONENT_ADD_INCLUDEDIRS += ./esp32_s2_kaluga_1_v1_2 COMPONENT_SRCDIRS += ./esp32_s2_kaluga_1_v1_2 endif + +ifdef CONFIG_ESP_AI_THINKER_ES8388_BOARD +COMPONENT_ADD_INCLUDEDIRS += ./ai_thinker_es8388 +COMPONENT_SRCDIRS += ./ai_thinker_es8388 +endif diff --git a/components/audio_hal/driver/es8388/es8388.c b/components/audio_hal/driver/es8388/es8388.c index bc4d9ec..a278102 100644 --- a/components/audio_hal/driver/es8388/es8388.c +++ b/components/audio_hal/driver/es8388/es8388.c @@ -30,7 +30,7 @@ #include "i2c_bus.h" #include -#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD +#if defined(CONFIG_ESP_LYRAT_V4_3_BOARD) || defined(CONFIG_ESP_AI_THINKER_ES8388_BOARD) #include "headphone_detect.h" #endif @@ -292,7 +292,7 @@ es8388_deinit (void) res = es_write_reg (ES8388_ADDR, ES8388_CHIPPOWER, 0xFF); // reset and stop es8388 i2c_bus_delete (i2c_handle); -#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD +#if defined(CONFIG_ESP_LYRAT_V4_3_BOARD) || defined(CONFIG_ESP_AI_THINKER_ES8388_BOARD) headphone_detect_deinit (); #endif @@ -308,7 +308,7 @@ esp_err_t es8388_init (audio_hal_codec_config_t *cfg) { int res = 0; -#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD +#if defined(CONFIG_ESP_LYRAT_V4_3_BOARD) || defined(CONFIG_ESP_AI_THINKER_ES8388_BOARD) headphone_detect_init (get_headphone_detect_gpio ()); #endif @@ -445,11 +445,28 @@ es8388_set_voice_volume (int volume) volume = 0; else if (volume > 100) volume = 100; + /* Audio Settings can be checked here: + * https://dl.radxa.com/rock2/docs/hw/ds/ES8388%20user%20Guide.pdf + * + * ES8388_DACCONTROL4 & ES8388_DACCONTROL5 + * 0 = 0dB + * 192 = -96dB + * + * ES8388_DACCONTROL24 - ES8388_DACCONTROL27 + * 0 = -45dB + * 33 = 4.5dB + */ + + + int inv_volume = (100 - volume)*1.92; + res = es_write_reg (ES8388_ADDR, ES8388_DACCONTROL5, inv_volume); + res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL4, inv_volume); + volume /= 3; - res = es_write_reg (ES8388_ADDR, ES8388_DACCONTROL24, volume); + res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL24, volume); res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL25, volume); - res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL26, 0); - res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL27, 0); + res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL26, volume); + res |= es_write_reg (ES8388_ADDR, ES8388_DACCONTROL27, volume); return res; } diff --git a/components/audio_hal/driver/es8388/headphone_detect.c b/components/audio_hal/driver/es8388/headphone_detect.c index 9329c2d..f97927b 100644 --- a/components/audio_hal/driver/es8388/headphone_detect.c +++ b/components/audio_hal/driver/es8388/headphone_detect.c @@ -36,7 +36,7 @@ #include "freertos/task.h" #include "freertos/timers.h" -#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD +#if defined(CONFIG_ESP_LYRAT_V4_3_BOARD) || defined(CONFIG_ESP_AI_THINKER_ES8388_BOARD) #define HP_DELAY_TIME_MS 1000 @@ -107,4 +107,4 @@ headphone_detect_init (int num) gpio_install_isr_service (0); gpio_isr_handler_add (num, headphone_gpio_intr_handler, (void *)num); } -#endif /* CONFIG_ESP_LYRAT_V4_3_BOARD */ +#endif /* defined(CONFIG_ESP_LYRAT_V4_3_BOARD) || defined(CONFIG_ESP_AI_THINKER_ES8388_BOARD) */