From 7469df6c14cd26ce04ffabdbd8bc35b92bca282f Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Thu, 9 Nov 2023 18:20:17 +0800 Subject: [PATCH 01/10] fix(pm/ext1): fix c6 h2 lp_aon_ll_ext1_set_wakeup_pins func --- components/hal/esp32c6/include/hal/lp_aon_ll.h | 13 +++---------- components/hal/esp32h2/include/hal/lp_aon_ll.h | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/components/hal/esp32c6/include/hal/lp_aon_ll.h b/components/hal/esp32c6/include/hal/lp_aon_ll.h index ef77b7561d..93dc73a9f7 100644 --- a/components/hal/esp32c6/include/hal/lp_aon_ll.h +++ b/components/hal/esp32c6/include/hal/lp_aon_ll.h @@ -47,21 +47,14 @@ static inline void lp_aon_ll_ext1_clear_wakeup_status(void) */ static inline void lp_aon_ll_ext1_set_wakeup_pins(uint32_t io_mask, uint32_t level_mask) { - uint32_t wakeup_sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel); - wakeup_sel_mask |= io_mask; - HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, wakeup_sel_mask); - - uint32_t wakeup_level_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv); - wakeup_level_mask |= io_mask & level_mask; - wakeup_level_mask &= ~(io_mask & ~level_mask); - - HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv, wakeup_level_mask); + HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, io_mask); + HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv, level_mask); } /** * @brief Clear all ext1 wakup-source setting */ -static inline void lp_aon_ll_ext1_clear_wakeup_pins(void) +static inline void lp_aon_ll_ext1_clear_wakeup_pins(void) { HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, 0); } diff --git a/components/hal/esp32h2/include/hal/lp_aon_ll.h b/components/hal/esp32h2/include/hal/lp_aon_ll.h index 38492a1728..53e1f1fa5d 100644 --- a/components/hal/esp32h2/include/hal/lp_aon_ll.h +++ b/components/hal/esp32h2/include/hal/lp_aon_ll.h @@ -47,21 +47,14 @@ static inline void lp_aon_ll_ext1_clear_wakeup_status(void) */ static inline void lp_aon_ll_ext1_set_wakeup_pins(uint32_t io_mask, uint32_t level_mask) { - uint32_t wakeup_sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel); - wakeup_sel_mask |= io_mask; - HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, wakeup_sel_mask); - - uint32_t wakeup_level_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv); - wakeup_level_mask |= io_mask & level_mask; - wakeup_level_mask &= ~(io_mask & ~level_mask); - - HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv, wakeup_level_mask); + HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, io_mask); + HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_lv, level_mask); } /** * @brief Clear all ext1 wakup-source setting */ -static inline void lp_aon_ll_ext1_clear_wakeup_pins(void) +static inline void lp_aon_ll_ext1_clear_wakeup_pins(void) { HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, ext_wakeup_sel, 0); } From cc0e73a11fdd656c36529eac9f7ad6d7711e1cfe Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Thu, 9 Nov 2023 18:20:35 +0800 Subject: [PATCH 02/10] feat(pm/ext1): support esp_sleep_enable_io_ext1_wakeup and esp_sleep_disable_io_ext1_wakeup squash! feat(pm/ext1): support esp_sleep_enable_io_ext1_wakeup and esp_sleep_disable_io_ext1_wakeup --- components/esp_hw_support/include/esp_sleep.h | 78 ++++++++++++++++++- components/esp_hw_support/sleep_modes.c | 65 +++++++++++++++- docs/en/api-reference/system/sleep_modes.rst | 8 +- .../release-5.x/5.3/system.rst | 9 +++ .../api-reference/system/sleep_modes.rst | 8 +- 5 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 docs/en/migration-guides/release-5.x/5.3/system.rst diff --git a/components/esp_hw_support/include/esp_sleep.h b/components/esp_hw_support/include/esp_sleep.h index bb5db22e7d..2b709bdff5 100644 --- a/components/esp_hw_support/include/esp_sleep.h +++ b/components/esp_hw_support/include/esp_sleep.h @@ -267,6 +267,61 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level); * the pins during sleep. HOLD feature will be acted on the pin internally * before the system entering sleep, and this can further reduce power consumption. * + * @note Call this func will reset the previous ext1 configuration. + * + * @note This function will be deprecated in release/v6.0. Please switch to use `esp_sleep_set_ext1_wakeup_io` and `esp_sleep_clear_ext1_wakeup_io` + * + * @param io_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs + * which have RTC functionality can be used in this bit map. + * For different SoCs, the related GPIOs are: + * - ESP32: 0, 2, 4, 12-15, 25-27, 32-39 + * - ESP32-S2: 0-21 + * - ESP32-S3: 0-21 + * - ESP32-C6: 0-7 + * - ESP32-H2: 7-14 + * @param level_mode Select logic function used to determine wakeup condition: + * When target chip is ESP32: + * - ESP_EXT1_WAKEUP_ALL_LOW: wake up when all selected GPIOs are low + * - ESP_EXT1_WAKEUP_ANY_HIGH: wake up when any of the selected GPIOs is high + * When target chip is ESP32-S2, ESP32-S3, ESP32-C6 or ESP32-H2: + * - ESP_EXT1_WAKEUP_ANY_LOW: wake up when any of the selected GPIOs is low + * - ESP_EXT1_WAKEUP_ANY_HIGH: wake up when any of the selected GPIOs is high + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if io_mask is zero,, + * or mode is invalid + */ +esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode); + +/** + * @brief Enable ext1 wakeup pins with IO masks. + * + * This will append selected IOs to the wakeup IOs, it will not reset previously enabled IOs. + * To reset specific previously enabled IOs, call esp_sleep_clear_ext1_wakeup_io with the io_mask. + * To reset all the enabled IOs, call esp_sleep_clear_ext1_wakeup_io(0). + * + * This function uses external wakeup feature of RTC controller. + * It will work even if RTC peripherals are shut down during sleep. + * + * This feature can monitor any number of pins which are in RTC IOs. + * Once selected pins go into the state given by level_mode argument, + * the chip will be woken up. + * + * @note This function does not modify pin configuration. The pins are + * configured in esp_deep_sleep_start/esp_light_sleep_start, + * immediately before entering sleep mode. + * + * @note Internal pullups and pulldowns don't work when RTC peripherals are + * shut down. In this case, external resistors need to be added. + * Alternatively, RTC peripherals (and pullups/pulldowns) may be + * kept enabled using esp_sleep_pd_config function. If we turn off the + * ``RTC_PERIPH`` domain or certain chips lack the ``RTC_PERIPH`` domain, + * we will use the HOLD feature to maintain the pull-up and pull-down on + * the pins during sleep. HOLD feature will be acted on the pin internally + * before the system entering sleep, and this can further reduce power consumption. + * + * @note this func allows to increase the configuration for ext1 without resetting the previous configuration. + * * @param io_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs * which have RTC functionality can be used in this bit map. * For different SoCs, the related GPIOs are: @@ -286,8 +341,28 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level); * - ESP_OK on success * - ESP_ERR_INVALID_ARG if any of the selected GPIOs is not an RTC GPIO, * or mode is invalid + * - ESP_ERR_NOT_ALLOWED when wakeup level will become different between + * ext1 IOs if !SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN */ -esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode); +esp_err_t esp_sleep_set_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode); + +/** + * @brief Disable ext1 wakeup pins with IO masks. This will remove selected IOs from the wakeup IOs. + * @param io_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs + * which have RTC functionality can be used in this bit map. + * If value is zero, this func will remove all previous ext1 configuration. + * For different SoCs, the related GPIOs are: + * - ESP32: 0, 2, 4, 12-15, 25-27, 32-39 + * - ESP32-S2: 0-21 + * - ESP32-S3: 0-21 + * - ESP32-C6: 0-7 + * - ESP32-H2: 7-14 + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if any of the selected GPIOs is not an RTC GPIO. + */ +esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask); #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN /** @@ -328,6 +403,7 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m * or mode is invalid */ esp_err_t esp_sleep_enable_ext1_wakeup_with_level_mask(uint64_t io_mask, uint64_t level_mask); + #endif // SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN #endif // SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 4d03e5eecb..cb17d945c4 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1476,7 +1476,19 @@ static void ext0_wakeup_prepare(void) #if SOC_PM_SUPPORT_EXT1_WAKEUP esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode) { - if (level_mode > ESP_EXT1_WAKEUP_ANY_HIGH) { + if (io_mask == 0 && level_mode > ESP_EXT1_WAKEUP_ANY_HIGH) { + return ESP_ERR_INVALID_ARG; + } + // Reset all EXT1 configs + esp_sleep_clear_ext1_wakeup_io(0); + + return esp_sleep_set_ext1_wakeup_io(io_mask, level_mode); +} + + +esp_err_t esp_sleep_set_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode) +{ + if (io_mask == 0 && level_mode > ESP_EXT1_WAKEUP_ANY_HIGH) { return ESP_ERR_INVALID_ARG; } // Translate bit map of GPIO numbers into the bit map of RTC IO numbers @@ -1491,16 +1503,61 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m } rtc_gpio_mask |= BIT(rtc_io_number_get(gpio)); } - s_config.ext1_rtc_gpio_mask = rtc_gpio_mask; + +#if !SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN + uint32_t ext1_rtc_gpio_mask = 0; + uint32_t ext1_trigger_mode = 0; + + ext1_rtc_gpio_mask = s_config.ext1_rtc_gpio_mask | rtc_gpio_mask; if (level_mode) { - s_config.ext1_trigger_mode = rtc_gpio_mask; + ext1_trigger_mode = s_config.ext1_trigger_mode | rtc_gpio_mask; } else { - s_config.ext1_trigger_mode = 0; + ext1_trigger_mode = s_config.ext1_trigger_mode & (~rtc_gpio_mask); + } + if (((ext1_rtc_gpio_mask & ext1_trigger_mode) != ext1_rtc_gpio_mask) && + ((ext1_rtc_gpio_mask & ext1_trigger_mode) != 0)) { + return ESP_ERR_NOT_ALLOWED; + } +#endif + + s_config.ext1_rtc_gpio_mask |= rtc_gpio_mask; + if (level_mode) { + s_config.ext1_trigger_mode |= rtc_gpio_mask; + } else { + s_config.ext1_trigger_mode &= (~rtc_gpio_mask); } s_config.wakeup_triggers |= RTC_EXT1_TRIG_EN; return ESP_OK; } +esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask) +{ + if (io_mask == 0) { + s_config.ext1_rtc_gpio_mask = 0; + s_config.ext1_trigger_mode = 0; + } else { + // Translate bit map of GPIO numbers into the bit map of RTC IO numbers + uint32_t rtc_gpio_mask = 0; + for (int gpio = 0; io_mask; ++gpio, io_mask >>= 1) { + if ((io_mask & 1) == 0) { + continue; + } + if (!esp_sleep_is_valid_wakeup_gpio(gpio)) { + ESP_LOGE(TAG, "Not an RTC IO Considering io_mask: GPIO%d", gpio); + return ESP_ERR_INVALID_ARG; + } + rtc_gpio_mask |= BIT(rtc_io_number_get(gpio)); + } + s_config.ext1_rtc_gpio_mask &= (~rtc_gpio_mask); + s_config.ext1_trigger_mode &= (~rtc_gpio_mask); + } + + if (s_config.ext1_rtc_gpio_mask == 0) { + s_config.wakeup_triggers &= (~RTC_EXT1_TRIG_EN); + } + return ESP_OK; +} + #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN esp_err_t esp_sleep_enable_ext1_wakeup_with_level_mask(uint64_t io_mask, uint64_t level_mask) { diff --git a/docs/en/api-reference/system/sleep_modes.rst b/docs/en/api-reference/system/sleep_modes.rst index 112ad7c340..0d82c21baf 100644 --- a/docs/en/api-reference/system/sleep_modes.rst +++ b/docs/en/api-reference/system/sleep_modes.rst @@ -248,11 +248,15 @@ RTC peripherals or RTC memories do not need to be powered on during sleep in thi gpio_pullup_dis(gpio_num); gpio_pulldown_en(gpio_num); - :cpp:func:`esp_sleep_enable_ext1_wakeup` function can be used to enable this wakeup source for general ext1 wakeup. + :cpp:func:`esp_sleep_append_ext1_wakeup` function can be used to append ext1 wakeup IO and set corresponding wakeup level. + + :cpp:func:`esp_sleep_remove_ext1_wakeup` function can be used to remove ext1 wakeup IO. + + :cpp:func:`esp_sleep_enable_ext1_wakeup` function can be used to reset all previous ext1 wakeup configurations and enable new ext1 wakeup IO and set corresponding wakeup level. .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - Besides the above mentioned general ext1 wakeup, the RTC controller also contains a more powerful logic to trigger wakeup using multiple RTC GPIOs with a customized RTC IO wakeup level bitmap. This can be configured with :cpp:func`esp_sleep_enable_ext1_wakeup_with_level_mask`. + The RTC controller also supports triggering wakeup, allowing configurable IO to use different wakeup levels simultaneously. This can be configured with :cpp:func`esp_sleep_append_ext1_wakeup`. .. warning:: diff --git a/docs/en/migration-guides/release-5.x/5.3/system.rst b/docs/en/migration-guides/release-5.x/5.3/system.rst new file mode 100644 index 0000000000..3563c2285f --- /dev/null +++ b/docs/en/migration-guides/release-5.x/5.3/system.rst @@ -0,0 +1,9 @@ +System +====== + +:link_to_translation:`zh_CN:[中文]` + +Power Management +----------------------- + +* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_append_ext1_wakeup`` and ``esp_sleep_remove_ext1_wakeup`` instead. diff --git a/docs/zh_CN/api-reference/system/sleep_modes.rst b/docs/zh_CN/api-reference/system/sleep_modes.rst index 8c3c6055c5..10dcedc9a6 100644 --- a/docs/zh_CN/api-reference/system/sleep_modes.rst +++ b/docs/zh_CN/api-reference/system/sleep_modes.rst @@ -248,11 +248,15 @@ RTC 控制器中内嵌定时器,可用于在预定义的时间到达后唤醒 gpio_pullup_dis(gpio_num); gpio_pulldown_en(gpio_num); - 可调用 :cpp:func:`esp_sleep_enable_ext1_wakeup` 函数来启用普通 ext1 唤醒。 + 可调用 :cpp:func:`esp_sleep_append_ext1_wakeup` 函数可用于增加 ext1 唤醒 IO 并设置相应的唤醒电平。 + + 可调用 :cpp:func:`esp_sleep_remove_ext1_wakeup` 函数可用于移除 ext1 唤醒 IO。 + + 可调用 :cpp:func:`esp_sleep_enable_ext1_wakeup` 函数可用于重置所有先前的 ext1 唤醒配置,并启用新的 ext1 唤醒 IO 并设置相应的唤醒电平。 .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - 除了上述提到的普通 ext1 唤醒之外,当前的 RTC 控制器也包含更强大的逻辑,可以使用多个 RTC GPIO 并根据自定义的 RTC IO 唤醒电平位图来唤醒。这可以通过:cpp:func:`esp_sleep_enable_ext1_wakeup_with_level_mask` 函数来进行配置。 + 当前的 RTC 控制器也包含更强大的逻辑,允许配置的 IO 同时使用不同的唤醒电平。这可以通过:cpp:func:`esp_sleep_append_ext1_wakeup` 函数来进行配置。 .. warning:: From 5b91acb1a1a1fe1ac81643670baaea427475608d Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Thu, 9 Nov 2023 20:34:47 +0800 Subject: [PATCH 03/10] fix(pm/ext1): ext1_wakeup_prepare func when s_config.wakeup_triggers & RTC_EXT1_TRIG_EN == false --- components/esp_hw_support/sleep_modes.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index cb17d945c4..bd1b7d4f61 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -259,6 +259,7 @@ static void ext0_wakeup_prepare(void); #endif #if SOC_PM_SUPPORT_EXT1_WAKEUP static void ext1_wakeup_prepare(void); +static void IRAM_ATTR ext1_wakeup_clear(void); #endif static esp_err_t timer_wakeup_prepare(int64_t sleep_duration); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 @@ -638,6 +639,8 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m #if SOC_PM_SUPPORT_EXT1_WAKEUP if (s_config.wakeup_triggers & RTC_EXT1_TRIG_EN) { ext1_wakeup_prepare(); + } else { + ext1_wakeup_clear(); } #endif @@ -1629,6 +1632,14 @@ static void ext1_wakeup_prepare(void) rtc_hal_ext1_set_wakeup_pins(s_config.ext1_rtc_gpio_mask, s_config.ext1_trigger_mode); } +static void ext1_wakeup_clear(void) +{ + // Clear state from previous wakeup + rtc_hal_ext1_clear_wakeup_status(); + // Clear all ext1 wakup-source setting + rtc_hal_ext1_clear_wakeup_pins(); +} + uint64_t esp_sleep_get_ext1_wakeup_status(void) { if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_EXT1) { From a02f72bb8119642f118e94bcdde437a7a9f3cdab Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Fri, 10 Nov 2023 15:24:05 +0800 Subject: [PATCH 04/10] change(pm/ext1): replace deprecated ext1 func --- components/esp_hw_support/include/esp_sleep.h | 3 ++- components/esp_pm/test_apps/esp_pm/main/test_pm.c | 2 +- .../esp_system_unity_tests/main/test_sleep.c | 12 ++++++------ .../components/cmd_system/cmd_system.c | 2 +- .../deep_sleep/main/esp_ot_sleepy_device.c | 4 ++-- .../components/cmd_system/cmd_system_sleep.c | 2 +- examples/system/deep_sleep/main/ext_wakeup.c | 8 +++----- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/components/esp_hw_support/include/esp_sleep.h b/components/esp_hw_support/include/esp_sleep.h index 2b709bdff5..88d3985809 100644 --- a/components/esp_hw_support/include/esp_sleep.h +++ b/components/esp_hw_support/include/esp_sleep.h @@ -402,7 +402,8 @@ esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask); * - ESP_ERR_INVALID_ARG if any of the selected GPIOs is not an RTC GPIO, * or mode is invalid */ -esp_err_t esp_sleep_enable_ext1_wakeup_with_level_mask(uint64_t io_mask, uint64_t level_mask); +esp_err_t esp_sleep_enable_ext1_wakeup_with_level_mask(uint64_t io_mask, uint64_t level_mask) +__attribute__((deprecated("please use 'esp_sleep_set_ext1_wakeup_io' and 'esp_sleep_clear_ext1_wakeup_io' instead"))); #endif // SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN #endif // SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/components/esp_pm/test_apps/esp_pm/main/test_pm.c b/components/esp_pm/test_apps/esp_pm/main/test_pm.c index 5245c7527a..ac6e51446b 100644 --- a/components/esp_pm/test_apps/esp_pm/main/test_pm.c +++ b/components/esp_pm/test_apps/esp_pm/main/test_pm.c @@ -182,7 +182,7 @@ TEST_CASE("Can wake up from automatic light sleep by GPIO", "[pm][ignore]") rtc_gpio_set_level(ext1_wakeup_gpio, 0); /* Enable wakeup */ - TEST_ESP_OK(esp_sleep_enable_ext1_wakeup(1ULL << ext1_wakeup_gpio, ESP_EXT1_WAKEUP_ANY_HIGH)); + TEST_ESP_OK(esp_sleep_set_ext1_wakeup_io(1ULL << ext1_wakeup_gpio, ESP_EXT1_WAKEUP_ANY_HIGH)); /* To simplify test environment, we'll use a ULP program to set GPIO high */ ulp_insn_t ulp_code[] = { diff --git a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c index 22ec2f21af..325bd1fe0e 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c +++ b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c @@ -416,7 +416,7 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 high)", "[deepsleep][ig { // This test needs external pulldown ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13)); - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); esp_deep_sleep_start(); } @@ -425,9 +425,9 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 low)", "[deepsleep][ign // This test needs external pullup ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13)); #if CONFIG_IDF_TARGET_ESP32 - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); #else - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); #endif esp_deep_sleep_start(); } @@ -438,7 +438,7 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 high)", "[deepsleep][ign ESP_ERROR_CHECK(gpio_pullup_dis(GPIO_NUM_13)); ESP_ERROR_CHECK(gpio_pulldown_en(GPIO_NUM_13)); ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON)); - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); esp_deep_sleep_start(); } @@ -449,9 +449,9 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 low)", "[deepsleep][igno ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_13)); ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON)); #if CONFIG_IDF_TARGET_ESP32 - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); #else - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); #endif esp_deep_sleep_start(); } diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c index 060cd61c31..f3dc53317b 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c @@ -217,7 +217,7 @@ static int deep_sleep(int argc, char **argv) io_num, level ? "HIGH" : "LOW"); #if SOC_PM_SUPPORT_EXT1_WAKEUP - ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup(1ULL << io_num, level) ); + ESP_ERROR_CHECK( esp_sleep_set_ext1_wakeup_io(1ULL << io_num, level) ); #endif } diff --git a/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c b/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c index 4c2e592485..16aaa4eebd 100644 --- a/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c +++ b/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c @@ -150,8 +150,8 @@ static void ot_deep_sleep_init(void) const uint64_t gpio_wakeup_pin_mask = 1ULL << gpio_wakeup_pin; // The configuration mode depends on your hardware design. // Since the BOOT button is connected to a pull-up resistor, the wake-up mode is configured as LOW. - const uint64_t ext_wakeup_mode = 0 << gpio_wakeup_pin; - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_with_level_mask(gpio_wakeup_pin_mask, ext_wakeup_mode)); + const uint64_t ext_wakeup_mode = 0; + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(gpio_wakeup_pin_mask, ext_wakeup_mode)); // Also these two GPIO configurations are also depended on the hardware design. // The BOOT button is connected to the pull-up resistor, so enable the pull-up mode and disable the pull-down mode. diff --git a/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c b/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c index e656e5207e..41a52c6b74 100644 --- a/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c +++ b/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c @@ -82,7 +82,7 @@ static int deep_sleep(int argc, char **argv) ESP_LOGI(TAG, "Enabling wakeup on GPIO%d, wakeup on %s level", io_num, level ? "HIGH" : "LOW"); - ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup(1ULL << io_num, level) ); + ESP_ERROR_CHECK( esp_sleep_set_ext1_wakeup_io(1ULL << io_num, level) ); ESP_LOGE(TAG, "GPIO wakeup from deep sleep currently unsupported on ESP32-C3"); } #endif // SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/examples/system/deep_sleep/main/ext_wakeup.c b/examples/system/deep_sleep/main/ext_wakeup.c index de329b6973..9560fd685f 100644 --- a/examples/system/deep_sleep/main/ext_wakeup.c +++ b/examples/system/deep_sleep/main/ext_wakeup.c @@ -40,12 +40,10 @@ void example_deep_sleep_register_ext1_wakeup(void) printf("Enabling EXT1 wakeup on pins GPIO%d, GPIO%d\n", ext_wakeup_pin_1, ext_wakeup_pin_2); #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - const uint64_t ext_wakeup_mode = CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1 << ext_wakeup_pin_1 | \ - CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_2 << ext_wakeup_pin_2; - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_with_level_mask(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ext_wakeup_mode)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(ext_wakeup_pin_1_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_2)); #else - const esp_sleep_ext1_wakeup_mode_t ext_wakeup_mode = CONFIG_EXAMPLE_EXT1_WAKEUP_MODE; - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ext_wakeup_mode)); + ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE)); #endif /* If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO From aaa1ea8af157a055abd591092d5e8a359728ef51 Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Fri, 10 Nov 2023 15:56:50 +0800 Subject: [PATCH 05/10] docs(pm/ext1): support esp_sleep_enable_io_ext1_wakeup and esp_sleep_disable_io_ext1_wakeup --- docs/en/api-reference/system/sleep_modes.rst | 8 ++++---- docs/en/migration-guides/release-5.x/5.3/index.rst | 1 + docs/en/migration-guides/release-5.x/5.3/system.rst | 2 +- docs/zh_CN/api-reference/system/sleep_modes.rst | 8 ++++---- docs/zh_CN/migration-guides/release-5.x/5.3/index.rst | 1 + docs/zh_CN/migration-guides/release-5.x/5.3/system.rst | 1 + 6 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 docs/zh_CN/migration-guides/release-5.x/5.3/system.rst diff --git a/docs/en/api-reference/system/sleep_modes.rst b/docs/en/api-reference/system/sleep_modes.rst index 0d82c21baf..10dfafcb62 100644 --- a/docs/en/api-reference/system/sleep_modes.rst +++ b/docs/en/api-reference/system/sleep_modes.rst @@ -220,7 +220,7 @@ RTC peripherals or RTC memories do not need to be powered on during sleep in thi External Wakeup (``ext1``) ^^^^^^^^^^^^^^^^^^^^^^^^^^ - The RTC controller contains the logic to trigger wakeup using multiple RTC GPIOs. One of the following two logic functions can be used to trigger general ext1 wakeup: + The RTC controller contains the logic to trigger wakeup using multiple RTC GPIOs. One of the following two logic functions can be used to trigger ext1 wakeup: .. only:: esp32 @@ -248,15 +248,15 @@ RTC peripherals or RTC memories do not need to be powered on during sleep in thi gpio_pullup_dis(gpio_num); gpio_pulldown_en(gpio_num); - :cpp:func:`esp_sleep_append_ext1_wakeup` function can be used to append ext1 wakeup IO and set corresponding wakeup level. + :cpp:func:`esp_sleep_set_ext1_wakeup_io` function can be used to append ext1 wakeup IO and set corresponding wakeup level. - :cpp:func:`esp_sleep_remove_ext1_wakeup` function can be used to remove ext1 wakeup IO. + :cpp:func:`esp_sleep_clear_ext1_wakeup_io` function can be used to remove ext1 wakeup IO. :cpp:func:`esp_sleep_enable_ext1_wakeup` function can be used to reset all previous ext1 wakeup configurations and enable new ext1 wakeup IO and set corresponding wakeup level. .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - The RTC controller also supports triggering wakeup, allowing configurable IO to use different wakeup levels simultaneously. This can be configured with :cpp:func`esp_sleep_append_ext1_wakeup`. + The RTC controller also supports triggering wakeup, allowing configurable IO to use different wakeup levels simultaneously. This can be configured with :cpp:func`esp_sleep_set_ext1_wakeup_io`. .. warning:: diff --git a/docs/en/migration-guides/release-5.x/5.3/index.rst b/docs/en/migration-guides/release-5.x/5.3/index.rst index caccc54187..b4717423b3 100644 --- a/docs/en/migration-guides/release-5.x/5.3/index.rst +++ b/docs/en/migration-guides/release-5.x/5.3/index.rst @@ -7,3 +7,4 @@ Migration from 5.2 to 5.3 :maxdepth: 1 peripherals + system diff --git a/docs/en/migration-guides/release-5.x/5.3/system.rst b/docs/en/migration-guides/release-5.x/5.3/system.rst index 3563c2285f..de3c7ead05 100644 --- a/docs/en/migration-guides/release-5.x/5.3/system.rst +++ b/docs/en/migration-guides/release-5.x/5.3/system.rst @@ -6,4 +6,4 @@ System Power Management ----------------------- -* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_append_ext1_wakeup`` and ``esp_sleep_remove_ext1_wakeup`` instead. +* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_set_ext1_wakeup_io`` and ``esp_sleep_clear_ext1_wakeup_io`` instead. diff --git a/docs/zh_CN/api-reference/system/sleep_modes.rst b/docs/zh_CN/api-reference/system/sleep_modes.rst index 10dcedc9a6..ed02cb5f0b 100644 --- a/docs/zh_CN/api-reference/system/sleep_modes.rst +++ b/docs/zh_CN/api-reference/system/sleep_modes.rst @@ -220,7 +220,7 @@ RTC 控制器中内嵌定时器,可用于在预定义的时间到达后唤醒 外部唤醒 (``ext1``) ^^^^^^^^^^^^^^^^^^^^^^ - RTC 控制器中包含使用多个 RTC GPIO 触发唤醒的逻辑。从以下两个逻辑函数中任选其一,均可触发普通 ext1 唤醒: + RTC 控制器中包含使用多个 RTC GPIO 触发唤醒的逻辑。从以下两个逻辑函数中任选其一,均可触发 ext1 唤醒: .. only:: esp32 @@ -248,15 +248,15 @@ RTC 控制器中内嵌定时器,可用于在预定义的时间到达后唤醒 gpio_pullup_dis(gpio_num); gpio_pulldown_en(gpio_num); - 可调用 :cpp:func:`esp_sleep_append_ext1_wakeup` 函数可用于增加 ext1 唤醒 IO 并设置相应的唤醒电平。 + 可调用 :cpp:func:`esp_sleep_set_ext1_wakeup_io` 函数可用于增加 ext1 唤醒 IO 并设置相应的唤醒电平。 - 可调用 :cpp:func:`esp_sleep_remove_ext1_wakeup` 函数可用于移除 ext1 唤醒 IO。 + 可调用 :cpp:func:`esp_sleep_clear_ext1_wakeup_io` 函数可用于移除 ext1 唤醒 IO。 可调用 :cpp:func:`esp_sleep_enable_ext1_wakeup` 函数可用于重置所有先前的 ext1 唤醒配置,并启用新的 ext1 唤醒 IO 并设置相应的唤醒电平。 .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - 当前的 RTC 控制器也包含更强大的逻辑,允许配置的 IO 同时使用不同的唤醒电平。这可以通过:cpp:func:`esp_sleep_append_ext1_wakeup` 函数来进行配置。 + 当前的 RTC 控制器也包含更强大的逻辑,允许配置的 IO 同时使用不同的唤醒电平。这可以通过:cpp:func:`esp_sleep_set_ext1_wakeup_io` 函数来进行配置。 .. warning:: diff --git a/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst b/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst index 25aeb7dff3..40d26176f4 100644 --- a/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst +++ b/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst @@ -7,3 +7,4 @@ :maxdepth: 1 peripherals + system diff --git a/docs/zh_CN/migration-guides/release-5.x/5.3/system.rst b/docs/zh_CN/migration-guides/release-5.x/5.3/system.rst new file mode 100644 index 0000000000..d984c08a77 --- /dev/null +++ b/docs/zh_CN/migration-guides/release-5.x/5.3/system.rst @@ -0,0 +1 @@ +.. include:: ../../../../en/migration-guides/release-5.x/5.3/system.rst \ No newline at end of file From 7343d16a134e2ea38629a36db1b577586eba4a52 Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Wed, 15 Nov 2023 19:45:38 +0800 Subject: [PATCH 06/10] change(pm): add ESP_PM_LOCK_MAX in esp_pm_lock_type_t and change some description for esp_pm_lock_create --- components/esp_pm/include/esp_pm.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_pm/include/esp_pm.h b/components/esp_pm/include/esp_pm.h index b7f7d045fd..cb6919084b 100644 --- a/components/esp_pm/include/esp_pm.h +++ b/components/esp_pm/include/esp_pm.h @@ -55,6 +55,7 @@ typedef enum { * Argument is unused and should be set to 0. */ ESP_PM_NO_LIGHT_SLEEP, + ESP_PM_LOCK_MAX, } esp_pm_lock_type_t; /** @@ -100,10 +101,13 @@ typedef struct esp_pm_lock* esp_pm_lock_handle_t; * @param[out] out_handle handle returned from this function. Use this handle when calling * esp_pm_lock_delete, esp_pm_lock_acquire, esp_pm_lock_release. * Must not be NULL. + * + * @note If the lock_type argument is not valid, it will cause an abort. + * * @return * - ESP_OK on success * - ESP_ERR_NO_MEM if the lock structure can not be allocated - * - ESP_ERR_INVALID_ARG if out_handle is NULL or type argument is not valid + * - ESP_ERR_INVALID_ARG if out_handle is NULL * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig */ esp_err_t esp_pm_lock_create(esp_pm_lock_type_t lock_type, int arg, From d97f45b3a892b22cc7dbe3d15047636ce572aeb6 Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Fri, 17 Nov 2023 16:53:19 +0800 Subject: [PATCH 07/10] bugfix: ext0_wakeup_prepare func when s_config.wakeup_triggers & RTC_EXT0_TRIG_EN == false --- components/esp_hw_support/sleep_modes.c | 9 +++++++++ components/hal/esp32/include/hal/rtc_io_ll.h | 12 +++++++++++- components/hal/esp32s2/include/hal/rtc_io_ll.h | 11 +++++++++++ components/hal/esp32s3/include/hal/rtc_io_ll.h | 11 +++++++++++ components/hal/include/hal/rtc_io_hal.h | 7 ++++++- 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index bd1b7d4f61..eb057a959a 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -256,6 +256,7 @@ void esp_sleep_periph_use_8m(bool use_or_not) static uint32_t get_power_down_flags(void); #if SOC_PM_SUPPORT_EXT0_WAKEUP static void ext0_wakeup_prepare(void); +static void IRAM_ATTR ext0_wakeup_clear(void); #endif #if SOC_PM_SUPPORT_EXT1_WAKEUP static void ext1_wakeup_prepare(void); @@ -634,6 +635,8 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m // Configure pins for external wakeup if (s_config.wakeup_triggers & RTC_EXT0_TRIG_EN) { ext0_wakeup_prepare(); + } else { + ext0_wakeup_clear(); } #endif #if SOC_PM_SUPPORT_EXT1_WAKEUP @@ -1474,6 +1477,12 @@ static void ext0_wakeup_prepare(void) rtcio_hal_function_select(rtc_gpio_num, RTCIO_LL_FUNC_RTC); rtcio_hal_input_enable(rtc_gpio_num); } + +static void ext0_wakeup_clear(void) +{ + rtcio_hal_ext0_clear_wakeup_pins(); +} + #endif // SOC_PM_SUPPORT_EXT0_WAKEUP #if SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/components/hal/esp32/include/hal/rtc_io_ll.h b/components/hal/esp32/include/hal/rtc_io_ll.h index d92ab124fd..86b340fb77 100644 --- a/components/hal/esp32/include/hal/rtc_io_ll.h +++ b/components/hal/esp32/include/hal/rtc_io_ll.h @@ -360,7 +360,7 @@ static inline void rtcio_ll_disable_sleep_setting(int rtcio_num) } /** - * Set specific logic level on an RTC IO pin as a wakeup trigger. + * Set specific logic level on an RTC IO pin as a ext0 wakeup trigger. * * @param rtcio_num The index of rtcio. 0 ~ MAX(rtcio). * @param level Logic level (0) @@ -373,6 +373,16 @@ static inline void rtcio_ll_ext0_set_wakeup_pin(int rtcio_num, int level) level , RTC_CNTL_EXT_WAKEUP0_LV_S); } +/** + * Clear ext0 wakeup trigger. + */ +static inline void rtcio_ll_ext0_clear_wakeup_pins(void) +{ + REG_SET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL, 0); + // Clear level which will trigger wakeup + SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, + 0 , RTC_CNTL_EXT_WAKEUP0_LV_S); +} #ifdef __cplusplus } #endif diff --git a/components/hal/esp32s2/include/hal/rtc_io_ll.h b/components/hal/esp32s2/include/hal/rtc_io_ll.h index ad05ea95dd..d7033fb636 100644 --- a/components/hal/esp32s2/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s2/include/hal/rtc_io_ll.h @@ -376,6 +376,17 @@ static inline void rtcio_ll_ext0_set_wakeup_pin(int rtcio_num, int level) level , RTC_CNTL_EXT_WAKEUP0_LV_S); } +/** + * Clear ext0 wakeup trigger. + */ +static inline void rtcio_ll_ext0_clear_wakeup_pins(void) +{ + REG_SET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL, 0); + // Clear level which will trigger wakeup + SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, + 0 , RTC_CNTL_EXT_WAKEUP0_LV_S); +} + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32s3/include/hal/rtc_io_ll.h b/components/hal/esp32s3/include/hal/rtc_io_ll.h index 323e126c11..64088b0cd2 100644 --- a/components/hal/esp32s3/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s3/include/hal/rtc_io_ll.h @@ -391,6 +391,17 @@ static inline void rtcio_ll_ext0_set_wakeup_pin(int rtcio_num, int level) level , RTC_CNTL_EXT_WAKEUP0_LV_S); } +/** + * Clear ext0 wakeup trigger. + */ +static inline void rtcio_ll_ext0_clear_wakeup_pins(void) +{ + REG_SET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL, 0); + // Clear level which will trigger wakeup + SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, + 0 , RTC_CNTL_EXT_WAKEUP0_LV_S); +} + #ifdef __cplusplus } #endif diff --git a/components/hal/include/hal/rtc_io_hal.h b/components/hal/include/hal/rtc_io_hal.h index 2e6d50ca81..35732be4fd 100644 --- a/components/hal/include/hal/rtc_io_hal.h +++ b/components/hal/include/hal/rtc_io_hal.h @@ -259,13 +259,18 @@ void rtcio_hal_set_direction_in_sleep(int rtcio_num, rtc_gpio_mode_t mode); #define rtcio_hal_wakeup_disable(rtcio_num) rtcio_ll_wakeup_disable(rtcio_num) /** - * Set specific logic level on an RTC IO pin as a wakeup trigger. + * Set specific logic level on an RTC IO pin as a ext0 wakeup trigger. * * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. * @param level Logic level (0) */ #define rtcio_hal_ext0_set_wakeup_pin(rtcio_num, level) rtcio_ll_ext0_set_wakeup_pin(rtcio_num, level) +/** + * Clear ext0 wakeup trigger. + */ +#define rtcio_hal_ext0_clear_wakeup_pins() rtcio_ll_ext0_clear_wakeup_pins() + #endif #if SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED From 8db9f79bd289d6105c6823880c6ff0f23a2b894d Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Mon, 20 Nov 2023 14:27:54 +0800 Subject: [PATCH 08/10] change(pm/ext1): replace esp_sleep_set_ext1_wakeup_io by esp_sleep_enable_ext1_wakeup_io --- components/esp_hw_support/include/esp_sleep.h | 8 +++----- components/esp_hw_support/sleep_modes.c | 4 ++-- components/esp_pm/test_apps/esp_pm/main/test_pm.c | 2 +- .../esp_system_unity_tests/main/test_sleep.c | 12 ++++++------ docs/en/api-reference/system/sleep_modes.rst | 6 ++---- docs/en/migration-guides/release-5.x/5.3/system.rst | 2 +- docs/zh_CN/api-reference/system/sleep_modes.rst | 6 ++---- .../components/cmd_system/cmd_system.c | 2 +- .../deep_sleep/main/esp_ot_sleepy_device.c | 2 +- .../components/cmd_system/cmd_system_sleep.c | 2 +- examples/system/deep_sleep/main/ext_wakeup.c | 6 +++--- 11 files changed, 23 insertions(+), 29 deletions(-) diff --git a/components/esp_hw_support/include/esp_sleep.h b/components/esp_hw_support/include/esp_sleep.h index 88d3985809..6fb1df4cba 100644 --- a/components/esp_hw_support/include/esp_sleep.h +++ b/components/esp_hw_support/include/esp_sleep.h @@ -269,7 +269,7 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level); * * @note Call this func will reset the previous ext1 configuration. * - * @note This function will be deprecated in release/v6.0. Please switch to use `esp_sleep_set_ext1_wakeup_io` and `esp_sleep_clear_ext1_wakeup_io` + * @note This function will be deprecated in release/v6.0. Please switch to use `esp_sleep_enable_ext1_wakeup_io` and `esp_sleep_clear_ext1_wakeup_io` * * @param io_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs * which have RTC functionality can be used in this bit map. @@ -320,8 +320,6 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m * the pins during sleep. HOLD feature will be acted on the pin internally * before the system entering sleep, and this can further reduce power consumption. * - * @note this func allows to increase the configuration for ext1 without resetting the previous configuration. - * * @param io_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs * which have RTC functionality can be used in this bit map. * For different SoCs, the related GPIOs are: @@ -344,7 +342,7 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m * - ESP_ERR_NOT_ALLOWED when wakeup level will become different between * ext1 IOs if !SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN */ -esp_err_t esp_sleep_set_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode); +esp_err_t esp_sleep_enable_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode); /** * @brief Disable ext1 wakeup pins with IO masks. This will remove selected IOs from the wakeup IOs. @@ -403,7 +401,7 @@ esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask); * or mode is invalid */ esp_err_t esp_sleep_enable_ext1_wakeup_with_level_mask(uint64_t io_mask, uint64_t level_mask) -__attribute__((deprecated("please use 'esp_sleep_set_ext1_wakeup_io' and 'esp_sleep_clear_ext1_wakeup_io' instead"))); +__attribute__((deprecated("please use 'esp_sleep_enable_ext1_wakeup_io' and 'esp_sleep_clear_ext1_wakeup_io' instead"))); #endif // SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN #endif // SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index eb057a959a..29421ffbec 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1494,11 +1494,11 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m // Reset all EXT1 configs esp_sleep_clear_ext1_wakeup_io(0); - return esp_sleep_set_ext1_wakeup_io(io_mask, level_mode); + return esp_sleep_enable_ext1_wakeup_io(io_mask, level_mode); } -esp_err_t esp_sleep_set_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode) +esp_err_t esp_sleep_enable_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeup_mode_t level_mode) { if (io_mask == 0 && level_mode > ESP_EXT1_WAKEUP_ANY_HIGH) { return ESP_ERR_INVALID_ARG; diff --git a/components/esp_pm/test_apps/esp_pm/main/test_pm.c b/components/esp_pm/test_apps/esp_pm/main/test_pm.c index ac6e51446b..14c1d5c2cb 100644 --- a/components/esp_pm/test_apps/esp_pm/main/test_pm.c +++ b/components/esp_pm/test_apps/esp_pm/main/test_pm.c @@ -182,7 +182,7 @@ TEST_CASE("Can wake up from automatic light sleep by GPIO", "[pm][ignore]") rtc_gpio_set_level(ext1_wakeup_gpio, 0); /* Enable wakeup */ - TEST_ESP_OK(esp_sleep_set_ext1_wakeup_io(1ULL << ext1_wakeup_gpio, ESP_EXT1_WAKEUP_ANY_HIGH)); + TEST_ESP_OK(esp_sleep_enable_ext1_wakeup_io(1ULL << ext1_wakeup_gpio, ESP_EXT1_WAKEUP_ANY_HIGH)); /* To simplify test environment, we'll use a ULP program to set GPIO high */ ulp_insn_t ulp_code[] = { diff --git a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c index 325bd1fe0e..d830f3f27c 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c +++ b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c @@ -416,7 +416,7 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 high)", "[deepsleep][ig { // This test needs external pulldown ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13)); - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); esp_deep_sleep_start(); } @@ -425,9 +425,9 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 low)", "[deepsleep][ign // This test needs external pullup ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13)); #if CONFIG_IDF_TARGET_ESP32 - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); #else - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); #endif esp_deep_sleep_start(); } @@ -438,7 +438,7 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 high)", "[deepsleep][ign ESP_ERROR_CHECK(gpio_pullup_dis(GPIO_NUM_13)); ESP_ERROR_CHECK(gpio_pulldown_en(GPIO_NUM_13)); ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON)); - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH)); esp_deep_sleep_start(); } @@ -449,9 +449,9 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 low)", "[deepsleep][igno ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_13)); ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON)); #if CONFIG_IDF_TARGET_ESP32 - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW)); #else - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_LOW)); #endif esp_deep_sleep_start(); } diff --git a/docs/en/api-reference/system/sleep_modes.rst b/docs/en/api-reference/system/sleep_modes.rst index 10dfafcb62..8030cf20df 100644 --- a/docs/en/api-reference/system/sleep_modes.rst +++ b/docs/en/api-reference/system/sleep_modes.rst @@ -248,15 +248,13 @@ RTC peripherals or RTC memories do not need to be powered on during sleep in thi gpio_pullup_dis(gpio_num); gpio_pulldown_en(gpio_num); - :cpp:func:`esp_sleep_set_ext1_wakeup_io` function can be used to append ext1 wakeup IO and set corresponding wakeup level. + :cpp:func:`esp_sleep_enable_ext1_wakeup_io` function can be used to append ext1 wakeup IO and set corresponding wakeup level. :cpp:func:`esp_sleep_clear_ext1_wakeup_io` function can be used to remove ext1 wakeup IO. - :cpp:func:`esp_sleep_enable_ext1_wakeup` function can be used to reset all previous ext1 wakeup configurations and enable new ext1 wakeup IO and set corresponding wakeup level. - .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - The RTC controller also supports triggering wakeup, allowing configurable IO to use different wakeup levels simultaneously. This can be configured with :cpp:func`esp_sleep_set_ext1_wakeup_io`. + The RTC controller also supports triggering wakeup, allowing configurable IO to use different wakeup levels simultaneously. This can be configured with :cpp:func`esp_sleep_enable_ext1_wakeup_io`. .. warning:: diff --git a/docs/en/migration-guides/release-5.x/5.3/system.rst b/docs/en/migration-guides/release-5.x/5.3/system.rst index de3c7ead05..0747e0e77b 100644 --- a/docs/en/migration-guides/release-5.x/5.3/system.rst +++ b/docs/en/migration-guides/release-5.x/5.3/system.rst @@ -6,4 +6,4 @@ System Power Management ----------------------- -* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_set_ext1_wakeup_io`` and ``esp_sleep_clear_ext1_wakeup_io`` instead. +* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_enable_ext1_wakeup_io`` and ``esp_sleep_clear_ext1_wakeup_io`` instead. diff --git a/docs/zh_CN/api-reference/system/sleep_modes.rst b/docs/zh_CN/api-reference/system/sleep_modes.rst index ed02cb5f0b..bca4d8dcb3 100644 --- a/docs/zh_CN/api-reference/system/sleep_modes.rst +++ b/docs/zh_CN/api-reference/system/sleep_modes.rst @@ -248,15 +248,13 @@ RTC 控制器中内嵌定时器,可用于在预定义的时间到达后唤醒 gpio_pullup_dis(gpio_num); gpio_pulldown_en(gpio_num); - 可调用 :cpp:func:`esp_sleep_set_ext1_wakeup_io` 函数可用于增加 ext1 唤醒 IO 并设置相应的唤醒电平。 + 可调用 :cpp:func:`esp_sleep_enable_ext1_wakeup_io` 函数可用于增加 ext1 唤醒 IO 并设置相应的唤醒电平。 可调用 :cpp:func:`esp_sleep_clear_ext1_wakeup_io` 函数可用于移除 ext1 唤醒 IO。 - 可调用 :cpp:func:`esp_sleep_enable_ext1_wakeup` 函数可用于重置所有先前的 ext1 唤醒配置,并启用新的 ext1 唤醒 IO 并设置相应的唤醒电平。 - .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - 当前的 RTC 控制器也包含更强大的逻辑,允许配置的 IO 同时使用不同的唤醒电平。这可以通过:cpp:func:`esp_sleep_set_ext1_wakeup_io` 函数来进行配置。 + 当前的 RTC 控制器也包含更强大的逻辑,允许配置的 IO 同时使用不同的唤醒电平。这可以通过:cpp:func:`esp_sleep_enable_ext1_wakeup_io` 函数来进行配置。 .. warning:: diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c index f3dc53317b..59fe12c6e8 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c @@ -217,7 +217,7 @@ static int deep_sleep(int argc, char **argv) io_num, level ? "HIGH" : "LOW"); #if SOC_PM_SUPPORT_EXT1_WAKEUP - ESP_ERROR_CHECK( esp_sleep_set_ext1_wakeup_io(1ULL << io_num, level) ); + ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup_io(1ULL << io_num, level) ); #endif } diff --git a/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c b/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c index 16aaa4eebd..64659f6db9 100644 --- a/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c +++ b/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c @@ -151,7 +151,7 @@ static void ot_deep_sleep_init(void) // The configuration mode depends on your hardware design. // Since the BOOT button is connected to a pull-up resistor, the wake-up mode is configured as LOW. const uint64_t ext_wakeup_mode = 0; - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(gpio_wakeup_pin_mask, ext_wakeup_mode)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(gpio_wakeup_pin_mask, ext_wakeup_mode)); // Also these two GPIO configurations are also depended on the hardware design. // The BOOT button is connected to the pull-up resistor, so enable the pull-up mode and disable the pull-down mode. diff --git a/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c b/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c index 41a52c6b74..0dd3ef9a18 100644 --- a/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c +++ b/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c @@ -82,7 +82,7 @@ static int deep_sleep(int argc, char **argv) ESP_LOGI(TAG, "Enabling wakeup on GPIO%d, wakeup on %s level", io_num, level ? "HIGH" : "LOW"); - ESP_ERROR_CHECK( esp_sleep_set_ext1_wakeup_io(1ULL << io_num, level) ); + ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup_io(1ULL << io_num, level) ); ESP_LOGE(TAG, "GPIO wakeup from deep sleep currently unsupported on ESP32-C3"); } #endif // SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/examples/system/deep_sleep/main/ext_wakeup.c b/examples/system/deep_sleep/main/ext_wakeup.c index 9560fd685f..35dcaf4b94 100644 --- a/examples/system/deep_sleep/main/ext_wakeup.c +++ b/examples/system/deep_sleep/main/ext_wakeup.c @@ -40,10 +40,10 @@ void example_deep_sleep_register_ext1_wakeup(void) printf("Enabling EXT1 wakeup on pins GPIO%d, GPIO%d\n", ext_wakeup_pin_1, ext_wakeup_pin_2); #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(ext_wakeup_pin_1_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1)); - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_2)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(ext_wakeup_pin_1_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_2)); #else - ESP_ERROR_CHECK(esp_sleep_set_ext1_wakeup_io(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE)); + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE)); #endif /* If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO From b86d550ec5e615436590faf90803dc69ec655320 Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Mon, 20 Nov 2023 16:35:27 +0800 Subject: [PATCH 09/10] change(pm/ext): remove ext0_wakeup_clear and ext1_wakeup_clear --- components/esp_hw_support/sleep_modes.c | 21 ++----------------- components/hal/esp32/include/hal/rtc_io_ll.h | 10 --------- .../hal/esp32s2/include/hal/rtc_io_ll.h | 11 ---------- .../hal/esp32s3/include/hal/rtc_io_ll.h | 11 ---------- components/hal/include/hal/rtc_io_hal.h | 5 ----- 5 files changed, 2 insertions(+), 56 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 29421ffbec..5ab78ab228 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -256,11 +256,9 @@ void esp_sleep_periph_use_8m(bool use_or_not) static uint32_t get_power_down_flags(void); #if SOC_PM_SUPPORT_EXT0_WAKEUP static void ext0_wakeup_prepare(void); -static void IRAM_ATTR ext0_wakeup_clear(void); #endif #if SOC_PM_SUPPORT_EXT1_WAKEUP static void ext1_wakeup_prepare(void); -static void IRAM_ATTR ext1_wakeup_clear(void); #endif static esp_err_t timer_wakeup_prepare(int64_t sleep_duration); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 @@ -635,16 +633,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m // Configure pins for external wakeup if (s_config.wakeup_triggers & RTC_EXT0_TRIG_EN) { ext0_wakeup_prepare(); - } else { - ext0_wakeup_clear(); } + // for !(s_config.wakeup_triggers & RTC_EXT0_TRIG_EN), ext0 wakeup will be turned off in hardware in the real call to sleep #endif #if SOC_PM_SUPPORT_EXT1_WAKEUP if (s_config.wakeup_triggers & RTC_EXT1_TRIG_EN) { ext1_wakeup_prepare(); - } else { - ext1_wakeup_clear(); } + // for !(s_config.wakeup_triggers & RTC_EXT1_TRIG_EN), ext1 wakeup will be turned off in hardware in the real call to sleep #endif #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP @@ -1478,11 +1474,6 @@ static void ext0_wakeup_prepare(void) rtcio_hal_input_enable(rtc_gpio_num); } -static void ext0_wakeup_clear(void) -{ - rtcio_hal_ext0_clear_wakeup_pins(); -} - #endif // SOC_PM_SUPPORT_EXT0_WAKEUP #if SOC_PM_SUPPORT_EXT1_WAKEUP @@ -1641,14 +1632,6 @@ static void ext1_wakeup_prepare(void) rtc_hal_ext1_set_wakeup_pins(s_config.ext1_rtc_gpio_mask, s_config.ext1_trigger_mode); } -static void ext1_wakeup_clear(void) -{ - // Clear state from previous wakeup - rtc_hal_ext1_clear_wakeup_status(); - // Clear all ext1 wakup-source setting - rtc_hal_ext1_clear_wakeup_pins(); -} - uint64_t esp_sleep_get_ext1_wakeup_status(void) { if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_EXT1) { diff --git a/components/hal/esp32/include/hal/rtc_io_ll.h b/components/hal/esp32/include/hal/rtc_io_ll.h index 86b340fb77..d10deaa96b 100644 --- a/components/hal/esp32/include/hal/rtc_io_ll.h +++ b/components/hal/esp32/include/hal/rtc_io_ll.h @@ -373,16 +373,6 @@ static inline void rtcio_ll_ext0_set_wakeup_pin(int rtcio_num, int level) level , RTC_CNTL_EXT_WAKEUP0_LV_S); } -/** - * Clear ext0 wakeup trigger. - */ -static inline void rtcio_ll_ext0_clear_wakeup_pins(void) -{ - REG_SET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL, 0); - // Clear level which will trigger wakeup - SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 0 , RTC_CNTL_EXT_WAKEUP0_LV_S); -} #ifdef __cplusplus } #endif diff --git a/components/hal/esp32s2/include/hal/rtc_io_ll.h b/components/hal/esp32s2/include/hal/rtc_io_ll.h index d7033fb636..ad05ea95dd 100644 --- a/components/hal/esp32s2/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s2/include/hal/rtc_io_ll.h @@ -376,17 +376,6 @@ static inline void rtcio_ll_ext0_set_wakeup_pin(int rtcio_num, int level) level , RTC_CNTL_EXT_WAKEUP0_LV_S); } -/** - * Clear ext0 wakeup trigger. - */ -static inline void rtcio_ll_ext0_clear_wakeup_pins(void) -{ - REG_SET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL, 0); - // Clear level which will trigger wakeup - SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 0 , RTC_CNTL_EXT_WAKEUP0_LV_S); -} - #ifdef __cplusplus } #endif diff --git a/components/hal/esp32s3/include/hal/rtc_io_ll.h b/components/hal/esp32s3/include/hal/rtc_io_ll.h index 64088b0cd2..323e126c11 100644 --- a/components/hal/esp32s3/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s3/include/hal/rtc_io_ll.h @@ -391,17 +391,6 @@ static inline void rtcio_ll_ext0_set_wakeup_pin(int rtcio_num, int level) level , RTC_CNTL_EXT_WAKEUP0_LV_S); } -/** - * Clear ext0 wakeup trigger. - */ -static inline void rtcio_ll_ext0_clear_wakeup_pins(void) -{ - REG_SET_FIELD(RTC_IO_EXT_WAKEUP0_REG, RTC_IO_EXT_WAKEUP0_SEL, 0); - // Clear level which will trigger wakeup - SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 0 , RTC_CNTL_EXT_WAKEUP0_LV_S); -} - #ifdef __cplusplus } #endif diff --git a/components/hal/include/hal/rtc_io_hal.h b/components/hal/include/hal/rtc_io_hal.h index 35732be4fd..67b2201bca 100644 --- a/components/hal/include/hal/rtc_io_hal.h +++ b/components/hal/include/hal/rtc_io_hal.h @@ -266,11 +266,6 @@ void rtcio_hal_set_direction_in_sleep(int rtcio_num, rtc_gpio_mode_t mode); */ #define rtcio_hal_ext0_set_wakeup_pin(rtcio_num, level) rtcio_ll_ext0_set_wakeup_pin(rtcio_num, level) -/** - * Clear ext0 wakeup trigger. - */ -#define rtcio_hal_ext0_clear_wakeup_pins() rtcio_ll_ext0_clear_wakeup_pins() - #endif #if SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED From ea7cfc40ae4ec8f6c90b39085883119e33350e42 Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Mon, 20 Nov 2023 19:30:50 +0800 Subject: [PATCH 10/10] change(pm/ext1): replace esp_sleep_clear_ext1_wakeup_io by esp_sleep_disable_ext1_wakeup_io --- components/esp_hw_support/include/esp_sleep.h | 10 +++++----- components/esp_hw_support/sleep_modes.c | 4 ++-- docs/en/api-reference/system/sleep_modes.rst | 2 +- docs/en/migration-guides/release-5.x/5.3/system.rst | 2 +- docs/zh_CN/api-reference/system/sleep_modes.rst | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/esp_hw_support/include/esp_sleep.h b/components/esp_hw_support/include/esp_sleep.h index 6fb1df4cba..29c2af96d8 100644 --- a/components/esp_hw_support/include/esp_sleep.h +++ b/components/esp_hw_support/include/esp_sleep.h @@ -269,7 +269,7 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level); * * @note Call this func will reset the previous ext1 configuration. * - * @note This function will be deprecated in release/v6.0. Please switch to use `esp_sleep_enable_ext1_wakeup_io` and `esp_sleep_clear_ext1_wakeup_io` + * @note This function will be deprecated in release/v6.0. Please switch to use `esp_sleep_enable_ext1_wakeup_io` and `esp_sleep_disable_ext1_wakeup_io` * * @param io_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs * which have RTC functionality can be used in this bit map. @@ -297,8 +297,8 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m * @brief Enable ext1 wakeup pins with IO masks. * * This will append selected IOs to the wakeup IOs, it will not reset previously enabled IOs. - * To reset specific previously enabled IOs, call esp_sleep_clear_ext1_wakeup_io with the io_mask. - * To reset all the enabled IOs, call esp_sleep_clear_ext1_wakeup_io(0). + * To reset specific previously enabled IOs, call esp_sleep_disable_ext1_wakeup_io with the io_mask. + * To reset all the enabled IOs, call esp_sleep_disable_ext1_wakeup_io(0). * * This function uses external wakeup feature of RTC controller. * It will work even if RTC peripherals are shut down during sleep. @@ -360,7 +360,7 @@ esp_err_t esp_sleep_enable_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeu * - ESP_OK on success * - ESP_ERR_INVALID_ARG if any of the selected GPIOs is not an RTC GPIO. */ -esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask); +esp_err_t esp_sleep_disable_ext1_wakeup_io(uint64_t io_mask); #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN /** @@ -401,7 +401,7 @@ esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask); * or mode is invalid */ esp_err_t esp_sleep_enable_ext1_wakeup_with_level_mask(uint64_t io_mask, uint64_t level_mask) -__attribute__((deprecated("please use 'esp_sleep_enable_ext1_wakeup_io' and 'esp_sleep_clear_ext1_wakeup_io' instead"))); +__attribute__((deprecated("please use 'esp_sleep_enable_ext1_wakeup_io' and 'esp_sleep_disable_ext1_wakeup_io' instead"))); #endif // SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN #endif // SOC_PM_SUPPORT_EXT1_WAKEUP diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 5ab78ab228..cefe36448c 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1483,7 +1483,7 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t io_mask, esp_sleep_ext1_wakeup_m return ESP_ERR_INVALID_ARG; } // Reset all EXT1 configs - esp_sleep_clear_ext1_wakeup_io(0); + esp_sleep_disable_ext1_wakeup_io(0); return esp_sleep_enable_ext1_wakeup_io(io_mask, level_mode); } @@ -1533,7 +1533,7 @@ esp_err_t esp_sleep_enable_ext1_wakeup_io(uint64_t io_mask, esp_sleep_ext1_wakeu return ESP_OK; } -esp_err_t esp_sleep_clear_ext1_wakeup_io(uint64_t io_mask) +esp_err_t esp_sleep_disable_ext1_wakeup_io(uint64_t io_mask) { if (io_mask == 0) { s_config.ext1_rtc_gpio_mask = 0; diff --git a/docs/en/api-reference/system/sleep_modes.rst b/docs/en/api-reference/system/sleep_modes.rst index 8030cf20df..b6a4603923 100644 --- a/docs/en/api-reference/system/sleep_modes.rst +++ b/docs/en/api-reference/system/sleep_modes.rst @@ -250,7 +250,7 @@ RTC peripherals or RTC memories do not need to be powered on during sleep in thi :cpp:func:`esp_sleep_enable_ext1_wakeup_io` function can be used to append ext1 wakeup IO and set corresponding wakeup level. - :cpp:func:`esp_sleep_clear_ext1_wakeup_io` function can be used to remove ext1 wakeup IO. + :cpp:func:`esp_sleep_disable_ext1_wakeup_io` function can be used to remove ext1 wakeup IO. .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN diff --git a/docs/en/migration-guides/release-5.x/5.3/system.rst b/docs/en/migration-guides/release-5.x/5.3/system.rst index 0747e0e77b..32c4f08b69 100644 --- a/docs/en/migration-guides/release-5.x/5.3/system.rst +++ b/docs/en/migration-guides/release-5.x/5.3/system.rst @@ -6,4 +6,4 @@ System Power Management ----------------------- -* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_enable_ext1_wakeup_io`` and ``esp_sleep_clear_ext1_wakeup_io`` instead. +* ``esp_sleep_enable_ext1_wakeup_with_level_mask`` is deprecated, use ``esp_sleep_enable_ext1_wakeup_io`` and ``esp_sleep_disable_ext1_wakeup_io`` instead. diff --git a/docs/zh_CN/api-reference/system/sleep_modes.rst b/docs/zh_CN/api-reference/system/sleep_modes.rst index bca4d8dcb3..36ae29930e 100644 --- a/docs/zh_CN/api-reference/system/sleep_modes.rst +++ b/docs/zh_CN/api-reference/system/sleep_modes.rst @@ -250,7 +250,7 @@ RTC 控制器中内嵌定时器,可用于在预定义的时间到达后唤醒 可调用 :cpp:func:`esp_sleep_enable_ext1_wakeup_io` 函数可用于增加 ext1 唤醒 IO 并设置相应的唤醒电平。 - 可调用 :cpp:func:`esp_sleep_clear_ext1_wakeup_io` 函数可用于移除 ext1 唤醒 IO。 + 可调用 :cpp:func:`esp_sleep_disable_ext1_wakeup_io` 函数可用于移除 ext1 唤醒 IO。 .. only:: SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN