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

#include <BQ25896Power.hpp>

Inheritance diagram for BQ25896Power:
[legend]

Public Member Functions

 BQ25896Power (BQ25896Core &core)
 Construct power management interface.
 
 ~BQ25896Power ()=default
 
bool setMinimumSystemVoltage (uint32_t mv) override
 Set minimum system voltage.
 
uint32_t getMinimumSystemVoltage () const override
 Get minimum system voltage.
 
bool setInputVoltageLimit (uint32_t mv) override
 Set input voltage limit (VINDPM)
 
uint32_t getInputVoltageLimit () const override
 Get input voltage limit.
 
bool setInputCurrentLimit (uint32_t mA) override
 Set input current limit.
 
uint32_t getInputCurrentLimit () const override
 Get input current limit.
 
bool enableBoost (bool enable) override
 Enable or disable OTG (boost) mode.
 
bool isBoostEnabled () const override
 Check if boost mode is enabled.
 
bool setBoostVoltage (uint16_t mv) override
 Set boost output voltage.
 
uint16_t getBoostVoltage () const override
 Get boost output voltage.
 
bool enableShipMode (bool enable) override
 Enable or disable ship mode.
 
bool isShipModeEnabled () const override
 Check if ship mode is enabled.
 
bool enableWatchdog (bool enable) override
 Enable or disable the I2C watchdog timer.
 
bool isWatchdogEnabled () const override
 Check if watchdog is enabled.
 
bool setWatchdogTimeout (uint16_t timeout_s) override
 Set the watchdog timeout duration.
 
uint16_t getWatchdogTimeout () const override
 Get the current watchdog timeout setting.
 
bool resetWatchdog () override
 Reset the watchdog timer (feed the watchdog)
 
- Public Member Functions inherited from PmicPowerBase
virtual ~PmicPowerBase ()=default
 Virtual destructor.
 
- Public Member Functions inherited from PmicWatchdogBase
virtual ~PmicWatchdogBase ()=default
 Virtual destructor.
 

Detailed Description

Definition at line 85 of file BQ25896Power.hpp.

Constructor & Destructor Documentation

◆ BQ25896Power()

BQ25896Power::BQ25896Power ( BQ25896Core core)
explicit

Construct power management interface.

Parameters
coreReference to BQ25896 core communication

Definition at line 38 of file BQ25896Power.cpp.

◆ ~BQ25896Power()

BQ25896Power::~BQ25896Power ( )
default

Member Function Documentation

◆ enableBoost()

bool BQ25896Power::enableBoost ( bool  enable)
overridevirtual

Enable or disable OTG (boost) mode.

Enables or disables the boost (OTG) mode. When enabled, the BQ25896 operates as a power source, converting battery voltage to 5V on VBUS to power external USB devices (phones, tablets, accessories).

Parameters
enabletrue to enable boost/OTG mode, false to disable
Returns
true on success, false on I2C error or VBUS present
Warning
Boost mode cannot be enabled when VBUS is connected! The method will return false if VBUS is detected.
Note
Before enabling boost:
  • Ensure no USB cable is connected to VBUS input
  • Battery voltage must be above minimum threshold
  • Battery must have sufficient charge
Default boost voltage: 4.998V (BOOSTV = 0111)
Default boost current limit: 1.4A (BOOST_LIM = 011)
See also
isBoostEnabled()
setBoostVoltage()
getBoostVoltage()

Reimplemented from PmicPowerBase.

Definition at line 103 of file BQ25896Power.cpp.

References BQ25896Core::isVbusPresent(), and SensorCommWrapper::updateBits().

◆ enableShipMode()

bool BQ25896Power::enableShipMode ( bool  enable)
overridevirtual

Enable or disable ship mode.

Ship mode disconnects the battery from the system by turning off the BATFET. This is used for:

  • Shipping mode (device stored for long periods)
  • Complete power off when no external power is available

When ship mode is enabled and no VBUS is present, the system is completely powered down (only the charger IC remains in low-power mode).

Parameters
enabletrue to enter ship mode (battery disconnected), false to exit
Returns
true on success, false on I2C error
Note
To exit ship mode, connect VBUS. The BATFET will automatically turn on when valid VBUS is detected.
This function writes to REG09 BATFET_DIS bit.
See also
isShipModeEnabled()

