esp_sleep.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include "esp_err.h"
  9. #include "hal/touch_sensor_types.h"
  10. #include "hal/gpio_types.h"
  11. #include "soc/soc_caps.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /*
  16. Definitions for the deepsleep prepare callbacks
  17. */
  18. typedef void (*esp_deep_sleep_cb_t)(void);
  19. /**
  20. * @brief Logic function used for EXT1 wakeup mode.
  21. */
  22. typedef enum {
  23. ESP_EXT1_WAKEUP_ALL_LOW = 0, //!< Wake the chip when all selected GPIOs go low
  24. ESP_EXT1_WAKEUP_ANY_HIGH = 1 //!< Wake the chip when any of the selected GPIOs go high
  25. } esp_sleep_ext1_wakeup_mode_t;
  26. #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
  27. typedef enum {
  28. ESP_GPIO_WAKEUP_GPIO_LOW = 0,
  29. ESP_GPIO_WAKEUP_GPIO_HIGH = 1
  30. } esp_deepsleep_gpio_wake_up_mode_t;
  31. #endif
  32. /**
  33. * @brief Power domains which can be powered down in sleep mode
  34. */
  35. typedef enum {
  36. #if SOC_PM_SUPPORT_RTC_PERIPH_PD
  37. ESP_PD_DOMAIN_RTC_PERIPH, //!< RTC IO, sensors and ULP co-processor
  38. #endif
  39. #if SOC_PM_SUPPORT_RTC_SLOW_MEM_PD
  40. ESP_PD_DOMAIN_RTC_SLOW_MEM, //!< RTC slow memory
  41. #endif
  42. #if SOC_PM_SUPPORT_RTC_FAST_MEM_PD
  43. ESP_PD_DOMAIN_RTC_FAST_MEM, //!< RTC fast memory
  44. #endif
  45. ESP_PD_DOMAIN_XTAL, //!< XTAL oscillator
  46. #if SOC_PM_SUPPORT_XTAL32K_PD
  47. ESP_PD_DOMAIN_XTAL32K, //!< External 32 kHz XTAL oscillator
  48. #endif
  49. #if SOC_PM_SUPPORT_RC32K_PD
  50. ESP_PD_DOMAIN_RC32K, //!< Internal 32 kHz RC oscillator
  51. #endif
  52. #if SOC_PM_SUPPORT_RC_FAST_PD
  53. ESP_PD_DOMAIN_RC_FAST, //!< Internal Fast oscillator
  54. #endif
  55. #if SOC_PM_SUPPORT_CPU_PD
  56. ESP_PD_DOMAIN_CPU, //!< CPU core
  57. #endif
  58. #if SOC_PM_SUPPORT_VDDSDIO_PD
  59. ESP_PD_DOMAIN_VDDSDIO, //!< VDD_SDIO
  60. #endif
  61. #if SOC_PM_SUPPORT_MODEM_PD
  62. ESP_PD_DOMAIN_MODEM, //!< MODEM, includes WiFi, Bluetooth and IEEE802.15.4
  63. #endif
  64. #if SOC_PM_SUPPORT_TOP_PD
  65. ESP_PD_DOMAIN_TOP, //!< SoC TOP
  66. #endif
  67. ESP_PD_DOMAIN_MAX //!< Number of domains
  68. } esp_sleep_pd_domain_t;
  69. #define ESP_PD_DOMAIN_RTC8M _Pragma("GCC warning \"'ESP_PD_DOMAIN_RTC8M' enum is deprecated\"") ESP_PD_DOMAIN_RC_FAST
  70. /**
  71. * @brief Power down options
  72. */
  73. typedef enum {
  74. ESP_PD_OPTION_OFF, //!< Power down the power domain in sleep mode
  75. ESP_PD_OPTION_ON, //!< Keep power domain enabled during sleep mode
  76. ESP_PD_OPTION_AUTO //!< Keep power domain enabled in sleep mode, if it is needed by one of the wakeup options. Otherwise power it down.
  77. } esp_sleep_pd_option_t;
  78. /**
  79. * @brief Sleep wakeup cause
  80. */
  81. typedef enum {
  82. ESP_SLEEP_WAKEUP_UNDEFINED, //!< In case of deep sleep, reset was not caused by exit from deep sleep
  83. ESP_SLEEP_WAKEUP_ALL, //!< Not a wakeup cause, used to disable all wakeup sources with esp_sleep_disable_wakeup_source
  84. ESP_SLEEP_WAKEUP_EXT0, //!< Wakeup caused by external signal using RTC_IO
  85. ESP_SLEEP_WAKEUP_EXT1, //!< Wakeup caused by external signal using RTC_CNTL
  86. ESP_SLEEP_WAKEUP_TIMER, //!< Wakeup caused by timer
  87. ESP_SLEEP_WAKEUP_TOUCHPAD, //!< Wakeup caused by touchpad
  88. ESP_SLEEP_WAKEUP_ULP, //!< Wakeup caused by ULP program
  89. ESP_SLEEP_WAKEUP_GPIO, //!< Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)
  90. ESP_SLEEP_WAKEUP_UART, //!< Wakeup caused by UART (light sleep only)
  91. ESP_SLEEP_WAKEUP_WIFI, //!< Wakeup caused by WIFI (light sleep only)
  92. ESP_SLEEP_WAKEUP_COCPU, //!< Wakeup caused by COCPU int
  93. ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG, //!< Wakeup caused by COCPU crash
  94. ESP_SLEEP_WAKEUP_BT, //!< Wakeup caused by BT (light sleep only)
  95. } esp_sleep_source_t;
  96. /**
  97. * @brief Sleep mode
  98. */
  99. typedef enum {
  100. ESP_SLEEP_MODE_LIGHT_SLEEP, //!< light sleep mode
  101. ESP_SLEEP_MODE_DEEP_SLEEP //!< deep sleep mode
  102. } esp_sleep_mode_t;
  103. /* Leave this type define for compatibility */
  104. typedef esp_sleep_source_t esp_sleep_wakeup_cause_t;
  105. enum {
  106. ESP_ERR_SLEEP_REJECT = ESP_ERR_INVALID_STATE,
  107. ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION = ESP_ERR_INVALID_ARG,
  108. };
  109. /**
  110. * @brief Disable wakeup source
  111. *
  112. * This function is used to deactivate wake up trigger for source
  113. * defined as parameter of the function.
  114. *
  115. * @note This function does not modify wake up configuration in RTC.
  116. * It will be performed in esp_deep_sleep_start/esp_light_sleep_start function.
  117. *
  118. * See docs/sleep-modes.rst for details.
  119. *
  120. * @param source - number of source to disable of type esp_sleep_source_t
  121. * @return
  122. * - ESP_OK on success
  123. * - ESP_ERR_INVALID_STATE if trigger was not active
  124. */
  125. esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source);
  126. #if SOC_ULP_SUPPORTED
  127. /**
  128. * @brief Enable wakeup by ULP coprocessor
  129. * @note On ESP32, ULP wakeup source cannot be used when RTC_PERIPH power domain is forced,
  130. * to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup source is used.
  131. * @return
  132. * - ESP_OK on success
  133. * - ESP_ERR_NOT_SUPPORTED if additional current by touch (CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT) is enabled.
  134. * - ESP_ERR_INVALID_STATE if ULP co-processor is not enabled or if wakeup triggers conflict
  135. */
  136. esp_err_t esp_sleep_enable_ulp_wakeup(void);
  137. #endif // SOC_ULP_SUPPORTED
  138. /**
  139. * @brief Enable wakeup by timer
  140. * @param time_in_us time before wakeup, in microseconds
  141. * @return
  142. * - ESP_OK on success
  143. * - ESP_ERR_INVALID_ARG if value is out of range (TBD)
  144. */
  145. esp_err_t esp_sleep_enable_timer_wakeup(uint64_t time_in_us);
  146. #if SOC_TOUCH_SENSOR_SUPPORTED
  147. /**
  148. * @brief Enable wakeup by touch sensor
  149. *
  150. * @note On ESP32, touch wakeup source can not be used when RTC_PERIPH power domain is forced
  151. * to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup source is used.
  152. *
  153. * @note The FSM mode of the touch button should be configured
  154. * as the timer trigger mode.
  155. *
  156. * @return
  157. * - ESP_OK on success
  158. * - ESP_ERR_NOT_SUPPORTED if additional current by touch (CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT) is enabled.
  159. * - ESP_ERR_INVALID_STATE if wakeup triggers conflict
  160. */
  161. esp_err_t esp_sleep_enable_touchpad_wakeup(void);
  162. /**
  163. * @brief Get the touch pad which caused wakeup
  164. *
  165. * If wakeup was caused by another source, this function will return TOUCH_PAD_MAX;
  166. *
  167. * @return touch pad which caused wakeup
  168. */
  169. touch_pad_t esp_sleep_get_touchpad_wakeup_status(void);
  170. #endif // SOC_TOUCH_SENSOR_SUPPORTED
  171. /**
  172. * @brief Returns true if a GPIO number is valid for use as wakeup source.
  173. *
  174. * @note For SoCs with RTC IO capability, this can be any valid RTC IO input pin.
  175. *
  176. * @param gpio_num Number of the GPIO to test for wakeup source capability
  177. *
  178. * @return True if this GPIO number will be accepted as a sleep wakeup source.
  179. */
  180. bool esp_sleep_is_valid_wakeup_gpio(gpio_num_t gpio_num);
  181. #if SOC_PM_SUPPORT_EXT0_WAKEUP
  182. /**
  183. * @brief Enable wakeup using a pin
  184. *
  185. * This function uses external wakeup feature of RTC_IO peripheral.
  186. * It will work only if RTC peripherals are kept on during sleep.
  187. *
  188. * This feature can monitor any pin which is an RTC IO. Once the pin transitions
  189. * into the state given by level argument, the chip will be woken up.
  190. *
  191. * @note This function does not modify pin configuration. The pin is
  192. * configured in esp_deep_sleep_start/esp_light_sleep_start,
  193. * immediately before entering sleep mode.
  194. *
  195. * @note ESP32: ext0 wakeup source can not be used together with touch or ULP wakeup sources.
  196. *
  197. * @param gpio_num GPIO number used as wakeup source. Only GPIOs with the RTC
  198. * functionality can be used. For different SoCs, the related GPIOs are:
  199. * - ESP32: 0, 2, 4, 12-15, 25-27, 32-39;
  200. * - ESP32-S2: 0-21;
  201. * - ESP32-S3: 0-21.
  202. * @param level input level which will trigger wakeup (0=low, 1=high)
  203. * @return
  204. * - ESP_OK on success
  205. * - ESP_ERR_INVALID_ARG if the selected GPIO is not an RTC GPIO,
  206. * or the mode is invalid
  207. * - ESP_ERR_INVALID_STATE if wakeup triggers conflict
  208. */
  209. esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level);
  210. #endif // SOC_PM_SUPPORT_EXT0_WAKEUP
  211. #if SOC_PM_SUPPORT_EXT1_WAKEUP
  212. /**
  213. * @brief Enable wakeup using multiple pins
  214. *
  215. * This function uses external wakeup feature of RTC controller.
  216. * It will work even if RTC peripherals are shut down during sleep.
  217. *
  218. * This feature can monitor any number of pins which are in RTC IOs.
  219. * Once any of the selected pins goes into the state given by mode argument,
  220. * the chip will be woken up.
  221. *
  222. * @note This function does not modify pin configuration. The pins are
  223. * configured in esp_deep_sleep_start/esp_light_sleep_start,
  224. * immediately before entering sleep mode.
  225. *
  226. * @note Internal pullups and pulldowns don't work when RTC peripherals are
  227. * shut down. In this case, external resistors need to be added.
  228. * Alternatively, RTC peripherals (and pullups/pulldowns) may be
  229. * kept enabled using esp_sleep_pd_config function.
  230. *
  231. * @param mask bit mask of GPIO numbers which will cause wakeup. Only GPIOs
  232. * which have RTC functionality can be used in this bit map.
  233. * For different SoCs, the related GPIOs are:
  234. * - ESP32: 0, 2, 4, 12-15, 25-27, 32-39;
  235. * - ESP32-S2: 0-21;
  236. * - ESP32-S3: 0-21.
  237. * - ESP32-C6: 0-7.
  238. * @param mode select logic function used to determine wakeup condition:
  239. * - ESP_EXT1_WAKEUP_ALL_LOW: wake up when all selected GPIOs are low
  240. * - ESP_EXT1_WAKEUP_ANY_HIGH: wake up when any of the selected GPIOs is high
  241. * @return
  242. * - ESP_OK on success
  243. * - ESP_ERR_INVALID_ARG if any of the selected GPIOs is not an RTC GPIO,
  244. * or mode is invalid
  245. */
  246. esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t mask, esp_sleep_ext1_wakeup_mode_t mode);
  247. #endif // SOC_PM_SUPPORT_EXT1_WAKEUP
  248. #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
  249. /**
  250. * @brief Enable wakeup using specific gpio pins
  251. *
  252. * This function enables an IO pin to wake up the chip from deep sleep.
  253. *
  254. * @note This function does not modify pin configuration. The pins are
  255. * configured inside esp_deep_sleep_start, immediately before entering sleep mode.
  256. *
  257. * @note You don't need to care to pull-up or pull-down before using this
  258. * function, because this will be set internally in esp_deep_sleep_start
  259. * based on the wakeup mode. BTW, when you use low level to wake up the
  260. * chip, we strongly recommend you to add external resistors (pull-up).
  261. *
  262. * @param gpio_pin_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs
  263. * which have RTC functionality (pads that powered by VDD3P3_RTC) can be used in this bit map.
  264. * @param mode Select logic function used to determine wakeup condition:
  265. * - ESP_GPIO_WAKEUP_GPIO_LOW: wake up when the gpio turn to low.
  266. * - ESP_GPIO_WAKEUP_GPIO_HIGH: wake up when the gpio turn to high.
  267. * @return
  268. * - ESP_OK on success
  269. * - ESP_ERR_INVALID_ARG if the mask contains any invalid deep sleep wakeup pin or wakeup mode is invalid
  270. */
  271. esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepsleep_gpio_wake_up_mode_t mode);
  272. #endif
  273. /**
  274. * @brief Enable wakeup from light sleep using GPIOs
  275. *
  276. * Each GPIO supports wakeup function, which can be triggered on either low level
  277. * or high level. Unlike EXT0 and EXT1 wakeup sources, this method can be used
  278. * both for all IOs: RTC IOs and digital IOs. It can only be used to wakeup from
  279. * light sleep though.
  280. *
  281. * To enable wakeup, first call gpio_wakeup_enable, specifying gpio number and
  282. * wakeup level, for each GPIO which is used for wakeup.
  283. * Then call this function to enable wakeup feature.
  284. *
  285. * @note On ESP32, GPIO wakeup source can not be used together with touch or ULP wakeup sources.
  286. *
  287. * @return
  288. * - ESP_OK on success
  289. * - ESP_ERR_INVALID_STATE if wakeup triggers conflict
  290. */
  291. esp_err_t esp_sleep_enable_gpio_wakeup(void);
  292. /**
  293. * @brief Enable wakeup from light sleep using UART
  294. *
  295. * Use uart_set_wakeup_threshold function to configure UART wakeup threshold.
  296. *
  297. * Wakeup from light sleep takes some time, so not every character sent
  298. * to the UART can be received by the application.
  299. *
  300. * @note ESP32 does not support wakeup from UART2.
  301. *
  302. * @param uart_num UART port to wake up from
  303. * @return
  304. * - ESP_OK on success
  305. * - ESP_ERR_INVALID_ARG if wakeup from given UART is not supported
  306. */
  307. esp_err_t esp_sleep_enable_uart_wakeup(int uart_num);
  308. /**
  309. * @brief Enable wakeup by bluetooth
  310. * @return
  311. * - ESP_OK on success
  312. * - ESP_ERR_NOT_SUPPORTED if wakeup from bluetooth is not supported
  313. */
  314. esp_err_t esp_sleep_enable_bt_wakeup(void);
  315. /**
  316. * @brief Disable wakeup by bluetooth
  317. * @return
  318. * - ESP_OK on success
  319. * - ESP_ERR_NOT_SUPPORTED if wakeup from bluetooth is not supported
  320. */
  321. esp_err_t esp_sleep_disable_bt_wakeup(void);
  322. /**
  323. * @brief Enable wakeup by WiFi MAC
  324. * @return
  325. * - ESP_OK on success
  326. */
  327. esp_err_t esp_sleep_enable_wifi_wakeup(void);
  328. /**
  329. * @brief Disable wakeup by WiFi MAC
  330. * @return
  331. * - ESP_OK on success
  332. */
  333. esp_err_t esp_sleep_disable_wifi_wakeup(void);
  334. /**
  335. * @brief Enable beacon wakeup by WiFi MAC, it will wake up the system into modem state
  336. * @return
  337. * - ESP_OK on success
  338. */
  339. esp_err_t esp_sleep_enable_wifi_beacon_wakeup(void);
  340. /**
  341. * @brief Disable beacon wakeup by WiFi MAC
  342. * @return
  343. * - ESP_OK on success
  344. */
  345. esp_err_t esp_sleep_disable_wifi_beacon_wakeup(void);
  346. /**
  347. * @brief Get the bit mask of GPIOs which caused wakeup (ext1)
  348. *
  349. * If wakeup was caused by another source, this function will return 0.
  350. *
  351. * @return bit mask, if GPIOn caused wakeup, BIT(n) will be set
  352. */
  353. uint64_t esp_sleep_get_ext1_wakeup_status(void);
  354. #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
  355. /**
  356. * @brief Get the bit mask of GPIOs which caused wakeup (gpio)
  357. *
  358. * If wakeup was caused by another source, this function will return 0.
  359. *
  360. * @return bit mask, if GPIOn caused wakeup, BIT(n) will be set
  361. */
  362. uint64_t esp_sleep_get_gpio_wakeup_status(void);
  363. #endif //SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
  364. /**
  365. * @brief Set power down mode for an RTC power domain in sleep mode
  366. *
  367. * If not set set using this API, all power domains default to ESP_PD_OPTION_AUTO.
  368. *
  369. * @param domain power domain to configure
  370. * @param option power down option (ESP_PD_OPTION_OFF, ESP_PD_OPTION_ON, or ESP_PD_OPTION_AUTO)
  371. * @return
  372. * - ESP_OK on success
  373. * - ESP_ERR_INVALID_ARG if either of the arguments is out of range
  374. */
  375. esp_err_t esp_sleep_pd_config(esp_sleep_pd_domain_t domain,
  376. esp_sleep_pd_option_t option);
  377. /**
  378. * @brief Enter deep sleep with the configured wakeup options
  379. *
  380. * This function does not return.
  381. */
  382. void esp_deep_sleep_start(void) __attribute__((noreturn));
  383. /**
  384. * @brief Enter light sleep with the configured wakeup options
  385. *
  386. * @return
  387. * - ESP_OK on success (returned after wakeup)
  388. * - ESP_ERR_SLEEP_REJECT sleep request is rejected(wakeup source set before the sleep request)
  389. * - ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION after deducting the sleep flow overhead, the final sleep duration
  390. * is too short to cover the minimum sleep duration of the chip, when
  391. * rtc timer wakeup source enabled
  392. */
  393. esp_err_t esp_light_sleep_start(void);
  394. /**
  395. * @brief Enter deep-sleep mode
  396. *
  397. * The device will automatically wake up after the deep-sleep time
  398. * Upon waking up, the device calls deep sleep wake stub, and then proceeds
  399. * to load application.
  400. *
  401. * Call to this function is equivalent to a call to esp_deep_sleep_enable_timer_wakeup
  402. * followed by a call to esp_deep_sleep_start.
  403. *
  404. * esp_deep_sleep does not shut down WiFi, BT, and higher level protocol
  405. * connections gracefully.
  406. * Make sure relevant WiFi and BT stack functions are called to close any
  407. * connections and deinitialize the peripherals. These include:
  408. * - esp_bluedroid_disable
  409. * - esp_bt_controller_disable
  410. * - esp_wifi_stop
  411. *
  412. * This function does not return.
  413. *
  414. * @note The device will wake up immediately if the deep-sleep time is set to 0
  415. *
  416. * @param time_in_us deep-sleep time, unit: microsecond
  417. */
  418. void esp_deep_sleep(uint64_t time_in_us) __attribute__((noreturn));
  419. /**
  420. * @brief Register a callback to be called from the deep sleep prepare
  421. *
  422. * @warning deepsleep callbacks should without parameters, and MUST NOT,
  423. * UNDER ANY CIRCUMSTANCES, CALL A FUNCTION THAT MIGHT BLOCK.
  424. *
  425. * @param new_dslp_cb Callback to be called
  426. *
  427. * @return
  428. * - ESP_OK: Callback registered to the deepsleep misc_modules_sleep_prepare
  429. * - ESP_ERR_NO_MEM: No more hook space for register the callback
  430. */
  431. esp_err_t esp_deep_sleep_register_hook(esp_deep_sleep_cb_t new_dslp_cb);
  432. /**
  433. * @brief Unregister an deepsleep callback
  434. *
  435. * @param old_dslp_cb Callback to be unregistered
  436. */
  437. void esp_deep_sleep_deregister_hook(esp_deep_sleep_cb_t old_dslp_cb);
  438. /**
  439. * @brief Get the wakeup source which caused wakeup from sleep
  440. *
  441. * @return cause of wake up from last sleep (deep sleep or light sleep)
  442. */
  443. esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void);
  444. /**
  445. * @brief Default stub to run on wake from deep sleep.
  446. *
  447. * Allows for executing code immediately on wake from sleep, before
  448. * the software bootloader or ESP-IDF app has started up.
  449. *
  450. * This function is weak-linked, so you can implement your own version
  451. * to run code immediately when the chip wakes from
  452. * sleep.
  453. *
  454. * See docs/deep-sleep-stub.rst for details.
  455. */
  456. void esp_wake_deep_sleep(void);
  457. /**
  458. * @brief Function type for stub to run on wake from sleep.
  459. *
  460. */
  461. typedef void (*esp_deep_sleep_wake_stub_fn_t)(void);
  462. /**
  463. * @brief Install a new stub at runtime to run on wake from deep sleep
  464. *
  465. * If implementing esp_wake_deep_sleep() then it is not necessary to
  466. * call this function.
  467. *
  468. * However, it is possible to call this function to substitute a
  469. * different deep sleep stub. Any function used as a deep sleep stub
  470. * must be marked RTC_IRAM_ATTR, and must obey the same rules given
  471. * for esp_wake_deep_sleep().
  472. */
  473. void esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub);
  474. /**
  475. * @brief Set wake stub entry to default `esp_wake_stub_entry`
  476. */
  477. void esp_set_deep_sleep_wake_stub_default_entry(void);
  478. /**
  479. * @brief Get current wake from deep sleep stub
  480. * @return Return current wake from deep sleep stub, or NULL if
  481. * no stub is installed.
  482. */
  483. esp_deep_sleep_wake_stub_fn_t esp_get_deep_sleep_wake_stub(void);
  484. /**
  485. * @brief The default esp-idf-provided esp_wake_deep_sleep() stub.
  486. *
  487. * See docs/deep-sleep-stub.rst for details.
  488. */
  489. void esp_default_wake_deep_sleep(void);
  490. /**
  491. * @brief Disable logging from the ROM code after deep sleep.
  492. *
  493. * Using LSB of RTC_STORE4.
  494. */
  495. void esp_deep_sleep_disable_rom_logging(void);
  496. #ifdef SOC_PM_SUPPORT_CPU_PD
  497. #if SOC_PM_CPU_RETENTION_BY_RTCCNTL
  498. /**
  499. * @brief CPU Power down low-level initialize, enable CPU power down during light sleep
  500. * @return
  501. * - ESP_OK on success
  502. * - ESP_ERR_NO_MEM not enough retention memory
  503. */
  504. esp_err_t esp_sleep_cpu_pd_low_init(void);
  505. /**
  506. * @brief CPU Power down low-level deinitialize, disable CPU power down during light sleep
  507. * @return
  508. * - ESP_OK on success
  509. * - ESP_ERR_NO_MEM not enough retention memory
  510. */
  511. esp_err_t esp_sleep_cpu_pd_low_deinit(void);
  512. #endif
  513. /**
  514. * @brief CPU Power down initialize
  515. *
  516. * @return
  517. * - ESP_OK on success
  518. * - ESP_ERR_NO_MEM not enough retention memory
  519. */
  520. esp_err_t esp_sleep_cpu_retention_init(void);
  521. /**
  522. * @brief CPU Power down de-initialize
  523. *
  524. * @return
  525. * - ESP_OK on success
  526. *
  527. * Release system retention memory.
  528. */
  529. esp_err_t esp_sleep_cpu_retention_deinit(void);
  530. #endif
  531. /**
  532. * @brief Configure to isolate all GPIO pins in sleep state
  533. */
  534. void esp_sleep_config_gpio_isolate(void);
  535. /**
  536. * @brief Enable or disable GPIO pins status switching between slept status and waked status.
  537. * @param enable decide whether to switch status or not
  538. */
  539. void esp_sleep_enable_gpio_switch(bool enable);
  540. #if CONFIG_MAC_BB_PD
  541. /**
  542. * @brief Function type for stub to run mac bb power down.
  543. */
  544. typedef void (* mac_bb_power_down_cb_t)(void);
  545. /**
  546. * @brief Function type for stub to run mac bb power up.
  547. */
  548. typedef void (* mac_bb_power_up_cb_t)(void);
  549. /**
  550. * @brief Registet mac bb power down callback.
  551. * @param cb mac bb power down callback.
  552. * @return
  553. * - ESP_OK on success
  554. */
  555. esp_err_t esp_register_mac_bb_pd_callback(mac_bb_power_down_cb_t cb);
  556. /**
  557. * @brief Unregistet mac bb power down callback.
  558. * @param cb mac bb power down callback.
  559. * @return
  560. * - ESP_OK on success
  561. */
  562. esp_err_t esp_unregister_mac_bb_pd_callback(mac_bb_power_down_cb_t cb);
  563. /**
  564. * @brief Registet mac bb power up callback.
  565. * @param cb mac bb power up callback.
  566. * @return
  567. * - ESP_OK on success
  568. */
  569. esp_err_t esp_register_mac_bb_pu_callback(mac_bb_power_up_cb_t cb);
  570. /**
  571. * @brief Unregistet mac bb power up callback.
  572. * @param cb mac bb power up callback.
  573. * @return
  574. * - ESP_OK on success
  575. */
  576. esp_err_t esp_unregister_mac_bb_pu_callback(mac_bb_power_up_cb_t cb);
  577. #endif
  578. #ifdef __cplusplus
  579. }
  580. #endif