SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
axp1xx::AdcTraitsBase< CoreType > Class Template Reference

Base traits class for AXP1xxAdc template specialization. More...

#include <AXP1xxAdcTraits.hpp>

Static Public Member Functions

static uint32_t getChannelMask (PmicAdcBase::Channel ch)
 Map a Channel enum to its hardware enable mask.
 
static bool hasSpecialEnablement (PmicAdcBase::Channel ch)
 Check if a channel requires special enablement logic.
 
static bool enableSpecialChannel (CoreType &core, PmicAdcBase::Channel ch)
 Perform special channel enablement.
 
static bool disableSpecialChannel (CoreType &core, PmicAdcBase::Channel ch)
 Perform special channel disablement.
 
static bool readChannel (CoreType &core, PmicAdcBase::Channel ch, float &out)
 Main ADC channel reading implementation.
 

Static Public Attributes

static constexpr uint8_t ADC_EN1_ADDR = 0x82
 ADC_EN1 register address.
 
static constexpr uint8_t ADC_EN2_ADDR = 0x83
 ADC_EN2 register address.
 

Detailed Description

template<typename CoreType>
class axp1xx::AdcTraitsBase< CoreType >

Base traits class for AXP1xxAdc template specialization.

Specializations of this class must provide:

  1. Static register addresses (ADC_EN1_ADDR, ADC_EN2_ADDR)
  2. Channel mask mapping function (getChannelMask)
  3. Special enablement/disablement handlers (for TS pin, etc.)
  4. Main channel reading logic (readChannel)

The design uses static polymorphism (templates) rather than virtual functions to avoid vtable overhead and enable compiler optimizations.

Template Parameters
CoreTypeThe I2C communication core type (unused in base, required for specializations)

Definition at line 53 of file AXP1xxAdcTraits.hpp.

Member Function Documentation

◆ disableSpecialChannel()

template<typename CoreType >
static bool axp1xx::AdcTraitsBase< CoreType >::disableSpecialChannel ( CoreType &  core,
PmicAdcBase::Channel  ch 
)
inlinestatic

Perform special channel disablement.

Called by AXP1xxAdc::disableChannels() for channels where hasSpecialEnablement() returns true.

Parameters
coreReference to I2C communication core
chThe channel to disable
Returns
true on success

Definition at line 136 of file AXP1xxAdcTraits.hpp.

◆ enableSpecialChannel()

template<typename CoreType >
static bool axp1xx::AdcTraitsBase< CoreType >::enableSpecialChannel ( CoreType &  core,
PmicAdcBase::Channel  ch 
)
inlinestatic

Perform special channel enablement.

Called by AXP1xxAdc::enableChannels() for channels where hasSpecialEnablement() returns true. Implementations should perform chip-specific register writes outside the standard ADC enable procedure.

Default implementation is a no-op.

Parameters
coreReference to I2C communication core
chThe channel to enable
Returns
true on success

Definition at line 119 of file AXP1xxAdcTraits.hpp.

◆ getChannelMask()

template<typename CoreType >
static uint32_t axp1xx::AdcTraitsBase< CoreType >::getChannelMask ( PmicAdcBase::Channel  ch)
inlinestatic

Map a Channel enum to its hardware enable mask.

Returns the bitmask(s) that must be set in the ADC enable registers to activate the given channel. The mask is split into:

  • Lower 8 bits: bits for ADC_EN1 register
  • Upper 8 bits: bits for ADC_EN2 register
Parameters
chChannel from PmicAdcBase::Channel enum
Returns
Enable mask, or 0 if channel is not supported

Definition at line 83 of file AXP1xxAdcTraits.hpp.

◆ hasSpecialEnablement()

template<typename CoreType >
static bool axp1xx::AdcTraitsBase< CoreType >::hasSpecialEnablement ( PmicAdcBase::Channel  ch)
inlinestatic

Check if a channel requires special enablement logic.

Some channels need custom handling outside the standard ADC enable register writes. For example, AXP2101's TS pin requires configuration in a separate TS_PIN_CTRL register.

Parameters
chThe channel to check
Returns
true if enableSpecialChannel() must be called

Definition at line 99 of file AXP1xxAdcTraits.hpp.

◆ readChannel()

template<typename CoreType >
static bool axp1xx::AdcTraitsBase< CoreType >::readChannel ( CoreType &  core,
PmicAdcBase::Channel  ch,
float &  out 
)
inlinestatic

Main ADC channel reading implementation.

This is the workhorse method that handles all channel-specific register reads, conversions, and state checks. Must be specialized for each PMIC variant.

Implementations should:

  1. Check device state (VBUS present, battery present, charging, etc.)
  2. Read ADC registers (using readH8L4, readH8L5 helpers)
  3. Apply conversion factors
  4. Return true on success, false on error
Parameters
coreReference to I2C communication core
chChannel to read
outReference to output float
Returns
true on success

Definition at line 161 of file AXP1xxAdcTraits.hpp.

Member Data Documentation

◆ ADC_EN1_ADDR

template<typename CoreType >
constexpr uint8_t axp1xx::AdcTraitsBase< CoreType >::ADC_EN1_ADDR = 0x82
staticconstexpr

ADC_EN1 register address.

This is the primary ADC enable register, typically containing channel enable bits for 0-7 (VBUS, VBUS_CUR, APS, TS, BAT, ACIN, etc.)

Definition at line 62 of file AXP1xxAdcTraits.hpp.

◆ ADC_EN2_ADDR

template<typename CoreType >
constexpr uint8_t axp1xx::AdcTraitsBase< CoreType >::ADC_EN2_ADDR = 0x83
staticconstexpr

ADC_EN2 register address.

Optional secondary ADC enable register for additional channels. Set to same value as ADC_EN1_ADDR if not used.

Definition at line 70 of file AXP1xxAdcTraits.hpp.


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