Reimplemented from PmicPowerBase.

Definition at line 142 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

◆ enableWatchdog()

bool BQ25896Power::enableWatchdog ( bool  enable)
overridevirtual

Enable or disable the I2C watchdog timer.

When enabled, the watchdog monitors I2C communication. If no I2C access occurs within the timeout period, the PMIC will reset and restore default register values.

Parameters
enabletrue to enable watchdog (default 40s timeout), false to disable
Returns
true on success, false on I2C error
Note
When watchdog expires, register settings are reset to defaults. Call resetWatchdog() regularly to prevent this.
This function controls REG07 WATCHDOG[1:0] bits.
See also
setWatchdogTimeout()
resetWatchdog()
isWatchdogEnabled()

Implements PmicWatchdogBase.

Definition at line 154 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

◆ getBoostVoltage()

uint16_t BQ25896Power::getBoostVoltage ( ) const
overridevirtual

Get boost output voltage.

Reads the configured boost voltage.

Returns
Boost voltage in millivolts (4550-5510mV)

Reimplemented from PmicPowerBase.

Definition at line 134 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

Referenced by loop().

◆ getInputCurrentLimit()

uint32_t BQ25896Power::getInputCurrentLimit ( ) const
overridevirtual

Get input current limit.

Reads the configured input current limit.

Returns
Input current limit in milliamps

Implements PmicPowerBase.

Definition at line 96 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getInputVoltageLimit()

uint32_t BQ25896Power::getInputVoltageLimit ( ) const
overridevirtual

Get input voltage limit.

Reads the configured VINDPM threshold.

Returns
Input voltage limit in millivolts

Implements PmicPowerBase.

Definition at line 74 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getMinimumSystemVoltage()

uint32_t BQ25896Power::getMinimumSystemVoltage ( ) const
overridevirtual

Get minimum system voltage.

Reads the configured minimum system voltage.

Returns
Minimum system voltage in millivolts

Implements PmicPowerBase.

Definition at line 53 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

Referenced by setup().

◆ getWatchdogTimeout()

uint16_t BQ25896Power::getWatchdogTimeout ( ) const
overridevirtual

Get the current watchdog timeout setting.

Returns
Timeout in seconds (0 if disabled, or 40/80/160)
See also
setWatchdogTimeout()

Implements PmicWatchdogBase.

Definition at line 185 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

◆ isBoostEnabled()

bool BQ25896Power::isBoostEnabled ( ) const
overridevirtual

Check if boost mode is enabled.

Returns the current boost/OTG mode status.

Returns
true if boost mode is active (supplying power to VBUS)
false if boost mode is disabled

Reimplemented from PmicPowerBase.

Definition at line 115 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

Referenced by loop().

◆ isShipModeEnabled()

bool BQ25896Power::isShipModeEnabled ( ) const
overridevirtual

Check if ship mode is enabled.

Reads the BATFET_DIS bit from REG09 to determine if ship mode is active.

Returns
true if ship mode is active (battery disconnected)
false if ship mode is disabled (battery connected)
See also
enableShipMode()

Reimplemented from PmicPowerBase.

Definition at line 148 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

◆ isWatchdogEnabled()

bool BQ25896Power::isWatchdogEnabled ( ) const
overridevirtual

Check if watchdog is enabled.

Returns
true if watchdog is enabled, false if disabled
See also
enableWatchdog()

Implements PmicWatchdogBase.

Definition at line 163 of file BQ25896Power.cpp.

References SensorCommWrapper::readReg().

◆ resetWatchdog()

bool BQ25896Power::resetWatchdog ( )
overridevirtual

Reset the watchdog timer (feed the watchdog)

This must be called regularly before the watchdog timeout expires to prevent the PMIC from resetting due to I2C communication timeout.

Returns
true on success, false on I2C error
Note
Should be called at least once before the watchdog timeout. Recommended to call every 20-30 seconds for 40s timeout.
This function writes to REG03 WD_RST bit (self-clearing).
See also
enableWatchdog()
setWatchdogTimeout()

Implements PmicWatchdogBase.

Definition at line 194 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

◆ setBoostVoltage()

bool BQ25896Power::setBoostVoltage ( uint16_t  mv)
overridevirtual

Set boost output voltage.

