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.

참고

A hardware or software reset will cancel the pending shipmode request.

매개변수:

hardware_reset[in] hardware reset if true while soft reset if false

bool bq25180_read_event(struct bq25180_event *p)

Read the device events.

매개변수:

p[in] bq25180_event

반환:

true on success or false

bool bq25180_read_state(struct bq25180_state *p)

Read the device state.

매개변수:

p[in] bq25180_state

반환:

true on success or false

void bq25180_enable_battery_charging(bool enable)

Enable or disable battery charging.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

milliampere[in] from 5mA up to 1000mA

void bq25180_set_termination_current(uint8_t pct)

Set the termination current.

10% by default on reset.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

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.

매개변수:

val[in] one of bq25180_sys_regulation

void bq25180_enable_thermal_protection(bool enable)

Enable or disable thermal protection.

매개변수:

enable[in] enable if true or disable if false

void bq25180_enable_push_button(bool enable)

Enable or disable push button on battery only.

매개변수:

enable[in] enable if true or disable if false

void bq25180_enable_interrupt(uint8_t mask)

Enable interrupts.

매개변수:

mask[in] combined interrupt mask bq25180_intr

void bq25180_disable_interrupt(uint8_t mask)

Disable interrupts.

매개변수:

mask[in] combined interrupt mask bq25180_intr

struct bq25180_event
#include <bq25180.h>

Public Members

uint8_t battery_overcurrent
uint8_t battery_undervoltage
uint8_t input_overvoltage
uint8_t thermal_regulation
uint8_t vindpm_fault
uint8_t vdppm_fault
uint8_t ilim_fault
uint8_t battery_thermal_fault
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

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

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

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
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

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

enum bq25180_vindpm

Values:

enumerator BQ25180_VINDPM_4200mV
enumerator BQ25180_VINDPM_4500mV
enumerator BQ25180_VINDPM_4700mV
enumerator BQ25180_VINDPM_DISABLE
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)

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.

참고

This function should be implemented for the specific platform or board. The default one does nothing being linked weak.

매개변수:
  • addr[in] device address

  • reg[in] register address to read from

  • buf[in] buffer to get the value in

  • bufsize[in] size of buf

반환:

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.

참고

This function should be implemented for the specific platform or board. The default one does nothing being linked weak.

매개변수:
  • 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

반환:

The number of bytes written on success. Otherwise a negative integer error code