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

#include <BQ25896Charger.hpp>

Inheritance diagram for BQ25896Charger:
[legend]

Public Member Functions

 BQ25896Charger (BQ25896Core &core)
 Construct charger interface.
 
 ~BQ25896Charger ()=default
 
bool enableCharging (bool enable) override
 Enable or disable charging.
 
bool isCharging () override
 Check if charging is in progress.
 
bool setPreChargeCurrent (uint16_t mA) override
 Set pre-charge current.
 
uint16_t getPreChargeCurrent () override
 Get pre-charge current.
 
bool setFastChargeCurrent (uint16_t mA) override
 Set fast charge (constant-current) current.
 
uint16_t getFastChargeCurrent () override
 Get fast charge current.
 
bool setTerminationCurrent (uint16_t mA) override
 Set termination current.
 
uint16_t getTerminationCurrent () override
 Get termination current.
 
bool setChargeVoltage (uint16_t mV) override
 Set charge voltage (constant voltage phase)
 
uint16_t getChargeVoltage () override
 Get charge voltage.
 
Status getStatus () override
 Get charger status.
 
- Public Member Functions inherited from PmicChargerBase
virtual ~PmicChargerBase ()=default
 Virtual destructor.
 

Additional Inherited Members

- Public Types inherited from PmicChargerBase
enum class  ChargingStatus : uint8_t {
  NO_CHARGING = 0 , PRE_CHARGE = 1 , FAST_CHARGE = 2 , TERMINATION = 3 ,
  UNKNOWN = 0xFF
}
 Charging status enumeration. More...
 

Detailed Description

Definition at line 67 of file BQ25896Charger.hpp.

Constructor & Destructor Documentation

◆ BQ25896Charger()

BQ25896Charger::BQ25896Charger ( BQ25896Core core)
explicit

Construct charger interface.

Parameters
coreReference to BQ25896 core communication

Definition at line 38 of file BQ25896Charger.cpp.

◆ ~BQ25896Charger()

BQ25896Charger::~BQ25896Charger ( )
default

Member Function Documentation

◆ enableCharging()

bool BQ25896Charger::enableCharging ( bool  enable)
overridevirtual

Enable or disable charging.

Enables or disables the charging function. When disabled, the charger stops all charging operations immediately.

Parameters
enabletrue to enable charging, false to disable
Returns
true on success, false on I2C error
Note
Even when enabled, charging may not start if:
  • No valid input power (VBUS not present)
  • Battery voltage is out of range
  • A fault condition exists (thermal, NTC, etc.)
See also
isCharging() to check if charging is actually happening
getStatus() for detailed charger state

Implements PmicChargerBase.

Definition at line 40 of file BQ25896Charger.cpp.

References SensorCommWrapper::updateBits().

◆ getChargeVoltage()

uint16_t BQ25896Charger::getChargeVoltage ( )
overridevirtual

Get charge voltage.

Reads the configured charge voltage from hardware.

Returns
Charge voltage in millivolts (3840-4608mV)
See also
setChargeVoltage()

Implements PmicChargerBase.

Definition at line 133 of file BQ25896Charger.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getFastChargeCurrent()

uint16_t BQ25896Charger::getFastChargeCurrent ( )
overridevirtual

Get fast charge current.

Reads the configured fast charge current from hardware.

Returns
Fast charge current in milliamps (0-3008mA)
0 if charging is disabled
See also
setFastChargeCurrent()

Implements PmicChargerBase.

Definition at line 92 of file BQ25896Charger.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getPreChargeCurrent()

uint16_t BQ25896Charger::getPreChargeCurrent ( )
overridevirtual

Get pre-charge current.

Reads the configured pre-charge current from hardware.

Returns
Pre-charge current in milliamps (64-1024mA)
See also
setPreChargeCurrent()

Implements PmicChargerBase.

Definition at line 69 of file BQ25896Charger.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getStatus()

PmicChargerBase::Status BQ25896Charger::getStatus ( )
overridevirtual

Get charger status.

Returns a comprehensive status structure containing all relevant charger state information.

Returns
Status structure containing:
  • online: Device is responding
  • vbusPresent: USB power connected
  • charging: Currently charging
  • chargeDone: Charge cycle complete
  • chargingStatus: NO_CHARGING/PRE_CHARGE/FAST_CHARGE/TERMINATION
  • fault: Any fault condition present
  • faultCode: Raw fault register value for detailed analysis
Note
The faultCode can be decoded using IRQ_* macros in BQ25896Regs.hpp

Implements PmicChargerBase.

Definition at line 144 of file BQ25896Charger.cpp.

