2019-09-07 19:52:25 +02:00
|
|
|
#ifndef _POWER_H
|
|
|
|
#define _POWER_H
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2019-09-07 23:10:53 +02:00
|
|
|
#include <driver/adc.h>
|
2019-10-16 21:14:34 +02:00
|
|
|
#include <driver/rtc_io.h>
|
2019-09-07 23:10:53 +02:00
|
|
|
#include <esp_adc_cal.h>
|
2019-10-16 21:14:34 +02:00
|
|
|
#include "i2c.h"
|
2019-09-07 19:52:25 +02:00
|
|
|
|
2019-09-07 23:10:53 +02:00
|
|
|
#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
|
|
|
|
|
2019-10-16 21:14:34 +02:00
|
|
|
extern RTC_DATA_ATTR runmode_t RTC_runmode;
|
|
|
|
|
2019-09-23 15:45:47 +02:00
|
|
|
uint16_t read_voltage(void);
|
|
|
|
void calibrate_voltage(void);
|
|
|
|
bool batt_sufficient(void);
|
2019-10-16 21:14:34 +02:00
|
|
|
void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio);
|
2019-10-19 21:14:04 +02:00
|
|
|
int64_t exit_deepsleep(void);
|
2019-09-23 15:45:47 +02:00
|
|
|
|
2019-09-07 19:52:25 +02:00
|
|
|
#ifdef HAS_PMU
|
|
|
|
#include <axp20x.h>
|
2019-10-16 21:14:34 +02:00
|
|
|
void AXP192_powerevent_IRQ(void);
|
2019-09-09 23:00:06 +02:00
|
|
|
void AXP192_power(bool on);
|
2019-09-07 19:52:25 +02:00
|
|
|
void AXP192_init(void);
|
2019-09-23 15:45:47 +02:00
|
|
|
void AXP192_showstatus(void);
|
2019-09-30 12:35:03 +02:00
|
|
|
uint8_t i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len);
|
|
|
|
uint8_t i2c_readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len);
|
2019-09-23 15:45:47 +02:00
|
|
|
#endif // HAS_PMU
|
2019-09-09 21:45:19 +02:00
|
|
|
|
2019-09-07 19:52:25 +02:00
|
|
|
#endif
|