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

#include <BQ25896Core.hpp>

Inheritance diagram for BQ25896Core:
[legend]

Public Member Functions

 BQ25896Core ()=default
 
 ~BQ25896Core ()=default
 
void end ()
 Deinitialize and release resources.
 
bool isValid () const
 Check if device is valid/present.
 
uint8_t getDeviceRevision () const
 Get device revision.
 
uint8_t getDeviceConfig ()
 Get device configuration/part number.
 
void reset ()
 Reset device to default state.
 
bool isVbusPresent ()
 Check if VBUS (USB power) is present.
 
uint8_t getBusStatus ()
 Get USB port type status.
 
uint8_t getChargeStatus ()
 Get charging status.
 
bool isPowerGood ()
 Check if power is good.
 
bool isCharging ()
 Check if actively charging.
 
bool isChargeDone ()
 Check if charging is complete.
 
bool isOtg ()
 Check if in OTG (boost) mode.
 
bool isVsysInRegulation ()
 Check if VSYS is in regulation.
 
bool isVindpmActive ()
 Get fault status.
 
bool isIindpmActive ()
 Check if IINDPM is active (input current limiting)
 
bool getFaultStatus (uint8_t &fault)
 Get fault status.
 
bool isInputCurrentOptimizerOptimized ()
 Check if Input Current Optimizer has optimized.
 
- Public Member Functions inherited from I2CDeviceWithHal
bool begin (SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
 Initialize the sensor using custom callback interface.
 
- Public Member Functions inherited from DeviceBeginCommon
virtual ~DeviceBeginCommon ()
 
uint8_t getAddress () const
 
uint8_t getInterface () const
 
- Public Member Functions inherited from SensorCommWrapper
 SensorCommWrapper ()=default
 
int readReg (uint8_t reg) const
 
int readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const
 
int readBuff (uint8_t *buf, size_t len) const
 
int writeReg (uint8_t reg, uint8_t val)
 
int writeRegBuff (uint8_t reg, uint8_t *buf, size_t len)
 
int writeBuff (uint8_t *buf, size_t len)
 
int writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
 
bool setRegBit (uint8_t reg, uint8_t bit)
 
bool clrRegBit (uint8_t reg, uint8_t bit)
 
bool getRegBit (uint8_t reg, uint8_t bit)
 
int updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted)
 
void setAddress (uint8_t address)
 
void setAck (bool enable)
 
- Public Member Functions inherited from SensorCommInterface
virtual ~SensorCommInterface ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from I2CDeviceWithHal
bool ensureValid () const override
 Ensure the communication interface is valid.
 
- Protected Member Functions inherited from DeviceBeginCommon
 DeviceBeginCommon ()=default
 
virtual SensorCommBasegetComm () const override
 
virtual void beforeBegin ()
 
virtual void afterCommReady ()
 
virtual void afterInitSuccess (uint8_t param)
 
virtual void onBeginFail ()
 
bool fail ()
 
void clearCommState ()
 
template<typename CreateComm >
bool beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm)
 
- Protected Attributes inherited from DeviceBeginCommon
std::unique_ptr< SensorCommBasecomm
 
std::unique_ptr< SensorHalhal
 
std::unique_ptr< SensorCommStaticstaticComm
 
uint8_t _addr = 0
 
uint8_t _iface = COMM_CUSTOM
 

Detailed Description

Definition at line 120 of file BQ25896Core.hpp.

Constructor & Destructor Documentation

◆ BQ25896Core()

BQ25896Core::BQ25896Core ( )
default

◆ ~BQ25896Core()

BQ25896Core::~BQ25896Core ( )
default

Member Function Documentation

◆ end()

void BQ25896Core::end ( )

Deinitialize and release resources.

Called when shutting down the device. Currently a no-op but may be used for cleanup in derived implementations.

Definition at line 38 of file BQ25896Core.cpp.

Referenced by PmicBQ25896::end().

◆ getBusStatus()

