ESP32-PaxCounter/include/power.h

37 lines
824 B
C
Raw Normal View History

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>
#include <esp_adc_cal.h>
2020-03-29 18:08:52 +02:00
2019-10-16 21:14:34 +02:00
#include "i2c.h"
2019-10-20 20:47:03 +02:00
#include "reset.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
2020-04-10 23:26:29 +02:00
#ifndef BAT_MAX_VOLTAGE
2020-04-11 23:36:17 +02:00
#define BAT_MAX_VOLTAGE 4300 // millivolts
2020-04-11 21:30:09 +02:00
#endif
#ifndef BAT_MIN_VOLTAGE
2020-04-12 17:33:13 +02:00
#define BAT_MIN_VOLTAGE 3200 // millivolts
2020-04-10 23:26:29 +02:00
#endif
uint16_t read_voltage(void);
2020-04-11 21:30:09 +02:00
uint8_t read_battlevel(void);
void calibrate_voltage(void);
bool batt_sufficient(void);
2019-09-07 19:52:25 +02:00
#ifdef HAS_PMU
2019-09-07 19:52:25 +02:00
#include <axp20x.h>
enum pmu_power_t { pmu_power_on, pmu_power_off, pmu_power_sleep };
2019-10-16 21:14:34 +02:00
void AXP192_powerevent_IRQ(void);
void AXP192_power(pmu_power_t powerlevel);
2019-09-07 19:52:25 +02:00
void AXP192_init(void);
void AXP192_showstatus(void);
#endif // HAS_PMU
2019-09-07 19:52:25 +02:00
#endif