Skip to content

Commit f45622f

Browse files
committed
driver/rtc: add rtc_gpio_isolate helper function to disconnect RTC IO
1 parent e381c6a commit f45622f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

components/driver/include/driver/rtc_io.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num);
224224
*/
225225
esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num);
226226

227+
/**
228+
* @brief Helper function to disconnect internal circuits from an RTC IO
229+
* This function disables input, output, pullup, pulldown, and enables
230+
* hold feature for an RTC IO.
231+
* Use this function if an RTC IO needs to be disconnected from internal
232+
* circuits in deep sleep, to minimize leakage current.
233+
*
234+
* In particular, for ESP32-WROVER module, call
235+
* rtc_gpio_isolate(GPIO_NUM_12) before entering deep sleep, to reduce
236+
* deep sleep current.
237+
*
238+
* @param gpio_num GPIO number (e.g. GPIO_NUM_12).
239+
* @return
240+
* - ESP_OK on success
241+
* - ESP_ERR_INVALID_ARG if GPIO is not an RTC IO
242+
*/
243+
esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num);
244+
227245
/**
228246
* @brief Disable force hold signal for all RTC IOs
229247
*

components/driver/rtc_module.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num)
381381
return ESP_OK;
382382
}
383383

384+
esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num)
385+
{
386+
if (rtc_gpio_desc[gpio_num].reg == 0) {
387+
return ESP_ERR_INVALID_ARG;
388+
}
389+
390+
rtc_gpio_pullup_dis(gpio_num);
391+
rtc_gpio_pulldown_dis(gpio_num);
392+
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED);
393+
rtc_gpio_hold_en(gpio_num);
394+
395+
return ESP_OK;
396+
}
384397

385398
void rtc_gpio_force_hold_dis_all()
386399
{

0 commit comments

Comments
 (0)