deep sleep fixes
This commit is contained in:
parent
bc034b1a67
commit
221fde0026
@ -5,6 +5,7 @@
|
|||||||
#include <driver/adc.h>
|
#include <driver/adc.h>
|
||||||
#include <esp_adc_cal.h>
|
#include <esp_adc_cal.h>
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
#include "reset.h"
|
||||||
|
|
||||||
#define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate
|
#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
|
#define NO_OF_SAMPLES 64 // we do some multisampling to get better values
|
||||||
@ -12,8 +13,6 @@
|
|||||||
uint16_t read_voltage(void);
|
uint16_t read_voltage(void);
|
||||||
void calibrate_voltage(void);
|
void calibrate_voltage(void);
|
||||||
bool batt_sufficient(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
|
#ifdef HAS_PMU
|
||||||
|
|
||||||
|
@ -8,6 +8,5 @@
|
|||||||
void do_reset(bool warmstart);
|
void do_reset(bool warmstart);
|
||||||
void do_after_reset(int reason);
|
void do_after_reset(int reason);
|
||||||
void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio);
|
void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio);
|
||||||
int64_t exit_deepsleep(void);
|
|
||||||
|
|
||||||
#endif // _RESET_H
|
#endif // _RESET_H
|
@ -75,7 +75,7 @@ void AXP192_power(pmu_power_t powerlevel) {
|
|||||||
pmu.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
pmu.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
||||||
pmu.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
pmu.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
||||||
pmu.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
pmu.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||||
//pmu.setPowerOutPut(AXP192_DCDC3, AXP202_OFF);
|
// pmu.setPowerOutPut(AXP192_DCDC3, AXP202_OFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case pmu_power_sleep:
|
case pmu_power_sleep:
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = __FILE__;
|
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
|
// variable keep its values after restart or wakeup from sleep
|
||||||
RTC_NOINIT_ATTR runmode_t RTC_runmode;
|
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
|
case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core
|
||||||
RTC_runmode = RUNMODE_WAKEUP;
|
RTC_runmode = RUNMODE_WAKEUP;
|
||||||
exit_deepsleep();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SW_RESET: // 0x03 Software reset digital core
|
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);
|
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
|
// store LMIC keys and counters in RTC memory
|
||||||
#if (HAS_LORA)
|
#if (HAS_LORA)
|
||||||
LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey);
|
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();
|
i2c_deinit();
|
||||||
|
|
||||||
// enter sleep mode
|
// enter sleep mode
|
||||||
|
ESP_LOGI(TAG, "Going to sleep...");
|
||||||
esp_deep_sleep_start();
|
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;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user