mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-27 04:40:48 +03:00
big merge
This commit is contained in:
@@ -29,12 +29,11 @@
|
||||
#include "driver/spi_common_internal.h"
|
||||
#include "esp32/rom/efuse.h"
|
||||
#include "adac.h"
|
||||
#include "trace.h"
|
||||
#include "tools.h"
|
||||
#include "monitor.h"
|
||||
#include "messaging.h"
|
||||
#include "network_ethernet.h"
|
||||
|
||||
|
||||
static const char *TAG = "services";
|
||||
const char *i2c_name_type="I2C";
|
||||
const char *spi_name_type="SPI";
|
||||
@@ -63,7 +62,6 @@ static char * config_spdif_get_string(){
|
||||
",ws=" STR(CONFIG_SPDIF_WS_IO) ",do=" STR(CONFIG_SPDIF_DO_IO));
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -110,9 +108,9 @@ bool is_spdif_config_locked(){
|
||||
static void set_i2s_pin(char *config, i2s_pin_config_t *pin_config) {
|
||||
char *p;
|
||||
pin_config->bck_io_num = pin_config->ws_io_num = pin_config->data_out_num = pin_config->data_in_num = -1;
|
||||
if ((p = strcasestr(config, "bck")) != NULL) pin_config->bck_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "ws")) != NULL) pin_config->ws_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "do")) != NULL) pin_config->data_out_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "bck"))) sscanf(p, "bck%*[^=]=%d", &pin_config->bck_io_num);
|
||||
if ((p = strcasestr(config, "ws"))) sscanf(p, "ws%*[^=]=%d", &pin_config->ws_io_num);
|
||||
if ((p = strcasestr(config, "do"))) sscanf(p, "do%*[^=]=%d", &pin_config->data_out_num);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
@@ -120,19 +118,20 @@ static void set_i2s_pin(char *config, i2s_pin_config_t *pin_config) {
|
||||
*/
|
||||
const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
|
||||
static EXT_RAM_ATTR i2s_platform_config_t i2s_dac_pin;
|
||||
memset(&i2s_dac_pin, 0xFF, sizeof(i2s_dac_pin));
|
||||
memset(&i2s_dac_pin, 0xff, sizeof(i2s_dac_pin));
|
||||
set_i2s_pin(dac_config, &i2s_dac_pin.pin);
|
||||
strcpy(i2s_dac_pin.model, "i2s");
|
||||
char * p=NULL;
|
||||
if ((p = strcasestr(dac_config, "i2c")) != NULL) i2s_dac_pin.i2c_addr = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(dac_config, "sda")) != NULL) i2s_dac_pin.sda = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(dac_config, "scl")) != NULL) i2s_dac_pin.scl = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(dac_config, "model")) != NULL) sscanf(p, "%*[^=]=%31[^,]", i2s_dac_pin.model);
|
||||
if ((p = strcasestr(dac_config, "mute")) != NULL) {
|
||||
|
||||
PARSE_PARAM(dac_config, "i2c", '=', i2s_dac_pin.i2c_addr);
|
||||
PARSE_PARAM(dac_config, "sda", '=', i2s_dac_pin.sda);
|
||||
PARSE_PARAM(dac_config, "scl", '=', i2s_dac_pin.scl);
|
||||
PARSE_PARAM_STR(dac_config, "model", '=', i2s_dac_pin.model, 31);
|
||||
if ((p = strcasestr(dac_config, "mute"))) {
|
||||
char mute[8] = "";
|
||||
sscanf(p, "%*[^=]=%7[^,]", mute);
|
||||
i2s_dac_pin.mute_gpio = atoi(mute);
|
||||
if ((p = strchr(mute, ':')) != NULL) i2s_dac_pin.mute_level = atoi(p + 1);
|
||||
PARSE_PARAM(p, "mute", ':', i2s_dac_pin.mute_level);
|
||||
}
|
||||
return &i2s_dac_pin;
|
||||
}
|
||||
@@ -140,52 +139,56 @@ const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
|
||||
/****************************************************************************************
|
||||
* Get eth config structure from config string
|
||||
*/
|
||||
const eth_config_t * config_get_eth_from_str(char * eth_config ){
|
||||
char * p=NULL;
|
||||
static EXT_RAM_ATTR eth_config_t eth_pin;
|
||||
memset(ð_pin, 0xFF, sizeof(eth_pin));
|
||||
memset(ð_pin.model, 0x00, sizeof(eth_pin.model));
|
||||
eth_pin.valid = true;
|
||||
const eth_config_t * config_get_eth_from_str(char* config ){
|
||||
static EXT_RAM_ATTR eth_config_t eth_config;
|
||||
memset(ð_config, 0xff, sizeof(eth_config));
|
||||
memset(ð_config.model, 0x00, sizeof(eth_config.model));
|
||||
eth_config.valid = true;
|
||||
|
||||
if ((p = strcasestr(eth_config, "model")) != NULL) sscanf(p, "%*[^=]=%15[^,]", eth_pin.model);
|
||||
if ((p = strcasestr(eth_config, "mdc")) != NULL) eth_pin.mdc = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "mdio")) != NULL) eth_pin.mdio = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "rst")) != NULL) eth_pin.rst = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "mosi")) != NULL) eth_pin.mosi = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "miso")) != NULL) eth_pin.miso = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "intr")) != NULL) eth_pin.intr = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "cs")) != NULL) eth_pin.cs = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "speed")) != NULL) eth_pin.speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "clk")) != NULL) eth_pin.clk = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(eth_config, "host")) != NULL) eth_pin.host = atoi(strchr(p, '=') + 1);
|
||||
PARSE_PARAM_STR(config, "model", '=', eth_config.model, 15);
|
||||
PARSE_PARAM(config, "mdc", '=', eth_config.mdc);
|
||||
PARSE_PARAM(config, "mdio", '=', eth_config.mdio);
|
||||
PARSE_PARAM(config, "rst", '=', eth_config.rst);
|
||||
PARSE_PARAM(config, "mosi", '=', eth_config.mosi);
|
||||
PARSE_PARAM(config, "miso", '=', eth_config.miso);
|
||||
PARSE_PARAM(config, "intr", '=', eth_config.intr);
|
||||
PARSE_PARAM(config, "cs", '=', eth_config.cs);
|
||||
PARSE_PARAM(config, "speed", '=', eth_config.speed);
|
||||
PARSE_PARAM(config, "clk", '=', eth_config.clk);
|
||||
|
||||
if(!eth_pin.model || strlen(eth_pin.model)==0){
|
||||
eth_pin.valid = false;
|
||||
return ð_pin;
|
||||
// only system host is available
|
||||
eth_config.host = spi_system_host;
|
||||
|
||||
if(!eth_config.model || strlen(eth_config.model)==0){
|
||||
eth_config.valid = false;
|
||||
return ð_config;
|
||||
}
|
||||
network_ethernet_driver_t* network_driver = network_ethernet_driver_autodetect(eth_pin.model);
|
||||
|
||||
network_ethernet_driver_t* network_driver = network_ethernet_driver_autodetect(eth_config.model);
|
||||
|
||||
if(!network_driver || !network_driver->valid){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: model %s %s",eth_pin.model,network_driver?"was not compiled in":"was not found");
|
||||
eth_pin.valid = false;
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: model %s %s",eth_config.model,network_driver?"was not compiled in":"was not found");
|
||||
eth_config.valid = false;
|
||||
}
|
||||
|
||||
if(network_driver){
|
||||
eth_pin.rmii = network_driver->rmii;
|
||||
eth_pin.spi = network_driver->spi;
|
||||
eth_config.rmii = network_driver->rmii;
|
||||
eth_config.spi = network_driver->spi;
|
||||
|
||||
if(network_driver->rmii){
|
||||
if(!GPIO_IS_VALID_GPIO(eth_pin.mdio) || !GPIO_IS_VALID_GPIO(eth_pin.mdc)){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: %s %s",!GPIO_IS_VALID_GPIO(eth_pin.mdc)?"Invalid MDC":"",!GPIO_IS_VALID_GPIO(eth_pin.mdio)?"Invalid mdio":"");
|
||||
eth_pin.valid = false;
|
||||
if(!GPIO_IS_VALID_GPIO(eth_config.mdio) || !GPIO_IS_VALID_GPIO(eth_config.mdc)){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: %s %s",!GPIO_IS_VALID_GPIO(eth_config.mdc)?"Invalid MDC":"",!GPIO_IS_VALID_GPIO(eth_config.mdio)?"Invalid mdio":"");
|
||||
eth_config.valid = false;
|
||||
}
|
||||
}
|
||||
else if(network_driver->spi){
|
||||
if(!GPIO_IS_VALID_GPIO(eth_pin.cs)){
|
||||
if(!GPIO_IS_VALID_GPIO(eth_config.cs)){
|
||||
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: invalid CS pin");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ð_pin;
|
||||
return ð_config;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
@@ -468,16 +471,18 @@ const display_config_t * config_display_get(){
|
||||
sscanf(p, "%*[^:]:%u", &dstruct.depth);
|
||||
dstruct.drivername = display_conf_get_driver_name(strchr(p, '=') + 1);
|
||||
}
|
||||
|
||||
if ((p = strcasestr(config, "width")) != NULL) dstruct.width = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "height")) != NULL) dstruct.height = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "reset")) != NULL) dstruct.RST_pin = atoi(strchr(p, '=') + 1);
|
||||
|
||||
PARSE_PARAM(config, "width", '=', dstruct.width);
|
||||
PARSE_PARAM(config, "height", '=', dstruct.height);
|
||||
PARSE_PARAM(config, "reset", '=', dstruct.RST_pin);
|
||||
PARSE_PARAM(config, "address", '=', dstruct.address);
|
||||
PARSE_PARAM(config, "cs", '=', dstruct.CS_pin);
|
||||
PARSE_PARAM(config, "speed", '=', dstruct.speed);
|
||||
PARSE_PARAM(config, "back", '=', dstruct.back);
|
||||
|
||||
if (strstr(config, "I2C") ) dstruct.type=i2c_name_type;
|
||||
if ((p = strcasestr(config, "address")) != NULL) dstruct.address = atoi(strchr(p, '=') + 1);
|
||||
if (strstr(config, "SPI") ) dstruct.type=spi_name_type;
|
||||
if ((p = strcasestr(config, "cs")) != NULL) dstruct.CS_pin = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "speed")) != NULL) dstruct.speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "back")) != NULL) dstruct.back = atoi(strchr(p, '=') + 1);
|
||||
|
||||
dstruct.hflip= strcasestr(config, "HFlip") ? true : false;
|
||||
dstruct.vflip= strcasestr(config, "VFlip") ? true : false;
|
||||
dstruct.rotate= strcasestr(config, "rotate") ? true : false;
|
||||
@@ -488,7 +493,7 @@ const display_config_t * config_display_get(){
|
||||
*
|
||||
*/
|
||||
const i2c_config_t * config_i2c_get(int * i2c_port) {
|
||||
char *nvs_item, *p;
|
||||
char *nvs_item;
|
||||
static i2c_config_t i2c = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = -1,
|
||||
@@ -502,10 +507,10 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
|
||||
|
||||
nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "scl")) != NULL) i2c.scl_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "sda")) != NULL) i2c.sda_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "speed")) != NULL) i2c.master.clk_speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
|
||||
PARSE_PARAM(nvs_item, "scl", '=', i2c.scl_io_num);
|
||||
PARSE_PARAM(nvs_item, "sda", '=', i2c.sda_io_num);
|
||||
PARSE_PARAM(nvs_item, "speed", '=', i2c.master.clk_speed);
|
||||
PARSE_PARAM(nvs_item, "port", '=', i2c_system_port);
|
||||
free(nvs_item);
|
||||
}
|
||||
if(i2c_port) {
|
||||
@@ -518,6 +523,46 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
|
||||
return &i2c;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Get IO expander config structure from config string
|
||||
*/
|
||||
const gpio_exp_config_t* config_gpio_exp_get(int index) {
|
||||
char *nvs_item, *item, *p;
|
||||
static gpio_exp_config_t config;
|
||||
|
||||
// re-initialize config every time
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.intr = -1; config.count = 16; config.base = GPIO_NUM_MAX; config.phy.port = i2c_system_port; config.phy.host = spi_system_host;
|
||||
|
||||
nvs_item = config_alloc_get(NVS_TYPE_STR, "gpio_exp_config");
|
||||
if (!nvs_item || !*nvs_item) return NULL;
|
||||
|
||||
// search index items
|
||||
for (item = strtok(nvs_item, ";"); index && item; index--) {
|
||||
if ((item = strtok(NULL, ";")) == NULL) {
|
||||
free(nvs_item);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PARSE_PARAM(item, "addr", '=', config.phy.addr);
|
||||
PARSE_PARAM(item, "cs", '=', config.phy.cs_pin);
|
||||
PARSE_PARAM(item, "speed", '=', config.phy.speed);
|
||||
PARSE_PARAM(item, "intr", '=', config.intr);
|
||||
PARSE_PARAM(item, "base", '=', config.base);
|
||||
PARSE_PARAM(item, "count", '=', config.count);
|
||||
PARSE_PARAM_STR(item, "model", '=', config.model, 31);
|
||||
|
||||
if ((p = strcasestr(item, "port")) != NULL) {
|
||||
char port[8] = "";
|
||||
sscanf(p, "%*[^=]=%7[^,]", port);
|
||||
if (strcasestr(port, "dac")) config.phy.port = 0;
|
||||
}
|
||||
|
||||
free(nvs_item);
|
||||
return &config;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -596,18 +641,19 @@ const set_GPIO_struct_t * get_gpio_struct(){
|
||||
*
|
||||
*/
|
||||
const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host) {
|
||||
char *nvs_item, *p;
|
||||
char *nvs_item;
|
||||
static EXT_RAM_ATTR spi_bus_config_t spi;
|
||||
memset(&spi, 0xFF, sizeof(spi));
|
||||
memset(&spi, 0xff, sizeof(spi));
|
||||
|
||||
nvs_item = config_alloc_get_str("spi_config", CONFIG_SPI_CONFIG, NULL);
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "data")) != NULL) spi.mosi_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "mosi")) != NULL) spi.mosi_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "miso")) != NULL) spi.miso_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "clk")) != NULL) spi.sclk_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "dc")) != NULL) spi_system_dc_gpio = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "host")) != NULL) spi_system_host = atoi(strchr(p, '=') + 1);
|
||||
PARSE_PARAM(nvs_item, "data", '=', spi.mosi_io_num);
|
||||
PARSE_PARAM(nvs_item, "mosi", '=', spi.mosi_io_num);
|
||||
PARSE_PARAM(nvs_item, "miso", '=', spi.miso_io_num);
|
||||
PARSE_PARAM(nvs_item, "clk", '=', spi.sclk_io_num);
|
||||
PARSE_PARAM(nvs_item, "dc", '=', spi_system_dc_gpio);
|
||||
// only VSPI (1) can be used as Flash and PSRAM run at 80MHz
|
||||
// if ((p = strcasestr(nvs_item, "host")) != NULL) spi_system_host = atoi(strchr(p, '=') + 1);
|
||||
free(nvs_item);
|
||||
}
|
||||
if(spi_host) *spi_host = spi_system_host;
|
||||
@@ -642,11 +688,11 @@ const rotary_struct_t * config_rotary_get() {
|
||||
char *config = config_alloc_get_default(NVS_TYPE_STR, "rotary_config", NULL, 0);
|
||||
if (config && *config) {
|
||||
char *p;
|
||||
|
||||
|
||||
// parse config
|
||||
if ((p = strcasestr(config, "A")) != NULL) rotary.A = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "B")) != NULL) rotary.B = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "SW")) != NULL) rotary.SW = atoi(strchr(p, '=') + 1);
|
||||
PARSE_PARAM(config, "A", '=', rotary.A);
|
||||
PARSE_PARAM(config, "B", '=', rotary.B);
|
||||
PARSE_PARAM(config, "SW", '=', rotary.SW);
|
||||
if ((p = strcasestr(config, "knobonly")) != NULL) {
|
||||
p = strchr(p, '=');
|
||||
rotary.knobonly = true;
|
||||
@@ -691,13 +737,10 @@ cJSON * add_gpio_for_value(cJSON * list,const char * name,int gpio, const char *
|
||||
*/
|
||||
cJSON * add_gpio_for_name(cJSON * list,const char * nvs_entry,const char * name, const char * prefix, bool fixed){
|
||||
cJSON * llist = list?list:cJSON_CreateArray();
|
||||
char *p;
|
||||
int gpioNum=0;
|
||||
if ((p = strcasestr(nvs_entry, name)) != NULL) {
|
||||
gpioNum = atoi(strchr(p, '=') + 1);
|
||||
if(gpioNum>=0){
|
||||
cJSON_AddItemToArray(llist,get_gpio_entry(name,prefix,gpioNum,fixed));
|
||||
}
|
||||
PARSE_PARAM(nvs_entry, name, '=', gpioNum);
|
||||
if(gpioNum>=0){
|
||||
cJSON_AddItemToArray(llist,get_gpio_entry(name,prefix,gpioNum,fixed));
|
||||
}
|
||||
return llist;
|
||||
}
|
||||
@@ -1059,14 +1102,11 @@ cJSON * get_gpio_list(bool refresh) {
|
||||
#ifndef CONFIG_BAT_LOCKED
|
||||
char *bat_config = config_alloc_get_default(NVS_TYPE_STR, "bat_config", NULL, 0);
|
||||
if (bat_config) {
|
||||
char *p;
|
||||
int channel;
|
||||
if ((p = strcasestr(bat_config, "channel") ) != NULL) {
|
||||
channel = atoi(strchr(p, '=') + 1);
|
||||
if(channel != -1){
|
||||
if(adc1_pad_get_io_num(channel,&gpio_num )==ESP_OK){
|
||||
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,false));
|
||||
}
|
||||
int channel = -1;
|
||||
PARSE_PARAM(bat_config, "channel", '=', channel);
|
||||
if(channel != -1){
|
||||
if(adc1_pad_get_io_num(channel,&gpio_num )==ESP_OK){
|
||||
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,false));
|
||||
}
|
||||
}
|
||||
free(bat_config);
|
||||
|
||||
Reference in New Issue
Block a user