Major UI Update

- Bug fixes 
- Jack doesn't show as plugged in if no jack detection is configured 
- New layout
- Updated jQuery to latest version
- Updated bootstrap to latest version
- Updated the command processing backend to support UI interactions
- Added a number of accessors to normalize read/update various configuration entries 
- Added more GPIOs to the status tab GPIO list
- Added several configuration sections for hardware and system
- Removed pop-over windows from system messages
- Added a message count pill to the status tab
- Added support for message count pill based on the highest severity 
- Updated the message list table to set colours based on messages severity
- Added command processing message area close to the action buttons to provide feedback from running the commands
This commit is contained in:
Sebastien
2020-10-08 17:19:22 -04:00
parent 6ae47a908b
commit be1d841039
60 changed files with 3885 additions and 1319 deletions

View File

@@ -20,10 +20,24 @@
#include "driver/gpio.h"
#include "stdbool.h"
#include "driver/adc.h"
#include "esp_attr.h"
#include "soc/spi_periph.h"
#include "esp_err.h"
#include "soc/rtc.h"
#include "sdkconfig.h"
#include "soc/efuse_periph.h"
#include "driver/gpio.h"
#include "driver/spi_common_internal.h"
#include "esp32/rom/efuse.h"
#include "adac.h"
#include "trace.h"
#include "monitor.h"
#include "messaging.h"
static const char *TAG = "services";
static const char *i2c_name="I2C";
static const char *spi_name="SPI";
const char *i2c_name_type="I2C";
const char *spi_name_type="SPI";
static cJSON * gpio_list=NULL;
#define min(a,b) (((a) < (b)) ? (a) : (b))
#ifndef QUOTE
@@ -33,19 +47,250 @@ static cJSON * gpio_list=NULL;
#define STR(macro) QUOTE(macro)
#endif
bool are_statistics_enabled(){
#if defined(CONFIG_FREERTOS_USE_TRACE_FACILITY) && defined (CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS)
return true;
#endif
return false;
}
/****************************************************************************************
*
*/
static char * config_spdif_get_string(){
return config_alloc_get_str("spdif_config", CONFIG_SPDIF_CONFIG, "bck=" STR(CONFIG_SPDIF_BCK_IO)
",ws=" STR(CONFIG_SPDIF_WS_IO) ",do=" STR(CONFIG_SPDIF_DO_IO));
}
/****************************************************************************************
*
*/
static char * get_dac_config_string(){
return 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)
",sda=" STR(CONFIG_I2C_SDA) ",scl=" STR(CONFIG_I2C_SCL)
",mute=" STR(CONFIG_MUTE_GPIO));
}
/****************************************************************************************
*
*/
bool is_dac_config_locked(){
#if ( defined CONFIG_DAC_CONFIG )
if(strlen(CONFIG_DAC_CONFIG) > 0){
return true;
}
#endif
#if defined(CONFIG_I2S_BCK_IO) && CONFIG_I2S_BCK_IO>0
return true;
#endif
return false;
}
/****************************************************************************************
*
*/
bool is_spdif_config_locked(){
#if ( defined CONFIG_SPDIF_CONFIG )
if(strlen(CONFIG_SPDIF_CONFIG) > 0){
return true;
}
#endif
#if defined(CONFIG_SPDIF_BCK_IO) && CONFIG_SPDIF_BCK_IO>0
return true;
#endif
return false;
}
/****************************************************************************************
* Set pin from config string
*/
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);
}
/****************************************************************************************
* Get i2s config structure from config string
*/
const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
static i2s_platform_config_t i2s_dac_pin = {
.i2c_addr = -1,
.sda= -1,
.scl = -1,
.mute_gpio = -1,
.mute_level = -1
};
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) {
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);
}
return &i2s_dac_pin;
}
/****************************************************************************************
* Get spdif config structure
*/
const i2s_platform_config_t * config_spdif_get( ){
char * spdif_config = config_spdif_get_string();
static i2s_platform_config_t i2s_dac_config;
memcpy(&i2s_dac_config, config_get_i2s_from_str(spdif_config), sizeof(i2s_dac_config));
free(spdif_config);
return &i2s_dac_config;
}
/****************************************************************************************
* Get dac config structure
*/
const i2s_platform_config_t * config_dac_get(){
char * spdif_config = get_dac_config_string();
static i2s_platform_config_t i2s_dac_config;
memcpy(&i2s_dac_config, config_get_i2s_from_str(spdif_config), sizeof(i2s_dac_config));
free(spdif_config);
return &i2s_dac_config;
}
/****************************************************************************************
*
*/
esp_err_t config_i2c_set(const i2c_config_t * config, int port){
int buffer_size=255;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
if(config_buffer) {
snprintf(config_buffer,buffer_size,"scl=%u sda=%u speed=%u port=%u",config->scl_io_num,config->sda_io_num,config->master.clk_speed,port);
ESP_LOGI(TAG,"Updating i2c configuration to %s",config_buffer);
config_set_value(NVS_TYPE_STR, "i2c_config", config_buffer);
snprintf(config_buffer,buffer_size,"scl=%u,sda=%u,speed=%u,port=%u",config->scl_io_num,config->sda_io_num,config->master.clk_speed,port);
log_send_messaging(MESSAGING_INFO,"Updating I2C configuration to %s",config_buffer);
err = config_set_value(NVS_TYPE_STR, "i2c_config", config_buffer);
if(err!=ESP_OK){
log_send_messaging(MESSAGING_ERROR,"Error: %s",esp_err_to_name(err));
}
free(config_buffer);
}
return ESP_OK;
return err;
}
/****************************************************************************************
*
*/
esp_err_t config_display_set(const display_config_t * config){
int buffer_size=512;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer2=calloc(buffer_size,1);
if(config_buffer && config_buffer2) {
snprintf(config_buffer,buffer_size,"%s:width=%i,height=%i",config->type,config->width,config->height);
if(strcasecmp("I2C",config->type)==0){
if(config->address>0 ){
snprintf(config_buffer2,buffer_size,"%s,address=%i",config_buffer,config->address);
strcpy(config_buffer,config_buffer2);
}
}
else {
if(config->CS_pin >=0 ){
snprintf(config_buffer2,buffer_size,"%s,cs=%i",config_buffer,config->CS_pin);
strcpy(config_buffer,config_buffer2);
}
}
if(config->RST_pin >=0 ){
snprintf(config_buffer2,buffer_size,"%s,reset=%i",config_buffer,config->RST_pin);
strcpy(config_buffer,config_buffer2);
}
// I2C,width=<pixels>,height=<pixels>[address=<i2c_address>][,reset=<gpio>][,HFlip][,VFlip][driver=SSD1306|SSD1326[:1|4]|SSD1327|SH1106]
// SPI,width=<pixels>,height=<pixels>,cs=<gpio>[,back=<gpio>][,reset=<gpio>][,speed=<speed>][,HFlip][,VFlip][driver=SSD1306|SSD1322|SSD1326[:1|4]|SSD1327|SH1106|SSD1675|ST7735|ST7789[,rotate]]
if(config->back >=0 ){
snprintf(config_buffer2,buffer_size,"%s,back=%i",config_buffer,config->back);
strcpy(config_buffer,config_buffer2);
}
if(config->speed >0 && strcasecmp("SPI",config->type)==0){
snprintf(config_buffer2,buffer_size,"%s,speed=%i",config_buffer,config->speed);
strcpy(config_buffer,config_buffer2);
}
snprintf(config_buffer2,buffer_size,"%s,driver=%s%s%s%s",config_buffer,config->drivername,config->hflip?",HFlip":"",config->vflip?",VFlip":"",config->rotate?",rotate":"");
strcpy(config_buffer,config_buffer2);
log_send_messaging(MESSAGING_INFO,"Updating display configuration to %s",config_buffer);
err = config_set_value(NVS_TYPE_STR, "display_config", config_buffer);
if(err!=ESP_OK){
log_send_messaging(MESSAGING_ERROR,"Error: %s",esp_err_to_name(err));
}
}
else {
err = ESP_ERR_NO_MEM;
}
FREE_AND_NULL(config_buffer);
FREE_AND_NULL(config_buffer2);
return err;
}
/****************************************************************************************
*
*/
esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name){
int buffer_size=255;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer2=calloc(buffer_size,1);
if(config_buffer && config_buffer2) {
snprintf(config_buffer,buffer_size,"model=%s,bck=%u,ws=%u,do=%u",config->model,config->pin.bck_io_num,config->pin.ws_io_num,config->pin.data_out_num);
if(config->mute_gpio>=0){
snprintf(config_buffer2,buffer_size,"%s,mute=%u:%u",config_buffer,config->mute_gpio,config->mute_level);
strcpy(config_buffer,config_buffer2);
}
if(config->sda>=0){
snprintf(config_buffer2,buffer_size,"%s,sda=%u,scl=%u",config_buffer,config->sda,config->scl);
strcpy(config_buffer,config_buffer2);
}
if(config->i2c_addr>0){
snprintf(config_buffer2,buffer_size,"%s,i2c=%u",config_buffer,config->i2c_addr);
strcpy(config_buffer,config_buffer2);
}
log_send_messaging(MESSAGING_INFO,"Updating dac configuration to %s",config_buffer);
err = config_set_value(NVS_TYPE_STR, nvs_name, config_buffer);
if(err!=ESP_OK){
log_send_messaging(MESSAGING_ERROR,"Error: %s",esp_err_to_name(err));
}
}
else {
err = ESP_ERR_NO_MEM;
}
FREE_AND_NULL(config_buffer);
FREE_AND_NULL(config_buffer2);
return err;
}
/****************************************************************************************
*
*/
esp_err_t config_spdif_set(const i2s_platform_config_t * config){
int buffer_size=255;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
if(config_buffer ) {
snprintf(config_buffer,buffer_size,"bck=%u,ws=%u,do=%u",config->pin.bck_io_num,config->pin.ws_io_num,config->pin.data_out_num);
log_send_messaging(MESSAGING_INFO,"Updating SPDIF configuration to %s",config_buffer);
err = config_set_value(NVS_TYPE_STR, "spdif_config", config_buffer);
if(err!=ESP_OK){
log_send_messaging(MESSAGING_ERROR,"Error: %s",esp_err_to_name(err));
}
}
else {
err = ESP_ERR_NO_MEM;
}
FREE_AND_NULL(config_buffer);
return err;
}
/****************************************************************************************
@@ -53,21 +298,39 @@ esp_err_t config_i2c_set(const i2c_config_t * config, int port){
*/
esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc){
int buffer_size=255;
esp_err_t err = ESP_OK;
char * config_buffer=calloc(buffer_size,1);
if(config_buffer) {
snprintf(config_buffer,buffer_size,"data=%u,clk=%u,dc=%u,host=%u",config->mosi_io_num,config->sclk_io_num,dc,host);
ESP_LOGI(TAG,"Updating SPI configuration to %s",config_buffer);
config_set_value(NVS_TYPE_STR, "spi_config", config_buffer);
log_send_messaging(MESSAGING_INFO,"Updating SPI configuration to %s",config_buffer);
err = config_set_value(NVS_TYPE_STR, "spi_config", config_buffer);
if(err!=ESP_OK){
log_send_messaging(MESSAGING_ERROR,"Error: %s",esp_err_to_name(err));
}
free(config_buffer);
}
return ESP_OK;
return err;
}
/****************************************************************************************
*
*/
const display_config_t * config_display_get(){
static display_config_t dstruct;
static display_config_t dstruct = {
.back = -1,
.CS_pin = -1,
.RST_pin = -1,
.depth = -1,
.address = 0,
.drivername = NULL,
.height = 0,
.width = 0,
.vflip = false,
.hflip = false,
.type = NULL,
.speed = 0,
.rotate = false
};
char *config = config_alloc_get(NVS_TYPE_STR, "display_config");
if (!config) {
return NULL;
@@ -76,19 +339,20 @@ const display_config_t * config_display_get(){
char * p=NULL;
if ((p = strcasestr(config, "driver")) != NULL){
sscanf(p, "%*[^:]:%u", &dstruct.depth);
dstruct.drivername = display_conf_get_driver_name(strchr(p, '=') + 1);
}
dstruct.drivername=dstruct.drivername?dstruct.drivername:"SSD1306";
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);
dstruct.i2c_system_port=i2c_system_port;
if (strstr(config, "I2C") ) dstruct.type=i2c_name;
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;
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;
@@ -119,7 +383,13 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
free(nvs_item);
}
if(i2c_port) *i2c_port=i2c_system_port;
if(i2c_port) {
#ifdef CONFIG_I2C_LOCKED
*i2c_port= I2C_NUM_1;
#else
*i2c_port=i2c_system_port;
#endif
}
return &i2c;
}
@@ -182,25 +452,135 @@ cJSON * get_gpio_entry(const char * name, const char * prefix, int gpio, bool fi
/****************************************************************************************
*
*/
cJSON * get_GPIO_list() {
cJSON * list = cJSON_CreateArray();
cJSON * get_GPIO_nvs_list(cJSON * list) {
cJSON * ilist = list?list:cJSON_CreateArray();
char *nvs_item, *p, type[16];
int gpio;
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) == NULL) return list;
bool fixed=false;
#ifdef CONFIG_JACK_LOCKED
bool bFoundJack=false;
#endif
#ifdef CONFIG_SPKFAULT_LOCKED
bool bFoundSpkFault = false;
#endif
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) == NULL) return ilist;
p = nvs_item;
do {
fixed=false;
if (sscanf(p, "%d=%15[^,]", &gpio, type) > 0 && (GPIO_IS_VALID_GPIO(gpio) || gpio==GPIO_NUM_NC)){
cJSON_AddItemToArray(list,get_gpio_entry(type,"gpio", gpio, false));
#ifdef CONFIG_JACK_LOCKED
if(strcasecmp(type,"jack")==0){
fixed=true;
bFoundJack=true;
}
#endif
#ifdef CONFIG_SPKFAULT_LOCKED
if(strcasecmp(type,"spkfault")==0){
fixed=true;
bFoundSpkFault=true;
}
#endif
cJSON_AddItemToArray(ilist,get_gpio_entry(type,"gpio", gpio, fixed));
}
p = strchr(p, ',');
} while (p++);
#ifdef CONFIG_JACK_LOCKED
if(!bFoundJack){
monitor_gpio_t *jack= get_jack_insertion_gpio();
cJSON_AddItemToArray(list,get_gpio_entry("jack", "other", jack->gpio, true));
}
#endif
#ifdef CONFIG_SPKFAULT_LOCKED
if(!bFoundSpkFault){
monitor_gpio_t *jack= get_spkfault_gpio();
cJSON_AddItemToArray(list,get_gpio_entry("spkfault", "other", jack->gpio, true));
}
#endif
free(nvs_item);
return ilist;
}
return list;
/****************************************************************************************
*
*/
cJSON * get_DAC_GPIO(cJSON * list){
cJSON * llist = list;
if(!llist){
llist = cJSON_CreateArray();
}
const i2s_platform_config_t * i2s_config= config_dac_get();
if(i2s_config->pin.bck_io_num>=0){
cJSON_AddItemToArray(llist,get_gpio_entry("bck","dac",i2s_config->pin.bck_io_num,is_dac_config_locked()));
cJSON_AddItemToArray(llist,get_gpio_entry("ws","dac",i2s_config->pin.ws_io_num,is_dac_config_locked()));
cJSON_AddItemToArray(llist,get_gpio_entry("do","dac",i2s_config->pin.data_out_num,is_dac_config_locked()));
if(i2s_config->sda>=0){
cJSON_AddItemToArray(llist,get_gpio_entry("sda","dac",i2s_config->sda,is_dac_config_locked()));
cJSON_AddItemToArray(llist,get_gpio_entry("scl","dac",i2s_config->scl,is_dac_config_locked()));
}
if(i2s_config->mute_gpio>=0){
cJSON_AddItemToArray(llist,get_gpio_entry("mute","dac",i2s_config->mute_gpio,is_dac_config_locked()));
}
}
return llist;
}
/****************************************************************************************
*
*/
cJSON * get_Display_GPIO(cJSON * list){
cJSON * llist = list;
if(!llist){
llist = cJSON_CreateArray();
}
const display_config_t * config= config_display_get();
if(config->back >=0){
cJSON_AddItemToArray(llist,get_gpio_entry("backlight","display",config->back,false));
}
if(config->CS_pin >=0){
cJSON_AddItemToArray(llist,get_gpio_entry("CS","display",config->CS_pin,false));
}
if(config->RST_pin >=0){
cJSON_AddItemToArray(llist,get_gpio_entry("reset","display",config->RST_pin,false));
}
return llist;
}
/****************************************************************************************
*
*/
cJSON * get_I2C_GPIO(cJSON * list){
cJSON * llist = list;
if(!llist){
llist = cJSON_CreateArray();
}
int port=0;
const i2c_config_t * i2c_config = config_i2c_get(&port);
if(i2c_config->scl_io_num>=0){
cJSON_AddItemToArray(llist,get_gpio_entry("scl","i2c",i2c_config->scl_io_num,false));
cJSON_AddItemToArray(llist,get_gpio_entry("sda","i2c",i2c_config->sda_io_num,false));
}
return llist;
}
/****************************************************************************************
*
*/
cJSON * get_SPI_GPIO(cJSON * list){
cJSON * llist = list;
if(!llist){
llist = cJSON_CreateArray();
}
spi_host_device_t spi_host;
const spi_bus_config_t * spi_config = config_spi_get(&spi_host);
if(spi_config->miso_io_num>=0){
cJSON_AddItemToArray(llist,get_gpio_entry("data","spi",spi_config->miso_io_num,false));
cJSON_AddItemToArray(llist,get_gpio_entry("data","clk",spi_config->sclk_io_num,false));
}
if(spi_system_dc_gpio>0){
cJSON_AddItemToArray(llist,get_gpio_entry("data","dc",spi_system_dc_gpio,false));
}
return llist;
}
/****************************************************************************************
@@ -223,19 +603,19 @@ cJSON * get_GPIO_from_string(const char * nvs_item, const char * prefix, cJSON *
p=p?p+1:nvs_item;
while((((ret1=sscanf(p, "%[^=]=%d%n", type,&gpio,&offset)) ==2) || ((sret=sscanf(p, "%[^=]=%[^, ],%n", buf1,buf2,&soffset)) > 0 )) && (offset || soffset)){
if(ret1==2 && (GPIO_IS_VALID_GPIO(gpio) || gpio==GPIO_NUM_NC)){
cJSON_AddItemToArray(list,get_gpio_entry(type,prefix,gpio,fixed));
if(gpio>0){
cJSON_AddItemToArray(llist,get_gpio_entry(type,prefix,gpio,fixed));
}
p+=offset;
} else {
p+=soffset;
}
while(*p==' ' || *p==',') p++;
gpio=-1;
}
free(buf1);
free(buf2);
return llist;
}
/****************************************************************************************
@@ -256,7 +636,6 @@ cJSON * get_GPIO_from_nvs(const char * item, const char * prefix, cJSON * list,
esp_err_t get_gpio_structure(cJSON * gpio_entry, gpio_entry_t ** gpio){
esp_err_t err = ESP_OK;
*gpio = malloc(sizeof(gpio_entry_t));
//gpio,name,fixed
cJSON * val = cJSON_GetObjectItem(gpio_entry,"gpio");
if(val){
(*gpio)->gpio= (int)val->valuedouble;
@@ -339,16 +718,104 @@ gpio_entry_t * get_gpio_by_name(char * name,char * group, bool refresh){
return gpio;
}
#ifndef PICO_PSRAM_CLK_IO
#define PICO_PSRAM_CLK_IO 6
#endif
#ifndef PSRAM_SPIQ_SD0_IO
#define PSRAM_SPIQ_SD0_IO 7
#define PSRAM_SPID_SD1_IO 8
#define PSRAM_SPIWP_SD3_IO 10
#define PSRAM_SPIHD_SD2_IO 9
#define FLASH_HSPI_CLK_IO 14
#define FLASH_HSPI_CS_IO 15
#define PSRAM_HSPI_SPIQ_SD0_IO 12
#define PSRAM_HSPI_SPID_SD1_IO 13
#define PSRAM_HSPI_SPIWP_SD3_IO 2
#define PSRAM_HSPI_SPIHD_SD2_IO 4
#endif
cJSON * get_psram_gpio_list(cJSON * list){
const char * psram_dev = "psram";
const char * flash_dev = "flash";
const char * clk = "clk";
const char * cs = "cs";
const char * spiq_sd0_io="spiq_sd0_io";
const char * spid_sd1_io = "spid_sd1_io";
const char * spiwp_sd3_io = "spiwp_sd3_io";
const char * spihd_sd2_io = "spihd_sd2_io";
cJSON * llist=list;
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_ver = chip_ver & 0x7;
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5) {
rtc_vddsdio_config_t cfg = rtc_vddsdio_get_config();
if (cfg.tieh != RTC_VDDSDIO_TIEH_1_8V) {
return llist;
}
cJSON_AddItemToArray(list,get_gpio_entry(clk,psram_dev,CONFIG_D2WD_PSRAM_CLK_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,psram_dev,CONFIG_D2WD_PSRAM_CS_IO,true));
} else if ((pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) || (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4)) {
rtc_vddsdio_config_t cfg = rtc_vddsdio_get_config();
if (cfg.tieh != RTC_VDDSDIO_TIEH_3_3V) {
return llist;
}
cJSON_AddItemToArray(list,get_gpio_entry(clk,psram_dev,PICO_PSRAM_CLK_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,psram_dev,CONFIG_PICO_PSRAM_CS_IO,true));
} else if ((pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6) || (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5)){
cJSON_AddItemToArray(list,get_gpio_entry(clk,psram_dev,CONFIG_D0WD_PSRAM_CLK_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,psram_dev,CONFIG_D0WD_PSRAM_CS_IO,true));
} else {
ESP_LOGW(TAG, "Cant' determine GPIOs for PSRAM chip id: %d", pkg_ver);
cJSON_AddItemToArray(list,get_gpio_entry(clk,psram_dev,-1,true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,psram_dev,-1,true));
}
const uint32_t spiconfig = ets_efuse_get_spiconfig();
if (spiconfig == EFUSE_SPICONFIG_SPI_DEFAULTS) {
cJSON_AddItemToArray(list,get_gpio_entry(spiq_sd0_io,psram_dev,PSRAM_SPIQ_SD0_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(spid_sd1_io,psram_dev,PSRAM_SPID_SD1_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(spiwp_sd3_io,psram_dev,PSRAM_SPIWP_SD3_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(spihd_sd2_io,psram_dev,PSRAM_SPIHD_SD2_IO,true));
} else if (spiconfig == EFUSE_SPICONFIG_HSPI_DEFAULTS) {
cJSON_AddItemToArray(list,get_gpio_entry(spiq_sd0_io,psram_dev,PSRAM_HSPI_SPIQ_SD0_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(spid_sd1_io,psram_dev,PSRAM_HSPI_SPID_SD1_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(spiwp_sd3_io,psram_dev,PSRAM_HSPI_SPIWP_SD3_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(spihd_sd2_io,psram_dev,PSRAM_HSPI_SPIHD_SD2_IO,true));
} else {
cJSON_AddItemToArray(list,get_gpio_entry(spiq_sd0_io,psram_dev,EFUSE_SPICONFIG_RET_SPIQ(spiconfig),true));
cJSON_AddItemToArray(list,get_gpio_entry(spid_sd1_io,psram_dev,EFUSE_SPICONFIG_RET_SPID(spiconfig),true));
cJSON_AddItemToArray(list,get_gpio_entry(spihd_sd2_io,psram_dev,EFUSE_SPICONFIG_RET_SPIHD(spiconfig),true));
// If flash mode is set to QIO or QOUT, the WP pin is equal the value configured in bootloader.
// If flash mode is set to DIO or DOUT, the WP pin should config it via menuconfig.
#if CONFIG_ESPTOOLPY_FLASHMODE_QIO || CONFIG_FLASHMODE_QOUT
cJSON_AddItemToArray(list,get_gpio_entry(spiwp_sd3_io,psram_dev,CONFIG_BOOTLOADER_SPI_WP_PIN,true));
#else
cJSON_AddItemToArray(list,get_gpio_entry(spiwp_sd3_io,psram_dev,CONFIG_SPIRAM_SPIWP_SD3_PIN,true));
#endif
}
if (spiconfig == EFUSE_SPICONFIG_SPI_DEFAULTS) {
cJSON_AddItemToArray(list,get_gpio_entry(clk,flash_dev,SPI_IOMUX_PIN_NUM_CLK,true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,flash_dev,SPI_IOMUX_PIN_NUM_CS,true));
} else if (spiconfig == EFUSE_SPICONFIG_HSPI_DEFAULTS) {
cJSON_AddItemToArray(list,get_gpio_entry(clk,flash_dev,FLASH_HSPI_CLK_IO,true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,flash_dev,FLASH_HSPI_CS_IO,true));
} else {
cJSON_AddItemToArray(list,get_gpio_entry(clk,flash_dev,EFUSE_SPICONFIG_RET_SPICLK(spiconfig),true));
cJSON_AddItemToArray(list,get_gpio_entry(cs,flash_dev,EFUSE_SPICONFIG_RET_SPICS0(spiconfig),true));
}
return llist;
}
/****************************************************************************************
*
*/
cJSON * get_gpio_list() {
gpio_num_t gpio_num;
if(gpio_list){
cJSON_free(gpio_list);
cJSON_Delete(gpio_list);
}
gpio_list = get_GPIO_list();
gpio_list = cJSON_CreateArray();
#ifndef CONFIG_BAT_LOCKED
char *bat_config = config_alloc_get_default(NVS_TYPE_STR, "bat_config", NULL, 0);
if (bat_config) {
@@ -358,7 +825,7 @@ cJSON * get_gpio_list() {
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","",gpio_num,false));
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,false));
}
}
}
@@ -366,23 +833,17 @@ cJSON * get_gpio_list() {
}
#else
if(adc1_pad_get_io_num(CONFIG_BAT_CHANNEL,&gpio_num )==ESP_OK){
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","",gpio_num,true));
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,true));
}
#endif
gpio_list = get_GPIO_from_nvs("i2c_config","i2c", gpio_list, false);
gpio_list = get_GPIO_from_nvs("spi_config","spi", gpio_list, false);
char *spdif_config = config_alloc_get_str("spdif_config", CONFIG_SPDIF_CONFIG, "bck=" STR(CONFIG_SPDIF_BCK_IO)
",ws=" STR(CONFIG_SPDIF_WS_IO) ",do=" STR(CONFIG_SPDIF_DO_IO));
gpio_list=get_GPIO_from_string(spdif_config,"spdif", gpio_list, (strlen(CONFIG_SPDIF_CONFIG)>0 || CONFIG_SPDIF_DO_IO>0 ));
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)
",sda=" STR(CONFIG_I2C_SDA) ",scl=" STR(CONFIG_I2C_SCL)
",mute=" STR(CONFIG_MUTE_GPIO));
gpio_list=get_GPIO_from_string(dac_config,"dac", gpio_list, (strlen(CONFIG_DAC_CONFIG)>0 || CONFIG_I2S_DO_IO>0 ));
gpio_list = get_GPIO_nvs_list(gpio_list);
char * spdif_config = config_spdif_get_string();
gpio_list=get_GPIO_from_string(spdif_config,"spdif", gpio_list, is_spdif_config_locked());
free(spdif_config);
free(dac_config);
gpio_list=get_Display_GPIO(gpio_list);
gpio_list=get_SPI_GPIO(gpio_list);
gpio_list=get_I2C_GPIO(gpio_list);
gpio_list=get_DAC_GPIO(gpio_list);
gpio_list=get_psram_gpio_list(gpio_list);
return gpio_list;
}