From e6afaf7fe4f26d858ab43f9e3fc434d36abda9de Mon Sep 17 00:00:00 2001 From: Wizmo2 Date: Thu, 28 Sep 2023 20:40:10 -0400 Subject: [PATCH] improved locked updates --- .../app_squeezelite/cmd_squeezelite.c | 2 +- components/platform_console/cmd_config.c | 17 +++++++-- components/platform_console/cmd_i2ctools.c | 17 +++++++++ components/services/accessors.c | 38 +++++++++++++++++-- components/services/accessors.h | 6 ++- 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/components/platform_console/app_squeezelite/cmd_squeezelite.c b/components/platform_console/app_squeezelite/cmd_squeezelite.c index 654dbc6e5..8247fa077 100644 --- a/components/platform_console/app_squeezelite/cmd_squeezelite.c +++ b/components/platform_console/app_squeezelite/cmd_squeezelite.c @@ -13,6 +13,7 @@ #include "esp_app_format.h" #include "tools.h" #include "messaging.h" +#include "accessors.h" extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length); static const char * TAG = "squeezelite_cmd"; @@ -42,7 +43,6 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { extern void register_audio_config(void); extern void register_rotary_config(void); -extern void register_ledvu_config(void); void register_optional_cmd(void) { register_rotary_config(); diff --git a/components/platform_console/cmd_config.c b/components/platform_console/cmd_config.c index a7143f224..fa018b755 100644 --- a/components/platform_console/cmd_config.c +++ b/components/platform_console/cmd_config.c @@ -559,6 +559,12 @@ static int do_spdif_cmd(int argc, char **argv){ static int do_rotary_cmd(int argc, char **argv){ rotary_struct_t rotary={ .A = -1, .B = -1, .SW = -1, .longpress = 0, .knobonly=0,.volume_lock=false}; + + if(is_ledvu_config_locked()) { + cmd_send_messaging(argv[0],MESSAGING_ERROR,"Rotary Encoder Configuration is locked on this platform\n"); + return 1; + } + esp_err_t err=ESP_OK; int nerrors = arg_parse(argc, argv,(void **)&rotary_args); if (rotary_args.clear->count) { @@ -1375,6 +1381,9 @@ static void register_bt_source_config(void){ } void register_rotary_config(void){ + if (!is_rotary_config_locked()){ + return; + } rotary_args.rem = arg_rem("remark","One rotary encoder is supported, quadrature shift with press. Such encoders usually have 2 pins for encoders (A and B), and common C that must be set to ground and an optional SW pin for press. A, B and SW must be pulled up, so automatic pull-up is provided by ESP32, but you can add your own resistors. A bit of filtering on A and B (~470nF) helps for debouncing which is not made by software.\r\nEncoder is normally hard-coded to respectively knob left, right and push on LMS and to volume down/up/play toggle on BT and AirPlay."); rotary_args.A = arg_int1(NULL,"A","gpio","A/DT gpio"); rotary_args.B = arg_int1(NULL,"B","gpio","B/CLK gpio"); @@ -1398,6 +1407,9 @@ void register_rotary_config(void){ } void register_ledvu_config(void){ + if (is_ledvu_config_locked()){ + return; + } ledvu_args.type = arg_str0(NULL,"type","WS2812|APA102","Led type (supports one rgb strip to display built in effects and allow remote control through 'dmx' messaging)"); ledvu_args.length = arg_int1(NULL,"length","<1..255>","Strip length (1-255 supported)"); ledvu_args.gpio = arg_int1(NULL,"gpio","","Data pin"); @@ -1506,9 +1518,8 @@ void register_config_cmd(void){ if(!is_spdif_config_locked()){ register_spdif_config(); } - if (is_ledvu_config_locked()){ - register_ledvu_config(); - } + register_ledvu_config(); + register_optional_cmd(); } diff --git a/components/platform_console/cmd_i2ctools.c b/components/platform_console/cmd_i2ctools.c index 16cce3a8c..8520f653b 100644 --- a/components/platform_console/cmd_i2ctools.c +++ b/components/platform_console/cmd_i2ctools.c @@ -299,6 +299,10 @@ static esp_err_t i2c_master_driver_initialize(const char * cmdname, i2c_config_t static int do_i2c_set_display(int argc, char **argv) { + if(is_display_config_locked()) { + cmd_send_messaging(argv[0],MESSAGING_ERROR,"Display Configuration is locked on this platform\n"); + return 1; + } bool bHasi2cConfig = false, bHasSpiConfig=false; int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cdisp_args); display_config_t config = { @@ -445,6 +449,11 @@ static int do_spiconfig_cmd(int argc, char **argv){ .quadwp_io_num = -1, .quadhd_io_num = -1 }; + + if(is_spi_config_locked()) { + cmd_send_messaging(argv[0],MESSAGING_ERROR,"SPI Configuration is locked on this platform\n"); + return 1; + } int dc=-1,host = 0; esp_err_t err=ESP_OK; int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&spiconfig_args); @@ -979,6 +988,10 @@ cJSON * i2c_set_display_cb(){ } static void register_i2c_set_display(){ + if (is_display_config_locked()){ + return; + } + char * supported_drivers = display_get_supported_drivers(); i2cdisp_args.width = arg_int1("w", "width", "", "Width"); @@ -1112,6 +1125,10 @@ cJSON * spiconfig_cb(){ static void register_spiconfig(void) { + if (is_spi_config_locked()){ + return; + } + spiconfig_args.clear = arg_lit0(NULL, "clear", "Clear configuration"); spiconfig_args.clk = arg_int0("k", "clk", "", "Clock GPIO"); spiconfig_args.data = arg_int0("d","data", "","Data OUT GPIO"); diff --git a/components/services/accessors.c b/components/services/accessors.c index bba9a0e57..cb3e2945d 100644 --- a/components/services/accessors.c +++ b/components/services/accessors.c @@ -103,9 +103,6 @@ bool is_spdif_config_locked(){ return false; } -/**************************************************************************************** - * - */ bool is_ledvu_config_locked(){ #if ( defined CONFIG_LED_VU_CONFIG ) if(strlen(CONFIG_LED_VU_CONFIG) > 0){ @@ -115,6 +112,41 @@ bool is_ledvu_config_locked(){ return false; } +bool is_display_config_locked(){ +#if ( defined CONFIG_DISPLAY_CONFIG ) + if(strlen(CONFIG_DISPLAY_CONFIG) > 0){ + return true; + } +#endif + return false; +} + +bool is_rotary_config_locked(){ +#if ( defined CONFIG_ROTARY_CONFIG ) + if(strlen(CONFIG_ROTARY_CONFIG) > 0){ + return true; + } +#endif + return false; +} + +bool is_spi_config_locked(){ +#if ( defined CONFIG_SPI_CONFIG ) + if(strlen(CONFIG_SPI_CONFIG) > 0){ + return true; + } +#endif + return false; +} + +bool is_i2c_config_locked(){ +#if ( defined CONFIG_I2C_CONFIG ) + if(strlen(CONFIG_I2C_CONFIG) > 0){ + return true; + } +#endif + return false; +} /**************************************************************************************** * Set pin from config string diff --git a/components/services/accessors.h b/components/services/accessors.h index 34c44ae6a..09f9c62c7 100644 --- a/components/services/accessors.h +++ b/components/services/accessors.h @@ -103,10 +103,13 @@ const display_config_t * config_display_get(); const eth_config_t * config_eth_get( ); void config_eth_init( eth_config_t * target ); esp_err_t config_display_set(const display_config_t * config); +bool is_display_config_locked(); esp_err_t config_i2c_set(const i2c_config_t * config, int port); esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name); esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc); +bool is_spi_config_locked(); const i2c_config_t * config_i2c_get(int * i2c_port); +bool is_i2c_config_locked(); const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host); const gpio_exp_config_t * config_gpio_exp_get(int index); void parse_set_GPIO(void (*cb)(int gpio, char *value)); @@ -123,6 +126,7 @@ bool is_dac_config_locked(); bool are_statistics_enabled(); const rotary_struct_t * config_rotary_get(); esp_err_t config_rotary_set(rotary_struct_t * rotary); +bool is_rotary_config_locked(); const ledvu_struct_t * config_ledvu_get(); esp_err_t config_ledvu_set(ledvu_struct_t * ledvu); -bool is_ledvu_config_locked(); \ No newline at end of file +bool is_ledvu_config_locked();