From f45622ff17563cd5045097dfbeefbe24e2c10ef2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sat, 10 Feb 2018 00:28:30 +0800 Subject: [PATCH] driver/rtc: add rtc_gpio_isolate helper function to disconnect RTC IO --- components/driver/include/driver/rtc_io.h | 18 ++++++++++++++++++ components/driver/rtc_module.c | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/components/driver/include/driver/rtc_io.h b/components/driver/include/driver/rtc_io.h index c7219d3eb..522a9f9b6 100644 --- a/components/driver/include/driver/rtc_io.h +++ b/components/driver/include/driver/rtc_io.h @@ -224,6 +224,24 @@ esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num); */ esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num); +/** + * @brief Helper function to disconnect internal circuits from an RTC IO + * This function disables input, output, pullup, pulldown, and enables + * hold feature for an RTC IO. + * Use this function if an RTC IO needs to be disconnected from internal + * circuits in deep sleep, to minimize leakage current. + * + * In particular, for ESP32-WROVER module, call + * rtc_gpio_isolate(GPIO_NUM_12) before entering deep sleep, to reduce + * deep sleep current. + * + * @param gpio_num GPIO number (e.g. GPIO_NUM_12). + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if GPIO is not an RTC IO + */ +esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num); + /** * @brief Disable force hold signal for all RTC IOs * diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 9a6b6faf1..0d3974c5c 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -381,6 +381,19 @@ esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num) return ESP_OK; } +esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num) +{ + if (rtc_gpio_desc[gpio_num].reg == 0) { + return ESP_ERR_INVALID_ARG; + } + + rtc_gpio_pullup_dis(gpio_num); + rtc_gpio_pulldown_dis(gpio_num); + rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED); + rtc_gpio_hold_en(gpio_num); + + return ESP_OK; +} void rtc_gpio_force_hold_dis_all() {