Skip to content

Commit

Permalink
esp32: Added reset code as string
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrunot committed Aug 12, 2024
1 parent 56df943 commit 1e9f4ca
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
5 changes: 3 additions & 2 deletions include/Espressif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 41 additions & 1 deletion src/Espressif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char, 13> result; // +1 for null termination

Expand Down Expand Up @@ -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";
}
}
}
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1e9f4ca

Please sign in to comment.