use esp_idf_sys::*;
#[doc(alias = "esp_reset_reason_t")]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum ResetReason {
Software,
ExternalPin,
Watchdog,
Sdio,
Panic,
InterruptWatchdog,
PowerOn,
Unknown,
Brownout,
TaskWatchdog,
DeepSleep,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
esp_idf_version_full = "5.1.0",
esp_idf_version_full = "5.1.1",
esp_idf_version_full = "5.1.2",
esp_idf_version_full = "5.1.3",
)))]
USBPeripheral,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
esp_idf_version_full = "5.1.0",
esp_idf_version_full = "5.1.1",
esp_idf_version_full = "5.1.2",
esp_idf_version_full = "5.1.3",
)))]
JTAG,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
esp_idf_version_full = "5.2.0",
esp_idf_version_full = "5.2.1",
)))]
EfuseError,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
esp_idf_version_full = "5.2.0",
esp_idf_version_full = "5.2.1",
)))]
PowerGlitch,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
esp_idf_version_full = "5.2.0",
esp_idf_version_full = "5.2.1",
)))]
CPULockup,
}
impl From<esp_reset_reason_t> for ResetReason {
#[allow(non_upper_case_globals)]
fn from(value: esp_reset_reason_t) -> Self {
match value {
esp_reset_reason_t_ESP_RST_SW => Self::Software,
esp_reset_reason_t_ESP_RST_EXT => Self::ExternalPin,
esp_reset_reason_t_ESP_RST_WDT => Self::Watchdog,
esp_reset_reason_t_ESP_RST_SDIO => Self::Sdio,
esp_reset_reason_t_ESP_RST_PANIC => Self::Panic,
esp_reset_reason_t_ESP_RST_INT_WDT => Self::InterruptWatchdog,
esp_reset_reason_t_ESP_RST_POWERON => Self::PowerOn,
esp_reset_reason_t_ESP_RST_UNKNOWN => Self::Unknown,
esp_reset_reason_t_ESP_RST_BROWNOUT => Self::Brownout,
esp_reset_reason_t_ESP_RST_TASK_WDT => Self::TaskWatchdog,
esp_reset_reason_t_ESP_RST_DEEPSLEEP => Self::DeepSleep,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
esp_idf_version_full = "5.1.0",
esp_idf_version_full = "5.1.1",
esp_idf_version_full = "5.1.2",
esp_idf_version_full = "5.1.3",
)))]
esp_reset_reason_t_ESP_RST_USB => Self::USBPeripheral,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
esp_idf_version_full = "5.1.0",
esp_idf_version_full = "5.1.1",
esp_idf_version_full = "5.1.2",
esp_idf_version_full = "5.1.3",
)))]
esp_reset_reason_t_ESP_RST_JTAG => Self::JTAG,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
esp_idf_version_full = "5.2.0",
esp_idf_version_full = "5.2.1",
)))]
esp_reset_reason_t_ESP_RST_EFUSE => Self::EfuseError,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
esp_idf_version_full = "5.2.0",
esp_idf_version_full = "5.2.1",
)))]
esp_reset_reason_t_ESP_RST_PG => Self::PowerGlitch,
#[cfg(not(any(
esp_idf_version_major = "4",
all(esp_idf_version_major = "5", esp_idf_version_minor = "0"),
all(esp_idf_version_major = "5", esp_idf_version_minor = "1"),
esp_idf_version_full = "5.2.0",
esp_idf_version_full = "5.2.1",
)))]
esp_reset_reason_t_ESP_RST_CPU => Self::CPULockup,
_ => unreachable!(),
}
}
}
impl ResetReason {
#[doc(alias = "esp_reset_reason")]
pub fn get() -> Self {
let rr = unsafe { esp_reset_reason() };
rr.into()
}
}
#[doc(alias = "esp_sleep_source_t")]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum WakeupReason {
Unknown,
ULP,
Button,
Timer,
Other(u32),
}
impl From<esp_sleep_source_t> for WakeupReason {
#[allow(non_upper_case_globals)]
fn from(value: esp_sleep_source_t) -> Self {
match value {
esp_sleep_source_t_ESP_SLEEP_WAKEUP_UNDEFINED => Self::Unknown,
esp_sleep_source_t_ESP_SLEEP_WAKEUP_EXT0 => Self::Button,
esp_sleep_source_t_ESP_SLEEP_WAKEUP_EXT1 => Self::Button,
esp_sleep_source_t_ESP_SLEEP_WAKEUP_ULP => Self::ULP,
esp_sleep_source_t_ESP_SLEEP_WAKEUP_COCPU => Self::ULP,
esp_sleep_source_t_ESP_SLEEP_WAKEUP_TIMER => Self::Timer,
other => Self::Other(other),
}
}
}
impl WakeupReason {
#[doc(alias = "esp_sleep_get_wakeup_cause")]
pub fn get() -> Self {
let wr = unsafe { esp_sleep_get_wakeup_cause() };
wr.into()
}
}
pub fn restart() -> ! {
unsafe { esp_restart() }
}