Sets the output voltage when in OTG boost mode. This is the voltage that appears on VBUS when operating as a power source.

Parameters
mvBoost voltage in millivolts (4550-5510mV) Value will be quantized to nearest valid step (64mV).
Returns
true on success, false on I2C error
Note
Formula: VBOOST = 4.55V + [BOOSTV] * 64mV
Default: 4.998V (BOOSTV = 0111)
Common values: 5V (5000mV), 5.1V (5184mV), 5.2V (5248mV)
Cannot change boost voltage while boost is enabled. Disable boost first, then change voltage.
See also
getBoostVoltage()
enableBoost()

Reimplemented from PmicPowerBase.

Definition at line 121 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

◆ setInputCurrentLimit()

bool BQ25896Power::setInputCurrentLimit ( uint32_t  mA)
overridevirtual

Set input current limit.

Sets the maximum input current drawn from VBUS. This prevents the charger from drawing more current than the adapter can provide.

The actual limit is the lower of this setting and the ILIM pin (if EN_ILIM is enabled).

Parameters
mAInput current limit in milliamps (100-3250mA) Value will be quantized to nearest valid step (50mA).
Returns
true on success, false on I2C error
Note
Formula: IINLIM = 100mA + [IINLIM] * 50mA
Default: 500mA (IINLIM = 001000)
Range: 100mA (000000) to 3250mA (111111)
The Input Current Optimizer (ICO) can automatically detect the maximum safe input current. Enable via REG02 ICO_EN.
See also
getInputCurrentLimit()
isIindpmActive() to check if current limiting is active

Implements PmicPowerBase.

Definition at line 83 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().

◆ setInputVoltageLimit()

bool BQ25896Power::setInputVoltageLimit ( uint32_t  mv)
overridevirtual

Set input voltage limit (VINDPM)

Sets the VINDPM threshold - the minimum voltage the input source is allowed to be pulled down to. This protects weak or low-quality adapters from being overloaded.

When VBUS voltage drops to this threshold, the charger automatically reduces input current to prevent the adapter from collapsing.

Parameters
mvInput voltage limit in millivolts (3900-15300mV) Value will be quantized to nearest valid step (100mV).
Returns
true on success, false on I2C error
Note
Formula: VINDPM = 2.6V + [VINDPM] * 100mV (absolute mode)
Minimum clamped at 3.9V
Default: 4.4V (VINDPM = 0010010)
The BQ25896 supports both relative and absolute VINDPM modes:
  • Relative mode: VINDPM offset from VBUS no-load voltage
  • Absolute mode: Fixed voltage threshold (this method)
See also
getInputVoltageLimit()
isVindpmActive() to check if VINDPM is active

Implements PmicPowerBase.

Definition at line 61 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().

◆ setMinimumSystemVoltage()

bool BQ25896Power::setMinimumSystemVoltage ( uint32_t  mv)
overridevirtual

Set minimum system voltage.

Sets the minimum VSYS voltage threshold. VSYS is the charger output that powers the system load. During high load or low battery conditions, VSYS may drop but will not go below this value.

Parameters
mvMinimum system voltage in millivolts (3000-3700mV) Value will be quantized to nearest valid step (100mV).
Returns
true on success, false on I2C error
Note
Formula: SYS_MIN = 3.0V + [SYS_MIN] * 0.1V
Default: 3.5V (SYS_MIN = 101)
Range: 3000mV (000) to 3700mV (111)
See also
getMinimumSystemVoltage()

Implements PmicPowerBase.

Definition at line 40 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().

Referenced by setup().

◆ setWatchdogTimeout()

bool BQ25896Power::setWatchdogTimeout ( uint16_t  timeout_s)
overridevirtual

Set the watchdog timeout duration.

Sets how long the watchdog will wait before triggering a fault. Must be called after enableWatchdog(true).

Parameters
timeout_sTimeout in seconds (0=disabled, values >0 enable watchdog) Valid chip values: 0, 40, 80, 160 seconds. Other values will be clamped.
Returns
true on success, false on I2C error
Note
Default timeout after enableWatchdog(true) is 40 seconds.
See also
enableWatchdog()
getWatchdogTimeout()

Implements PmicWatchdogBase.

Definition at line 170 of file BQ25896Power.cpp.

References SensorCommWrapper::updateBits().


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