From 5e6b0f64bd54272ed47ee62fc3c0c1f425ff1979 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 22 Oct 2023 17:40:38 +0200 Subject: [PATCH] add E32V2 board profile, fix autodetect and GPIOs --- interface/src/project/validators.ts | 3 +- src/console.cpp | 2 +- src/system.cpp | 4 ++- src/version.h | 2 +- src/web/WebSettingsService.cpp | 51 ++++++++++++++++++++++------- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/interface/src/project/validators.ts b/interface/src/project/validators.ts index 246c22a7f..cd3a2a1d2 100644 --- a/interface/src/project/validators.ts +++ b/interface/src/project/validators.ts @@ -8,8 +8,7 @@ export const GPIO_VALIDATOR = { if ( value && (value === 1 || - (value >= 6 && value <= 12) || - (value >= 14 && value <= 15) || + (value >= 6 && value <= 11) || value === 20 || value === 24 || (value >= 28 && value <= 31) || diff --git a/src/console.cpp b/src/console.cpp index dfc0f5792..8d8ad0190 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -284,7 +284,7 @@ static void setup_commands(std::shared_ptr & commands) { std::vector data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode std::string board_profile = Helpers::toUpper(arguments.front()); if (!to_app(shell).system_.load_board_profile(data, board_profile)) { - shell.println("Invalid board profile (S32, E32, MH-ET, NODEMCU, OLIMEX, OLIMEXPOE, C3MINI, S2MINI, S3MINI, CUSTOM)"); + shell.println("Invalid board profile (S32, E32, E32V2, MH-ET, NODEMCU, OLIMEX, OLIMEXPOE, C3MINI, S2MINI, S3MINI, CUSTOM)"); return; } to_app(shell).webSettingsService.update( diff --git a/src/system.cpp b/src/system.cpp index e44dac9e5..4746ac810 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -391,7 +391,7 @@ void System::wifi_tweak() { // and https://nodemcu.readthedocs.io/en/dev-esp32/modules/gpio/ bool System::is_valid_gpio(uint8_t pin) { #if CONFIG_IDF_TARGET_ESP32 || EMSESP_STANDALONE - if ((pin == 1) || (pin >= 6 && pin <= 12) || (pin >= 14 && pin <= 15) || (pin == 20) || (pin == 24) || (pin >= 28 && pin <= 31) || (pin > 40)) { + if ((pin == 1) || (pin >= 6 && pin <= 11) || (pin == 20) || (pin == 24) || (pin >= 28 && pin <= 31) || (pin > 40)) { #elif CONFIG_IDF_TARGET_ESP32S2 if ((pin >= 19 && pin <= 20) || (pin >= 22 && pin <= 32) || (pin > 40)) { #elif CONFIG_IDF_TARGET_ESP32C3 @@ -1440,6 +1440,8 @@ bool System::load_board_profile(std::vector & data, const std::string & data = {2, 18, 23, 5, 0, PHY_type::PHY_TYPE_NONE, 0, 0, 0}; // BBQKees Gateway S32 } else if (board_profile == "E32") { data = {2, 4, 5, 17, 33, PHY_type::PHY_TYPE_LAN8720, 16, 1, 0}; // BBQKees Gateway E32 + } else if (board_profile == "E32V2") { + data = {2, 14, 4, 5, 0, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1}; // BBQKees Gateway E32 V2 } else if (board_profile == "MH-ET") { data = {2, 18, 23, 5, 0, PHY_type::PHY_TYPE_NONE, 0, 0, 0}; // MH-ET Live D1 Mini } else if (board_profile == "NODEMCU") { diff --git a/src/version.h b/src/version.h index e0ab57b39..015303d8c 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.6.3-dev.4a" +#define EMSESP_APP_VERSION "3.6.3-dev.4b" diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index 8aa6a1fa3..8203fcafa 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -101,17 +101,33 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) if (!System::load_board_profile(data, settings.board_profile.c_str())) { // unknown, check for ethernet, use default E32/S32 // data is led, dallas, rx, tx, pbutton, phy, eth_power, eth_addr, eth_clock -#ifndef EMSESP_STANDALONE -#if CONFIG_IDF_TARGET_ESP32 - if (ETH.begin((eth_phy_type_t)1, 16, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_IN)) { - // BBQKees Gateway E32 - data = {EMSESP_DEFAULT_LED_GPIO, 4, 5, 17, 33, PHY_type::PHY_TYPE_LAN8720, 16, 1, 0}; +#if CONFIG_IDF_TARGET_ESP32 && !defined(EMSESP_STANDALONE) + switch (EMSESP::nvs_.getUChar("boot")) { + case 0: + if (ETH.begin((eth_phy_type_t)1, 16, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_IN)) { + EMSESP::nvs_.putUChar("boot", 2); // set to E32 + ESP.restart(); + } + EMSESP::nvs_.putUChar("boot", 1); // next test for E32V2 + ESP.restart(); + case 1: + if (ETH.begin((eth_phy_type_t)0, 15, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_OUT)) { + EMSESP::nvs_.putUChar("boot", 3); // set to E32V2 + ESP.restart(); + } + EMSESP::nvs_.putUChar("boot", 4); // set to S32 + ESP.restart(); + case 2: settings.board_profile = "E32"; - } else -#endif -#endif - { - // BBQKees Gateway S32 + data = {EMSESP_DEFAULT_LED_GPIO, 4, 5, 17, 33, PHY_type::PHY_TYPE_LAN8720, 16, 1, 0}; + break; + case 3: + settings.board_profile = "E32V2"; + data = {EMSESP_DEFAULT_LED_GPIO, 14, 4, 5, 0, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1}; // BBQKees Gateway E32 V2 + break; + case 4: + default: + settings.board_profile = "S32"; data = {EMSESP_DEFAULT_LED_GPIO, EMSESP_DEFAULT_DALLAS_GPIO, EMSESP_DEFAULT_RX_GPIO, @@ -121,8 +137,21 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) 0, 0, 0}; - settings.board_profile = "S32"; + break; } +#else + // BBQKees Gateway S32 + data = {EMSESP_DEFAULT_LED_GPIO, + EMSESP_DEFAULT_DALLAS_GPIO, + EMSESP_DEFAULT_RX_GPIO, + EMSESP_DEFAULT_TX_GPIO, + EMSESP_DEFAULT_PBUTTON_GPIO, + EMSESP_DEFAULT_PHY_TYPE, + 0, + 0, + 0}; + settings.board_profile = "S32"; +#endif EMSESP::logger().info("No board profile found. Re-setting to %s", settings.board_profile.c_str()); } else { EMSESP::logger().info("Loading board profile %s", settings.board_profile.c_str());