Skip to content

Commit 448d65e

Browse files
committed
better description of deep sleep v4 and v5 differences
1 parent 7295d01 commit 448d65e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/sleep.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,17 @@ impl<'a> DeepSleep<'a> {
361361
Ok(())
362362
}
363363

364+
// In esp idf version 5.x the esp_deep_sleep_start() function CAN return
365+
// if deep sleep was rejected. So in order for this function to return !
366+
// it needs to panic. This cause unreachable code for v4.4 and earlier,
367+
// thus the warning is disabled.
368+
#[allow(unreachable_code)]
364369
pub fn sleep(&self) -> ! {
365-
unsafe { esp_deep_sleep_start() };
366-
367-
// Ensure that funciton never returns for esp idf version 5.x
368-
#[cfg(esp_idf_version_major = "5")]
369-
panic!();
370+
unsafe { esp_deep_sleep_start() }
371+
// Normally not reached, but if it is, then panic will restart the
372+
// chip, which is similar to what would happen with a very short deep
373+
// sleep.
374+
panic!("Failed to deep sleep, will panic instead");
370375
}
371376

372377
pub fn prepare_and_sleep(&self) -> Result<(), EspError> {

0 commit comments

Comments
 (0)