gpio exclusion, add name

This commit is contained in:
proddy
2026-01-04 11:44:28 +01:00
parent 4afe041880
commit 68ebcdded4
5 changed files with 47 additions and 42 deletions

View File

@@ -1721,11 +1721,11 @@ void EMSESP::start() {
LOG_INFO("EMS-ESP version %s", EMSESP_APP_VERSION); LOG_INFO("EMS-ESP version %s", EMSESP_APP_VERSION);
#endif #endif
// check if the firmware is fresh // check if the firmware is fresh, i.e. a new install or a new version has been uploaded
// this is set in UploadFileService::uploadComplete() // this is set in UploadFileService::uploadComplete()
// and reset in System::set_partition_install_date() // and reset in System::set_partition_install_date()
if (!EMSESP::nvs_.getBool(EMSESP_NVS_BOOT_NEW_FIRMWARE)) { if (!EMSESP::nvs_.getBool(EMSESP_NVS_BOOT_NEW_FIRMWARE)) {
LOG_DEBUG("Firmware is fresh"); LOG_DEBUG("Firmware is fresh install");
} }
LOG_DEBUG("System is running in Debug mode"); LOG_DEBUG("System is running in Debug mode");
@@ -1837,7 +1837,7 @@ void EMSESP::loop() {
if (EMSESP::system_.systemStatus() == SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO) { if (EMSESP::system_.systemStatus() == SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO) {
static bool only_once = false; static bool only_once = false;
if (!only_once) { if (!only_once) {
LOG_ERROR("Invalid GPIOs used. Please check your settings and log"); LOG_ERROR("Invalid GPIOs used. Please check your settings and the system log");
only_once = true; only_once = true;
} }
} }

View File

@@ -105,8 +105,8 @@ uint32_t System::led_flash_duration_ = 0;
bool System::led_flash_timer_ = false; bool System::led_flash_timer_ = false;
// GPIOs // GPIOs
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::valid_system_gpios_; std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::valid_system_gpios_;
std::vector<System::GpioInfo, AllocatorPSRAM<System::GpioInfo>> System::used_gpios_; std::vector<System::GpioUsage, AllocatorPSRAM<System::GpioUsage>> System::used_gpios_;
// find the index of the language // find the index of the language
// 0 = EN, 1 = DE, etc... // 0 = EN, 1 = DE, etc...
@@ -1216,16 +1216,16 @@ void System::show_system(uuid::console::Shell & shell) {
// GPIOs // GPIOs
shell.println(" GPIOs:"); shell.println(" GPIOs:");
shell.printf(" in use:"); shell.printf(" in use:");
for (const auto & gpio_info : used_gpios_) { for (const auto & usage : used_gpios_) {
shell.printf(" %d(%s)", gpio_info.pin, gpio_info.name.c_str()); shell.printf(" %d(%s)", usage.pin, usage.source.c_str());
} }
shell.printfln(" (total %d)", used_gpios_.size()); shell.printfln(" [total %d]", used_gpios_.size());
auto available = available_gpios(); auto available = available_gpios();
shell.printf(" available:"); shell.printf(" available:");
for (const auto & gpio : available) { for (const auto & gpio : available) {
shell.printf(" %d", gpio); shell.printf(" %d", gpio);
} }
shell.printfln(" (total %d)", available.size()); shell.printfln(" [total %d]", available.size());
// List all partitions and their version info // List all partitions and their version info
shell.println(" Partitions:"); shell.println(" Partitions:");
for (const auto & partition : partition_info_) { for (const auto & partition : partition_info_) {
@@ -1410,7 +1410,7 @@ bool System::check_upgrade() {
// see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022 // see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022
missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5)); missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5));
if (missing_version) { if (missing_version) {
LOG_WARNING("No version information found"); LOG_WARNING("No version information found. Assuming version 3.5.0");
settingsVersion = "3.5.0"; // this was the last stable version without version info settingsVersion = "3.5.0"; // this was the last stable version without version info
} }
@@ -1422,7 +1422,7 @@ bool System::check_upgrade() {
bool save_version = true; bool save_version = true;
bool reboot_required = false; bool reboot_required = false;
LOG_DEBUG("Checking for version upgrades (settings file is v%d.%d.%d%s)", LOG_DEBUG("Checking for version upgrades from v%d.%d.%d%s",
settings_version.major(), settings_version.major(),
settings_version.minor(), settings_version.minor(),
settings_version.patch(), settings_version.patch(),
@@ -2031,8 +2031,8 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
#else #else
node["version"] = EMSESP_APP_VERSION; node["version"] = EMSESP_APP_VERSION;
#endif #endif
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
node["uptimeSec"] = uuid::get_uptime_sec(); node["uptimeSec"] = uuid::get_uptime_sec();
node["resetReason"] = EMSESP::system_.reset_reason(0) + " / " + EMSESP::system_.reset_reason(1); node["resetReason"] = EMSESP::system_.reset_reason(0) + " / " + EMSESP::system_.reset_reason(1);
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
node["platform"] = EMSESP_PLATFORM; node["platform"] = EMSESP_PLATFORM;
@@ -2045,8 +2045,8 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
node["usedApp"] = EMSESP::system_.appUsed(); // kilobytes node["usedApp"] = EMSESP::system_.appUsed(); // kilobytes
node["freeApp"] = EMSESP::system_.appFree(); // kilobytes node["freeApp"] = EMSESP::system_.appFree(); // kilobytes
node["partition"] = (const char *)esp_ota_get_running_partition()->label; // active partition node["partition"] = (const char *)esp_ota_get_running_partition()->label; // active partition
node["flash_chip_size"] = ESP.getFlashChipSize() / 1024; // kilobytes node["flash_chip_size"] = ESP.getFlashChipSize() / 1024; // kilobytes
node["psram"] = (EMSESP::system_.PSram() > 0); // make boolean node["psram"] = (EMSESP::system_.PSram() > 0); // make boolean
if (EMSESP::system_.PSram()) { if (EMSESP::system_.PSram()) {
node["psramSize"] = EMSESP::system_.PSram(); node["psramSize"] = EMSESP::system_.PSram();
node["freePsram"] = ESP.getFreePsram() / 1024; node["freePsram"] = ESP.getFreePsram() / 1024;
@@ -2060,11 +2060,11 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
// GPIO information // GPIO information
std::string gpios_in_use_str; std::string gpios_in_use_str;
for (const auto & gpio_info : EMSESP::system_.used_gpios_) { for (const auto & usage : EMSESP::system_.used_gpios_) {
if (!gpios_in_use_str.empty()) { if (!gpios_in_use_str.empty()) {
gpios_in_use_str += ", "; gpios_in_use_str += ", ";
} }
gpios_in_use_str += Helpers::itoa(gpio_info.pin) + "(" + gpio_info.name + ")"; gpios_in_use_str += Helpers::itoa(usage.pin);
} }
node["gpios_in_use"] = gpios_in_use_str; node["gpios_in_use"] = gpios_in_use_str;
@@ -2866,9 +2866,10 @@ std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::string_range_to_vector(con
process_exclude(exclude.substr(prev)); process_exclude(exclude.substr(prev));
// remove excluded GPIOs from the main list // remove excluded GPIOs from the main list
gpios.erase(std::remove_if(gpios.begin(), gpios.end(), [&exclude_gpios](uint8_t gpio) { gpios.erase(std::remove_if(gpios.begin(),
return std::find(exclude_gpios.begin(), exclude_gpios.end(), gpio) != exclude_gpios.end(); gpios.end(),
}), gpios.end()); [&exclude_gpios](uint8_t gpio) { return std::find(exclude_gpios.begin(), exclude_gpios.end(), gpio) != exclude_gpios.end(); }),
gpios.end());
} }
return gpios; return gpios;
@@ -2885,7 +2886,7 @@ void System::set_valid_system_gpios() {
#if CONFIG_IDF_TARGET_ESP32C3 #if CONFIG_IDF_TARGET_ESP32C3
// not valid: // not valid:
// 20-21 are UART0 // 20-21 are UART0
valid_system_gpios_ = string_range_to_vector("0-10", "20-21"); valid_system_gpios_ = string_range_to_vector("0-21", "20-21");
#elif CONFIG_IDF_TARGET_ESP32S2 #elif CONFIG_IDF_TARGET_ESP32S2
// not valid: // not valid:
// 6-11 are used for SPI flash and PSRAM // 6-11 are used for SPI flash and PSRAM
@@ -2911,19 +2912,19 @@ void System::set_valid_system_gpios() {
// not valid: // not valid:
// 6-11 are used for SPI flash and PSRAM // 6-11 are used for SPI flash and PSRAM
// 16-17 are also used for SPI flash and PSRAM // 16-17 are also used for SPI flash and PSRAM
// 26-32 are used for SPI flash and PSRAM // 26-31 are used for SPI flash and PSRAM
// 33-37 also used for SPI flash and PSRAM, on Octal SPI PSRAM (ESP32-S3R8, ESP32-S3R8V, ESP32-S3R16V) // 19-20 are used for JTAG-USB
// 9-10 are used for SPI flash and PSRAM
// 19-20 used for JTAG-USB
// 45-46 are strapping pins // 45-46 are strapping pins
// 1 and 3 are UART0 pins, but used for some eth-boards (BBQKees-E32, OlimexPOE) // 1 & 3 are UART0 pins, but used for some eth-boards (BBQKees-E32, OlimexPOE)
// 42 transitions low on reset, slower than other GPIOs which can cause issues in time-sensitive applications // 42 transitions low on reset, slower than other GPIOs which can cause issues in time-sensitive applications
// notes: // notes:
// 32 is reserved for LED on E32V2_2 boards
// 34-39 are input only (ADC1), and can be used // 34-39 are input only (ADC1), and can be used
// 25 and 26 are DAC (Digital-to-Analog Converter) pins, and can be used // 25-26 are DAC (Digital-to-Analog Converter) pins, and can be used
// 36 & 39 are reserved for the internal supply_voltage and core_voltage
if (ESP.getPsramSize() > 0) { if (ESP.getPsramSize() > 0) {
// if psram is enabled remove pins 16 and 17 from the list // if psram is enabled remove pins 16 and 17 from the list
valid_system_gpios_ = string_range_to_vector("0-39", "6-11, 16-17, 26-32, 33-37, 9-10, 19-20, 45-46, 1, 3, 42"); valid_system_gpios_ = string_range_to_vector("0-39", "6-11, 16-17, 26-31, 19-20, 45-46, 1, 3, 42");
} else { } else {
valid_system_gpios_ = string_range_to_vector("0-39", "19-20, 45-46, 1, 3, 42"); valid_system_gpios_ = string_range_to_vector("0-39", "19-20, 45-46, 1, 3, 42");
} }
@@ -2938,9 +2939,9 @@ bool System::add_gpio(uint8_t pin, const char * source_name) {
// check if this is a valid user GPIO // check if this is a valid user GPIO
if (std::find(valid_system_gpios_.begin(), valid_system_gpios_.end(), pin) != valid_system_gpios_.end()) { if (std::find(valid_system_gpios_.begin(), valid_system_gpios_.end(), pin) != valid_system_gpios_.end()) {
// It's valid now check if it's already in the used list // It's valid now check if it's already in the used list
auto it = std::find_if(used_gpios_.begin(), used_gpios_.end(), [pin, source_name](const GpioInfo & gpio_info) { return gpio_info.pin == pin && gpio_info.name != source_name; }); auto it = std::find_if(used_gpios_.begin(), used_gpios_.end(), [pin](const GpioUsage & usage) { return usage.pin == pin; });
if (it != used_gpios_.end()) { if (it != used_gpios_.end()) {
LOG_WARNING("Can't add GPIO %d for %s, already in use by %s", pin, source_name, it->name.c_str()); LOG_WARNING("GPIO %d for %s is already in use by %s", pin, source_name, it->source.c_str());
return false; // Pin is already used return false; // Pin is already used
} }
} else { } else {
@@ -2953,14 +2954,14 @@ bool System::add_gpio(uint8_t pin, const char * source_name) {
remove_gpio(pin); remove_gpio(pin);
LOG_DEBUG("Adding GPIO %d for %s to used gpio list", pin, source_name); LOG_DEBUG("Adding GPIO %d for %s to used gpio list", pin, source_name);
used_gpios_.push_back({pin, source_name}); // add to used list with name used_gpios_.push_back({pin, source_name}); // add to used list
return true; return true;
} }
// remove a gpio from both valid and used lists // remove a gpio from both valid and used lists
void System::remove_gpio(uint8_t pin, bool also_system) { void System::remove_gpio(uint8_t pin, bool also_system) {
auto it = std::find_if(used_gpios_.begin(), used_gpios_.end(), [pin](const GpioInfo & gpio_info) { return gpio_info.pin == pin; }); auto it = std::find_if(used_gpios_.begin(), used_gpios_.end(), [pin](const GpioUsage & usage) { return usage.pin == pin; });
if (it != used_gpios_.end()) { if (it != used_gpios_.end()) {
LOG_DEBUG("GPIO %d removed from used gpio list", pin); LOG_DEBUG("GPIO %d removed from used gpio list", pin);
used_gpios_.erase(it); used_gpios_.erase(it);
@@ -2979,8 +2980,7 @@ void System::remove_gpio(uint8_t pin, bool also_system) {
std::vector<uint8_t> System::available_gpios() { std::vector<uint8_t> System::available_gpios() {
std::vector<uint8_t> gpios; std::vector<uint8_t> gpios;
for (const auto & gpio : valid_system_gpios_) { for (const auto & gpio : valid_system_gpios_) {
auto it = std::find_if(used_gpios_.begin(), used_gpios_.end(), [gpio](const GpioInfo & gpio_info) { return gpio_info.pin == gpio; }); if (std::find_if(used_gpios_.begin(), used_gpios_.end(), [gpio](const GpioUsage & usage) { return usage.pin == gpio; }) == used_gpios_.end()) {
if (it == used_gpios_.end()) {
gpios.push_back(gpio); // didn't find it in used_gpios_, so it's available gpios.push_back(gpio); // didn't find it in used_gpios_, so it's available
} }
} }
@@ -2989,8 +2989,8 @@ std::vector<uint8_t> System::available_gpios() {
// make a snapshot of the current GPIOs // make a snapshot of the current GPIOs
void System::make_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios) { void System::make_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios) {
for (const auto & gpio_info : used_gpios_) { for (const auto & usage : used_gpios_) {
u_gpios.push_back(gpio_info.pin); u_gpios.push_back(usage.pin);
} }
for (const auto & gpio : valid_system_gpios_) { for (const auto & gpio : valid_system_gpios_) {
s_gpios.push_back(gpio); s_gpios.push_back(gpio);

View File

@@ -442,8 +442,12 @@ class System {
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range, const std::string & exclude = ""); static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range, const std::string & exclude = "");
// GPIOs // GPIOs
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used struct GpioUsage {
static std::vector<GpioInfo, AllocatorPSRAM<GpioInfo>> used_gpios_; // list of GPIOs used by the application with their names uint8_t pin;
std::string source;
};
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used
static std::vector<GpioUsage, AllocatorPSRAM<GpioUsage>> used_gpios_; // list of GPIOs used by the application
int8_t wifi_quality(int8_t dBm); int8_t wifi_quality(int8_t dBm);

View File

@@ -97,7 +97,7 @@ void WebLogService::show(Shell & shell) {
} }
shell.println(); shell.println();
shell.printfln("Recent Log (level %s, max %d messages):", uuid::log::format_level_uppercase(level_), maximum_log_messages_); shell.printfln("Recent Log:");
shell.println(); shell.println();
for (const auto & message : log_messages_) { for (const auto & message : log_messages_) {

View File

@@ -116,7 +116,8 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
// see if the user has changed the board profile // see if the user has changed the board profile
// this will set: led_gpio, dallas_gpio, rx_gpio, tx_gpio, pbutton_gpio, phy_type, eth_power, eth_phy_addr, eth_clock_mode, led_type // this will set: led_gpio, dallas_gpio, rx_gpio, tx_gpio, pbutton_gpio, phy_type, eth_power, eth_phy_addr, eth_clock_mode, led_type
// this will always run when EMS-ESP starts since original_settings{} is empty // this will always run when EMS-ESP starts since original_settings{} is empty
if (original_settings.board_profile != settings.board_profile) { if (original_settings.board_profile != settings.board_profile || original_settings.board_profile == "default"
|| original_settings.board_profile.length() == 0) {
set_board_profile(settings); set_board_profile(settings);
add_flags(ChangeFlags::RESTART); add_flags(ChangeFlags::RESTART);
} }