Integration Guide
CMake
Library
add_subdirectory(bq25180)
target_link_libraries(${YOUR_PROJECT} bq25180)
FetchContent
include(FetchContent)
FetchContent_Declare(bq25180
GIT_REPOSITORY https://github.com/libmcu/bq25180.git
GIT_TAG main
)
FetchContent_MakeAvailable(bq25180)
Source files
include(sources.cmake)
add_executable(${YOUR_PROJECT} ${BQ25180_SRCS})
target_include_directories(${YOUR_PROJECT} ${BQ25180_INCS})
Make
include sources.mk
SRCS += BQ25180_SRCS
INCS += BQ25180_INCS
API
Functions
-
void bq25180_reset(bool hardware_reset)
Reset the system.
The device will reset all of the registers to the defaults. A hardware reset to completely powercycle the system.
Note
A hardware or software reset will cancel the pending shipmode request.
- Parameters:
hardware_reset – [in] hardware reset if true while soft reset if false
-
bool bq25180_read_event(struct bq25180_event *p)
Read the device events.
- Parameters:
p – [in] bq25180_event
- Returns:
true on success or false
-
bool bq25180_read_state(struct bq25180_state *p)
Read the device state.
- Parameters:
p – [in] bq25180_state
- Returns:
true on success or false
-
void bq25180_enable_battery_charging(bool enable)
Enable or disable battery charging.
- Parameters:
enable – [in] battery charging to be enabled if true or false to be disabled
-
void bq25180_set_safety_timer(enum bq25180_safety_timer opt)
Set the safety time.
If charging has not terminated before the programmed safety time, charging is disabled.
When the safety timer is active, changing the safety timer duration resets the safety timer.
6 hour by default on reset.
- Parameters:
opt – [in] one of bq25180_safety_timer
-
void bq25180_set_watchdog_timer(enum bq25180_watchdog opt)
Set the watchdog time.
Once the initial transaction is received, the watchdog timer is started. The watchdog timer is reset by any transaction by the host using the I2C interface. If the watchdog timer expires without a reset from the I2C interface, all charger parameters registers are reset to the default values.
160 sec by default on reset.
- Parameters:
opt – [in] one of bq25180_watchdog
-
void bq25180_set_battery_regulation_voltage(uint16_t millivoltage)
Set the battery regulation target.
The charging current starts tapering off once the battery voltage approches the battery regulation target.
4200mV by default on reset.
- Parameters:
millivoltage – [in] from 3500mV up to 4650mV
-
void bq25180_set_battery_discharge_current(enum bq25180_bat_discharge_current opt)
Set the battery discharge current limit.
BQ25180_BAT_DISCHAGE_500mA by default on reset.
- Parameters:
opt – [in] one of bq25180_bat_discharge_current
-
void bq25180_set_battery_under_voltage(uint16_t millivoltage)
Set battery undervoltage lockout falling threshold.
When voltage at the battery drops below the configured, the BAT and SYS path gets disengaged.
The below levels are supported:
3000mV
2800mV
2600mV
2400mV
2200mV
2000mV
3000mV by default on reset.
- Parameters:
millivoltage – [in] from 2000mV up to 3000mV
-
void bq25180_set_precharge_threshold(uint16_t millivoltage)
Set the precharge voltage threshold.
3000mV by default on reset.
- Parameters:
millivoltage – [in] either of 2800mV or 3000mV only
-
void bq25180_set_precharge_current(bool double_termination_current)
Set the precharge current.
The precharge current is the same to the termination current by default on reset.
- Parameters:
double_termination_current – [in] double of termination current if true or same to the termination current if false
-
void bq25180_set_fastcharge_current(uint16_t milliampere)
Set the maximum charge current level.
10mA by default on reset.
- Parameters:
milliampere – [in] from 5mA up to 1000mA
-
void bq25180_set_termination_current(uint8_t pct)
Set the termination current.
10% by default on reset.
- Parameters:
pct – [in] percentage of the maximum charge current level
-
void bq25180_enable_vindpm(enum bq25180_vindpm opt)
Enable or disable Input Voltage Based Dynamic Power Management.
This sets input voltage threshold to keep the input voltage higher than configured.
This feature is disbled by default on reset.
- Parameters:
opt – [in] bq25180_vindpm
-
void bq25180_enable_dppm(bool enable)
Enable of disable Dynamic Power Path Management Mode.
This feature is enabled by default on reset.
- Parameters:
enable – [in] true to enable, false to disable
-
void bq25180_set_input_current(uint16_t milliampere)
Set the maximum input current.
The input DPM loop reduces input current if the sum of the charging and load currents exceeds the preset maximum input current.
500mA by default on reset.
- Parameters:
milliampere – [in] from 50mA up to 1100mA
-
void bq25180_set_sys_source(enum bq25180_sys_source source)
Set regulated system voltage source.
This sets how SYS is powered in any state, except SHIPMODE.
BQ25180_SYS_SRC_VIN_VBAT by default on reset.
- Parameters:
source – [in] one of bq25180_sys_source
-
void bq25180_set_sys_voltage(enum bq25180_sys_regulation val)
Set SYS regulation voltgage.
BQ25180_SYS_REG_V4_4 by default on reset.
- Parameters:
val – [in] one of bq25180_sys_regulation
-
void bq25180_enable_thermal_protection(bool enable)
Enable or disable thermal protection.
- Parameters:
enable – [in] enable if true or disable if false
-
void bq25180_enable_push_button(bool enable)
Enable or disable push button on battery only.
- Parameters:
enable – [in] enable if true or disable if false
-
void bq25180_enable_interrupt(uint8_t mask)
Enable interrupts.
- Parameters:
mask – [in] combined interrupt mask bq25180_intr
-
void bq25180_disable_interrupt(uint8_t mask)
Disable interrupts.
- Parameters:
mask – [in] combined interrupt mask bq25180_intr
-
struct bq25180_event
- #include <bq25180.h>
-
struct bq25180_state
- #include <bq25180.h>
Public Members
-
uint16_t vin_good
-
uint16_t thermal_regulation_active
-
uint16_t vindpm_active
-
uint16_t vdppm_active
-
uint16_t ilim_active
-
uint16_t charging_status
-
uint16_t tsmr_open
-
uint16_t wake2_raised
-
uint16_t wake1_raised
-
uint16_t safety_timer_fault
-
uint16_t ts_status
-
uint16_t battery_undervoltage_active
-
uint16_t vin_overvoltage_active
-
uint16_t vin_good
Enums
-
enum bq25180_sys_source
Values:
-
enumerator BQ25180_SYS_SRC_VIN_VBAT
Powered from VIN if present or VBAT
-
enumerator BQ25180_SYS_SRC_VBAT
Powered from VBAT only, even if VIN present
-
enumerator BQ25180_SYS_SRC_NONE_FLOATING
Disconnected and left floating
-
enumerator BQ25180_SYS_SRC_NONE_PULLDOWN
Disconnected with pulldown
-
enumerator BQ25180_SYS_SRC_VIN_VBAT
-
enum bq25180_sys_regulation
Values:
-
enumerator BQ25180_SYS_REG_VBAT
VBAT + 225 mV (3.8 V minimum)
-
enumerator BQ25180_SYS_REG_V4_4
4.4V
-
enumerator BQ25180_SYS_REG_V4_5
4.5V
-
enumerator BQ25180_SYS_REG_V4_6
4.6V
-
enumerator BQ25180_SYS_REG_V4_7
4.7V
-
enumerator BQ25180_SYS_REG_V4_8
4.8V
-
enumerator BQ25180_SYS_REG_V4_9
4.9V
-
enumerator BQ25180_SYS_REG_PASS_THROUGH
Pass through
-
enumerator BQ25180_SYS_REG_VBAT
-
enum bq25180_bat_discharge_current
Values:
-
enumerator BQ25180_BAT_DISCHAGE_500mA
-
enumerator BQ25180_BAT_DISCHAGE_1000mA
-
enumerator BQ25180_BAT_DISCHAGE_1500mA
-
enumerator BQ25180_BAT_DISCHAGE_DISABLE
-
enumerator BQ25180_BAT_DISCHAGE_500mA
-
enum bq25180_safety_timer
Values:
-
enumerator BQ25180_SAFETY_3H
3 hour fast charge
-
enumerator BQ25180_SAFETY_6H
6 hour fast charge
-
enumerator BQ25180_SAFETY_12H
12 hour fast charge
-
enumerator BQ25180_SAFETY_DISABLE
disable safty timer
-
enumerator BQ25180_SAFETY_3H
-
enum bq25180_watchdog
Values:
-
enumerator BQ25180_WDT_DEFAULT
160s hardware reset
-
enumerator BQ25180_WDT_160_SEC
160s hardware reset
-
enumerator BQ25180_WDT_40_SEC
40s hardware reset
-
enumerator BQ25180_WDT_DISABLE
Disable watchdog function
-
enumerator BQ25180_WDT_DEFAULT
-
enum bq25180_vindpm
Values:
-
enumerator BQ25180_VINDPM_4200mV
-
enumerator BQ25180_VINDPM_4500mV
-
enumerator BQ25180_VINDPM_4700mV
-
enumerator BQ25180_VINDPM_DISABLE
-
enumerator BQ25180_VINDPM_4200mV
-
enum bq25180_intr
Values:
-
enumerator BQ25180_INTR_CHARGING_STATUS = 0x01
-
enumerator BQ25180_INTR_CURRENT_LIMIT = 0x02
-
enumerator BQ25180_INTR_VDPM = 0x04
-
enumerator BQ25180_INTR_THERMAL_FAULT = 0x08
-
enumerator BQ25180_INTR_THERMAL_REGULATION = 0x10
-
enumerator BQ25180_INTR_BATTERY_RANGE = 0x20
-
enumerator BQ25180_INTR_POWER_ERROR = 0x40
-
enumerator BQ25180_INTR_ALL = (BQ25180_INTR_CHARGING_STATUS | BQ25180_INTR_CURRENT_LIMIT | BQ25180_INTR_VDPM | BQ25180_INTR_THERMAL_FAULT | BQ25180_INTR_THERMAL_REGULATION | BQ25180_INTR_BATTERY_RANGE | BQ25180_INTR_POWER_ERROR)
-
enumerator BQ25180_INTR_CHARGING_STATUS = 0x01
Defines
-
BQ25180_DEVICE_ADDRESS 0x6A /* 7-bit addressing only */
Functions
-
int bq25180_read(uint8_t addr, uint8_t reg, void *buf, size_t bufsize)
Read a register value via I2C.
Note
This function should be implemented for the specific platform or board. The default one does nothing being linked weak.
- Parameters:
addr – [in] device address
reg – [in] register address to read from
buf – [in] buffer to get the value in
bufsize – [in] size of buf
- Returns:
The number of bytes read on success. Otherwise a negative integer error code
-
int bq25180_write(uint8_t addr, uint8_t reg, const void *data, size_t data_len)
Write a value to a register via I2C.
Note
This function should be implemented for the specific platform or board. The default one does nothing being linked weak.
- Parameters:
addr – [in] device address
reg – [in] register address to write to
data – [in] data to be written in reg
data_len – [in] length of data
- Returns:
The number of bytes written on success. Otherwise a negative integer error code