uint8_t BQ25896Core::getBusStatus ( )

Get USB port type status.

Returns the detected USB port type from REG_STATUS (0x0B). This is updated after BC1.2/HVDCP detection.

Returns
Bus state:
  • 0: No input
  • 1: USB SDP (Standard Downstream Port, 500mA)
  • 2: Adapter (3.25A)
  • 7: OTG mode
Note
CDP (Charging Downstream Port) is detected as SDP or adapter depending on DCP detection results.

Definition at line 69 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by isOtg().

◆ getChargeStatus()

uint8_t BQ25896Core::getChargeStatus ( )

Get charging status.

Returns the current charging state from REG_STATUS (0x0B).

Returns
Charge state:
  • 0: Not Charging
  • 1: Pre-charge (battery < BATLOWV threshold)
  • 2: Fast Charging (CC/CV)
  • 3: Charge Termination Done

Definition at line 75 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by BQ25896Charger::getStatus(), isChargeDone(), and isCharging().

◆ getDeviceConfig()

uint8_t BQ25896Core::getDeviceConfig ( )

Get device configuration/part number.

Reads the PN bits from REG_DEVICE_REV (0x14).

Returns
Part number configuration (0x00 for BQ25896)

Definition at line 52 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

◆ getDeviceRevision()

uint8_t BQ25896Core::getDeviceRevision ( ) const

Get device revision.

Reads the device revision from REG_DEVICE_REV (0x14). The BQ25896 returns 0x02 for the revision.

Returns
Device revision byte (0x02 for BQ25896)

Definition at line 46 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by isValid().

◆ getFaultStatus()

bool BQ25896Core::getFaultStatus ( uint8_t &  fault)

Get fault status.

Reads the fault register REG0C (0x0C) and returns the raw fault byte for detailed fault analysis.

Parameters
faultReference to store fault byte
Returns
true on success, false on I2C error

Bits

  • Bit 7 (WATCHDOG_FAULT): Watchdog timer expired
  • Bit 6 (BOOST_FAULT): Boost mode fault - VBUS overloaded, OVP, or battery too low
  • Bits 5-4 (CHRG_FAULT): Charge fault
    • 00: Normal
    • 01: Input fault (VBUS OVP or VBAT < VBUS < 3.8V)
    • 10: Thermal shutdown
    • 11: Charge safety timer expiration
  • Bit 3 (BAT_FAULT): Battery over-voltage protection triggered
  • Bits 2-0 (NTC_FAULT): NTC temperature fault
    • Buck Mode: 000=Normal, 010=Warm, 011=Cool, 101=Cold, 110=Hot
    • Boost Mode: 000=Normal, 101=Cold, 110=Hot

Definition at line 120 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by BQ25896Charger::getStatus().

◆ isChargeDone()

bool BQ25896Core::isChargeDone ( )

Check if charging is complete.

Returns true when charge status is DONE (3). Indicates the battery has reached full charge and terminated.

Returns
true if charge cycle complete

Definition at line 92 of file BQ25896Core.cpp.

References getChargeStatus().

Referenced by BQ25896Charger::getStatus().

◆ isCharging()

bool BQ25896Core::isCharging ( )

Check if actively charging.

Returns true when charge status is not NO_CHARGE. This includes both pre-charge and fast-charge phases.

Returns
true if charging is in progress
Note
Use isChargeDone() to check for charge complete.

Definition at line 87 of file BQ25896Core.cpp.

References getChargeStatus().

Referenced by BQ25896Charger::getStatus(), BQ25896Charger::isCharging(), and BQ25896Adc::read().

◆ isIindpmActive()

bool BQ25896Core::isIindpmActive ( )

Check if IINDPM is active (input current limiting)

Reads the IDPM_STAT bit from REG13 (0x13). Returns true when input current has reached the IINDPM limit.

