deep sleep fixes

This commit is contained in:
Verkehrsrot 2019-10-20 20:47:03 +02:00
parent bc034b1a67
commit 221fde0026
4 changed files with 3 additions and 25 deletions

View File

@ -5,6 +5,7 @@
#include <driver/adc.h>
#include <esp_adc_cal.h>
#include "i2c.h"
#include "reset.h"
#define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate
#define NO_OF_SAMPLES 64 // we do some multisampling to get better values
@ -12,8 +13,6 @@
uint16_t read_voltage(void);
void calibrate_voltage(void);
bool batt_sufficient(void);
void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio);
int64_t exit_deepsleep(void);
#ifdef HAS_PMU

View File

@ -8,6 +8,5 @@
void do_reset(bool warmstart);
void do_after_reset(int reason);
void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio);
int64_t exit_deepsleep(void);
#endif // _RESET_H

View File

@ -5,8 +5,6 @@
// Local logging tag
static const char TAG[] = __FILE__;
// variable keep its values after wakeup from sleep
RTC_DATA_ATTR int64_t sleep_enter_time;
// variable keep its values after restart or wakeup from sleep
RTC_NOINIT_ATTR runmode_t RTC_runmode;
@ -43,7 +41,6 @@ void do_after_reset(int reason) {
case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core
RTC_runmode = RUNMODE_WAKEUP;
exit_deepsleep();
break;
case SW_RESET: // 0x03 Software reset digital core
@ -83,9 +80,6 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) {
esp_sleep_enable_ext1_wakeup(1ULL << wakeup_gpio, ESP_EXT1_WAKEUP_ALL_LOW);
}
// store sleep enter time
sleep_enter_time = esp_timer_get_time();
// store LMIC keys and counters in RTC memory
#if (HAS_LORA)
LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey);
@ -115,20 +109,6 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) {
i2c_deinit();
// enter sleep mode
ESP_LOGI(TAG, "Going to sleep...");
esp_deep_sleep_start();
}
int64_t exit_deepsleep(void) {
int64_t sleep_time_ms = (esp_timer_get_time() - sleep_enter_time) / 1000;
// re-init i2c bus
void i2c_init();
// switch on power if has PMU
#ifdef HAS_PMU
AXP192_power(pmu_power_on); // power on Lora, GPS, display
#endif
return sleep_time_ms;
}