SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP2101Adc Class Reference

ADC control for the AXP2101 PMIC. More...

#include <AXP2101Adc.hpp>

Inheritance diagram for AXP2101Adc:
[legend]

Public Member Functions

 AXP2101Adc (AXP2101Core &core)
 
 ~AXP2101Adc ()=default
 
bool enableChannels (uint32_t mask) override
 Enable one or more ADC channels.
 
bool disableChannels (uint32_t mask) override
 Disable one or more ADC channels (REG 0x30).
 
bool read (Channel ch, float &out) override
 Read an ADC channel value.
 
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 (Channel mask)
 Enable one or more ADC channels (REG 0x30).
 
virtual bool enableChannels (uint32_t mask)=0
 Enable one or more ADC channels (REG 0x30).
 
bool disableChannels (Channel mask)
 Disable one or more ADC channels by Channel enum.
 
virtual bool disableChannels (uint32_t mask)=0
 Disable one or more ADC channels.
 
- Public Member Functions inherited from PmicAdcBase
virtual ~PmicAdcBase ()=default
 
bool enableChannels (Channel mask)
 Enable one or more ADC channels by Channel enum.
 
bool disableChannels (Channel mask)
 Disable one or more ADC channels by Channel enum.
 

Static Public Attributes

static constexpr uint8_t ADC_DIE_TEMP_HW = 0x10
 
static constexpr uint8_t ADC_SYSTEM_VOLTAGE_HW = 0x08
 
static constexpr uint8_t ADC_VBUS_VOLTAGE_HW = 0x04
 
static constexpr uint8_t ADC_TS_PIN_HW = 0x02
 
static constexpr uint8_t ADC_BAT_VOLTAGE_HW = 0x01
 

Additional Inherited Members

- Public Types inherited from PmicAdcBase
enum class  Channel : uint16_t {
  VBUS_VOLTAGE = (1 << 0) , VBUS_CURRENT = (1 << 1) , BAT_VOLTAGE = (1 << 2) , BAT_CURRENT = (1 << 3) ,
  VSYS_VOLTAGE = (1 << 4) , DIE_TEMPERATURE = (1 << 5) , BAT_TEMPERATURE = (1 << 6) , BAT_PERCENTAGE = (1 << 7) ,
  ACIN_VOLTAGE = (1 << 8) , ACIN_CURRENT = (1 << 9)
}
 ADC channel bitmask. More...
 
- Static Protected Member Functions inherited from PmicAdcBase
template<typename Func >
static void forEachChannel (uint32_t mask, Func fn)
 Helper to iterate over set bits in a bitmask.
 

Detailed Description

ADC control for the AXP2101 PMIC.

Provides access to the 14-bit SAR ADC for measuring battery voltage, VBUS voltage, VSYS voltage, TS pin voltage (thermistor), die temperature, and battery percentage via the fuel gauge.

Channels

Channel Register Resolution Unit
VBAT voltage 0x34-0x35 14-bit 1 mV
VBUS voltage 0x38-0x39 14-bit 1 mV
VSYS voltage 0x3A-0x3B 14-bit 1 mV
TS pin voltage 0x36-0x37 14-bit 0.5 mV
Die temperature 0x3C-0x3D 14-bit formula
Battery percentage 0xA4 8-bit 1 %

Definition at line 52 of file AXP2101Adc.hpp.

Constructor & Destructor Documentation

◆ AXP2101Adc()

AXP2101Adc::AXP2101Adc ( AXP2101Core core)
explicit

Definition at line 39 of file AXP2101Adc.cpp.

◆ ~AXP2101Adc()

AXP2101Adc::~AXP2101Adc ( )
default

Member Function Documentation

◆ disableChannels() [1/3]

bool PmicAdcBase::disableChannels ( Channel  mask)
inline

Disable one or more ADC channels by Channel enum.

Parameters
maskBitwise OR of Channel values to disable.
Returns
True on success, false on failure.

Definition at line 94 of file PmicAdcBase.hpp.

◆ disableChannels() [2/3]

bool AXP2101Adc::disableChannels ( uint32_t  mask)
overridevirtual

Disable one or more ADC channels (REG 0x30).

Parameters
maskBitwise OR of Channel values to disable.
Returns
true on success.

Implements PmicAdcBase.

Definition at line 79 of file AXP2101Adc.cpp.

References axp2101_regs::adc::CHANNEL_CTRL, PmicAdcBase::forEachChannel(), SensorCommWrapper::readReg(), axp2101_regs::ts::TS_PIN_CTRL, and SensorCommWrapper::writeReg().

◆ disableChannels() [3/3]

virtual bool PmicAdcBase::disableChannels ( uint32_t  mask)
virtual

Disable one or more ADC channels.

Parameters
maskBitmask of channels to disable.
Returns
True on success, false on failure.

Implements PmicAdcBase.

◆ enableChannels() [1/3]

bool PmicAdcBase::enableChannels ( Channel  mask)
inline

Enable one or more ADC channels (REG 0x30).

Parameters
maskBitwise OR of Channel values to enable.
Returns
true on success.

Definition at line 84 of file PmicAdcBase.hpp.

