30#include "../../../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_PMIC_AXP517
59 auto ch =
static_cast<Channel>(bit);
60 hwMask |= axp517_channelToMask(ch);
62 if (hwMask == 0)
return false;
64 if (regVal < 0)
return false;
73 auto ch =
static_cast<Channel>(bit);
74 hwMask |= axp517_channelToMask(ch);
76 if (hwMask == 0)
return false;
78 if (regVal < 0)
return false;
86 uint8_t buffer[2] = {0, 0};
95 bool vbusPresent = (buffer[0] >> 5) & 0x01;
96 bool batPresent = (buffer[0] >> 3) & 0x01;
124 adcVal = (
static_cast<int16_t
>((buffer[0] & 0x3F) << 8 | buffer[1]));
135 adcVal = (
static_cast<int16_t
>(buffer[0]) << 8) | buffer[1];
141 adcVal = ((buffer[0] & 0x3F) << 8) | buffer[1];
147 adcVal = ((buffer[0] & 0x3F) << 8) | buffer[1];
148 out = (3552.0f - adcVal) / 1.79f + 25.0f;
154 out =
static_cast<float>(buffer[0]);
160 out =
static_cast<float>(buffer[0]);
AXP517Adc(AXP517Core &core)
Construct an AXP517 ADC driver.
bool enableChannels(uint32_t mask) override
Enable one or more ADC channels.
bool read(Channel ch, float &out) override
Read an ADC channel.
bool disableChannels(uint32_t mask) override
Disable one or more ADC channels.
AXP517 low-level core driver.
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 BAT_VOLT_H
BAT voltage ADC high.
static constexpr uint8_t ENABLE
ADC channel enable control.
static constexpr uint8_t VBUS_CURR_H
VBUS current ADC high.
static constexpr uint8_t BAT_CURR_H
BAT current ADC high.
static constexpr uint8_t DATA_H
ADC data high.
static constexpr uint8_t VBUS_VOLT_H
VBUS voltage ADC high.
static constexpr uint8_t DATA_SEL
ADC data select.
static constexpr uint8_t STATUS0
BMU status0.
static constexpr float FACTORY_BAT_CURRENT
16-Bit(including sign bit)
static constexpr float FACTORY_VBUS_CURRENT
14-Bit(including sign bit)
static constexpr float FACTORY_VBAT_VOLTAGE
14-Bit(including sign bit)
static constexpr float FACTORY_VSYS_VOLTAGE
14-Bit(including sign bit)
static constexpr float FACTORY_VBUS_VOLTAGE
14-Bit(including sign bit)
static constexpr uint8_t BAT_PERCENT
Battery percentage (RO)
static constexpr uint8_t BAT_TEMP
Battery temperature (RO)