Returns
true if IINDPM is active (input current limited)
false if input current is below IINDPM threshold
Note
This indicates the charger is drawing maximum allowed current from adapter
See also
setInputCurrentLimit() in BQ25896Power to configure IINDPM threshold

Definition at line 114 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by loop().

◆ isInputCurrentOptimizerOptimized()

bool BQ25896Core::isInputCurrentOptimizerOptimized ( )

Check if Input Current Optimizer has optimized.

Reads the ICO_OPTIMIZED bit from REG_DEVICE_REV (0x14). Returns true when ICO has determined the maximum input current.

Returns
true if ICO has completed optimization (maximum input current detected)
false if ICO is still in progress or disabled
Note
ICO (Input Current Optimizer) automatically finds the maximum input current the adapter can provide without collapsing.
This is a status flag, not a control. ICO runs automatically if enabled.
See also
ICO_EN bit in REG02 to enable/disable ICO

Definition at line 128 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by loop().

◆ isOtg()

bool BQ25896Core::isOtg ( )

Check if in OTG (boost) mode.

Returns true when bus status is OTG (7). Indicates the BQ25896 is supplying power to VBUS (5V/1A-2A).

Returns
true if OTG mode active (VBUS is output)

Definition at line 97 of file BQ25896Core.cpp.

References getBusStatus().

◆ isPowerGood()

bool BQ25896Core::isPowerGood ( )

Check if power is good.

Reads the PG_STAT bit from REG_STATUS (0x0B). Indicates valid input power (VBUS > VBUS_VALID and within spec).

Returns
true if power good (VBUS valid and within specifications)

Definition at line 81 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

◆ isValid()

bool BQ25896Core::isValid ( ) const

Check if device is valid/present.

Verifies communication by reading the device revision register and comparing against expected value (0x02).

Returns
true if device responds correctly with expected revision
Note
This should be called after begin() to verify the BQ25896 is properly connected.

Definition at line 40 of file BQ25896Core.cpp.

References getDeviceRevision().

Referenced by BQ25896Charger::getStatus().

◆ isVbusPresent()

bool BQ25896Core::isVbusPresent ( )

Check if VBUS (USB power) is present.

Reads the VBUS_GD bit from the VBUS ADC register (REG11). Returns true when VBUS voltage is above the valid threshold (≥3.8V).

Returns
true if VBUS is present and valid
Note
Returns false during boost (OTG) mode since VBUS is output, not input.
See also
getVbusVoltage() for actual voltage reading

Definition at line 63 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by BQ25896Power::enableBoost(), BQ25896Charger::getStatus(), and BQ25896Adc::read().

◆ isVindpmActive()

bool BQ25896Core::isVindpmActive ( )

Get fault status.

Reads the VDPM_STAT bit from REG13 (0x13). Returns true when input voltage has dropped to the VINDPM threshold.

Returns
true if VINDPM is active (input voltage limited)
false if input voltage is above VINDPM threshold
Note
This indicates the adapter is being loaded heavily and the charger is limiting input current to prevent the adapter from collapsing
See also
setInputVoltageLimit() in BQ25896Power to configure VINDPM threshold

Definition at line 108 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by loop().

◆ isVsysInRegulation()

bool BQ25896Core::isVsysInRegulation ( )

Check if VSYS is in regulation.

Reads the VSYS_STAT bit from REG_STATUS (0x0B). Returns true when system voltage is being regulated to SYS_MIN. This happens when battery voltage drops below the minimum system voltage.

Returns
true if VSYS is in minimum voltage regulation
Note
This typically occurs during high load or low battery conditions.

Definition at line 102 of file BQ25896Core.cpp.

References SensorCommWrapper::readReg().

Referenced by loop().

◆ reset()

void BQ25896Core::reset ( )

Reset device to default state.

Performs a register reset by setting the REG_RST bit in REG_DEVICE_REV (0x14). This resets all registers to their default values and resets the safety timer.

Definition at line 58 of file BQ25896Core.cpp.

References SensorCommWrapper::setRegBit().


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