References PmicChargerBase::Status::chargeDone, PmicChargerBase::Status::charging, PmicChargerBase::Status::chargingStatus, PmicChargerBase::FAST_CHARGE, PmicChargerBase::Status::fault, PmicChargerBase::Status::faultCode, BQ25896Core::getChargeStatus(), BQ25896Core::getFaultStatus(), BQ25896Core::isChargeDone(), BQ25896Core::isCharging(), BQ25896Core::isValid(), BQ25896Core::isVbusPresent(), PmicChargerBase::NO_CHARGING, PmicChargerBase::Status::online, PmicChargerBase::PRE_CHARGE, PmicChargerBase::TERMINATION, PmicChargerBase::UNKNOWN, and PmicChargerBase::Status::vbusPresent.

Referenced by loop().

◆ getTerminationCurrent()

uint16_t BQ25896Charger::getTerminationCurrent ( )
overridevirtual

Get termination current.

Reads the configured termination current from hardware.

Returns
Termination current in milliamps (64-1024mA)
See also
setTerminationCurrent()

Implements PmicChargerBase.

Definition at line 112 of file BQ25896Charger.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ isCharging()

bool BQ25896Charger::isCharging ( )
overridevirtual

Check if charging is in progress.

Returns the current charging state. This is a best-effort indication and may not always reflect the exact charger state.

Returns
true if charging is in progress (pre-charge or fast charge)
false if not charging (no charge, done, or disabled)
Note
Use getStatus() for more detailed state information

Implements PmicChargerBase.

Definition at line 51 of file BQ25896Charger.cpp.

References BQ25896Core::isCharging().

Referenced by loop().

◆ setChargeVoltage()

bool BQ25896Charger::setChargeVoltage ( uint16_t  mV)
overridevirtual

Set charge voltage (constant voltage phase)

Sets the target voltage during the constant voltage (CV) phase of charging. The charger maintains this voltage while the current gradually decreases.

Parameters
mVCharge voltage in millivolts (3840-4608mV) Value will be quantized to nearest valid step (16mV).
  • Input 3840-3848mV → 3840mV
  • Input 4200-4216mV → 4192mV
  • Input >4600mV → 4608mV (clamped)
Returns
true on success, false on I2C error
Note
Formula: VREG = 3.840V + [VREG] * 16mV
Default: 4.208V (VREG = 010111)
Common values: 4.2V (4200mV), 4.35V (4352mV), 4.4V (4416mV)
Warning
Do not exceed battery manufacturer's maximum voltage rating!
See also
getChargeVoltage()

Implements PmicChargerBase.

Definition at line 120 of file BQ25896Charger.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().

◆ setFastChargeCurrent()

bool BQ25896Charger::setFastChargeCurrent ( uint16_t  mA)
overridevirtual

Set fast charge (constant-current) current.

Sets the maximum charging current during the fast charge phase. This is the main charging current applied when battery voltage is above the BATLOWV threshold.

Parameters
mAFast charge current in milliamps (0-3008mA) Value will be quantized to nearest valid step (64mA).
  • Input 0-32mA → 0 (charge disabled)
  • Input 33-96mA → 64mA
  • Input 1984-2016mA → 1984mA
  • Input >3008mA → 3008mA (clamped)
Returns
true on success, false on I2C error
Note
Formula: ICHG = [ICHG] * 64mA
Setting 0 disables charging
Default: 2048mA (ICHG = 0010_0000)
Warning
Setting high charge current requires adequate thermal management. The device will reduce current if thermal regulation activates.
See also
getFastChargeCurrent()
setChargeVoltage()

Implements PmicChargerBase.

Definition at line 77 of file BQ25896Charger.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().

◆ setPreChargeCurrent()

bool BQ25896Charger::setPreChargeCurrent ( uint16_t  mA)
overridevirtual

Set pre-charge current.

Sets the current used during the pre-charge phase when battery voltage is below the BATLOWV threshold (default 3.0V).

Parameters
mAPre-charge current in milliamps (64-1024mA) Value will be quantized to nearest valid step (64mA).
  • Input 0-32mA → 64mA
  • Input 33-96mA → 64mA
  • Input 97-160mA → 128mA
  • etc.
Returns
true on success, false on I2C error
Note
Formula: IPRECHG = 64mA + [IPRECHG] * 64mA
Default: 128mA (IPRECHG = 0001)
See also
getPreChargeCurrent()
setFastChargeCurrent()

Implements PmicChargerBase.

Definition at line 56 of file BQ25896Charger.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().

◆ setTerminationCurrent()

bool BQ25896Charger::setTerminationCurrent ( uint16_t  mA)
overridevirtual

Set termination current.

Sets the current threshold used to detect charge termination. When charge current drops below this value, charging is considered complete.

Parameters
mATermination current in milliamps (64-1024mA) Value will be quantized to nearest valid step (64mA).
Returns
true on success, false on I2C error
Note
Formula: ITERM = 64mA + [ITERM] * 64mA
Default: 256mA (ITERM = 0011)
Termination detection requires EN_TERM to be enabled (default)
See also
getTerminationCurrent()
isChargeDone()

Implements PmicChargerBase.

Definition at line 99 of file BQ25896Charger.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().


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