diff --git a/include/Espressif.hpp b/include/Espressif.hpp index be222f58..ef1bcc76 100644 --- a/include/Espressif.hpp +++ b/include/Espressif.hpp @@ -11,9 +11,10 @@ namespace fabomatic::esp32 auto signalWatchdog() -> bool; auto showHeapStats() -> void; auto removeWatchdog() -> void; - [[nodiscard]] auto esp_serial() -> const std::string_view; + [[nodiscard]] auto esp_serial_str() -> const std::string_view; auto getFreeHeap() -> uint32_t; + [[nodiscard]] auto esp_reset_reason_str() -> const std::string_view; [[noreturn]] auto restart() -> void; -} +} // namespace fabomatic::esp32 #endif // ESPRESSIF_HPP \ No newline at end of file diff --git a/src/Espressif.cpp b/src/Espressif.cpp index 3622267a..5ccd039a 100644 --- a/src/Espressif.cpp +++ b/src/Espressif.cpp @@ -64,7 +64,7 @@ namespace fabomatic::esp32 } /// @brief Returns the ESP32 serial number as a string - [[nodiscard]] auto esp_serial() -> const std::string_view + [[nodiscard]] auto esp_serial_str() -> const std::string_view { static std::array result; // +1 for null termination @@ -95,4 +95,44 @@ namespace fabomatic::esp32 esp_restart(); } + auto esp_reset_reason_str() -> const std::string_view + { + switch (esp_reset_reason()) + { + case ESP_RST_UNKNOWN: //!< Reset reason can not be determined + return "Unknown"; + case ESP_RST_POWERON: //!< Reset due to power-on event + return "Power-on reset"; + case ESP_RST_EXT: //!< Reset by external pin (not applicable for ESP32) + return "External pin reset"; + case ESP_RST_SW: //!< Software reset via esp_restart + return "Software reset"; + case ESP_RST_PANIC: //!< Software reset due to exception/panic + return "Panic"; + case ESP_RST_INT_WDT: //!< Reset (software or hardware) due to interrupt watchdog + return "Interrupt watchdog reset"; + case ESP_RST_TASK_WDT: //!< Reset due to task watchdog + return "Task watchdog reset"; + case ESP_RST_WDT: //!< Reset due to other watchdogs + return "Watchdog reset"; + case ESP_RST_DEEPSLEEP: //!< Reset after exiting deep sleep mode + return "Deepsleep exit"; + case ESP_RST_BROWNOUT: //!< Brownout reset (software or hardware) + return "Brownout"; + case ESP_RST_SDIO: //!< Reset over SDIO + return "SDIO reset"; + case ESP_RST_USB: //!< Reset by USB peripheral + return "USB reset"; + case ESP_RST_JTAG: //!< Reset by JTAG + return "JTAG reset"; + case ESP_RST_EFUSE: //!< Reset due to efuse error + return "EFUSE error"; + case ESP_RST_PWR_GLITCH: //!< Reset due to power glitch detected + return "Power glitch"; + case ESP_RST_CPU_LOCKUP: //!< Reset due to CPU lock up + return "CPU lock up"; + default: + return "UNKNOWN"; + } + } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 508d1282..b17fb2db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -222,7 +222,7 @@ namespace fabomatic } // Skip factory reset for this specific board because Factory Reset is soldered under the MCU with the reset pin. - if (const auto &serial = esp32::esp_serial(); serial == "dcda0c419794") + if (const auto &serial = esp32::esp_serial_str(); serial == "dcda0c419794") { pinMode(pins.buttons.factory_defaults_pin, INPUT); // Disable pull-up/pull-downs return; @@ -447,7 +447,7 @@ void setup() hw_init &= logic.initBoard(); [[maybe_unused]] const auto count = fabomatic::SavedConfig::IncrementBootCount(); - ESP_LOGI(TAG, "Boot count: %d, reset reason: %d", count, esp_reset_reason()); + ESP_LOGI(TAG, "Boot count: %d, reset reason: %s", count, fabomatic::esp32::esp_reset_reason_str().data()); logic.changeStatus(Status::Booting);