ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
deep_sleep_bk72xx.cpp
Go to the documentation of this file.
1#ifdef USE_BK72XX
2
4#include "esphome/core/log.h"
5
7
8ESPHOME_LOG_TAG(TAG, "deep_sleep");
9
11 switch (lt_get_reboot_reason()) {
12 case REBOOT_REASON_SLEEP_GPIO:
13 return WAKEUP_CAUSE_GPIO;
14 case REBOOT_REASON_SLEEP_RTC:
15 return WAKEUP_CAUSE_TIMER;
16 case REBOOT_REASON_SLEEP_USB:
18 default:
19 return WAKEUP_CAUSE_NONE;
20 }
21}
22
23optional<uint32_t> DeepSleepComponent::get_run_duration_() const { return this->run_duration_; }
24
26 for (const WakeUpPinItem &item : this->wakeup_pins_) {
27 LOG_PIN(" Wakeup Pin: ", item.wakeup_pin);
28 }
29}
30
32 return (pin_item.wakeup_pin_mode == WAKEUP_PIN_MODE_KEEP_AWAKE && pin_item.wakeup_pin != nullptr &&
33 !this->sleep_duration_.has_value() && (pin_item.wakeup_level == get_real_pin_state_(*pin_item.wakeup_pin)));
34}
35
37 if (!this->wakeup_pins_.empty()) {
38 for (WakeUpPinItem &item : this->wakeup_pins_) {
39 if (this->pin_prevents_sleep_(item)) {
40 // Defer deep sleep until inactive
41 if (!this->next_enter_deep_sleep_) {
42 this->status_set_warning();
43 ESP_LOGV(TAG, "Waiting for pin to switch state to enter deep sleep...");
44 }
45 this->defer_sleep_();
46 return false;
47 }
48 }
49 }
50 return true;
51}
52
54 for (WakeUpPinItem &item : this->wakeup_pins_) {
55 if (item.wakeup_pin_mode == WAKEUP_PIN_MODE_INVERT_WAKEUP) {
56 if (item.wakeup_level == get_real_pin_state_(*item.wakeup_pin)) {
57 item.wakeup_level = !item.wakeup_level;
58 }
59 }
60 ESP_LOGI(TAG, "Wake-up on P%u %s (%" PRId32 ")", item.wakeup_pin->get_pin(), item.wakeup_level ? "HIGH" : "LOW",
61 static_cast<int32_t>(item.wakeup_pin_mode));
62 }
63
64 if (this->sleep_duration_.has_value())
65 lt_deep_sleep_config_timer((*this->sleep_duration_ / 1000) & 0xFFFFFFFF);
66
67 for (WakeUpPinItem &item : this->wakeup_pins_) {
68 lt_deep_sleep_config_gpio(1 << item.wakeup_pin->get_pin(), item.wakeup_level);
69 lt_deep_sleep_keep_floating_gpio(1 << item.wakeup_pin->get_pin(), true);
70 }
71
72 lt_deep_sleep_enter();
73}
74
76
77} // namespace esphome::deep_sleep
78
79#endif // USE_BK72XX
bool pin_prevents_sleep_(WakeUpPinItem &pin_item) const
optional< uint32_t > get_run_duration_() const
bool get_real_pin_state_(InternalGPIOPin &pin) const
@ WAKEUP_PIN_MODE_KEEP_AWAKE
As long as the wakeup pin is still in the wakeup state, keep awake.
@ WAKEUP_PIN_MODE_INVERT_WAKEUP
Automatically invert the wakeup level.
ESPHOME_LOG_TAG(TAG, "deep_sleep")
WakeupCause get_wakeup_cause()
Return why the device woke from deep sleep. Implemented per platform.
WakeupCause
Why the device woke from deep sleep. Passed to on_wake automations.
@ WAKEUP_CAUSE_GPIO
The device was woken by a GPIO pin (wakeup_pin or esp32_ext1_wakeup).
@ WAKEUP_CAUSE_TIMER
The device was woken by the sleep timer.
@ WAKEUP_CAUSE_UNKNOWN
The device woke from deep sleep, but the source could not be identified.
@ WAKEUP_CAUSE_NONE
The device did not wake from deep sleep (for example a cold boot, reset or OTA restart).