◆ enableChannels() [2/3]

bool AXP2101Adc::enableChannels ( uint32_t  mask)
overridevirtual

Enable one or more ADC channels.

Accepts Channel bitmask values. Common channels (Channel::XXX) can be combined with bitwise OR. Subclasses may also accept chip-specific mask values for channels not in the Channel enum.

Parameters
maskBitmask of channels to enable.
Returns
True on success, false on failure.

Implements PmicAdcBase.

Definition at line 55 of file AXP2101Adc.cpp.

References axp2101_regs::adc::CHANNEL_CTRL, PmicAdcBase::forEachChannel(), SensorCommWrapper::readReg(), axp2101_regs::ts::TS_PIN_CTRL, and SensorCommWrapper::writeReg().

Referenced by setup().

◆ enableChannels() [3/3]

virtual bool PmicAdcBase::enableChannels ( uint32_t  mask)
virtual

Enable one or more ADC channels (REG 0x30).

Parameters
maskBitwise OR of Channel values to enable.
Returns
true on success.

Implements PmicAdcBase.

◆ getTsTemperature()

float AXP2101Adc::getTsTemperature ( float  SteinhartA = 1.126e-3f,
float  SteinhartB = 2.38e-4f,
float  SteinhartC = 8.5e-8f 
)

Read TS pin temperature using Steinhart-Hart equation.

Converts the raw TS ADC voltage to temperature in Celsius using the Steinhart-Hart thermistor equation: 1/T = A + B*ln(R) + C*ln(R)^3 where R = V_ts / I_source (default 50uA).

Parameters
SteinhartACoefficient A (default 1.126e-3 for 10k NTC).
SteinhartBCoefficient B (default 2.38e-4 for 10k NTC).
SteinhartCCoefficient C (default 8.5e-8 for 10k NTC).
Returns
Temperature in degrees Celsius. Returns 0.0f on error or if the ADC reading is saturated.

Definition at line 177 of file AXP2101Adc.cpp.

References PmicAdcBase::BAT_TEMPERATURE, and read().

◆ read()

bool AXP2101Adc::read ( Channel  ch,
float &  out 
)
overridevirtual

Read an ADC channel value.

For VBUS/BAT voltage channels, returns 0.0 if the source is not present. VBUS_CURRENT and BAT_CURRENT are not supported (return 0.0).

Parameters
chChannel to read.
[out]outResult value. Units depend on channel:
  • Voltage channels: millivolts (mV)
  • DIE_TEMPERATURE: degrees Celsius
  • BAT_TEMPERATURE: millivolts (raw TS pin voltage * 0.5)
  • BAT_PERCENTAGE: percentage (0-100)
Returns
true on success.

Implements PmicAdcBase.

Definition at line 102 of file AXP2101Adc.cpp.

References PmicAdcBase::BAT_CURRENT, axp2101_regs::gauge::BAT_PERCENT, PmicAdcBase::BAT_PERCENTAGE, PmicAdcBase::BAT_TEMPERATURE, axp2101_regs::adc::BAT_VOLT_H, PmicAdcBase::BAT_VOLTAGE, axp2101_regs::adc::DIE_TEMP_H, PmicAdcBase::DIE_TEMPERATURE, SensorCommWrapper::readReg(), SensorCommWrapper::readRegBuff(), axp2101_regs::bmu::STATUS1, axp2101_regs::factory::TS_STEP, axp2101_regs::adc::TS_VOLT_H, axp2101_regs::factory::VBAT_STEP, PmicAdcBase::VBUS_CURRENT, axp2101_regs::factory::VBUS_STEP, axp2101_regs::adc::VBUS_VOLT_H, PmicAdcBase::VBUS_VOLTAGE, axp2101_regs::factory::VSYS_STEP, axp2101_regs::adc::VSYS_VOLT_H, and PmicAdcBase::VSYS_VOLTAGE.

Referenced by getTsTemperature().

Member Data Documentation

◆ ADC_BAT_VOLTAGE_HW

constexpr uint8_t AXP2101Adc::ADC_BAT_VOLTAGE_HW = 0x01
staticconstexpr

Definition at line 60 of file AXP2101Adc.hpp.

◆ ADC_DIE_TEMP_HW

constexpr uint8_t AXP2101Adc::ADC_DIE_TEMP_HW = 0x10
staticconstexpr

Definition at line 56 of file AXP2101Adc.hpp.

◆ ADC_SYSTEM_VOLTAGE_HW

constexpr uint8_t AXP2101Adc::ADC_SYSTEM_VOLTAGE_HW = 0x08
staticconstexpr

Definition at line 57 of file AXP2101Adc.hpp.

◆ ADC_TS_PIN_HW

constexpr uint8_t AXP2101Adc::ADC_TS_PIN_HW = 0x02
staticconstexpr

Definition at line 59 of file AXP2101Adc.hpp.

◆ ADC_VBUS_VOLTAGE_HW

constexpr uint8_t AXP2101Adc::ADC_VBUS_VOLTAGE_HW = 0x04
staticconstexpr

Definition at line 58 of file AXP2101Adc.hpp.


The documentation for this class was generated from the following files: