Loading...
Searching...
No Matches

Device driver interface for the BQ2429x Single-Cell USB Charger More...

Detailed Description

Device driver interface for the BQ2429x Single-Cell USB Charger

BQ2429x series power management ICs by Texas Instruments are controllable by I2C, allowing to change charge parameters in the runtime.

For more information, see the datasheets:

It can be used for USB OTG to power other devices, see the bq2429x_enable_otg and bq2429x_disable_otg functions, an additional pin bq2429x_params_t::otg_pin can be set to control it also by hardware and these functions will take care of setting it.

To enable/disable charge the functions bq2429x_enable_charge and bq2429x_disable_charge can be used, and as with the OTG an additional pin bq2429x_params_t::ce_pin can be set to control it also by hardware and these functions will take care of setting it.

When a change happens on the FAULT registers of the device the BQ2429x device generates an interrupt to inform when that happens, this functionality has to be enabled with the bq2429x_int module and can be used with the bq2429x_init_int functions.

Files

file  bq2429x_internal.h
 Internal address, registers, constants for the BQ2429x family power ICs.
 
file  bq2429x_params.h
 Default configuration for BQ2429x power ICs.
 
file  bq2429x.h
 Device driver interface for the BQ2429x Single-Cell USB Charger.
 

Data Structures

struct  bq2429x_status_t
 Device status. More...
 
struct  bq2429x_fault_t
 Device faults. More...
 
struct  bq2429x_params_t
 BQ2429x device parameters. More...
 
struct  bq2429x_t
 BQ2429x device descriptor. More...
 

Typedefs

typedef void(* bq2429x_int_cb_t) (void *)
 Callback function for BQ2429x interrupts.
 

Enumerations

enum  { BQ2429X_OK = 0 , BQ2429X_ERR_I2C = -1 , BQ2429X_ERR_GPIO = -2 }
 Driver return values. More...
 
enum  bq2429x_vbus_stat_t { BQ2429X_VBUS_NONE = 0 , BQ2429X_VBUS_USB_CHARGER , BQ2429X_VBUS_AP_CHARGER , BQ2429X_VBUS_OTG }
 Used VBUS type. More...
 
enum  bq2429x_chrg_stat_t { BQ2429X_CHARGE_NONE = 0 , BQ2429X_CHARGE_PRE , BQ2429X_CHARGE_FAST , BQ2429X_CHARGE_DONE }
 Battery charging status. More...
 
enum  bq2429x_chrg_fault_t { BQ2429x_CHRG_FAULT_NORMAL = 0 , BQ2429x_CHRG_FAULT_INPUT , BQ2429x_CHRG_FAULT_THERMAL_SHUTDOWN , BQ2429x_CHRG_FAULT_CHARGE_TIMER_EXPIRATION }
 Charge fault values. More...
 
enum  bq2429x_input_voltage_limit_t {
  BQ2429X_VLIM_3880 = 0 , BQ2429X_VLIM_3960 , BQ2429X_VLIM_4040 , BQ2429X_VLIM_4120 ,
  BQ2429X_VLIM_4200 , BQ2429X_VLIM_4280 , BQ2429X_VLIM_4360 , BQ2429X_VLIM_4440 ,
  BQ2429X_VLIM_4520 , BQ2429X_VLIM_4600 , BQ2429X_VLIM_4680 , BQ2429X_VLIM_4760 ,
  BQ2429X_VLIM_4840 , BQ2429X_VLIM_4920 , BQ2429X_VLIM_5000 , BQ2429X_VLIM_5080
}
 Input Voltage Limit (VLIM). More...
 
enum  bq2429x_input_current_limit_t {
  BQ2429X_ILIM_100 = 0 , BQ2429X_ILIM_150 , BQ2429X_ILIM_500 , BQ2429X_ILIM_900 ,
  BQ2429X_ILIM_1000 , BQ2429X_ILIM_1500 , BQ2429X_ILIM_2000 , BQ2429X_ILIM_3000
}
 Input Current Limit (ILIM). More...
 
enum  bq2429x_charge_current_t {
  BQ2429X_ICHG_512 = 0 , BQ2429X_ICHG_1024 = 8 , BQ2429X_ICHG_2048 = 24 , BQ2429X_ICHG_3008 = 39 ,
  BQ2429X_ICHG_4032 = 55 , BQ2429X_ICHG_4544 = 63
}
 Charge Current (ICHG) More...
 
enum  bq2429x_charge_voltage_limit_t {
  BQ2429X_VREG_3504 = 0 , BQ2429X_VREG_3600 = 6 , BQ2429X_VREG_3808 = 19 , BQ2429X_VREG_3904 = 25 ,
  BQ2429X_VREG_4000 = 31 , BQ2429X_VREG_4112 = 38 , BQ2429X_VREG_4208 = 44 , BQ2429X_VREG_4304 = 50 ,
  BQ2429X_VREG_4352 = 53 , BQ2429X_VREG_4400 = 56
}
 Charge Voltage Limit (VREG). More...
 

Functions

int bq2429x_init (bq2429x_t *dev, const bq2429x_params_t *params)
 Initialize device.
 
int bq2429x_init_int (bq2429x_t *dev, bq2429x_int_cb_t cb, void *arg)
 Initialize interrupt support for the device.
 
int bq2429x_get_status (const bq2429x_t *dev, bq2429x_status_t *status)
 Get device status.
 
int bq2429x_get_fault (const bq2429x_t *dev, bq2429x_fault_t *fault)
 Get device faults.
 
int bq2429x_enable_otg (const bq2429x_t *dev)
 Enable OTG.
 
int bq2429x_disable_otg (const bq2429x_t *dev)
 Disable OTG.
 
int bq2429x_enable_charge (const bq2429x_t *dev)
 Enable battery charging.
 
int bq2429x_disable_charge (const bq2429x_t *dev)
 Disable battery charging.
 
int bq2429x_set_vlim (bq2429x_t *dev, bq2429x_input_voltage_limit_t vlim)
 Set Input Voltage Limit.
 
int bq2429x_get_vlim (const bq2429x_t *dev, bq2429x_input_voltage_limit_t *vlim)
 Get Input Voltage Limit.
 
int bq2429x_set_ilim (bq2429x_t *dev, bq2429x_input_current_limit_t ilim)
 Set Input Current Limit.
 
int bq2429x_get_ilim (const bq2429x_t *dev, bq2429x_input_current_limit_t *ilim)
 Get Input Current Limit.
 
int bq2429x_set_ichg (bq2429x_t *dev, bq2429x_charge_current_t ichg)
 Set Charge Current.
 
int bq2429x_get_ichg (const bq2429x_t *dev, bq2429x_charge_current_t *ichg)
 Get Charge Current.
 
int bq2429x_set_vreg (bq2429x_t *dev, bq2429x_charge_voltage_limit_t vreg)
 Set Charge Voltage Limit.
 
int bq2429x_get_vreg (const bq2429x_t *dev, bq2429x_charge_voltage_limit_t *vreg)
 Get Charge Voltage Limit.
 

Typedef Documentation

◆ bq2429x_int_cb_t

typedef void(* bq2429x_int_cb_t) (void *)

Callback function for BQ2429x interrupts.

Definition at line 282 of file bq2429x.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Driver return values.

Enumerator
BQ2429X_OK 

Everything is ok.

BQ2429X_ERR_I2C 

I2C error.

BQ2429X_ERR_GPIO 

GPIO initialization error.

Definition at line 67 of file bq2429x.h.

◆ bq2429x_charge_current_t

Charge Current (ICHG)

Enumerator
BQ2429X_ICHG_512 

512 mA

BQ2429X_ICHG_1024 

1024 mA

BQ2429X_ICHG_2048 

2048 mA

BQ2429X_ICHG_3008 

4032 mA

BQ2429X_ICHG_4032 

4544 mA

Definition at line 215 of file bq2429x.h.

◆ bq2429x_charge_voltage_limit_t

Charge Voltage Limit (VREG).

Enumerator
BQ2429X_VREG_3504 

3504 mV

BQ2429X_VREG_3600 

3600 mV

BQ2429X_VREG_3808 

3808 mV

BQ2429X_VREG_3904 

3904 mV

BQ2429X_VREG_4000 

4000 mV

BQ2429X_VREG_4112 

4112 mV

BQ2429X_VREG_4208 

4208 mV

BQ2429X_VREG_4304 

4304 mV

BQ2429X_VREG_4352 

4352 mV

BQ2429X_VREG_4400 

4400 mV

Definition at line 227 of file bq2429x.h.

◆ bq2429x_chrg_fault_t

Charge fault values.

Enumerator
BQ2429x_CHRG_FAULT_NORMAL 

No fault, normal.

BQ2429x_CHRG_FAULT_INPUT 

Input fault (OVP or bad source)

BQ2429x_CHRG_FAULT_THERMAL_SHUTDOWN 

Thermal shutdown.

BQ2429x_CHRG_FAULT_CHARGE_TIMER_EXPIRATION 

Charge timer expiration.

Definition at line 129 of file bq2429x.h.

◆ bq2429x_chrg_stat_t

Battery charging status.

Enumerator
BQ2429X_CHARGE_NONE 

The device is not charging a battery.

BQ2429X_CHARGE_PRE 

Pre-charge state.

BQ2429X_CHARGE_FAST 

Fast charging.

BQ2429X_CHARGE_DONE 

Charging done.

Definition at line 86 of file bq2429x.h.

◆ bq2429x_input_current_limit_t

Input Current Limit (ILIM).

Enumerator
BQ2429X_ILIM_100 

100 mA

BQ2429X_ILIM_150 

150 mA

BQ2429X_ILIM_500 

500 mA

BQ2429X_ILIM_900 

900 mA

BQ2429X_ILIM_1000 

1000 mA

BQ2429X_ILIM_1500 

1500 mA

BQ2429X_ILIM_2000 

2000 mA

BQ2429X_ILIM_3000 

3000 mA

Definition at line 201 of file bq2429x.h.

◆ bq2429x_input_voltage_limit_t

Input Voltage Limit (VLIM).

Enumerator
BQ2429X_VLIM_3880 

3880 mV

BQ2429X_VLIM_3960 

3960 mV

BQ2429X_VLIM_4040 

4040 mV

BQ2429X_VLIM_4120 

4120 mV

BQ2429X_VLIM_4200 

4200 mV

BQ2429X_VLIM_4280 

4280 mV

BQ2429X_VLIM_4360 

4360 mV

BQ2429X_VLIM_4440 

4440 mV

BQ2429X_VLIM_4520 

4520 mV

BQ2429X_VLIM_4600 

4600 mV

BQ2429X_VLIM_4680 

4680 mV

BQ2429X_VLIM_4760 

4760 mV

BQ2429X_VLIM_4840 

4840 mV

BQ2429X_VLIM_4920 

4920 mV

BQ2429X_VLIM_5000 

5000 mV

BQ2429X_VLIM_5080 

5080 mV

Definition at line 179 of file bq2429x.h.

◆ bq2429x_vbus_stat_t

Used VBUS type.

Enumerator
BQ2429X_VBUS_NONE 

No input source detected.

BQ2429X_VBUS_USB_CHARGER 

USB charger input.

BQ2429X_VBUS_AP_CHARGER 

Adapter port charge input.

BQ2429X_VBUS_OTG 

VBUS is used for OTG.

Definition at line 76 of file bq2429x.h.

Function Documentation

◆ bq2429x_disable_charge()

int bq2429x_disable_charge ( const bq2429x_t * dev)

Disable battery charging.

Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_disable_otg()

int bq2429x_disable_otg ( const bq2429x_t * dev)

Disable OTG.

Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_enable_charge()

int bq2429x_enable_charge ( const bq2429x_t * dev)

Enable battery charging.

Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_enable_otg()

int bq2429x_enable_otg ( const bq2429x_t * dev)

Enable OTG.

This allows powering USB devices from the same port, i.e. to provide power or charge other devices.

Note
This will disable charging of the battery, if previously bq2429x_enable_charge was called, to enable charge again only disable OTG mode with bq2429x_disable_otg.
Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_get_fault()

int bq2429x_get_fault ( const bq2429x_t * dev,
bq2429x_fault_t * fault )

Get device faults.

Precondition
dev != NULL && fault != NULL
Parameters
[in]devDevice descriptor.
[out]faultPointer where device faults will be stored.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C error.

◆ bq2429x_get_ichg()

int bq2429x_get_ichg ( const bq2429x_t * dev,
bq2429x_charge_current_t * ichg )

Get Charge Current.

Precondition
dev != NULL && ichg != NULL
Parameters
[in]devDevice descriptor.
[out]ichgCharge current.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_get_ilim()

int bq2429x_get_ilim ( const bq2429x_t * dev,
bq2429x_input_current_limit_t * ilim )

Get Input Current Limit.

Precondition
dev != NULL && ilim != NULL
Parameters
[in]devDevice descriptor.
[out]ilimCurrent limit.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_get_status()

int bq2429x_get_status ( const bq2429x_t * dev,
bq2429x_status_t * status )

Get device status.

Precondition
dev != NULL && status != NULL
Parameters
[in]devDevice descriptor.
[out]statusPointer where device status will be stored.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C error.

◆ bq2429x_get_vlim()

int bq2429x_get_vlim ( const bq2429x_t * dev,
bq2429x_input_voltage_limit_t * vlim )

Get Input Voltage Limit.

Precondition
dev != NULL && vlim != NULL
Parameters
[in]devDevice descriptor.
[out]vlimVoltage limit.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_get_vreg()

int bq2429x_get_vreg ( const bq2429x_t * dev,
bq2429x_charge_voltage_limit_t * vreg )

Get Charge Voltage Limit.

Precondition
dev != NULL && vreg != NULL
Parameters
[in]devDevice descriptor.
[out]vregVoltage limit.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_init()

int bq2429x_init ( bq2429x_t * dev,
const bq2429x_params_t * params )

Initialize device.

Precondition
dev != NULL && params != NULL
Parameters
[out]devDevice descriptor.
[in]paramsDevice parameters.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.
BQ2429X_ERR_GPIO on GPIO initialization failure (CE or OTG pin failed).

◆ bq2429x_init_int()

int bq2429x_init_int ( bq2429x_t * dev,
bq2429x_int_cb_t cb,
void * arg )

Initialize interrupt support for the device.

Precondition
dev != NULL && cb != NULL

The callback cb is called in an ISR context, so keep in mind that heavy work shouldn't be done there.

Note
bq2429x_init MUST have been called before!
Parameters
[in]devDevice descriptor.
[in]cbCallback called on interrupt.
[in]argArgument to be passed when the callback is called.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_GPIO on GPIO initialization failure.

◆ bq2429x_set_ichg()

int bq2429x_set_ichg ( bq2429x_t * dev,
bq2429x_charge_current_t ichg )

Set Charge Current.

Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
[in]ichgCharge current.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_set_ilim()

int bq2429x_set_ilim ( bq2429x_t * dev,
bq2429x_input_current_limit_t ilim )

Set Input Current Limit.

Sets the maximum current limit, this limit is also limited by hardware by setting a resistor to the VLIM pin which sets (by hardware) the upper limit.

Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
[in]ilimCurrent limit.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_set_vlim()

int bq2429x_set_vlim ( bq2429x_t * dev,
bq2429x_input_voltage_limit_t vlim )

Set Input Voltage Limit.

Note
This is a limit on the lower bound of the voltage, for example, if the VLIM is set to BQ2429X_VLIM_5000 (5.0V) and the supply voltage is lower than it (4.8V), it will result in a fault and no power will be delivered through the output pin (SYS pin).
Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
[in]vlimVoltage limit.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.

◆ bq2429x_set_vreg()

int bq2429x_set_vreg ( bq2429x_t * dev,
bq2429x_charge_voltage_limit_t vreg )

Set Charge Voltage Limit.

Precondition
dev != NULL
Parameters
[in]devDevice descriptor.
[in]vregVoltage limit.
Returns
BQ2429X_OK on success.
BQ2429X_ERR_I2C on I2C failure.