mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +03:00
basic I2S compile
This commit is contained in:
10
components/squeezelite/external/dac_external.c
vendored
10
components/squeezelite/external/dac_external.c
vendored
@@ -22,6 +22,7 @@
|
|||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <driver/i2s.h>
|
#include <driver/i2s.h>
|
||||||
|
#include "esp_log.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "adac.h"
|
#include "adac.h"
|
||||||
|
|
||||||
@@ -34,13 +35,16 @@ static void power(adac_power_e mode) { };
|
|||||||
|
|
||||||
struct adac_s dac_external = { init, deinit, power, speaker, headset, volume };
|
struct adac_s dac_external = { init, deinit, power, speaker, headset, volume };
|
||||||
|
|
||||||
|
static char TAG[] = "DAC external";
|
||||||
|
|
||||||
static bool init(int i2c_port_num, int i2s_num, i2s_config_t *config) {
|
static bool init(int i2c_port_num, int i2s_num, i2s_config_t *config) {
|
||||||
#if !defined(CONFIG_SQUEEZEAMP) && !defined(CONFIG_A1S)
|
#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,
|
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 };
|
.data_out_num = CONFIG_I2S_DO_IO, .data_in_num = -1 };
|
||||||
char *nvs_item = config_alloc_get(NVS_TYPE_STR, "dac_config");
|
char *nvs_item = config_alloc_get(NVS_TYPE_STR, "dac_config");
|
||||||
|
|
||||||
if (nvs_item) {
|
if (nvs_item) {
|
||||||
|
char *p;
|
||||||
if ((p = strcasestr(nvs_item, "bck")) != NULL) i2s_pin_config.bck_io_num = atoi(strchr(p, '=') + 1);
|
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, "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);
|
if ((p = strcasestr(nvs_item, "do")) != NULL) i2s_pin_config.data_out_num = atoi(strchr(p, '=') + 1);
|
||||||
@@ -48,14 +52,14 @@ static bool init(int i2c_port_num, int i2s_num, i2s_config_t *config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i2s_pin_config.bck_io_num != -1 && i2s_pin_config.ws_io_num != -1 && i2s_pin_config.data_out_num != -1) {
|
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_driver_install(i2s_num, config, 0, NULL);
|
||||||
i2s_set_pin(i2s_num, &i2s_pin_config);
|
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);
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN("Cannot initialize I2S for SPDIF bck:%d ws:%d do:%d", i2s_pin_config.bck_io_num,
|
ESP_LOGI(TAG, "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.ws_io_num,
|
||||||
i2s_pin_config.data_out_num);
|
i2s_pin_config.data_out_num);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -113,14 +113,13 @@ static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *cou
|
|||||||
static void (*jack_handler_chain)(bool inserted);
|
static void (*jack_handler_chain)(bool inserted);
|
||||||
|
|
||||||
// force all GPIOs to what we need
|
// force all GPIOs to what we need
|
||||||
#ifdef CONFIG_SQUEEZEAMP
|
|
||||||
#undef CONFIG_I2S_NUM
|
#undef CONFIG_I2S_NUM
|
||||||
#define CONFIG_I2S_NUM 0
|
#define CONFIG_I2S_NUM 0
|
||||||
|
|
||||||
|
#ifdef CONFIG_SQUEEZEAMP
|
||||||
#undef CONFIG_SPDIF_DO_IO
|
#undef CONFIG_SPDIF_DO_IO
|
||||||
#define CONFIG_SPDIF_DO_IO 15
|
#define CONFIG_SPDIF_DO_IO 15
|
||||||
#elif defined CONFIG_A1S
|
#elif defined CONFIG_A1S
|
||||||
#undef CONFIG_I2S_NUM
|
|
||||||
#define CONFIG_I2S_NUM 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define I2C_PORT 0
|
#define I2C_PORT 0
|
||||||
|
|||||||
Reference in New Issue
Block a user