ESPHome 2026.8.0-dev
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
8static const char *const TAG = "deep_sleep.bk72xx";
9
10#ifdef USE_DEEP_SLEEP_ON_WAKE
12 switch (lt_get_reboot_reason()) {
13 case REBOOT_REASON_SLEEP_GPIO:
14 return WAKEUP_CAUSE_GPIO;
15 case REBOOT_REASON_SLEEP_RTC:
16 return WAKEUP_CAUSE_TIMER;
17 case REBOOT_REASON_SLEEP_USB:
19 default:
20 return WAKEUP_CAUSE_NONE;
21 }
22}
23#endif // USE_DEEP_SLEEP_ON_WAKE
24
25optional<uint32_t> DeepSleepComponent::get_run_duration_() const { return this->run_duration_; }
26
28 for (const WakeUpPinItem &item : this->wakeup_pins_) {
29 LOG_PIN(" Wakeup Pin: ", item.wakeup_pin);
30 }
31}
32
34 return (pin_item.wakeup_pin_mode == WAKEUP_PIN_MODE_KEEP_AWAKE && pin_item.wakeup_pin != nullptr &&
35 !this->sleep_duration_.has_value() && (pin_item.wakeup_level == get_real_pin_state_(*pin_item.wakeup_pin)));
36}
37
39 if (!this->wakeup_pins_.empty()) {
40 for (WakeUpPinItem &item : this->wakeup_pins_) {
41 if (this->pin_prevents_sleep_(item)) {
42 // Defer deep sleep until inactive
43 if (!this->next_enter_deep_sleep_) {
44 this->status_set_warning();
45 ESP_LOGV(TAG, "Waiting for pin to switch state to enter deep sleep...");
46 }
47 this->next_enter_deep_sleep_ = true;
48 return false;
49 }
50 }
51 }
52 return true;
53}
54
56 for (WakeUpPinItem &item : this->wakeup_pins_) {
57 if (item.wakeup_pin_mode == WAKEUP_PIN_MODE_INVERT_WAKEUP) {
58 if (item.wakeup_level == get_real_pin_state_(*item.wakeup_pin)) {
59 item.wakeup_level = !item.wakeup_level;
60 }
61 }
62 ESP_LOGI(TAG, "Wake-up on P%u %s (%" PRId32 ")", item.wakeup_pin->get_pin(), item.wakeup_level ? "HIGH" : "LOW",
63 static_cast<int32_t>(item.wakeup_pin_mode));
64 }
65
66 if (this->sleep_duration_.has_value())
67 lt_deep_sleep_config_timer((*this->sleep_duration_ / 1000) & 0xFFFFFFFF);
68
69 for (WakeUpPinItem &item : this->wakeup_pins_) {
70 lt_deep_sleep_config_gpio(1 << item.wakeup_pin->get_pin(), item.wakeup_level);
71 lt_deep_sleep_keep_floating_gpio(1 << item.wakeup_pin->get_pin(), true);
72 }
73
74 lt_deep_sleep_enter();
75}
76
78
79} // namespace esphome::deep_sleep
80
81#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.
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).