32#include "../../SensorBuildOpt.h"
33#if !SENSORLIB_EXCLUDE_GAUGE_AXP2602
36#include "../GaugeBase.hpp"
39static constexpr uint8_t AXP2602_SLAVE_ADDRESS = (0x62);
143 bool begin(TwoWire &wire,
int sda = -1,
int scl = -1)
148#elif defined(ESP_PLATFORM)
150#if defined(SENSORLIB_USE_I2C_LEGACY)
159 bool begin(i2c_port_t port_num,
int sda = -1,
int scl = -1)
170 bool begin(i2c_master_bus_handle_t handle)
197 if (!
comm)
return false;
212 if (vbatHigh >= 0 && vbatLow >= 0) {
219 if (ibatHigh >= 0 && ibatLow >= 0) {
220 uint16_t raw = (ibatHigh << 8) | ibatLow;
238 if (tdieHigh >= 0 && tdieLow >= 0) {
255 if (timeEmptyHigh >= 0 && timeEmptyLow >= 0) {
261 if (timeFullHigh >= 0 && timeFullLow >= 0) {
267 if (irqStatus >= 0) {
370 return lowSoc & 0x3F;
383 return otThld & 0x7F;
525 if (threshold > 63) {
532 lowSoc |= (threshold & 0x3F);
543 if (threshold > 127) {
627 val = (val & ~0x03) | (resistorValue & 0x03);
691 if (low_level_trigger) {
757 if (len != 128 ||
data == NULL)
return false;
768 for (uint8_t
i = 0;
i < 128;
i++) {
788 if (len != 128 ||
data == NULL)
return false;
791 memset(buffer, 0,
sizeof(buffer));
795 for (uint8_t
i = 0;
i < 128;
i++) {
806 return memcmp(
data, buffer, 128) == 0;
820 bool initImpl(uint8_t param)
override
#define SENSORLIB_LOG_E(...)
std::unique_ptr< SensorCommBase > comm
std::unique_ptr< SensorHal > hal
bool writeGaugeData(uint8_t *data, uint8_t len)
Write Gauge Data.
static constexpr uint8_t REG_IRQ_STATUS
float getCurrentResolution(CurrentSenseResistor resistor)
Obtain current resolution based on the sampling resistor.
@ IRQ_ENABLE_OVER_TEMPERATURE
uint16_t getStateOfCharge() override
Get the battery percentage.
static constexpr uint8_t REG_PARA_CONFIG
static constexpr uint8_t REG_TDIE_ADC_LOW
static constexpr uint8_t REG_TEMP_RESULT
static constexpr uint8_t REG_TIME_TO_EMPTY_LOW
static constexpr uint8_t REG_OPERATING_MODE
void sleep()
Put the AXP2602 chip into sleep mode.
void reset() override
Reset Gauge AXP2602.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback)
Begin with custom callback functions.
void setThermalDieMeasurement(bool enable)
Enable or disable the thermal die measurement.
static constexpr uint8_t REG_IBAT_ADC_HIGH
uint16_t getTimeToFull() override
Get the battery time to full.
bool isSleepModeEnabled()
Check if the AXP2602 chip is in sleep mode.
static constexpr uint8_t REG_RDC25_CONFIG_LOW
static constexpr uint8_t REG_SOH
static constexpr uint8_t REG_IBAT_ADC_LOW
static constexpr uint8_t REG_TIME_TO_FULL_HIGH
uint16_t getTimeToEmpty() override
Get the battery time to empty.
static constexpr uint8_t REG_RDC25_QMAX_SEL
bool compareGaugeData(uint8_t *data, uint8_t len)
Compare Gauge Data.
static constexpr uint8_t REG_RDC25_CONFIG_HIGH
void enableIRQ(IRQEnable irq, bool enable, bool low_level_trigger=true)
Enable or disable specific IRQs.
void setOverTemperatureThreshold(uint8_t threshold)
Set the over-temperature threshold.
bool isDischarging() override
Checks if the battery is discharging.
static constexpr uint8_t REG_LOW_SOC_THLD
float getTemperature() override
Get the temperature.
void disableIRQ(IRQEnable irq)
Disable a specific IRQ.
uint16_t getVoltage() override
Get the battery voltage.
float getCurrent() override
Get the actual current value (considering the sampling resistor)
void setLowBatterySOCThreshold(uint8_t threshold)
Set the low battery SOC threshold.
static constexpr uint8_t REG_TDIE_ADC_HIGH
static constexpr uint8_t AXP2602_CHIP_ID
uint8_t getBatteryStatus()
Get the battery health status.
bool isCurrentMeasurementEnabled()
Check if battery current measurement is enabled.
static constexpr uint8_t REG_TIME_TO_FULL_LOW
static constexpr uint8_t REG_BROM
bool isBatteryVoltageMeasurementEnabled()
Check if battery voltage measurement is enabled.
bool isThermalDieMeasurementEnabled()
Check if thermal die measurement is enabled.
void setCurrentMeasurement(bool enable)
Enable or disable battery current detection.
OperatingMode getOperatingMode()
Get the operating mode.
void disableAllIRQ()
Disable all IRQs.
float getThermalDieTemperature()
Get the actual die temperature.
static constexpr uint8_t REG_IRQ_ENABLE
CurrentSenseResistor getCurrentSenseResistor()
Get the current sense resistor value.
@ IRQ_STATUS_OVER_TEMPERATURE
uint16_t getThermalDieTemperatureRaw()
Get the thermal die temperature.
static constexpr uint8_t REG_VBAT_ADC_LOW
float getChargingPower()
Get charging power (positive or 0)
int16_t getCurrentRaw()
Get the battery current.
float getDischargingPower()
Get discharging power (positive or 0)
static constexpr uint8_t REG_QMAX_CONFIG_LOW
static constexpr uint8_t REG_MODE
bool refresh() override
Refresh the AXP2602 chip data.
static constexpr uint8_t REG_VBAT_ADC_HIGH
static constexpr uint8_t REG_COMM_CONFIG
void setOperatingMode(OperatingMode mode)
Set the operating mode.
@ OPERATING_MODE_LOW_POWER
@ OPERATING_MODE_HIGH_PRECISION
float getAbsolutePower()
Get the absolute power (always positive)
static constexpr uint8_t REG_SOC
IRQStatus getIRQStatus()
Get the IRQ status.
static constexpr uint8_t REG_TIME_TO_EMPTY_HIGH
uint8_t getLowBatterySOCThreshold()
Get the low battery SOC threshold.
static constexpr uint8_t REG_AXP2602_ID
static constexpr uint8_t REG_QMAX_CONFIG_HIGH
uint8_t getOverTemperatureThreshold()
Get the over-temperature threshold.
void setBatteryDetection(bool enable)
Enable or disable battery voltage detection.
void clearIRQStatus()
Clear the IRQ status.
void enableIRQ(IRQEnable irq)
Enable a specific IRQ.
static constexpr uint8_t REG_OT_THLD
uint16_t getChipID() override
Get the chip ID.
void setCurrentSenseResistor(CurrentSenseResistor resistorValue)
Set the current sense resistor value.
void wakeup()
Wake up the AXP2602 chip.
bool isCharging() override
Checks if the battery is charging.
Base class for battery gauge implementations.
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
uint32_t(*)(Operation op, void *param1, void *param2) CustomHalCallback
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
bool setRegBit(uint8_t reg, uint8_t bit)
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
constexpr uint32_t _bv(uint8_t b)
OperatingMode operatingMode
uint16_t tdieTemperatureRaw
CurrentSenseResistor senseResistor
float actualDieTemperature
bool currentMeasurementEnabled
bool batteryDetectionEnabled