prepare 4.4 migration + esp32s3 + mck on 0,1,3

This commit is contained in:
philippe44
2023-05-15 15:29:16 +02:00
parent 9d7044f30c
commit e78e5a4df7
17 changed files with 75 additions and 44 deletions

View File

@@ -216,6 +216,7 @@ CONFIG_TARGET=""
# I2S settings
#
CONFIG_I2S_NUM=0
CONFIG_I2S_MCK_IO=-1
CONFIG_I2S_BCK_IO=-1
CONFIG_I2S_WS_IO=-1
CONFIG_I2S_DO_IO=-1

View File

@@ -217,6 +217,7 @@ CONFIG_TARGET="muse"
# I2S settings
#
CONFIG_I2S_NUM=0
CONFIG_I2S_MCK_IO=-1
CONFIG_I2S_BCK_IO=-1
CONFIG_I2S_WS_IO=-1
CONFIG_I2S_DO_IO=-1

View File

@@ -209,6 +209,7 @@ CONFIG_TARGET="squeezeamp"
# I2S settings
#
CONFIG_I2S_NUM=0
CONFIG_I2S_MCK_IO=-1
CONFIG_I2S_BCK_IO=-1
CONFIG_I2S_WS_IO=-1
CONFIG_I2S_DO_IO=-1

View File

@@ -23,7 +23,6 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "soc/rtc_cntl_reg.h"
#include "esp32/rom/uart.h"
#include "sdkconfig.h"
#include "platform_console.h"
#include "messaging.h"

View File

@@ -20,7 +20,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "soc/rtc_cntl_reg.h"
#include "esp32/rom/uart.h"
#include "esp_rom_uart.h"
#include "cmd_system.h"
#include "sdkconfig.h"
#include "esp_partition.h"
@@ -28,7 +28,6 @@
#include "platform_esp32.h"
#include "platform_config.h"
#include "esp_sleep.h"
#include "driver/uart.h" // for the uart driver access
#include "messaging.h"
#include "platform_console.h"
#include "tools.h"
@@ -791,7 +790,7 @@ static int light_sleep(int argc, char **argv)
ESP_ERROR_CHECK( esp_sleep_enable_uart_wakeup(CONFIG_ESP_CONSOLE_UART_NUM) );
}
fflush(stdout);
uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str;

View File

@@ -48,7 +48,7 @@ static const char TAG[] = "AC101";
return b;\
}
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config);
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config, bool *mck);
static void speaker(bool active);
static void headset(bool active);
static bool volume(unsigned left, unsigned right);
@@ -64,7 +64,7 @@ static void ac101_set_spk_volume(uint8_t volume);
/****************************************************************************************
* init
*/
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config) {
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config, bool *mck) {
adac_init(config, i2c_port);
if (adac_read_word(AC101_ADDR, CHIP_AUDIO_RS) == 0xffff) {
ESP_LOGW(TAG, "No AC101 detected");

View File

@@ -17,7 +17,7 @@ typedef enum { ADAC_ON = 0, ADAC_STANDBY, ADAC_OFF } adac_power_e;
struct adac_s {
char *model;
bool (*init)(char *config, int i2c_port_num, i2s_config_t *i2s_config);
bool (*init)(char *config, int i2c_port_num, i2s_config_t *i2s_config, bool *mck);
void (*deinit)(void);
void (*power)(adac_power_e mode);
void (*speaker)(bool active);

View File

@@ -29,16 +29,8 @@ static int i2c_port = -1;
* init
*/
int adac_init(char *config, int i2c_port_num) {
char *p;
int i2c_addr = 0;
// some crappy codecs require MCLK to work
if ((p = strcasestr(config, "mck")) != NULL) {
ESP_LOGI(TAG, "Configuring MCLK on GPIO0");
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
REG_WRITE(PIN_CTRL, 0xFFFFFFF0);
}
i2c_port = i2c_port_num;
// configure i2c

View File

@@ -24,7 +24,7 @@ static void speaker(bool active);
static void headset(bool active);
static bool volume(unsigned left, unsigned right) { return false; }
static void power(adac_power_e mode);
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config);
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config, bool *mck);
static bool i2c_json_execute(char *set);
@@ -56,7 +56,7 @@ static struct {
/****************************************************************************************
* init
*/
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config) {
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config, bool *mck) {
char *p;
i2c_addr = adac_init(config, i2c_port_num);
@@ -71,11 +71,7 @@ static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config) {
int i;
sscanf(p, "%*[^=]=%31[^,]", model);
for (i = 0; *model && ((p = codecs[i].controlset) != NULL) && strcasecmp(codecs[i].model, model); i++);
if (p && codecs[i].mclk) {
ESP_LOGI(TAG, "Configuring MCLK on GPIO0");
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
REG_WRITE(PIN_CTRL, 0xFFFFFFF0);
}
if (p) *mck = codecs[i].mclk;
}
i2c_json = cJSON_Parse(p);

View File

@@ -190,10 +190,14 @@ static void set_amp_gpio(int gpio, char *value) {
* Set pin from config string
*/
static void set_i2s_pin(char *config, i2s_pin_config_t *pin_config) {
pin_config->bck_io_num = pin_config->ws_io_num = pin_config->data_out_num = pin_config->data_in_num = -1;
pin_config->bck_io_num = pin_config->ws_io_num = pin_config->data_out_num = pin_config->data_in_num = -1;
PARSE_PARAM(config, "bck", '=', pin_config->bck_io_num);
PARSE_PARAM(config, "ws", '=', pin_config->ws_io_num);
PARSE_PARAM(config, "do", '=', pin_config->data_out_num);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
pin_config->mck_io_num = strcasestr(config, "mck") ? 0 : -1;
PARSE_PARAM(config, "mck", '=', pin_config->mck_io_num);
#endif
}
/****************************************************************************************
@@ -234,14 +238,19 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
",ws=" STR(CONFIG_SPDIF_WS_IO) ",do=" STR(CONFIG_SPDIF_DO_IO));
char *dac_config = config_alloc_get_str("dac_config", CONFIG_DAC_CONFIG, "model=i2s,bck=" STR(CONFIG_I2S_BCK_IO)
",ws=" STR(CONFIG_I2S_WS_IO) ",do=" STR(CONFIG_I2S_DO_IO)
",ws=" STR(CONFIG_I2S_WS_IO) ",do=" STR(CONFIG_I2S_DO_IO) ",mck=" STR(CONFIG_I2S_MCK_IO)
",sda=" STR(CONFIG_I2C_SDA) ",scl=" STR(CONFIG_I2C_SCL)
",mute=" STR(CONFIG_MUTE_GPIO));
i2s_pin_config_t i2s_dac_pin, i2s_spdif_pin;
i2s_pin_config_t i2s_dac_pin, i2s_spdif_pin;
set_i2s_pin(spdif_config, &i2s_spdif_pin);
set_i2s_pin(dac_config, &i2s_dac_pin);
if (i2s_dac_pin.data_out_num == -1 && i2s_spdif_pin.data_out_num == -1) {
LOG_WARN("DAC and SPDIF not configured, NOT launching i2s thread");
return;
}
/* BEWARE: i2s.c must be patched otherwise L/R are swapped in 32 bits mode */
// common I2S initialization
@@ -250,7 +259,9 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
i2s_config.communication_format = I2S_COMM_FORMAT_STAND_I2S;
// in case of overflow, do not replay old buffer
i2s_config.tx_desc_auto_clear = true;
i2s_config.use_apll = true;
#ifndef CONFIG_IDF_TARGET_ESP32S3
i2s_config.use_apll = true;
#endif
i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; //Interrupt level 1
if (strcasestr(device, "spdif")) {
@@ -303,12 +314,36 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
if ((p = strchr(mute, ':')) != NULL) mute_control.active = atoi(p + 1);
}
bool mck_required = false;
for (int i = 0; adac == &dac_external && dac_set[i]; i++) if (strcasestr(dac_set[i]->model, model)) adac = dac_set[i];
res = adac->init(dac_config, I2C_PORT, &i2s_config) ? ESP_OK : ESP_FAIL;
res = adac->init(dac_config, I2C_PORT, &i2s_config, &mck_required) ? ESP_OK : ESP_FAIL;
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 0)
int mck_io_num = strcasestr(dac_config, "mck") || mck_required ? 0 : -1;
PARSE_PARAM(dac_config, "mck", '=', mck_io_num);
LOG_INFO("configuring MCLK on GPIO %d", mck_io_num);
if (mck_io_num == GPIO_NUM_0) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
WRITE_PERI_REG(PIN_CTRL, CONFIG_I2S_NUM == I2S_NUM_0 ? 0xFFF0 : 0xFFFF);
} else if (mck_io_num == GPIO_NUM_1) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3);
WRITE_PERI_REG(PIN_CTRL, CONFIG_I2S_NUM == I2S_NUM_0 ? 0xF0F0 : 0xF0FF);
} else if (mck_io_num == GPIO_NUM_2) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2);
WRITE_PERI_REG(PIN_CTRL, CONFIG_I2S_NUM == I2S_NUM_0 ? 0xFF00 : 0xFF0F);
} else {
LOG_WARN("invalid MCK gpio %d", mck_io_num);
}
#else
if (mck_required && i2s_dac_pin.mck_io_num == -1) i2s_dac_pin.mck_io_num = 0;
LOG_INFO("configuring MCLK on GPIO %d", i2s_dac_pin.mck_io_num);
#endif
res |= i2s_driver_install(CONFIG_I2S_NUM, &i2s_config, 0, NULL);
res |= i2s_set_pin(CONFIG_I2S_NUM, &i2s_dac_pin);
if (res == ESP_OK && mute_control.gpio >= 0) {
gpio_pad_select_gpio(mute_control.gpio);
gpio_set_direction(mute_control.gpio, GPIO_MODE_OUTPUT);

View File

@@ -99,7 +99,7 @@ static char *new_server_cap;
static char player_name[PLAYER_NAME_LEN + 1] = "";
static const char *name_file = NULL;
void send_packet(u8_t *packet, size_t len) {
void slimproto_send_packet(u8_t *packet, size_t len) {
u8_t *ptr = packet;
unsigned try = 0;
ssize_t n;

View File

@@ -559,7 +559,8 @@ void buf_destroy(struct buffer *buf);
void slimproto(log_level level, char *server, u8_t mac[6], const char *name, const char *namefile, const char *modelname, int maxSampleRate);
void slimproto_stop(void);
void wake_controller(void);
void send_packet(u8_t *packet, size_t len);
void slimproto_send_packet(u8_t *packet, size_t len);
#define send_packet(p, s) slimproto_send_packet(p,s)
// stream.c
typedef enum { STOPPED = 0, DISCONNECT, STREAMING_WAIT,

View File

@@ -39,7 +39,7 @@
static const char TAG[] = "TAS5713";
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config);
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config, bool *mck);
static void speaker(bool active) { };
static void headset(bool active) { } ;
static bool volume(unsigned left, unsigned right);
@@ -65,7 +65,7 @@ typedef enum {
/****************************************************************************************
* init
*/
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config) {
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config, bool *mck) {
/* find if there is a tas5713 attached. Reg 0 should read non-zero but not 255 if so */
adac_init(config, i2c_port);
if (adac_read_byte(TAS5713, 0x00) == 255) {

View File

@@ -23,7 +23,7 @@
static const char TAG[] = "TAS575x/8x";
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config);
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config, bool *mck);
static void speaker(bool active);
static void headset(bool active);
static bool volume(unsigned left, unsigned right);
@@ -71,7 +71,7 @@ static int tas57_detect(void);
/****************************************************************************************
* init
*/
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config) {
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config, bool *mck) {
// find which TAS we are using (if any)
tas57_addr = adac_init(config, i2c_port);
if (!tas57_addr) tas57_addr = tas57_detect();

View File

@@ -23,7 +23,7 @@ static void speaker(bool active) { }
static void headset(bool active) { }
static bool volume(unsigned left, unsigned right) { return false; }
static void power(adac_power_e mode);
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config);
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config, bool *mck);
static esp_err_t i2c_write_shadow(uint8_t reg, uint16_t val);
static uint16_t i2c_read_shadow(uint8_t reg);
@@ -47,12 +47,14 @@ static uint16_t WM8978_REGVAL_TBL[58] = {
/****************************************************************************************
* init
*/
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config) {
static bool init(char *config, int i2c_port, i2s_config_t *i2s_config, bool *mck) {
WM8978 = adac_init(config, i2c_port);
if (!WM8978) WM8978 = 0x1a;
ESP_LOGI(TAG, "WM8978 detected @%d", WM8978);
*mck = true;
// init sequence
i2c_write_shadow(0, 0);
i2c_write_shadow(4, 16);
@@ -61,11 +63,6 @@ static bool init(char *config, int i2c_port, i2s_config_t *i2s_config) {
i2c_write_shadow(43, 16);
i2c_write_shadow(49, 102);
// Configure system clk to GPIO0 for DAC MCLK input
ESP_LOGI(TAG, "Configuring MCLK on GPIO0");
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
REG_WRITE(PIN_CTRL, 0xFFFFFFF0);
return true;
}

View File

@@ -4,7 +4,9 @@
#include "network_status.h"
#include <string.h>
#ifdef BT_ENABLED
#include "bt_app_core.h"
#endif
#include "esp_log.h"
#include "lwip/inet.h"
#include "monitor.h"
@@ -264,8 +266,10 @@ cJSON* network_status_get_basic_info(cJSON** old) {
*old = network_status_update_float(old, "Voltage", battery_value_svc());
*old = network_update_cjson_number(old, "disconnect_count", nm->num_disconnect);
*old = network_status_update_float(old, "avg_conn_time", nm->num_disconnect > 0 ? (nm->total_connected_time / nm->num_disconnect) : 0);
#ifdef BT_ENABLED
*old = network_update_cjson_number(old, "bt_status", bt_app_source_get_a2d_state());
*old = network_update_cjson_number(old, "bt_sub_status", bt_app_source_get_media_state());
#endif
#if DEPTH == 16
*old = network_update_cjson_number(old, "depth", 16);
#elif DEPTH == 32

View File

@@ -202,6 +202,11 @@ menu "Squeezelite-ESP32"
default -1
help
I2S data input gpio pin to use (not used mostly, leave it to -1).
config I2S_MCK_IO
int "I2S Master Clock GPIO number"
default -1
help
I2S data output gpio pin to use (not used mostly, leave it to -1).
endmenu
menu "I2C settings"
config I2C_SDA