mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 20:17:04 +03:00
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:
@@ -20,6 +20,7 @@
|
||||
#include "trace.h"
|
||||
#include "messaging.h"
|
||||
#include "display.h"
|
||||
#include "config.h"
|
||||
|
||||
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
@@ -31,13 +32,12 @@
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
extern int spi_system_host;
|
||||
extern int spi_system_dc_gpio;
|
||||
|
||||
extern int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out, bool mandatory);
|
||||
static const char *TAG = "cmd_i2ctools";
|
||||
#define NOT_OUTPUT "has input capabilities only"
|
||||
#define NOT_GPIO "is not a GPIO"
|
||||
static gpio_num_t i2c_gpio_sda = 19;
|
||||
static gpio_num_t i2c_gpio_scl = 18;
|
||||
static uint32_t i2c_frequency = 100000;
|
||||
const char * desc_spiconfig="SPI Bus Parameters";
|
||||
const char * desc_i2c = "I2C Bus Parameters";
|
||||
const char * desc_display="Display";
|
||||
|
||||
#ifdef CONFIG_I2C_LOCKED
|
||||
static i2c_port_t i2c_port = I2C_NUM_1;
|
||||
#else
|
||||
@@ -70,7 +70,6 @@ static struct {
|
||||
struct arg_int *freq;
|
||||
struct arg_int *sda;
|
||||
struct arg_int *scl;
|
||||
struct arg_lit *load;
|
||||
struct arg_lit *clear;
|
||||
struct arg_end *end;
|
||||
} i2cconfig_args;
|
||||
@@ -85,18 +84,9 @@ static struct {
|
||||
} spiconfig_args;
|
||||
|
||||
static struct {
|
||||
struct arg_int *port;
|
||||
struct arg_end *end;
|
||||
} i2cstop_args;
|
||||
|
||||
static struct {
|
||||
struct arg_int *port;
|
||||
struct arg_end *end;
|
||||
} i2ccheck_args;
|
||||
|
||||
static struct {
|
||||
struct arg_str *name;
|
||||
struct arg_str *type;
|
||||
struct arg_str *driver;
|
||||
struct arg_int *depth;
|
||||
struct arg_int *address;
|
||||
struct arg_int *width;
|
||||
struct arg_int *height;
|
||||
@@ -104,28 +94,13 @@ static struct {
|
||||
struct arg_lit *hflip;
|
||||
struct arg_lit *vflip;
|
||||
struct arg_int *speed;
|
||||
struct arg_int *cs;
|
||||
struct arg_int *back;
|
||||
struct arg_int *reset;
|
||||
struct arg_lit *clear;
|
||||
struct arg_end *end;
|
||||
} i2cdisp_args;
|
||||
|
||||
int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out){
|
||||
int res = 0;
|
||||
const char * name = gpio->hdr.longopts?gpio->hdr.longopts:gpio->hdr.glossary;
|
||||
*gpio_out=-1;
|
||||
int t_gpio=gpio->ival[0];
|
||||
if(gpio->count==0){
|
||||
fprintf(f,"Missing: %s\n", name);
|
||||
res++;
|
||||
} else if(!GPIO_IS_VALID_OUTPUT_GPIO(t_gpio)){
|
||||
fprintf(f,"Invalid %s gpio: [%d] %s\n",name, t_gpio, GPIO_IS_VALID_GPIO(t_gpio)?NOT_OUTPUT:NOT_GPIO );
|
||||
res++;
|
||||
}
|
||||
else{
|
||||
*gpio_out = t_gpio;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
bool is_i2c_started(i2c_port_t port){
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_LOGD(TAG,"Determining if i2c is started on port %u", port);
|
||||
@@ -267,13 +242,6 @@ static const i2c_db_t i2c_db[] = {
|
||||
{ .address = 0x7f, .description = "PCA9685"},
|
||||
{ .address = 0, .description = NULL}
|
||||
};
|
||||
void i2c_load_configuration(){
|
||||
ESP_LOGD(TAG,"Loading configuration from nvs");
|
||||
const i2c_config_t * conf = config_i2c_get((int *)&i2c_port);
|
||||
i2c_gpio_scl = conf->scl_io_num;
|
||||
i2c_gpio_sda = conf->sda_io_num;
|
||||
i2c_frequency = conf->master.clk_speed;
|
||||
}
|
||||
|
||||
const char * i2c_get_description(uint8_t address){
|
||||
uint8_t i=0;
|
||||
@@ -300,114 +268,35 @@ static esp_err_t i2c_get_port(int port, i2c_port_t *i2c_port)
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
static esp_err_t i2c_master_driver_install(){
|
||||
static esp_err_t i2c_master_driver_install(const char * cmdname){
|
||||
esp_err_t err=ESP_OK;
|
||||
ESP_LOGD(TAG,"Installing i2c driver on port %u", i2c_port);
|
||||
cmd_send_messaging(cmdname,MESSAGING_INFO,"Installing i2c driver on port %u\n", i2c_port);
|
||||
if((err=i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0))!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"Driver install failed! %s", esp_err_to_name(err));
|
||||
cmd_send_messaging(cmdname,MESSAGING_ERROR,"Driver install failed! %s\n", esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t i2c_master_driver_initialize()
|
||||
static esp_err_t i2c_master_driver_initialize(const char * cmdname, i2c_config_t * conf)
|
||||
{
|
||||
esp_err_t err=ESP_OK;
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = i2c_gpio_sda,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = i2c_gpio_scl,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = i2c_frequency
|
||||
};
|
||||
log_send_messaging(MESSAGING_INFO,"Initializing i2c driver configuration.\n mode = I2C_MODE_MASTER, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n i2c port = %u, \n sda_io_num = %u, \n sda_pullup_en = GPIO_PULLUP_ENABLE, \n scl_io_num = %u, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n master.clk_speed = %u", i2c_port, i2c_gpio_sda,i2c_gpio_scl,i2c_frequency);
|
||||
if((err=i2c_param_config(i2c_port, &conf))!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c driver config load failed. %s", esp_err_to_name(err));
|
||||
cmd_send_messaging(cmdname,MESSAGING_INFO,"Initializing i2c driver configuration.\n mode = I2C_MODE_MASTER, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n i2c port = %u, \n sda_io_num = %u, \n sda_pullup_en = GPIO_PULLUP_ENABLE, \n scl_io_num = %u, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n master.clk_speed = %u\n", i2c_port, conf->sda_io_num,conf->scl_io_num,conf->master.clk_speed);
|
||||
if((err=i2c_param_config(i2c_port, conf))!=ESP_OK){
|
||||
cmd_send_messaging(cmdname,MESSAGING_ERROR,"i2c driver config load failed. %s\n", esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t i2c_initialize_driver_from_config(){
|
||||
esp_err_t err = ESP_OK;
|
||||
ESP_LOGD(TAG,"Initializing driver from configuration.");
|
||||
i2c_load_configuration();
|
||||
if(is_i2c_started(i2c_port)){
|
||||
log_send_messaging(MESSAGING_WARNING,"Stopping i2c driver on port %u", i2c_port);
|
||||
// stop the current driver instance
|
||||
if((err=i2c_driver_delete(i2c_port))!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c driver delete failed. %s", esp_err_to_name(err));
|
||||
}
|
||||
}
|
||||
if(err==ESP_OK){
|
||||
err = i2c_master_driver_initialize();
|
||||
}
|
||||
if(err == ESP_OK){
|
||||
err = i2c_master_driver_install();
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int do_i2c_stop(int argc, char **argv ){
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cstop_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (i2cstop_args.port->count && i2c_get_port(i2cstop_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||
return 1;
|
||||
}
|
||||
log_send_messaging(MESSAGING_WARNING,"Stopping i2c on port %u.",i2c_port);
|
||||
i2c_driver_delete(i2c_port);
|
||||
return 0;
|
||||
}
|
||||
static int do_i2c_check(int argc, char **argv ){
|
||||
|
||||
i2c_port_t port=0;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2ccheck_args);
|
||||
if (nerrors != 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
port=i2c_port;
|
||||
|
||||
if (i2ccheck_args.port->count && i2c_get_port(i2ccheck_args.port->ival[0], &port) != ESP_OK) {
|
||||
return 1;
|
||||
}
|
||||
bool started=is_i2c_started(port);
|
||||
log_send_messaging(MESSAGING_INFO,"i2c is %s on port %u.", started?"started":"not started",port );
|
||||
return 0;
|
||||
}
|
||||
static int do_i2c_show_display(int argc, char **argv){
|
||||
char * config_string = (char * )config_alloc_get(NVS_TYPE_STR, "display_config") ;
|
||||
if(config_string){
|
||||
log_send_messaging(MESSAGING_INFO,"Display configuration string is : \n"
|
||||
"display_config = \"%s\"",config_string);
|
||||
free(config_string);
|
||||
}
|
||||
else {
|
||||
log_send_messaging(MESSAGING_WARNING,"No display configuration found in nvs config display_config");
|
||||
}
|
||||
char * nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item) {
|
||||
log_send_messaging(MESSAGING_INFO,"I2C configuration is: %s", nvs_item);
|
||||
free(nvs_item);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_i2c_set_display(int argc, char **argv)
|
||||
{
|
||||
int width=0, height=0, address=60, back=-1, speed=8000000 ;
|
||||
char * name = NULL;
|
||||
char * driver= NULL;
|
||||
char config_string[200]={};
|
||||
bool bHasi2cConfig = false, bHasSpiConfig=false;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cdisp_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
display_config_t config = {
|
||||
.back = -1,
|
||||
.CS_pin = -1,
|
||||
.RST_pin = -1,
|
||||
.depth = 0
|
||||
};
|
||||
char * nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item && strlen(nvs_item)>0) {
|
||||
bHasi2cConfig=true;
|
||||
@@ -420,9 +309,9 @@ static int do_i2c_set_display(int argc, char **argv)
|
||||
}
|
||||
FREE_AND_NULL(nvs_item);
|
||||
|
||||
/* Check "--clear" option */
|
||||
/* Check "--clear" option */
|
||||
if (i2cdisp_args.clear->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"Display config cleared");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"Display config cleared");
|
||||
config_set_value(NVS_TYPE_STR, "display_config", "");
|
||||
return 0;
|
||||
}
|
||||
@@ -430,95 +319,105 @@ static int do_i2c_set_display(int argc, char **argv)
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors>0){
|
||||
arg_print_errors(f,i2cdisp_args.end,desc_display);
|
||||
return 1;
|
||||
}
|
||||
/* Check "--type" option */
|
||||
if (i2cdisp_args.type->count ) {
|
||||
if(strcasecmp(i2c_name_type, i2cdisp_args.type->sval[0])==0){
|
||||
config.type = i2c_name_type;
|
||||
}
|
||||
else {
|
||||
config.type = spi_name_type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
config.type = i2c_name_type;
|
||||
}
|
||||
/* Check "--address" option */
|
||||
if (i2cdisp_args.address->count) {
|
||||
address=i2cdisp_args.address->ival[0];
|
||||
if(strcasecmp(config.type,"I2C")==0){
|
||||
if (i2cdisp_args.address->count>0) {
|
||||
config.address=i2cdisp_args.address->ival[0];
|
||||
}
|
||||
else {
|
||||
config.address = 60;
|
||||
}
|
||||
if(!bHasi2cConfig){
|
||||
fprintf(f,"I2C bus has to be configured first. \n");
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// SPI Bus connection
|
||||
if(!bHasSpiConfig){
|
||||
fprintf(f,"SPI bus has to be configured first. \n");
|
||||
nerrors++;
|
||||
}
|
||||
/* Check "--speed" option */
|
||||
if (i2cdisp_args.speed->count) {
|
||||
config.speed=i2cdisp_args.speed->ival[0];
|
||||
}
|
||||
else {
|
||||
config.speed = 8000000;
|
||||
}
|
||||
/* Check "--cs" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.cs,f,&config.CS_pin, true);
|
||||
}
|
||||
|
||||
nerrors +=is_output_gpio(i2cdisp_args.reset,f,&config.RST_pin, false);
|
||||
/* Check "--width" option */
|
||||
if (i2cdisp_args.width->count) {
|
||||
width=i2cdisp_args.width->ival[0];
|
||||
config.width=i2cdisp_args.width->ival[0];
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Missing parameter: --width\n");
|
||||
nerrors ++;
|
||||
}
|
||||
|
||||
/* Check "--height" option */
|
||||
if (i2cdisp_args.height->count) {
|
||||
height=i2cdisp_args.height->ival[0];
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Missing parameter: --height\n");
|
||||
nerrors ++;
|
||||
}
|
||||
|
||||
/* Check "--name" option */
|
||||
if (i2cdisp_args.name->count) {
|
||||
name=strdup(i2cdisp_args.name->sval[0]);
|
||||
config.height=i2cdisp_args.height->ival[0];
|
||||
}
|
||||
|
||||
/* Check "--driver" option */
|
||||
if (i2cdisp_args.driver->count) {
|
||||
driver=strdup(i2cdisp_args.driver->sval[0]);
|
||||
}
|
||||
|
||||
|
||||
/* Check "--back" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.back,f,&back);
|
||||
|
||||
|
||||
if(!name) name = strdup("I2C");
|
||||
/* Check "--speed" option */
|
||||
if (i2cdisp_args.speed->count) {
|
||||
speed=i2cdisp_args.speed->ival[0];
|
||||
config.drivername=display_conf_get_driver_name(i2cdisp_args.driver->sval[0]) ;
|
||||
}
|
||||
else {
|
||||
if(strcasestr(name,"I2C")){
|
||||
speed = 250000;
|
||||
}
|
||||
else {
|
||||
speed = 8000000;
|
||||
}
|
||||
config.drivername = display_conf_get_driver_name("SSD1306");
|
||||
}
|
||||
|
||||
|
||||
if(!driver) driver = strdup("SSD1306");
|
||||
|
||||
|
||||
if(!display_is_valid_driver(driver)){
|
||||
fprintf(f,"Unsupported display driver %s\n",driver);
|
||||
if(i2cdisp_args.depth->count > 0 && strcasecmp(config.drivername,"SSD1326")==0) {
|
||||
config.depth = i2cdisp_args.depth->ival[0];
|
||||
}
|
||||
/* Check "--back" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.back,f,&config.back, false);
|
||||
if(!display_is_valid_driver(config.drivername)){
|
||||
fprintf(f,"Unsupported display driver %s\n",config.drivername);
|
||||
nerrors++;
|
||||
}
|
||||
|
||||
if(strcasestr(name,"I2C") && !bHasi2cConfig){
|
||||
fprintf(f,"Please configure I2C bus first. \n");
|
||||
}else if(strcasestr(name,"SPI") && !bHasSpiConfig){
|
||||
fprintf(f,"Please configure SPI bus first. \n");
|
||||
if(!strcasestr(config.type,"I2C") && !strcasestr(config.type,"SPI")){
|
||||
fprintf(f,"Invalid display type %s\n",config.type);
|
||||
nerrors++;
|
||||
}
|
||||
else if(!strcasestr(name,"I2C") && !strcasestr(name,"SPI")){
|
||||
fprintf(f,"Invalid display type %s\n",name);
|
||||
}
|
||||
bool rotate = i2cdisp_args.rotate->count>0;
|
||||
config.rotate = i2cdisp_args.rotate->count>0;
|
||||
config.hflip = i2cdisp_args.hflip->count>0;
|
||||
config.vflip = i2cdisp_args.vflip->count>0;
|
||||
|
||||
if(nerrors==0){
|
||||
snprintf(config_string, sizeof(config_string),"%s:back=%i,speed=%i,width=%i,height=%i,address=%i,driver=%s%s%s",
|
||||
name,back,speed,width,height,address,driver,rotate || i2cdisp_args.hflip->count?",HFlip":"",rotate || i2cdisp_args.vflip->count?",VFlip":"" );
|
||||
fprintf(f,"Updating display configuration string configuration to :\n"
|
||||
"display_config = \"%s\"",config_string );
|
||||
nerrors = config_set_value(NVS_TYPE_STR, "display_config", config_string)!=ESP_OK;
|
||||
fprintf(f,"Saving display configuration\n");
|
||||
esp_err_t err = config_display_set(&config);
|
||||
if(err!=ESP_OK){
|
||||
fprintf(f,"Error: %s\n",esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
|
||||
FREE_AND_NULL(name);
|
||||
FREE_AND_NULL(driver);
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return nerrors==0;
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
|
||||
@@ -530,17 +429,13 @@ static int do_spiconfig_cmd(int argc, char **argv){
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1
|
||||
};
|
||||
|
||||
int data, clk, dc, host = 0;
|
||||
int dc=-1,host = 0;
|
||||
esp_err_t err=ESP_OK;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&spiconfig_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check "--clear" option */
|
||||
if (spiconfig_args.clear->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"spi config cleared");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"SPI config cleared.\n");
|
||||
config_set_value(NVS_TYPE_STR, "spi_config", "");
|
||||
return 0;
|
||||
}
|
||||
@@ -549,51 +444,72 @@ static int do_spiconfig_cmd(int argc, char **argv){
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors>0){
|
||||
arg_print_errors(f,spiconfig_args.end,desc_spiconfig);
|
||||
return 1;
|
||||
}
|
||||
/* Check "--clk" option */
|
||||
nerrors+=is_output_gpio(spiconfig_args.clk, f, &clk);
|
||||
nerrors+=is_output_gpio(spiconfig_args.data, f, &data);
|
||||
nerrors+=is_output_gpio(spiconfig_args.dc, f, &dc);
|
||||
nerrors+=is_output_gpio(spiconfig_args.host, f, &host);
|
||||
nerrors+=is_output_gpio(spiconfig_args.clk, f, &spi_config.sclk_io_num, true);
|
||||
nerrors+=is_output_gpio(spiconfig_args.data, f, &spi_config.mosi_io_num, true);
|
||||
nerrors+=is_output_gpio(spiconfig_args.dc, f, &dc, true);
|
||||
nerrors+=is_output_gpio(spiconfig_args.host, f, &host, true);
|
||||
|
||||
if(!nerrors){
|
||||
spi_config.mosi_io_num=data;
|
||||
spi_config.sclk_io_num=clk;
|
||||
|
||||
fprintf(f,"Configuring SPI data:%d clk:%d host:%u dc:%d", spi_config.mosi_io_num, spi_config.sclk_io_num, host, dc);
|
||||
if((err=spi_bus_initialize( host, &spi_config, 1 ))!=ESP_OK){
|
||||
fprintf(f,"SPI bus initialization failed. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
fprintf(f,"Configuring SPI data=%d clock=%d host=%u dc: %d\n", spi_config.mosi_io_num, spi_config.sclk_io_num, host, dc);
|
||||
err=spi_bus_initialize( host, &spi_config, 1 );
|
||||
if(err!=ESP_OK){
|
||||
if(err==ESP_ERR_INVALID_STATE){
|
||||
// if user is changing the host number, we need to try freeing both hosts
|
||||
if((err = spi_bus_free(host))!=ESP_OK && (err = spi_bus_free(host==1?2:1))!=ESP_OK){
|
||||
fprintf(f,"SPI bus init failed. Please clear SPI configuration, restart the device and try again. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
else if((err=spi_bus_initialize( host, &spi_config, 1 ))!=ESP_OK){
|
||||
fprintf(f,"Failed to initialize SPI Bus. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(f,"SPI bus initialization failed. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!nerrors){
|
||||
fprintf(f,"Storing SPI parameters.\n");
|
||||
config_spi_set(&spi_config, host, dc);
|
||||
nerrors += (config_spi_set(&spi_config, host, dc)!=ESP_OK);
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return nerrors==0;
|
||||
|
||||
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
|
||||
static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
{
|
||||
esp_err_t err=ESP_OK;
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = 19,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = 18,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = 100000
|
||||
};
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cconfig_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
/* Check "--clear" option */
|
||||
if (i2cconfig_args.clear->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"i2c config cleared");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"i2c config cleared\n");
|
||||
config_set_value(NVS_TYPE_STR, "i2c_config", "");
|
||||
return 0;
|
||||
}
|
||||
@@ -602,32 +518,27 @@ static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors>0){
|
||||
arg_print_errors(f,i2cconfig_args.end,desc_i2c);
|
||||
return 1;
|
||||
}
|
||||
/* Check "--port" option */
|
||||
if (i2cconfig_args.port->count) {
|
||||
if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||
fprintf(f,"Invalid port %u \n",i2cconfig_args.port->ival[0]);
|
||||
nerrors ++;
|
||||
}
|
||||
}
|
||||
/* Check "--freq" option */
|
||||
if (i2cconfig_args.freq->count) {
|
||||
conf.master.clk_speed = i2cconfig_args.freq->ival[0];
|
||||
}
|
||||
|
||||
/* Check "--load" option */
|
||||
if (i2cconfig_args.load->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"Loading i2c config");
|
||||
i2c_load_configuration();
|
||||
}
|
||||
else {
|
||||
|
||||
/* Check "--port" option */
|
||||
if (i2cconfig_args.port->count) {
|
||||
if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||
fprintf(f,"Invalid port %u \n",i2cconfig_args.port->ival[0]);
|
||||
nerrors ++;
|
||||
}
|
||||
}
|
||||
/* Check "--freq" option */
|
||||
if (i2cconfig_args.freq->count) {
|
||||
i2c_frequency = i2cconfig_args.freq->ival[0];
|
||||
}
|
||||
|
||||
nerrors +=is_output_gpio(i2cconfig_args.sda,f,&i2c_gpio_sda);
|
||||
nerrors +=is_output_gpio(i2cconfig_args.scl,f,&i2c_gpio_scl);
|
||||
}
|
||||
nerrors +=is_output_gpio(i2cconfig_args.sda,f,&conf.sda_io_num, true);
|
||||
nerrors +=is_output_gpio(i2cconfig_args.scl,f,&conf.scl_io_num, true);
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
if (i2c_port == I2C_NUM_0) {
|
||||
@@ -645,54 +556,38 @@ static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
if(!nerrors){
|
||||
fprintf(f,"Initializing driver with config scl=%u sda=%u speed=%u port=%u\n",i2c_gpio_scl,i2c_gpio_sda,i2c_frequency,i2c_port);
|
||||
if((err=i2c_master_driver_initialize())==ESP_OK){
|
||||
fprintf(f,"Initalize success.\n");
|
||||
// now start the i2c driver
|
||||
fprintf(f,"Starting the i2c driver.");
|
||||
if((err=i2c_master_driver_install())!=ESP_OK){
|
||||
fprintf(f,"I2C master driver install failed. %s\n", esp_err_to_name(err));
|
||||
if((err=i2c_master_driver_initialize(argv[0],&conf))==ESP_OK){
|
||||
if((err=i2c_master_driver_install(argv[0]))!=ESP_OK){
|
||||
nerrors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
fprintf(f,"i2c driver successfully started.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
fprintf(f,"I2C initialization failed. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
if(!nerrors && !i2cconfig_args.load->count){
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Storing i2c parameters.\n");
|
||||
i2c_config_t config={
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = i2c_gpio_sda,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = i2c_gpio_scl,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = i2c_frequency
|
||||
};
|
||||
config_i2c_set(&config, i2c_port);
|
||||
config_i2c_set(&conf, i2c_port);
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return nerrors==0;
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
#define RUN_SHOW_ERROR(c)
|
||||
|
||||
|
||||
static int do_i2cdump_cmd(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cdump_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check chip address: "-c" option */
|
||||
@@ -704,24 +599,19 @@ static int do_i2cdump_cmd(int argc, char **argv)
|
||||
}
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (size != 1 && size != 2 && size != 4) {
|
||||
log_send_messaging(MESSAGING_ERROR, "Wrong read size. Only support 1,2,4");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Wrong read size. Only support 1,2,4\n");
|
||||
return 1;
|
||||
}
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
return 0;
|
||||
}
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t data_addr;
|
||||
@@ -777,19 +667,16 @@ static int do_i2cdump_cmd(int argc, char **argv)
|
||||
// Don't stop the driver; our firmware may be using it for screen, etc
|
||||
//i2c_driver_delete(i2c_port);
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int do_i2cset_cmd(int argc, char **argv)
|
||||
{
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cset_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check chip address: "-c" option */
|
||||
@@ -802,18 +689,12 @@ static int do_i2cset_cmd(int argc, char **argv)
|
||||
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check data: "-d" option */
|
||||
int len = i2cset_args.data->count;
|
||||
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, chip_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
|
||||
@@ -827,11 +708,11 @@ static int do_i2cset_cmd(int argc, char **argv)
|
||||
esp_err_t ret = i2c_master_cmd_begin(loc_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if (ret == ESP_OK) {
|
||||
log_send_messaging(MESSAGING_INFO, "i2c Write OK");
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "i2c Write OK\n");
|
||||
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||
log_send_messaging(MESSAGING_WARNING, "i2c Bus is busy");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "i2c Bus is busy\n");
|
||||
} else {
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c Read failed");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"i2c Read failed\n");
|
||||
}
|
||||
// Don't stop the driver; our firmware may be using it for screen, etc
|
||||
//i2c_driver_delete(i2c_port);
|
||||
@@ -842,7 +723,7 @@ static int do_i2cget_cmd(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cget_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check chip address: "-c" option */
|
||||
@@ -859,21 +740,15 @@ static int do_i2cget_cmd(int argc, char **argv)
|
||||
}
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
return 0;
|
||||
}
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
@@ -902,19 +777,18 @@ static int do_i2cget_cmd(int argc, char **argv)
|
||||
fprintf(f,"\r\n");
|
||||
}
|
||||
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||
log_send_messaging(MESSAGING_WARNING, "i2c Bus is busy");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "i2c Bus is busy\n");
|
||||
} else {
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c Read failed");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"i2c Read failed\n");
|
||||
}
|
||||
free(data);
|
||||
|
||||
// Don't stop the driver; our firmware may be using it for screen, etc
|
||||
//i2c_driver_delete(i2c_port);
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -923,14 +797,9 @@ static int do_i2cdetect_cmd(int argc, char **argv)
|
||||
uint8_t matches[128]={};
|
||||
int last_match=0;
|
||||
esp_err_t ret = ESP_OK;
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
return 0;
|
||||
}
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t address;
|
||||
@@ -938,8 +807,8 @@ static int do_i2cdetect_cmd(int argc, char **argv)
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -979,7 +848,7 @@ static int do_i2cdetect_cmd(int argc, char **argv)
|
||||
}
|
||||
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
@@ -989,19 +858,40 @@ cJSON * i2c_set_display_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
const display_config_t * conf= config_display_get();
|
||||
if(conf){
|
||||
cJSON_AddNumberToObject(values,"address",conf->address);
|
||||
cJSON_AddNumberToObject(values,"width",conf->width);
|
||||
cJSON_AddNumberToObject(values,"height",conf->height);
|
||||
cJSON_AddStringToObject(values,"type",conf->type);
|
||||
cJSON_AddStringToObject(values,"driver",conf->drivername);
|
||||
if(conf->width>0){
|
||||
cJSON_AddNumberToObject(values,"width",conf->width);
|
||||
}
|
||||
if(conf->height>0) {
|
||||
cJSON_AddNumberToObject(values,"height",conf->height);
|
||||
}
|
||||
if(conf->address>0){
|
||||
cJSON_AddNumberToObject(values,"address",conf->address);
|
||||
}
|
||||
if(conf->RST_pin>=0) {
|
||||
cJSON_AddNumberToObject(values,"reset",conf->RST_pin);
|
||||
}
|
||||
if(conf->drivername && strlen(conf->drivername)>0){
|
||||
cJSON_AddStringToObject(values,"driver",conf->drivername);
|
||||
}
|
||||
if(conf->CS_pin>=0) {
|
||||
cJSON_AddNumberToObject(values,"cs",conf->CS_pin);
|
||||
}
|
||||
if(conf->speed>0){
|
||||
cJSON_AddNumberToObject(values,"speed",conf->speed);
|
||||
}
|
||||
if(conf->back>=0){
|
||||
cJSON_AddNumberToObject(values,"back",conf->back);
|
||||
}
|
||||
if(conf->depth>0){
|
||||
cJSON_AddNumberToObject(values,"depth",conf->depth);
|
||||
}
|
||||
if(conf->type && strlen(conf->type)){
|
||||
cJSON_AddStringToObject(values,"type",conf->type);
|
||||
}
|
||||
cJSON_AddBoolToObject(values,"rotate",conf->rotate);
|
||||
cJSON_AddBoolToObject(values,"hf",conf->hflip);
|
||||
cJSON_AddBoolToObject(values,"vf",conf->vflip);
|
||||
if(conf->vflip && conf->hflip){
|
||||
cJSON_AddBoolToObject(values,"rotate",true);
|
||||
}
|
||||
else {
|
||||
cJSON_AddBoolToObject(values,"rotate",false);
|
||||
}
|
||||
|
||||
}
|
||||
return values;
|
||||
}
|
||||
@@ -1009,37 +899,30 @@ cJSON * i2c_set_display_cb(){
|
||||
static void register_i2c_set_display(){
|
||||
char * supported_drivers = display_get_supported_drivers();
|
||||
|
||||
i2cdisp_args.address = arg_int0("a", "address", "<n>", "I2C address (default 60)");
|
||||
i2cdisp_args.width = arg_int0("w", "width", "<n>", "Width");
|
||||
i2cdisp_args.height = arg_int0("h", "height", "<n>", "Height");
|
||||
i2cdisp_args.name = arg_str0("t", "type", "<I2C|SPI>", "Interface (default I2C)");
|
||||
i2cdisp_args.driver = arg_str0("d", "driver", supported_drivers?supported_drivers:"<string>", "Driver (default SSD1306)");
|
||||
i2cdisp_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
|
||||
i2cdisp_args.hflip = arg_lit0(NULL, "hf", "Flip horizontally");
|
||||
i2cdisp_args.vflip = arg_lit0(NULL, "vf", "Flip vertically");
|
||||
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate 180 degrees");
|
||||
i2cdisp_args.back = arg_int0("b", "back", "<n>","Backlight GPIO (if applicable)");
|
||||
i2cdisp_args.speed = arg_int0("s", "speed", "<n>","Bus Speed (Default 8000000 for SPI, 250000 for I2C). SPI interface can work up to 26MHz~40MHz");
|
||||
i2cdisp_args.end = arg_end(8);
|
||||
i2cdisp_args.width = arg_int1("w", "width", "<n>", "Width");
|
||||
i2cdisp_args.height = arg_int1("h", "height", "<n>", "Height");
|
||||
i2cdisp_args.address = arg_int0("a", "address", "<n>", "I2C address (default 60)");
|
||||
i2cdisp_args.reset = arg_int0(NULL, "reset", "<n>", "Reset GPIO");
|
||||
i2cdisp_args.hflip = arg_lit0(NULL, "hf", "Flip horizontally");
|
||||
i2cdisp_args.vflip = arg_lit0(NULL, "vf", "Flip vertically");
|
||||
i2cdisp_args.driver = arg_str0("d", "driver", supported_drivers?supported_drivers:"<string>", "Driver (default SSD1306)");
|
||||
i2cdisp_args.cs = arg_int0("b", "cs", "<n>","SPI Only. CS GPIO (for SPI displays)");
|
||||
i2cdisp_args.speed = arg_int0("s", "speed", "<n>","SPI Only. Bus Speed (Default 8000000). SPI interface can work up to 26MHz~40MHz");
|
||||
i2cdisp_args.back = arg_int0("b", "back", "<n>","Backlight GPIO (if applicable)");
|
||||
i2cdisp_args.depth = arg_int0("p", "depth", "1|4", "Bit Depth (only for SSD1326 displays)");
|
||||
i2cdisp_args.type = arg_str0("t", "type", "<I2C|SPI>", "Interface (default I2C)");
|
||||
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate 180 degrees");
|
||||
i2cdisp_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
|
||||
i2cdisp_args.end = arg_end(8);
|
||||
const esp_console_cmd_t i2c_set_display= {
|
||||
.command = "setdisplay",
|
||||
.help="Display",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_set_display,
|
||||
.argtable = &i2cdisp_args
|
||||
};
|
||||
|
||||
const esp_console_cmd_t i2c_show_display= {
|
||||
.command = "getdisplay",
|
||||
.help="Shows display options and global i2c configuration",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_show_display,
|
||||
.argtable = NULL
|
||||
.command = CFG_TYPE_HW("display"),
|
||||
.help=desc_display,
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_set_display,
|
||||
.argtable = &i2cdisp_args
|
||||
};
|
||||
cmd_to_json_with_cb(&i2c_set_display,&i2c_set_display_cb);
|
||||
cmd_to_json(&i2c_show_display);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2c_set_display));
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2c_show_display));
|
||||
}
|
||||
static void register_i2cdectect(void)
|
||||
{
|
||||
@@ -1090,9 +973,6 @@ static void register_i2cset(void)
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cset_cmd));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void register_i2cdump(void)
|
||||
{
|
||||
i2cdump_args.chip_address = arg_int1("c", "chip", "<chip_addr>", "Specify the address of the chip on that bus");
|
||||
@@ -1109,36 +989,6 @@ static void register_i2cdump(void)
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cdump_cmd));
|
||||
}
|
||||
|
||||
static void register_i2ccheck(){
|
||||
i2ccheck_args.port = arg_int0("p", "port", "<0|1>", "Set the I2C bus port number");
|
||||
i2ccheck_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "i2ccheck",
|
||||
.help = "Check if the I2C bus is installed",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_check,
|
||||
.argtable = &i2ccheck_args
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
|
||||
|
||||
static void register_i2cstop(){
|
||||
i2cstop_args.port = arg_int0("p", "port", "<0|1>", "I2C bus port number");
|
||||
i2cstop_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t i2cconfig_cmd = {
|
||||
.command = "i2cstop",
|
||||
.help = "Stop the I2C bus",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_stop,
|
||||
.argtable = &i2cstop_args
|
||||
};
|
||||
cmd_to_json(&i2cconfig_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cconfig_cmd));
|
||||
}
|
||||
|
||||
cJSON * i2config_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
@@ -1151,9 +1001,9 @@ cJSON * i2config_cb(){
|
||||
cJSON_AddNumberToObject(values,"sda",i2c->sda_io_num);
|
||||
}
|
||||
if(i2c->master.clk_speed>0) {
|
||||
cJSON_AddNumberToObject(values,"freq",i2c->master.clk_speed);
|
||||
cJSON_AddNumberToObject(values,"speed",i2c->master.clk_speed);
|
||||
}
|
||||
if(i2c_port>0) {
|
||||
if(i2c_port>=0) {
|
||||
cJSON_AddNumberToObject(values,"port",i2c_port);
|
||||
}
|
||||
return values;
|
||||
@@ -1182,11 +1032,11 @@ static void register_spiconfig(void)
|
||||
spiconfig_args.clk = arg_int0("k", "clk", "<n>", "Clock GPIO");
|
||||
spiconfig_args.data = arg_int0("d","data", "<n>","Data GPIO");
|
||||
spiconfig_args.dc = arg_int0("c","dc", "<n>", "DC GPIO");
|
||||
spiconfig_args.host= arg_int0("h", "host", "int", "SPI Host Number");
|
||||
spiconfig_args.host= arg_int0("h", "host", "1|2", "SPI Host Number");
|
||||
spiconfig_args.end = arg_end(4);
|
||||
const esp_console_cmd_t spiconfig_cmd = {
|
||||
.command = "spiconfig",
|
||||
.help = "SPI Bus Parameters",
|
||||
.command = CFG_TYPE_HW("spi"),
|
||||
.help = desc_spiconfig,
|
||||
.hint = NULL,
|
||||
.func = &do_spiconfig_cmd,
|
||||
.argtable = &spiconfig_args
|
||||
@@ -1201,11 +1051,10 @@ static void register_i2cconfig(void)
|
||||
i2cconfig_args.freq = arg_int0("f", "speed", "int", "Frequency (Hz) e.g. 100000");
|
||||
i2cconfig_args.sda = arg_int0("d", "sda", "<n>", "SDA GPIO. e.g. 19");
|
||||
i2cconfig_args.scl = arg_int0("c", "scl", "<n>", "SCL GPIO. e.g. 18");
|
||||
i2cconfig_args.load = arg_lit0("l", "load", "Load Existing Configuration");
|
||||
i2cconfig_args.end = arg_end(4);
|
||||
const esp_console_cmd_t i2cconfig_cmd = {
|
||||
.command = "i2cconfig",
|
||||
.help = "I2C Bus Parameters",
|
||||
.command = CFG_TYPE_HW("i2c"),
|
||||
.help = desc_i2c,
|
||||
.hint = NULL,
|
||||
.func = &do_i2cconfig_cmd,
|
||||
.argtable = &i2cconfig_args
|
||||
@@ -1223,6 +1072,4 @@ void register_i2ctools(void)
|
||||
register_i2cset();
|
||||
register_i2cdump();
|
||||
register_i2c_set_display();
|
||||
register_i2cstop();
|
||||
register_i2ccheck();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user