Skip to content

Commit

Permalink
Merge branch 'bugfix/lyrat_mini_choose_adc_in_micropython' into 'master'
Browse files Browse the repository at this point in the history
audio_board: Fix esp32_lyrat_mini choose adc chip issue

See merge request adf/esp-adf-internal!1352
  • Loading branch information
jason-mao committed Nov 15, 2024
2 parents 1ece25c + b8a185c commit 3a28fcd
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitlab/ci/build-micropython-adf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

build_micropython_adf:
extends:
- .rules:build:non-regular-board-idf-ver-tag
- .rules:build:micropython-test
- .build_micropython_cmake_template
- .matrix_template
variables:
Expand Down
9 changes: 9 additions & 0 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
.if-label-example: &if-label-example
if: '$BOT_LABEL_EXAMPLE_TEST || $CI_MERGE_REQUEST_LABELS =~ /^(?:[^,\n\r]+,)*example(?:,[^,\n\r]+)*$/i'

.if-label-micropython-test: &if-label-micropython-test
if: '$BOT_LABEL_EXAMPLE_TEST || $CI_MERGE_REQUEST_LABELS =~ /^(?:[^,\n\r]+,)*micropython_test(?:,[^,\n\r]+)*$/i'

.if-idf-version-tag-v5-0: &if-idf-version-tag-v5-0
if: '($IDF_VERSION_TAG == "v5.0.4" || $IDF_VERSION_TAG == "v5.0")'
variables:
Expand Down Expand Up @@ -95,6 +98,12 @@
- <<: *if-ref-master
- <<: *if-schedule

.rules:build:micropython-test:
rules:
- <<: *if-label-micropython-test
- <<: *if-protected
- <<: *if-schedule

.rules:ref:check-label:
rules:
- <<: *if-protected
Expand Down
14 changes: 0 additions & 14 deletions components/audio_board/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ config ESP32_P4_FUNCTION_EV_BOARD

endchoice

choice ESP_LYRAT_MINI_V1_1_ADC
prompt "ESP LYRAT MINI Board ADC chip"
depends on ESP_LYRAT_MINI_V1_1_BOARD
default ESP_LYRAT_MINI_V1_1_ADC_ES7243E
help
Select ADC chip to use on ESP_LYRAT_MINI_V1_1 board

config ESP_LYRAT_MINI_V1_1_ADC_ES7243E
bool "ESP_LYRAT_MINI_V1_1_ADC_ES7243E"
config ESP_LYRAT_MINI_V1_1_ADC_ES7243
bool "ESP_LYRAT_MINI_V1_1_ADC_ES7243"

endchoice

choice ESP32_KORVO_DU1906_DAC
prompt "ESP32 KORVO DU1906 Board DAC chip"
depends on ESP32_KORVO_DU1906_BOARD
Expand Down
43 changes: 38 additions & 5 deletions components/audio_board/lyrat_mini_v1_1/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,40 @@
#include "periph_sdcard.h"
#include "led_indicator.h"
#include "periph_adc_button.h"
#include "i2c_bus.h"

#define ES7243E_ADDR 0x20
#define ES7243_ADDR 0x26

static const char *TAG = "AUDIO_BOARD";

static audio_board_handle_t board_handle = 0;

static int audio_board_probe_adc(uint8_t addr)
{
static i2c_bus_handle_t i2c_handle = NULL;
int res = 0;

if (i2c_handle == NULL) {
i2c_config_t es_i2c_cfg = {
.mode = I2C_MODE_MASTER,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 100000,
};
res = get_i2c_pins(I2C_NUM_0, &es_i2c_cfg);
if (res != 0) {
return res;
}
i2c_handle = i2c_bus_create(I2C_NUM_0, &es_i2c_cfg);
}

if (i2c_handle) {
return i2c_bus_probe_addr(i2c_handle, addr);
}
return ESP_FAIL;
}

audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
Expand All @@ -52,11 +81,15 @@ audio_hal_handle_t audio_board_adc_init(void)
audio_hal_handle_t adc_hal = NULL;
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE;
#ifdef CONFIG_ESP_LYRAT_MINI_V1_1_ADC_ES7243E
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243E_DEFAULT_HANDLE);
#elif CONFIG_ESP_LYRAT_MINI_V1_1_ADC_ES7243
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE);
#endif /* CONFIG_ESP_LYRAT_MINI_V1_1_ADC_ES7243E */

