1 /*
2  * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 #include <stdbool.h>
9 #include "sdkconfig.h"
10 #include "esp_sleep.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 
17 #if CONFIG_ESP_SLEEP_DEBUG
18 typedef struct {
19     uint32_t lightsleep_cnt;
20     uint64_t sleep_in_rtc_time_stamp;
21     uint64_t sleep_out_rtc_time_stamp;
22     uint32_t wakeup_triggers;
23     uint32_t sleep_flags;
24     esp_err_t sleep_request_result;
25 } esp_sleep_context_t;
26 
27 /**
28  * @brief Set the context pointer of last sleep request
29  * @param sleep_ctx Structure where the context of the sleep information needs to be recorded in
30  */
31 void esp_sleep_set_sleep_context(esp_sleep_context_t *sleep_ctx);
32 #endif
33 
34 /**
35  * @brief Enables the use of ADC and temperature sensor in monitor (ULP) mode
36  *
37  * @note  This state is kept in RTC memory and will keep its value after a deep sleep wakeup
38  *
39  */
40 void esp_sleep_enable_adc_tsens_monitor(bool enable);
41 
42 #if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
43 /**
44  * @brief Isolate all digital IOs except those that are held during deep sleep
45  *
46  * Reduce digital IOs current leakage during deep sleep.
47  */
48 void esp_sleep_isolate_digital_gpio(void);
49 #endif
50 
51 /**
52   * Register a callback to be called from the deep sleep prepare for maintain the PHY state
53   *          CPU is equal to min_freq_mhz (if DFS is enabled) when running this callback,
54   *          and PLL clock is exists)
55   *
56   * @warning deepsleep PHY callbacks should without parameters, and MUST NOT,
57   *          UNDER ANY CIRCUMSTANCES, CALL A FUNCTION THAT MIGHT BLOCK.
58   *
59   * @param new_dslp_cb     Callback to be called to close PHY related modules
60   *
61   * @return
62   *     - ESP_OK:         PHY callback registered to the phy modules deepsleep prepare
63   *     - ESP_ERR_NO_MEM: No more hook space for register the callback
64   */
65 esp_err_t esp_deep_sleep_register_phy_hook(esp_deep_sleep_cb_t new_dslp_cb);
66 
67 /**
68   * @brief Unregister an PHY deepsleep callback
69   *
70   * @param old_dslp_cb     Callback to be unregistered
71   */
72 void esp_deep_sleep_deregister_phy_hook(esp_deep_sleep_cb_t old_dslp_cb);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77