31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
59 auto ch =
static_cast<Channel>(bit);
60 hwMask |= axp2101_channelToMask(ch);
62 if (hwMask == 0)
return false;
67 if (tsCtrl < 0)
return false;
74 if (regVal < 0)
return false;
83 auto ch =
static_cast<Channel>(bit);
84 hwMask |= axp2101_channelToMask(ch);
86 if (hwMask == 0)
return false;
90 if (tsCtrl < 0)
return false;
97 if (regVal < 0)
return false;
104 uint8_t buffer[2] = {0, 0};
110 if (status1 < 0)
return false;
111 bool vbusPresent = (status1 >> 5) & 0x01;
112 bool batPresent = (status1 >> 3) & 0x01;
153 uint16_t raw = ((buffer[0] & 0x3F) << 8) | buffer[1];
155 out = 22.0f + (7274.0f -
static_cast<float>(raw)) / 20.0f;
165 if (val < 0)
return false;
166 out =
static_cast<float>(val);
179 float voltage_mV = 0.0f;
182 if (voltage_mV == 4095.0f)
return 0.0f;
184 float voltage_V = voltage_mV / 1000.0f;
185 float resistance = voltage_V / 5e-5f;
186 float ln_r = logf(resistance);
187 float t_inv = SteinhartA + SteinhartB * ln_r + SteinhartC * powf(ln_r, 3.0f);
188 return (1.0f / t_inv) - 273.15f;
bool disableChannels(uint32_t mask) override
Disable one or more ADC channels (REG 0x30).
float getTsTemperature(float SteinhartA=1.126e-3f, float SteinhartB=2.38e-4f, float SteinhartC=8.5e-8f)
Read TS pin temperature using Steinhart-Hart equation.
bool enableChannels(uint32_t mask) override
Enable one or more ADC channels.
bool read(Channel ch, float &out) override
Read an ADC channel value.
AXP2101Adc(AXP2101Core &core)
Core I2C communication layer for the AXP2101 PMIC.
static void forEachChannel(uint32_t mask, Func fn)
Helper to iterate over set bits in a bitmask.
Channel
ADC channel bitmask.
@ BAT_PERCENTAGE
Battery percentage.
@ DIE_TEMPERATURE
Die temperature.
@ BAT_VOLTAGE
Battery voltage.
@ BAT_TEMPERATURE
Battery temperature.
@ BAT_CURRENT
Battery current.
@ VBUS_CURRENT
VBUS current.
@ VBUS_VOLTAGE
VBUS voltage.
@ VSYS_VOLTAGE
VSYS voltage.
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
int readRegBuff(uint8_t reg, uint8_t *buf, size_t len) const
static constexpr uint8_t DIE_TEMP_H
static constexpr uint8_t TS_VOLT_H
static constexpr uint8_t VSYS_VOLT_H
static constexpr uint8_t VBUS_VOLT_H
static constexpr uint8_t BAT_VOLT_H
static constexpr uint8_t CHANNEL_CTRL
static constexpr uint8_t STATUS1
static constexpr float TS_STEP
static constexpr float VBAT_STEP
static constexpr float VSYS_STEP
static constexpr float VBUS_STEP
static constexpr uint8_t BAT_PERCENT
static constexpr uint8_t TS_PIN_CTRL