ESPHome 2026.1.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
11
13 for (const WakeUpPinItem &item : this->wakeup_pins_) {
14 LOG_PIN(" Wakeup Pin: ", item.wakeup_pin);
15 }
16}
17
19 return (pinItem.wakeup_pin_mode == WAKEUP_PIN_MODE_KEEP_AWAKE && pinItem.wakeup_pin != nullptr &&
20 !this->sleep_duration_.has_value() && (pinItem.wakeup_level == get_real_pin_state_(*pinItem.wakeup_pin)));
21}
22
24 if (wakeup_pins_.size() > 0) {
25 for (WakeUpPinItem &item : this->wakeup_pins_) {
26 if (pin_prevents_sleep_(item)) {
27 // Defer deep sleep until inactive
28 if (!this->next_enter_deep_sleep_) {
29 this->status_set_warning();
30 ESP_LOGV(TAG, "Waiting for pin to switch state to enter deep sleep...");
31 }
32 this->next_enter_deep_sleep_ = true;
33 return false;
34 }
35 }
36 }
37 return true;
38}
39
41 for (WakeUpPinItem &item : this->wakeup_pins_) {
42 if (item.wakeup_pin_mode == WAKEUP_PIN_MODE_INVERT_WAKEUP) {
43 if (item.wakeup_level == get_real_pin_state_(*item.wakeup_pin)) {
44 item.wakeup_level = !item.wakeup_level;
45 }
46 }
47 ESP_LOGI(TAG, "Wake-up on P%u %s (%d)", item.wakeup_pin->get_pin(), item.wakeup_level ? "HIGH" : "LOW",
48 static_cast<int32_t>(item.wakeup_pin_mode));
49 }
50
51 if (this->sleep_duration_.has_value())
52 lt_deep_sleep_config_timer((*this->sleep_duration_ / 1000) & 0xFFFFFFFF);
53
54 for (WakeUpPinItem &item : this->wakeup_pins_) {
55 lt_deep_sleep_config_gpio(1 << item.wakeup_pin->get_pin(), item.wakeup_level);
56 lt_deep_sleep_keep_floating_gpio(1 << item.wakeup_pin->get_pin(), true);
57 }
58
59 lt_deep_sleep_enter();
60}
61
62} // namespace esphome::deep_sleep
63
64#endif // USE_BK72XX
void status_set_warning(const char *message=nullptr)
optional< uint32_t > get_run_duration_() const
bool pin_prevents_sleep_(WakeUpPinItem &pinItem) const
bool get_real_pin_state_(InternalGPIOPin &pin) const
bool has_value() const
Definition optional.h:92
@ 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.