longfi-arduino/TTGO-TBeam-Tracker/main/sleep.ino

45 wiersze
1.2 KiB
C++

/*
Sleep module
Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <esp_sleep.h>
void sleep_interrupt(uint8_t gpio, uint8_t mode) {
esp_sleep_enable_ext0_wakeup((gpio_num_t) gpio, mode);
}
void sleep_interrupt_mask(uint64_t mask, uint8_t mode) {
esp_sleep_enable_ext1_wakeup(mask, (esp_sleep_ext1_wakeup_mode_t) mode);
}
void sleep_millis(uint64_t ms) {
esp_sleep_enable_timer_wakeup(ms * 1000);
esp_deep_sleep_start();
}
void sleep_seconds(uint32_t seconds) {
esp_sleep_enable_timer_wakeup(seconds * 1000000);
esp_deep_sleep_start();
}
void sleep_forever() {
esp_deep_sleep_start();
}