From c36915e8643d26f2fd0b38cf7eefa5b9dc07b806 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 18 Sep 2022 19:15:22 +0200 Subject: [PATCH] main button pin moved to webguiapp config --- Kconfig | 8 +++++++ src/SystemConfiguration.c | 49 +++++++++++---------------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/Kconfig b/Kconfig index 6afd141..6a9d380 100644 --- a/Kconfig +++ b/Kconfig @@ -15,6 +15,14 @@ menu "webguiapp configuration" config WEBGUIAPP_USERPASS string "Default user password" default "password" + + config MAIN_FUNCTIONAL_BUTTON_GPIO + int "Main functional button GPIO" + range -1 34 + default 15 + help + Set the GPIO number for main system button. Mainly needed for settings default reset. If not + used set -1 menu "SPI settings" config WEBGUIAPP_SPI_ENABLE diff --git a/src/SystemConfiguration.c b/src/SystemConfiguration.c index 8c35fda..2f92ee3 100644 --- a/src/SystemConfiguration.c +++ b/src/SystemConfiguration.c @@ -72,7 +72,13 @@ esp_err_t WebGuiAppInit(void) esp_err_t err = nvs_flash_init(); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); - if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND || MANUAL_RESET == 1 || gpio_get_level(GPIO_NUM_15) == 0) + if (err == ESP_ERR_NVS_NO_FREE_PAGES || + err == ESP_ERR_NVS_NEW_VERSION_FOUND || + MANUAL_RESET == 1 +#if (CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO >= 0) + || gpio_get_level(GPIO_NUM_15) == 0 +#endif + ) { // 1.OTA app partition table has a smaller NVS partition size than the non-OTA // partition table. This size mismatch may cause NVS initialization to fail. @@ -140,43 +146,16 @@ if(GetSysConf()->wifiSettings.Flags1.bIsAP) static void InitSysIO(void) { - /* - gpio_pad_select_gpio(GPIO_NUM_2); - gpio_pad_select_gpio(GPIO_NUM_0); - gpio_pad_select_gpio(GPIO_NUM_4); - gpio_pad_select_gpio(GPIO_NUM_34); - gpio_pad_select_gpio(GPIO_NUM_16); - gpio_pad_select_gpio(GPIO_NUM_17); - gpio_pad_select_gpio(GPIO_NUM_25); - gpio_pad_select_gpio(GPIO_NUM_26); - gpio_pad_select_gpio(GPIO_NUM_27); - gpio_pad_select_gpio(GPIO_NUM_32); - gpio_pad_select_gpio(GPIO_NUM_33); - gpio_pad_select_gpio(GPIO_NUM_39); +#if (CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO >= 0) + gpio_pad_select_gpio(CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO); + gpio_set_direction(CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO, GPIO_MODE_INPUT); + gpio_set_pull_mode(CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO, GPIO_PULLUP_ONLY); + gpio_pullup_en(CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO); - gpio_set_direction(GPIO_NUM_0, GPIO_MODE_INPUT); - gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_25, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_26, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_27, GPIO_MODE_INPUT); - gpio_set_direction(GPIO_NUM_32, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_NUM_33, GPIO_MODE_INPUT); - gpio_set_direction(GPIO_NUM_34, GPIO_MODE_INPUT); - gpio_set_direction(GPIO_NUM_39, GPIO_MODE_INPUT); +#endif - gpio_set_level(GPIO_NUM_2, 1); - gpio_set_level(GPIO_NUM_4, 1); - gpio_set_level(GPIO_NUM_16, 1); - gpio_set_level(GPIO_NUM_17, 1); - gpio_set_level(GPIO_NUM_25, 0); //RELAY - gpio_set_level(GPIO_NUM_26, 0); //TRIAC - gpio_set_level(GPIO_NUM_32, 1); //0- current , 1- voltage - */ ESP_ERROR_CHECK(gpio_install_isr_service(ESP_INTR_FLAG_IRAM)); - ESP_LOGI(TAG, "GPIO initialized OK"); + ESP_LOGI(TAG, "System GPIO's initialized OK"); }