mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
add dac_config NVS for generic I2S/DAC configuration
This commit is contained in:
1133
build-scripts/ESP32-A1S.defaults
Normal file
1133
build-scripts/ESP32-A1S.defaults
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
set(COMPONENT_ADD_INCLUDEDIRS .)
|
||||
|
||||
set(COMPONENT_SRCS "tas5756m.c")
|
||||
|
||||
set(COMPONENT_REQUIRES console spi_flash)
|
||||
|
||||
register_component()
|
||||
@@ -1,13 +0,0 @@
|
||||
#
|
||||
# Component Makefile
|
||||
#
|
||||
# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default,
|
||||
# this will take the sources in the src/ directory, compile them and link them into
|
||||
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
|
||||
# please read the SDK documents if you need to do this.
|
||||
#
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS := .
|
||||
CFLAGS += -Os -DPOSIX -DLINKALL -DLOOPBACK -DNO_FAAD -DEMBEDDED -DTREMOR_ONLY -DBYTES_PER_FRAME=4
|
||||
#CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
|
||||
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_INFO
|
||||
@@ -29,9 +29,8 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <driver/i2c.h>
|
||||
#include <driver/i2s.h>
|
||||
#include "adac.h"
|
||||
|
||||
//#include "audio_hal.h"
|
||||
#include "ac101.h"
|
||||
|
||||
const static char TAG[] = "AC101";
|
||||
|
||||
@@ -19,9 +19,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <driver/i2s.h>
|
||||
#include "config.h"
|
||||
#include "adac.h"
|
||||
|
||||
static bool init(int i2c_port_num, int i2s_num, i2s_config_t *config) { return true; };
|
||||
static bool init(int i2c_port_num, int i2s_num, i2s_config_t *config);
|
||||
static void deinit(void) { };
|
||||
static void speaker(bool active) { };
|
||||
static void headset(bool active) { } ;
|
||||
@@ -30,3 +34,34 @@ static void power(adac_power_e mode) { };
|
||||
|
||||
struct adac_s dac_null = { init, deinit, power, speaker, headset, volume };
|
||||
|
||||
static bool init(int i2c_port_num, int i2s_num, i2s_config_t *config) {
|
||||
#if !defined(CONFIG_SQUEEZEAMP) && !defined(CONFIG_A1S)
|
||||
i2s_pin_config_t i2s_pin_config = (i2s_pin_config_t) { .bck_io_num = CONFIG_I2S_BCK_IO, .ws_io_num = CONFIG_I2S_WS_IO,
|
||||
.data_out_num = CONFIG_I2S_DO_IO, .data_in_num = -1 //Not used };
|
||||
char *nvs_item = config_alloc_get(NVS_TYPE_STR, "dac_config");
|
||||
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "bck")) != NULL) i2s_pin_config.bck_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "ws")) != NULL) i2s_pin_config.ws_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "do")) != NULL) i2s_pin_config.data_out_num = atoi(strchr(p, '=') + 1);
|
||||
free(nvs_item);
|
||||
}
|
||||
|
||||
if (i2s_pin_config.bck_io_num != -1 && i2s_pin_config.ws_io_num != -1 && i2s_pin_config.data_out_num != -1) {
|
||||
i2s_driver_install(i2s_num, i2s_config, 0, NULL);
|
||||
i2s_set_pin(i2s_num, &i2s_pin_config);
|
||||
|
||||
ESP_LOGI(TAG, "DAC using I2S bck:%u, ws:%u, do:%u", i2s_pin_config.bck_io_num, i2s_pin_config.ws_io_num, i2s_pin_config.data_out_num);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
LOG_WARN("Cannot initialize I2S for SPDIF bck:%d ws:%d do:%d", i2s_pin_config.bck_io_num,
|
||||
i2s_pin_config.ws_io_num,
|
||||
i2s_pin_config.data_out_num);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -114,19 +114,11 @@ static void (*jack_handler_chain)(bool inserted);
|
||||
|
||||
// force all GPIOs to what we need
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define TAS57xx
|
||||
#undef CONFIG_SPDIF_BCK_IO
|
||||
#define CONFIG_SPDIF_BCK_IO 33
|
||||
#undef CONFIG_SPDIF_WS_IO
|
||||
#define CONFIG_SPDIF_WS_IO 25
|
||||
#undef CONFIG_SPDIF_DO_IO
|
||||
#define CONFIG_SPDIF_DO_IO 15
|
||||
#undef CONFIG_SPDIF_NUM
|
||||
#define CONFIG_SPDIF_NUM 0
|
||||
#undef CONFIG_I2S_NUM
|
||||
#define CONFIG_I2S_NUM 0
|
||||
#undef CONFIG_SPDIF_DO_IO
|
||||
#define CONFIG_SPDIF_DO_IO 15
|
||||
#elif defined CONFIG_A1S
|
||||
#define A1S
|
||||
#undef CONFIG_I2S_NUM
|
||||
#define CONFIG_I2S_NUM 0
|
||||
#endif
|
||||
@@ -221,9 +213,28 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
||||
|
||||
if (strcasestr(device, "spdif")) {
|
||||
spdif = true;
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
i2s_pin_config_t i2s_pin_config = (i2s_pin_config_t) { .bck_io_num = 33, .ws_io_num = 25,
|
||||
.data_out_num = CONFIG_SPDIF_DO_IO, .data_in_num = -1 };
|
||||
#else
|
||||
i2s_pin_config_t i2s_pin_config = (i2s_pin_config_t) { .bck_io_num = CONFIG_SPDIF_BCK_IO, .ws_io_num = CONFIG_SPDIF_WS_IO,
|
||||
.data_out_num = CONFIG_SPDIF_DO_IO, .data_in_num = -1 //Not used
|
||||
};
|
||||
.data_out_num = CONFIG_SPDIF_DO_IO, .data_in_num = -1 };
|
||||
char *nvs_item = config_alloc_get(NVS_TYPE_STR, "spdif_config");
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "bck")) != NULL) i2s_pin_config.bck_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "ws")) != NULL) i2s_pin_config.ws_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "do")) != NULL) i2s_pin_config.data_out_num = atoi(strchr(p, '=') + 1);
|
||||
free(nvs_item);
|
||||
}
|
||||
|
||||
if (i2s_pin_config.bck_io_num == -1 || i2s_pin_config.ws_io_num == -1 || i2s_pin_config.data_out_num == -1) {
|
||||
LOG_WARN("Cannot initialize I2S for SPDIF bck:%d ws:%d do:%d", i2s_pin_config.bck_io_num,
|
||||
i2s_pin_config.ws_io_num,
|
||||
i2s_pin_config.data_out_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
i2s_config.sample_rate = output.current_sample_rate * 2;
|
||||
i2s_config.bits_per_sample = 32;
|
||||
// Normally counted in frames, but 16 sample are transformed into 32 bits in spdif
|
||||
@@ -239,12 +250,12 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
||||
i2s_set_pin(CONFIG_I2S_NUM, &i2s_pin_config);
|
||||
LOG_INFO("SPDIF using I2S bck:%u, ws:%u, do:%u", i2s_pin_config.bck_io_num, i2s_pin_config.ws_io_num, i2s_pin_config.data_out_num);
|
||||
} else {
|
||||
#ifdef TAS57xx
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
gpio_pad_select_gpio(CONFIG_SPDIF_DO_IO);
|
||||
gpio_set_direction(CONFIG_SPDIF_DO_IO, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(CONFIG_SPDIF_DO_IO, 0);
|
||||
adac = &dac_tas57xx;
|
||||
#elif defined(A1S)
|
||||
#elif defined(CONFIG_A1S)
|
||||
adac = &dac_a1s;
|
||||
#endif
|
||||
i2s_config.sample_rate = output.current_sample_rate;
|
||||
|
||||
@@ -311,7 +311,7 @@ static void handleLogBuffer(int partnerSocket, UBaseType_t count){
|
||||
UBaseType_t uxItemsWaiting;
|
||||
UBaseType_t uxBytesToSend=count;
|
||||
|
||||
vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
if( partnerSocket ==0 && (uxItemsWaiting*100 / log_buf_size) <75){
|
||||
// We still have some room in the ringbuffer and there's no telnet
|
||||
// connection yet, so bail out for now.
|
||||
|
||||
@@ -328,6 +328,12 @@ void register_default_nvs(){
|
||||
ESP_LOGD(TAG,"Registering default value for key %s", "stats");
|
||||
config_set_default(NVS_TYPE_STR, "stats", "n", 0);
|
||||
|
||||
ESP_LOGD(TAG,"Registering default value for key %s", "spdif_config");
|
||||
config_set_default(NVS_TYPE_STR, "spdif_config", "", 0);
|
||||
|
||||
ESP_LOGD(TAG,"Registering default value for key %s", "dac_config");
|
||||
config_set_default(NVS_TYPE_STR, "dac_config", "", 0);
|
||||
|
||||
ESP_LOGD(TAG,"Done setting default values in nvs.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user