Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES8311 DAC support #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
82 changes: 82 additions & 0 deletions targets/esp32/components/audio_board/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
set(COMPONENT_ADD_INCLUDEDIRS ./include)

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES esp_peripherals audio_sal audio_hal esp_dispatcher display_service)


if (CONFIG_ESP_LYRAT_V4_2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRAT_V4_2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_v4_2)
set(COMPONENT_SRCS
./lyrat_v4_2/board.c
./lyrat_v4_2/board_pins_config.c
)
endif()

if (CONFIG_ESP_LYRAT_V4_3_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRAT_V4_3_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_v4_3)
set(COMPONENT_SRCS
./lyrat_v4_3/board.c
./lyrat_v4_3/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)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_mini_v1_1)
set(COMPONENT_SRCS
./lyrat_mini_v1_1/board.c
./lyrat_mini_v1_1/board_pins_config.c
)
endif()


if (CONFIG_ESP_LYRATD_MSC_V2_1_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRATD_MSC_V2_1_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyratd_msc_v2_1)
set(COMPONENT_SRCS
./lyratd_msc_v2_1/board.c
./lyratd_msc_v2_1/board_pins_config.c
)
endif()

if (CONFIG_ESP_LYRATD_MSC_V2_2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRATD_MSC_V2_2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyratd_msc_v2_2)
set(COMPONENT_SRCS
./lyratd_msc_v2_2/board.c
./lyratd_msc_v2_2/board_pins_config.c
)
endif()

if (CONFIG_ESP32_KORVO_DU1906_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_KORVO_DU1906_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_korvo_du1906)
set(COMPONENT_SRCS
./esp32_korvo_du1906/board.c
./esp32_korvo_du1906/board_pins_config.c
./esp32_korvo_du1906/du1906_bar_pattern.c
)
endif()

if (CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s2_kaluga_1_v1_2)
set(COMPONENT_SRCS
./esp32_s2_kaluga_1_v1_2/board.c
./esp32_s2_kaluga_1_v1_2/board_pins_config.c
)
endif()

if (CONFIG_ESP32_S3_KORVO2_V3_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_KORVO2_V3_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_korvo2_v3)
set(COMPONENT_SRCS
./esp32_s3_korvo2_v3/board.c
./esp32_s3_korvo2_v3/board_pins_config.c
)
endif()

register_component()
55 changes: 55 additions & 0 deletions targets/esp32/components/audio_board/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
menu "Audio HAL"

choice AUDIO_BOARD
prompt "Audio board"
default ESP_LYRAT_V4_3_BOARD
help
Select an audio board to use with the ESP-ADF
config AUDIO_BOARD_CUSTOM
bool "Custom audio board"
config ESP_LYRAT_V4_3_BOARD
bool "ESP32-Lyrat V4.3"
config ESP_LYRAT_V4_2_BOARD
bool "ESP32-Lyrat V4.2"
config ESP_LYRATD_MSC_V2_1_BOARD
bool "ESP32-LyraTD-MSC V2.1"
config ESP_LYRATD_MSC_V2_2_BOARD
bool "ESP32-LyraTD-MSC V2.2"
config ESP_LYRAT_MINI_V1_1_BOARD
bool "ESP32-Lyrat-Mini V1.1"
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 ESP32_S3_KORVO2_V3_BOARD
bool "ESP32-S3-Korvo-2 v3.0"

endchoice

choice ESP32_KORVO_DU1906_DAC
prompt "ESP32 KORVO DU1906 Board DAC chip"
depends on ESP32_KORVO_DU1906_BOARD
default ESP32_KORVO_DU1906_DAC_TAS5805M
help
Select DAC chip to use on ESP32_KORVO_DU1906 board

config ESP32_KORVO_DU1906_DAC_TAS5805M
bool "ESP32_KORVO_DU1906_DAC_TAS5805M"
config ESP32_KORVO_DU1906_DAC_ES7148
bool "ESP32_KORVO_DU1906_DAC_ES7148"

endchoice

