Code: Select all
#define DEFAULT_WAKEUP_PIN (35)
void do_deep_sleep(int64_t time_to_sleep_in_us)
{
int result;
gpio_config_t config;
printf("Going to sleep for %lld us\n",time_to_sleep_in_us); fflush(stdout);
result = esp_sleep_enable_timer_wakeup(time_to_sleep_in_us);
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
reset_gpio(DEFAULT_WAKEUP_PIN);
uint64_t mask = 1;
mask <<= DEFAULT_WAKEUP_PIN;
config.pin_bit_mask = mask;
config.mode = GPIO_MODE_INPUT;
config.pull_up_en = GPIO_PULLUP_DISABLE;
config.pull_down_en = GPIO_PULLDOWN_DISABLE;
config.intr_type = GPIO_INTR_DISABLE;
ESP_ERROR_CHECK(gpio_config(&config));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup((gpio_num_t)DEFAULT_WAKEUP_PIN,1));
/* Enter sleep mode */
if (result == ESP_OK)
esp_deep_sleep_start();
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}