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

#include <BQ25896Adc.hpp>

Inheritance diagram for BQ25896Adc:
[legend]

Public Member Functions

 BQ25896Adc (BQ25896Core &core)
 Construct ADC interface.
 
 ~BQ25896Adc ()=default
 
bool enableChannels (uint32_t mask) override
 Enable one or more ADC channels.
 
bool disableChannels (uint32_t mask) override
 Disable ADC channels (no-op for BQ25896)
 
bool read (Channel ch, float &out) override
 Read ADC value for specified channel.
 
bool startConversion ()
 Start a single ADC conversion.
 
bool setContinuousMode (bool enable)
 Enable or disable continuous ADC mode.
 
bool enableChannels (Channel mask)
 Enable ADC channels (no-op for BQ25896)
 
virtual bool enableChannels (uint32_t mask)=0
 Enable ADC channels (no-op for BQ25896)
 
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_CONV_START = 0x80
 ADC control flags.
 
static constexpr uint8_t ADC_CONV_RATE = 0x40
 Enable continuous conversion mode (1Hz)
 

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

Definition at line 82 of file BQ25896Adc.hpp.

Constructor & Destructor Documentation

◆ BQ25896Adc()

BQ25896Adc::BQ25896Adc ( BQ25896Core core)
explicit

Construct ADC interface.

Parameters
coreReference to BQ25896 core communication

Definition at line 38 of file BQ25896Adc.cpp.

◆ ~BQ25896Adc()

BQ25896Adc::~BQ25896Adc ( )
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 BQ25896Adc::disableChannels ( uint32_t  mask)
overridevirtual

Disable ADC channels (no-op for BQ25896)

Parameters
maskChannel mask (ignored)
Returns
true always

Implements PmicAdcBase.

Definition at line 46 of file BQ25896Adc.cpp.

◆ 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 ADC channels (no-op for BQ25896)

The BQ25896 has no per-channel enable control. All ADC channels are always available. Use startConversion() or setContinuousMode() to control ADC operation.

Parameters
maskChannel mask (ignored)
Returns
true always

Definition at line 84 of file PmicAdcBase.hpp.

◆ enableChannels() [2/3]

bool BQ25896Adc::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 40 of file BQ25896Adc.cpp.

Referenced by setup().

◆ enableChannels() [3/3]

virtual bool PmicAdcBase::enableChannels ( uint32_t  mask)
virtual

Enable ADC channels (no-op for BQ25896)

The BQ25896 has no per-channel enable control. All ADC channels are always available. Use startConversion() or setContinuousMode() to control ADC operation.

Parameters
maskChannel mask (ignored)
Returns
true always

Implements PmicAdcBase.

◆ read()

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

Read ADC value for specified channel.

Reads the raw ADC value from the appropriate register and converts it to the physical value using the step values defined in BQ25896Regs.hpp.

Parameters
chADC channel to read
outReference to store the converted value
  • Voltage channels (VBUS, BAT, VSYS): millivolts (mV)
  • Current channel (BAT_CURRENT): milliamps (mA)
  • Temperature channel (BAT_TEMPERATURE): percentage (21-80%) - NOT temperature!
  • DIE_TEMPERATURE: flag (0.0 = normal, 1.0 = thermal regulation active)
Returns
true on success, false on unsupported channel or I2C error

Details

  • VBUS_VOLTAGE: Returns 0 if VBUS not present (requires isVbusPresent())
  • BAT_VOLTAGE: Returns 0 if battery not connected (ADC value = 0)
  • VSYS_VOLTAGE: Always returns valid value
  • BAT_CURRENT: Returns 0 if not charging or VBAT < VBATSHORT
  • BAT_TEMPERATURE: Returns NTC percentage (21-80%), see important note above!
  • DIE_TEMPERATURE: Returns 1.0 if thermal regulation active, 0.0 otherwise
Note
For VBUS voltage, ensure VBUS is present first using isVbusPresent() or check that the returned value is non-zero.

Implements PmicAdcBase.

Definition at line 52 of file BQ25896Adc.cpp.

References PmicAdcBase::BAT_CURRENT, PmicAdcBase::BAT_PERCENTAGE, PmicAdcBase::BAT_TEMPERATURE, PmicAdcBase::BAT_VOLTAGE, PmicAdcBase::DIE_TEMPERATURE, BQ25896Core::isCharging(), BQ25896Core::isVbusPresent(), SensorCommWrapper::readReg(), startConversion(), PmicAdcBase::VBUS_CURRENT, PmicAdcBase::VBUS_VOLTAGE, and PmicAdcBase::VSYS_VOLTAGE.

Referenced by loop().

◆ setContinuousMode()

bool BQ25896Adc::setContinuousMode ( bool  enable)

Enable or disable continuous ADC mode.

In continuous mode, the ADC performs conversions automatically at 1Hz. This is useful for real-time monitoring applications where you need the latest values available immediately when calling read().

Parameters
enabletrue to enable continuous mode, false for one-shot mode
Returns
true on success, false on I2C error
Note
Continuous mode consumes more power - disable when not needed.
When in continuous mode, CONV_START is automatically set during conversion.

Definition at line 130 of file BQ25896Adc.cpp.

References SensorCommWrapper::updateBits().

◆ startConversion()

bool BQ25896Adc::startConversion ( )

Start a single ADC conversion.

Sets the CONV_START bit to trigger a one-shot ADC conversion. This is automatically called by read() if needed, but can be called explicitly to pre-trigger conversion before reading multiple values.

Returns
true on success, false on I2C error
Note
For continuous readings, use setContinuousMode(true) instead.

Definition at line 125 of file BQ25896Adc.cpp.

References SensorCommWrapper::updateBits().

Referenced by read().

Member Data Documentation

◆ ADC_CONV_RATE

constexpr uint8_t BQ25896Adc::ADC_CONV_RATE = 0x40
staticconstexpr

Enable continuous conversion mode (1Hz)

Definition at line 90 of file BQ25896Adc.hpp.

◆ ADC_CONV_START

constexpr uint8_t BQ25896Adc::ADC_CONV_START = 0x80
staticconstexpr

ADC control flags.

Start ADC conversion

Definition at line 89 of file BQ25896Adc.hpp.

Referenced by setup().


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