choice ESP32_KORVO_DU1906_ADC
prompt "ESP32 KORVO DU1906 Board ADC chip"
depends on ESP32_KORVO_DU1906_BOARD
default ESP32_KORVO_DU1906_ADC_ES7243
help
Select ADC chip to use on ESP32_KORVO_DU1906 board

config ESP32_KORVO_DU1906_ADC_ES7243
bool "ESP32_KORVO_DU1906_ADC_ES7243"
endchoice

endmenu

49 changes: 49 additions & 0 deletions targets/esp32/components/audio_board/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

COMPONENT_ADD_INCLUDEDIRS := ./include

ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyrat_v4_3
COMPONENT_SRCDIRS += ./lyrat_v4_3
endif

ifdef CONFIG_ESP_LYRAT_V4_2_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyrat_v4_2
COMPONENT_SRCDIRS += ./lyrat_v4_2
endif

ifdef CONFIG_ESP_LYRATD_MSC_V2_1_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyratd_msc_v2_1
COMPONENT_SRCDIRS += ./lyratd_msc_v2_1
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/../audio_hal/driver/zl38063/firmware -lfirmware
endif

ifdef CONFIG_ESP_LYRATD_MSC_V2_2_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyratd_msc_v2_2
COMPONENT_SRCDIRS += ./lyratd_msc_v2_2
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/../audio_hal/driver/zl38063/firmware -lfirmware
endif

ifdef CONFIG_ESP_LYRAT_MINI_V1_1_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyrat_mini_v1_1
COMPONENT_SRCDIRS += ./lyrat_mini_v1_1
endif

ifdef CONFIG_ESP32_KORVO_DU1906_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./esp32_korvo_du1906
COMPONENT_SRCDIRS += ./esp32_korvo_du1906
endif

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_ESP32_S3_KORVO2_V3_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./esp32_s3_korvo2_v3
COMPONENT_SRCDIRS += ./esp32_s3_korvo2_v3
endif

166 changes: 166 additions & 0 deletions targets/esp32/components/audio_board/esp32_korvo_du1906/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* 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"
#include "led_indicator.h"
#include "periph_adc_button.h"
#include "led_bar_ws2812.h"
#include "display_service.h"
#include "es7243.h"

static const char *TAG = "AUDIO_BOARD";

static audio_board_handle_t board_handle;


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_dac_init();
es7243_adc_set_addr(0x24);
board_handle->adc_line_in_hal = audio_board_adc_init();
es7243_adc_set_addr(0x26);
board_handle->adc_ref_pa_hal = audio_board_adc_init();
return board_handle;
}

audio_hal_handle_t audio_board_dac_init(void)
{
audio_hal_handle_t dac_hal = NULL;
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
#ifdef CONFIG_ESP32_KORVO_DU1906_DAC_TAS5805M
dac_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE);
#elif CONFIG_ESP32_KORVO_DU1906_DAC_ES7148
dac_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7148_DEFAULT_HANDLE);
i2s_mclk_gpio_select(I2S_NUM_0, GPIO_NUM_0);
#endif

AUDIO_NULL_CHECK(TAG, dac_hal, return NULL);
return dac_hal;
}

audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_handle_t adc_hal = NULL;
#ifdef CONFIG_ESP32_KORVO_DU1906_ADC_ES7243
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
#endif
return adc_hal;
}

display_service_handle_t audio_board_led_init(void)
{
led_bar_ws2812_handle_t led = led_bar_ws2812_init(get_ws2812_gpio_pin(), get_ws2812_num());
AUDIO_NULL_CHECK(TAG, led, return NULL);
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_bar_ws2812_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)
{
esp_err_t ret = ESP_OK;
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_btn_cfg.task_cfg.ext_stack = true;
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.adc_ch = ADC1_CHANNEL_0; // GPIO36
adc_btn_tag.total_steps = 4;
int btn_array[5] = {200, 900, 1500, 2100, 2930};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
ret = esp_periph_start(set, adc_btn_handle);
return ret;
}

esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE) {
ESP_LOGE(TAG, "current board only support 1-line SD 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;
}
Loading