// The new version of the esp32_lyrat_mini development board has replaced the ADC from ES7243 to ES7243E.
// Check the current ADC in use and initialize it.
if (audio_board_probe_adc(ES7243E_ADDR) == ESP_OK) {
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243E_DEFAULT_HANDLE);
} else if (audio_board_probe_adc(ES7243_ADDR) == ESP_OK) {
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE);
}

AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
return adc_hal;
}
Expand Down
3 changes: 0 additions & 3 deletions components/audio_board/lyrat_mini_v1_1/board_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@
#define BOARD_PA_GAIN (20) /* Power amplifier gain defined by board (dB) */

extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
#ifdef CONFIG_ESP_LYRAT_MINI_V1_1_ADC_ES7243E
extern audio_hal_func_t AUDIO_CODEC_ES7243E_DEFAULT_HANDLE;
#elif CONFIG_ESP_LYRAT_MINI_V1_1_ADC_ES7243
extern audio_hal_func_t AUDIO_CODEC_ES7243_DEFAULT_HANDLE;
#endif /* CONFIG_ESP_LYRAT_MINI_V1_1_ADC_ES7243E */

#define AUDIO_CODEC_DEFAULT_CONFIG() { \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
Expand Down
35 changes: 34 additions & 1 deletion micropython_adf/boards/lyratmini/board_init.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
#include "board_init.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "i2c_bus.h"

#define ES7243E_ADDR 0x20
#define ES7243_ADDR 0x26

static char *TAG = "LyraTMini_board";
static audio_hal_handle_t audio_hal = NULL;

static int audio_board_probe_adc(uint8_t addr)
{
static i2c_bus_handle_t i2c_handle = NULL;

if (i2c_handle == NULL) {
i2c_config_t es_i2c_cfg = {
.mode = I2C_MODE_MASTER,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 100000,
};
es_i2c_cfg.sda_io_num = 18;
es_i2c_cfg.scl_io_num = 23;
i2c_handle = i2c_bus_create(I2C_NUM_0, &es_i2c_cfg);
}

if (i2c_handle) {
return i2c_bus_probe_addr(i2c_handle, addr);
}
return ESP_FAIL;
}

audio_hal_handle_t board_codec_init(void)
{
if (audio_hal) {
Expand All @@ -15,7 +41,14 @@ audio_hal_handle_t board_codec_init(void)
audio_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
audio_hal_ctrl_codec(audio_hal, AUDIO_HAL_CODEC_MODE_DECODE, AUDIO_HAL_CTRL_START);

audio_hal_handle_t adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE);
// The new version of the esp32_lyrat_mini development board has replaced the ADC from ES7243 to ES7243E.
// Check the current ADC in use and initialize it.
audio_hal_handle_t adc_hal = NULL;
if (audio_board_probe_adc(ES7243E_ADDR) == ESP_OK) {
audio_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243E_DEFAULT_HANDLE);
} else if (audio_board_probe_adc(ES7243_ADDR) == ESP_OK) {
audio_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE);
}
audio_hal_ctrl_codec(adc_hal, AUDIO_HAL_CODEC_MODE_ENCODE, AUDIO_HAL_CTRL_START);

return audio_hal;
Expand Down
6 changes: 4 additions & 2 deletions micropython_adf/boards/lyratmini/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ set(ADF_BOARD_DIR "$ENV{ADF_PATH}/components/audio_board/lyrat_mini_v1_1")

set(ADF_BOARD_CODEC_SRC
${ADF_COMPS}/audio_hal/driver/es8311/es8311.c
${ADF_COMPS}/audio_hal/driver/es7243/es7243.c)
${ADF_COMPS}/audio_hal/driver/es7243/es7243.c
${ADF_COMPS}/audio_hal/driver/es7243e/es7243e.c)
set(ADF_BOARD_CODEC_INC
${ADF_COMPS}/audio_hal/driver/es8311
${ADF_COMPS}/audio_hal/driver/es7243)
${ADF_COMPS}/audio_hal/driver/es7243
${ADF_COMPS}/audio_hal/driver/es7243e)
set(ADF_BOARD_INIT_SRC
$ENV{ADF_PATH}/components $ENV{ADF_PATH}/micropython_adf/boards/lyratmini/board_init.c)

Expand Down

0 comments on commit 3a28fcd

Please sign in to comment.