From 3c604699ba4630ab39cdf524ac1673c2a1d56623 Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Tue, 17 Sep 2024 16:49:51 +0200 Subject: [PATCH] attempts to get running on lyrat boards. Loads OK but inputs and outputs silence. Still questionable but audible output from generic ESP32 boards with MAX98357A DAC/AMP and INMP 441 MEMS mic. --- .gitignore | 2 ++ CMakeLists.txt | 5 ++++ README.txt | 1 + main/espd.c | 78 +++++++++++++++++++++++++++++++------------------- main/espd.h | 8 +++--- 5 files changed, 61 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 378eac2..a7d6859 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ build +dependencies.lock +managed_components diff --git a/CMakeLists.txt b/CMakeLists.txt index 458c5fe..658b79f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,5 +2,10 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) +# for LyraT boards uncomment this line and use "esp_adf" instead of "esp_idf": +# +# include($ENV{ADF_PATH}/CMakeLists.txt) +# + include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(espd) diff --git a/README.txt b/README.txt index b5b2ca5..ec4257f 100644 --- a/README.txt +++ b/README.txt @@ -69,6 +69,7 @@ export IDF_PATH=~/bis/var/esp/esp-idf for LyraT boards: +### FIRST edit Cmakelists.txt to enable esp_adf ### export IDF_TOOLS_PATH=~/bis/var/esp/tools export ADF_PATH=~/bis/var/esp/esp-adf . $ADF_PATH/esp-idf/export.sh diff --git a/main/espd.c b/main/espd.c index fa35411..7099a29 100644 --- a/main/espd.c +++ b/main/espd.c @@ -9,11 +9,13 @@ #include "espd.h" #include -#include g +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#ifdef PD_LYRAT +#include "board.h" +#endif /* PD_LYRAT */ #include "driver/i2s.h" - #include "esp_log.h" #include "nvs.h" #include "nvs_flash.h" @@ -102,42 +104,60 @@ void senddacs( void) static void initdacs( void) { - i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX + i2s_config_t i2s_config = + { + .mode = (I2S_MODE_MASTER | I2S_MODE_TX #ifdef USEADC - | I2S_MODE_RX + | I2S_MODE_RX #endif ), - .sample_rate = 48000, - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, - .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, - .communication_format = - (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S), - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, /* high interrupt priority */ - .dma_buf_count = 16, - .dma_buf_len = 256, - .use_apll=0, - .tx_desc_auto_clear= true, - .fixed_mclk=-1 }; - i2s_pin_config_t i2s_pin_cfg = { -#if 1 /* generic board on big breadboard */ - .bck_io_num = 13, /* bit clock */ - .ws_io_num = 33, /* Word select, aka left right clock */ - .data_out_num = 32, /* Data out from ESP32, to DIN on 38357A */ - .data_in_num = 35 /* data from ADC */ -#endif -#if 0 - .bck_io_num = 33, /* bit clock */ - .ws_io_num = 25, /* Word select, aka left right clock */ - .data_out_num = 32, /* Data out from ESP32, to DIN on 38357A */ - .data_in_num = I2S_PIN_NO_CHANGE /* no ADC */ + .sample_rate = 48000, + .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, + .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, + .communication_format = I2S_COMM_FORMAT_STAND_I2S, + .dma_buf_count = 16, + .dma_buf_len = 256, +#ifdef PD_LYRAT + .use_apll=1, +#else + .use_apll=0, #endif + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, /* high interrupt priority */ + .tx_desc_auto_clear= true, + .fixed_mclk=-1 }; ESP_LOGI(TAG, "[ 1 ] Start audio codec chip"); +#ifdef PD_LYRAT + audio_board_handle_t board_handle = audio_board_init(); + audio_hal_ctrl_codec(board_handle->audio_hal, + AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START); + audio_hal_set_volume(board_handle->audio_hal, 100); +#endif + i2s_driver_install(TEST_I2S_NUM, &i2s_config, 0, NULL); - i2s_set_pin(TEST_I2S_NUM, &i2s_pin_cfg); + +#ifndef PD_LYRAT + { + i2s_pin_config_t i2s_pin_cfg = + { +#if 1 /* generic board 1 - edit this as needed */ + .bck_io_num = 13, /* bit clock */ + .ws_io_num = 33, /* Word select, aka left right clock */ + .data_out_num = 32, /* Data out from ESP32, to DIN on 38357A */ + .data_in_num = 35 /* data from ADC */ +#endif +#if 0 /* generic board 2 */ + .bck_io_num = 33, /* bit clock */ + .ws_io_num = 25, /* Word select, aka left right clock */ + .data_out_num = 32, /* Data out from ESP32, to DIN on 38357A */ + .data_in_num = I2S_PIN_NO_CHANGE /* no ADC */ +#endif + }; + i2s_set_pin(TEST_I2S_NUM, &i2s_pin_cfg); + } +#endif /* not PD_LYRAT */ } static int audiostate; diff --git a/main/espd.h b/main/espd.h index 74a40f4..5bab043 100644 --- a/main/espd.h +++ b/main/espd.h @@ -1,7 +1,7 @@ -/* #define PD_USE_BLUETOOTH */ -/* #define PD_USE_WIFI */ -#define PD_USE_CONSOLE - +/* #define PD_USE_BLUETOOTH */ /* messages to Pd over bluetooth */ +/* #define PD_USE_WIFI */ /* messages to/from Pd over wifi TCP */ +#define PD_USE_CONSOLE /* messages to Pd over "console" (USB serial) */ +/* #define PD_LYRAT */ /* using LyraT or LyraT mini board */ /* task priorities */ #define PRIORITY_WIFI 2