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

#include <PmicAdcBase.hpp>

Inheritance diagram for PmicAdcBase:
[legend]

Public Types

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...
 

Public Member Functions

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.
 
virtual bool enableChannels (uint32_t mask)=0
 Enable one or more ADC channels.
 
virtual bool disableChannels (uint32_t mask)=0
 Disable one or more ADC channels.
 
virtual bool read (Channel ch, float &out)=0
 Read a single ADC channel value.
 

Static Protected Member Functions

template<typename Func >
static void forEachChannel (uint32_t mask, Func fn)
 Helper to iterate over set bits in a bitmask.
 

Detailed Description

Definition at line 44 of file PmicAdcBase.hpp.

Member Enumeration Documentation

◆ Channel

enum class PmicAdcBase::Channel : uint16_t
strong

ADC channel bitmask.

Each common channel occupies a unique bit position so they can be combined with bitwise OR for batch enable/disable operations.

These values are passed directly to enableChannels(uint32_t). Subclasses may define additional chip-specific mask values beyond what is defined here (e.g. GPIO ADC channels).

Note
Values 0-9 are reserved for common channels. Subclasses may use higher bits for chip-specific channels.
Enumerator
VBUS_VOLTAGE 

VBUS voltage.

VBUS_CURRENT 

VBUS current.

BAT_VOLTAGE 

Battery voltage.

BAT_CURRENT 

Battery current.

VSYS_VOLTAGE 

VSYS voltage.

DIE_TEMPERATURE 

Die temperature.

BAT_TEMPERATURE 

Battery temperature.

BAT_PERCENTAGE 

Battery percentage.

ACIN_VOLTAGE 

ACIN voltage.

ACIN_CURRENT 

ACIN current.

Definition at line 60 of file PmicAdcBase.hpp.

Constructor & Destructor Documentation

◆ ~PmicAdcBase()

virtual PmicAdcBase::~PmicAdcBase ( )
virtualdefault

Member Function Documentation

◆ disableChannels() [1/2]

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.

References disableChannels().

Referenced by disableChannels().

◆ disableChannels() [2/2]

◆ enableChannels() [1/2]

bool PmicAdcBase::enableChannels ( Channel  mask)
inline

Enable one or more ADC channels by Channel enum.

Convenience overload that accepts Channel values directly without explicit cast. Delegates to enableChannels(uint32_t).

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

Definition at line 84 of file PmicAdcBase.hpp.

References enableChannels().

Referenced by enableChannels().

◆ enableChannels() [2/2]

virtual bool PmicAdcBase::enableChannels ( uint32_t  mask)
pure virtual

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.

Implemented in SY6970Adc, BQ25896Adc, axp1xx::AXP1xxAdc< CoreType, RegTraits >, axp1xx::AXP1xxAdc< AXP192Core, axp1xx::AdcTraitsBase< AXP192Core > >, axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >, AXP2101Adc, AXP517Adc, SY6970Adc, BQ25896Adc, axp1xx::AXP1xxAdc< CoreType, RegTraits >, axp1xx::AXP1xxAdc< AXP192Core, axp1xx::AdcTraitsBase< AXP192Core > >, axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >, AXP2101Adc, and AXP517Adc.

◆ forEachChannel()

template<typename Func >
static void PmicAdcBase::forEachChannel ( uint32_t  mask,
Func  fn 
)
inlinestaticprotected

Helper to iterate over set bits in a bitmask.

Usage in subclass implementations:

forEachBit(mask, [](uint32_t bit) {
// handle each individual bit
});
Parameters
maskBitmask to iterate
fnCallback invoked for each set bit

Definition at line 141 of file PmicAdcBase.hpp.

Referenced by AXP2101Adc::disableChannels(), AXP517Adc::disableChannels(), AXP2101Adc::enableChannels(), and AXP517Adc::enableChannels().

◆ read()

virtual bool PmicAdcBase::read ( Channel  ch,
float &  out 
)
pure virtual

Read a single ADC channel value.

Parameters
chSingle channel to read (must be a single bit, not a combination).
outOutput variable for the channel value in physical units.
Returns
True on success, false on failure.

Implemented in SY6970Adc, BQ25896Adc, axp1xx::AXP1xxAdc< CoreType, RegTraits >, axp1xx::AXP1xxAdc< AXP192Core, axp1xx::AdcTraitsBase< AXP192Core > >, axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >, AXP2101Adc, and AXP517Adc.

Referenced by loop().


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