Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PIN_A 32
- #define PIN_B 33
- #define PIN_C 34
- #define PIN_D 35
- #define P(x) P_(x)
- #define P_(x) GPIO_NUM_##x
- #define BUTTON_PIN_BITMASK ((uint64_t)1 << PIN_A) | ((uint64_t)1 << PIN_B) | ((uint64_t)1 << PIN_C) | ((uint64_t)1 << PIN_D)
- void goto_sleep();
- void after_wake();
- void print_GPIO_wake_up(){
- uint64_t GPIO_reason = esp_sleep_get_ext1_wakeup_status();
- Serial.print("GPIO that triggered the wake up: GPIO ");
- Serial.println((log(GPIO_reason))/log(2), 0);
- }
- void print_wakeup_reason(){
- esp_sleep_wakeup_cause_t wakeup_reason;
- wakeup_reason = esp_sleep_get_wakeup_cause();
- switch(wakeup_reason)
- {
- case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
- case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); print_GPIO_wake_up(); break;
- case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
- case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
- case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
- default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
- }
- }
- extern void goto_sleep() {
- esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK, ESP_EXT1_WAKEUP_ANY_HIGH);
- esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
- //rtc_gpio_set_level(P(PIN_A), 0);
- //rtc_gpio_set_level(P(PIN_B), 0);
- rtc_gpio_set_level(P(PIN_C), 0);
- rtc_gpio_set_level(P(PIN_D), 0);
- //rtc_gpio_set_direction(P(PIN_A), RTC_GPIO_MODE_INPUT_ONLY);
- //rtc_gpio_set_direction(P(PIN_B), RTC_GPIO_MODE_INPUT_ONLY);
- rtc_gpio_set_direction(P(PIN_C), RTC_GPIO_MODE_INPUT_ONLY);
- rtc_gpio_set_direction(P(PIN_D), RTC_GPIO_MODE_INPUT_ONLY);
- //rtc_gpio_pullup_dis(P(PIN_A));
- //rtc_gpio_pulldown_en(P(PIN_A));
- //rtc_gpio_pullup_dis(P(PIN_B));
- //rtc_gpio_pulldown_en(P(PIN_B));
- rtc_gpio_pullup_dis(P(PIN_C));
- rtc_gpio_pulldown_en(P(PIN_C));
- rtc_gpio_pullup_dis(P(PIN_D));
- rtc_gpio_pulldown_en(P(PIN_D));
- //rtc_gpio_hold_en(P(PIN_A));
- //rtc_gpio_hold_en(P(PIN_B));
- rtc_gpio_hold_en(P(PIN_C));
- rtc_gpio_hold_en(P(PIN_D));
- esp_deep_sleep_start();
- }
- extern void after_wake()
- {
- print_wakeup_reason();
- rtc_gpio_deinit(P(PIN_A));
- rtc_gpio_deinit(P(PIN_B));
- rtc_gpio_deinit(P(PIN_C));
- rtc_gpio_deinit(P(PIN_D));
- }
Advertisement
Add Comment
Please, Sign In to add comment