Commit 504cdd6
committed
Power: make timerSleep fail-closed and report when the device stays awake
timerSleep powered the device off even when the wake-up alarm had not been
armed, and returned void so the caller could not tell.
- The three overloads return bool: if the function returns, sleep was not
entered. Reasons: invalid arguments, an RTC without the needed feature
(PowerHub has no timer, use the date/time overloads), a failed cleanup of
the existing IRQ sources, a failed RTC setup, a failed wake-source
registration, the PC build.
- Everything is validated (including the driver's own limits through
canSetAlarm/hasTimerIRQ) before the existing IRQ sources are touched, so
a bad request changes nothing. A request whose alarm fields are all
wildcards is refused: the alarm API treats that as "clear", which must
not be mistaken for an armed wake-up.
- The old timer and alarm are disabled and cleared (both attempted, then
combined) before the new one is armed; the ESP timer wake-up is set to
the period the RTC actually applied so both sources share the deadline,
and an ESP timer left by an earlier light sleep is dropped before an
RTC-only sleep ("not registered" counts as clean). Without an RTC the
ESP timer wake-up is used as before and its registration must succeed.
- _powerOff / _timerSleep report a cancelled sleep: a failed EXT0 / GPIO /
EXT1 wake registration, a wake pin that cannot be released, a PowerHub
that does not accept the power-off request, a light sleep that cannot be
entered. On cancellation the display is woken up again, a GPIO wake-up
armed here is released (only the RTC pin, the GPIO wake source may carry
the application's pins), and the caller releases the RTC IRQ and the ESP
timer it armed. Without an RTC the RTC IRQ pin is not registered.
- Docs: timerSleep(seconds) owns the ESP timer wake source; the RTC alarm
wakes only boards where its IRQ is wired to a wake route (an external RTC
unit does not wake the board).1 parent 0e61d8e commit 504cdd6
2 files changed
Lines changed: 260 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
250 | 259 | | |
251 | 260 | | |
252 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
253 | 269 | | |
254 | 270 | | |
255 | | - | |
| 271 | + | |
256 | 272 | | |
257 | 273 | | |
258 | 274 | | |
259 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
260 | 283 | | |
261 | 284 | | |
262 | | - | |
| 285 | + | |
263 | 286 | | |
264 | 287 | | |
265 | 288 | | |
| |||
458 | 481 | | |
459 | 482 | | |
460 | 483 | | |
461 | | - | |
462 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
463 | 489 | | |
464 | 490 | | |
465 | 491 | | |
| |||
0 commit comments