2023-03-02 07:49:14 -05:00
|
|
|
/*
|
2024-04-10 05:33:08 -04:00
|
|
|
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
2023-03-02 07:49:14 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "esp_sleep.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "driver/rtc_io.h"
|
|
|
|
|
2023-07-03 09:25:56 -04:00
|
|
|
|
2023-03-02 07:49:14 -05:00
|
|
|
#if CONFIG_EXAMPLE_EXT0_WAKEUP
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2023-07-13 02:06:10 -04:00
|
|
|
const int ext_wakeup_pin_0 = 25;
|
2023-03-02 07:49:14 -05:00
|
|
|
#else
|
2023-07-13 02:06:10 -04:00
|
|
|
const int ext_wakeup_pin_0 = 3;
|
2023-03-02 07:49:14 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void example_deep_sleep_register_ext0_wakeup(void)
|
|
|
|
{
|
|
|
|
printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
|
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 1));
|
|
|
|
|
|
|
|
// Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
|
|
|
|
// EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
|
|
|
|
// No need to keep that power domain explicitly, unlike EXT1.
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_0));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_0));
|
|
|
|
}
|
|
|
|
#endif // CONFIG_EXAMPLE_EXT0_WAKEUP
|
|
|
|
|
|
|
|
#if CONFIG_EXAMPLE_EXT1_WAKEUP
|
|
|
|
void example_deep_sleep_register_ext1_wakeup(void)
|
|
|
|
{
|
2023-07-13 02:19:48 -04:00
|
|
|
const int ext_wakeup_pin_1 = CONFIG_EXAMPLE_EXT1_WAKEUP_PIN_1;
|
|
|
|
const int ext_wakeup_pin_2 = CONFIG_EXAMPLE_EXT1_WAKEUP_PIN_2;
|
2023-07-03 09:25:56 -04:00
|
|
|
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
|
|
|
|
const uint64_t ext_wakeup_pin_2_mask = 1ULL << ext_wakeup_pin_2;
|
2023-03-02 07:49:14 -05:00
|
|
|
printf("Enabling EXT1 wakeup on pins GPIO%d, GPIO%d\n", ext_wakeup_pin_1, ext_wakeup_pin_2);
|
2023-07-13 02:19:48 -04:00
|
|
|
|
2023-07-13 02:06:10 -04:00
|
|
|
#if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN
|
2024-04-10 05:33:08 -04:00
|
|
|
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));
|
2023-07-13 02:06:10 -04:00
|
|
|
#else
|
2024-04-10 05:33:08 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup_io(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, CONFIG_EXAMPLE_EXT1_WAKEUP_MODE));
|
2023-07-13 02:06:10 -04:00
|
|
|
#endif
|
2023-03-02 07:49:14 -05:00
|
|
|
|
|
|
|
/* If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO
|
|
|
|
* during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will
|
2023-07-11 05:15:59 -04:00
|
|
|
* increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if 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.*/
|
2023-03-02 07:49:14 -05:00
|
|
|
#if CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
|
2023-07-11 05:15:59 -04:00
|
|
|
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
2023-07-13 02:06:10 -04:00
|
|
|
#if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN
|
|
|
|
if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1) {
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_1));
|
|
|
|
} else {
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_1));
|
|
|
|
}
|
|
|
|
if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_2) {
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_2));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_2));
|
|
|
|
} else {
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_2));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_2));
|
|
|
|
}
|
|
|
|
#else // !SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN
|
|
|
|
if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE) {
|
2023-07-11 05:15:59 -04:00
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_2));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_2));
|
|
|
|
} else {
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_2));
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_2));
|
|
|
|
}
|
2023-07-13 02:06:10 -04:00
|
|
|
#endif
|
|
|
|
#else // ! SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
|
|
|
#if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN
|
|
|
|
if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1) {
|
|
|
|
gpio_pullup_dis(ext_wakeup_pin_1);
|
|
|
|
gpio_pulldown_en(ext_wakeup_pin_1);
|
|
|
|
} else {
|
|
|
|
gpio_pulldown_dis(ext_wakeup_pin_1);
|
|
|
|
gpio_pullup_en(ext_wakeup_pin_1);
|
|
|
|
}
|
|
|
|
if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_2) {
|
|
|
|
gpio_pullup_dis(ext_wakeup_pin_2);
|
|
|
|
gpio_pulldown_en(ext_wakeup_pin_2);
|
|
|
|
} else {
|
|
|
|
gpio_pulldown_dis(ext_wakeup_pin_2);
|
|
|
|
gpio_pullup_en(ext_wakeup_pin_2);
|
|
|
|
}
|
2023-07-03 09:25:56 -04:00
|
|
|
#else
|
2023-07-13 02:06:10 -04:00
|
|
|
if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE) {
|
2023-07-11 05:15:59 -04:00
|
|
|
ESP_ERROR_CHECK(gpio_pullup_dis(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(gpio_pulldown_en(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(gpio_pullup_dis(ext_wakeup_pin_2));
|
|
|
|
ESP_ERROR_CHECK(gpio_pulldown_en(ext_wakeup_pin_2));
|
|
|
|
} else {
|
|
|
|
ESP_ERROR_CHECK(gpio_pulldown_dis(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(gpio_pullup_en(ext_wakeup_pin_1));
|
|
|
|
ESP_ERROR_CHECK(gpio_pulldown_dis(ext_wakeup_pin_2));
|
|
|
|
ESP_ERROR_CHECK(gpio_pullup_en(ext_wakeup_pin_2));
|
|
|
|
}
|
2023-07-03 09:25:56 -04:00
|
|
|
#endif
|
2023-07-13 02:06:10 -04:00
|
|
|
#endif
|
2023-07-18 07:33:30 -04:00
|
|
|
#endif // CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
|
2023-03-02 07:49:14 -05:00
|
|
|
}
|
|
|
|
#endif // CONFIG_EXAMPLE_EXT1_WAKEUP
|