This class provides APIs to all of the registers of the TI BQ35100 battery gauge, as used on the u-blox C030 primary battery shield.
Dependents: example-battery-gauge-bq35100
BatteryGaugeBq35100 Class Reference
BQ35100 battery gauge driver. More...
#include <battery_gauge_bq35100.h>
Public Types | |
enum | SecurityMode { , SECURITY_MODE_FULL_ACCESS = 0x01, SECURITY_MODE_UNSEALED = 0x02, SECURITY_MODE_SEALED = 0x03 } |
The security mode of the BQ35100 chip. More... | |
Public Member Functions | |
BatteryGaugeBq35100 (void) | |
Constructor. | |
~BatteryGaugeBq35100 (void) | |
Destructor. | |
bool | init (I2C *pI2c, PinName gaugeEnable=NC, uint8_t address=BATTERY_GAUGE_BQ35100_ADDRESS, uint32_t sealCodes=SEAL_CODES_DEFAULT) |
Initialise the BQ35100 chip. | |
bool | enableGauge (bool nonVolatile=false) |
Switch on the battery gauge. | |
bool | disableGauge (void) |
Switch off the battery gauge. | |
bool | isGaugeEnabled (void) |
Check whether battery gauging is enabled or not. | |
bool | setDesignCapacity (uint32_t capacityMAh) |
Set the designed capacity of the cell. | |
bool | getDesignCapacity (uint32_t *pCapacityMAh) |
Get the designed capacity of the cell. | |
bool | getTemperature (int32_t *pTemperatureC) |
Read the temperature of the BQ35100 chip. | |
bool | getVoltage (int32_t *pVoltageMV) |
Read the voltage of the battery. | |
bool | getCurrent (int32_t *pCurrentMA) |
Read the current flowing from the battery. | |
bool | getUsedCapacity (uint32_t *pCapacityUAh) |
Read the battery capacity used in uAh (NOT mAh). | |
bool | getRemainingCapacity (uint32_t *pCapacityUAh) |
Get the remaining battery capacity in uAh (NOT mAh). | |
bool | getRemainingPercentage (int32_t *pBatteryPercentage) |
Get the remaining battery capacity in percent. | |
bool | newBattery (uint32_t capacityMAh) |
Indicate that a new battery has been inserted. | |
bool | advancedGetConfig (int32_t address, char *pData, int32_t length) |
An advanced function to read configuration data from the BQ35100 chip memory. | |
bool | advancedSetConfig (int32_t address, const char *pData, int32_t length) |
An advanced function to write configuration data to the BQ35100 chip memory. | |
bool | advancedSendControlWord (uint16_t controlWord, uint16_t *pDataReturned) |
Send a control word (see section 11.1 of the BQ35100 technical reference manual). | |
bool | advancedGet (uint8_t address, uint16_t *pDataReturned) |
Read two bytes starting at a given address on the chip. | |
SecurityMode | advancedGetSecurityMode (void) |
Advanced function to get the security mode of the chip. | |
bool | advancedSetSecurityMode (SecurityMode securityMode) |
Advanced function to set the security mode of the chip. | |
bool | advancedReset (void) |
Advanced function to perform a hard reset of the chip, reinitialising RAM data to defaults from ROM. | |
Protected Member Functions | |
bool | getTwoBytes (uint8_t registerAddress, uint16_t *pBytes) |
Read two bytes starting at a given address. | |
uint8_t | computeChecksum (const char *pData, int32_t length) |
Compute the checksum of a block of memory in the chip. | |
bool | readExtendedData (int32_t address, char *pData, int32_t length) |
Read data of a given length and class ID. | |
bool | writeExtendedData (int32_t address, const char *pData, int32_t length) |
Write an extended data block. | |
SecurityMode | getSecurityMode (void) |
Get the security mode of the chip. | |
bool | setSecurityMode (SecurityMode securityMode) |
Set the security mode of the chip. | |
bool | makeAdcReading (void) |
Make sure that the chip is awake and has taken a reading. | |
Protected Attributes | |
I2C * | gpI2c |
Pointer to the I2C interface. | |
uint8_t | gAddress |
The address of the device. | |
DigitalOut * | pGaugeEnable |
The gauge enable pin. | |
uint32_t | gSealCodes |
The seal codes for the device (step 1 in the higher word, step 2 the lower word), NOT byte reversed. | |
uint32_t | gFullAccessCodes |
The full access codes for the device (step 1 in the higher word, step 2 the lower word), NOT byte reversed. | |
bool | gReady |
Flag to indicate device is ready. |
Detailed Description
BQ35100 battery gauge driver.
Definition at line 52 of file battery_gauge_bq35100.h.
Member Enumeration Documentation
enum SecurityMode |
The security mode of the BQ35100 chip.
- Enumerator:
Definition at line 56 of file battery_gauge_bq35100.h.
Constructor & Destructor Documentation
BatteryGaugeBq35100 | ( | void | ) |
Constructor.
Definition at line 398 of file bq35100.cpp.
~BatteryGaugeBq35100 | ( | void | ) |
Destructor.
Definition at line 408 of file bq35100.cpp.
Member Function Documentation
bool advancedGet | ( | uint8_t | address, |
uint16_t * | pDataReturned | ||
) |
Read two bytes starting at a given address on the chip.
See sections 11.3 to 11.18 of the BQ35100 technical reference manual for the list of addresses. NOTE: this is not a read from data flash, for that you need the advancedGetConfig() method.
- Parameters:
-
address the start address to read from. For instance, for temperature this is 0x06. pDataReturned a place to put the word of data returned.
- Returns:
- true if successful, otherwise false.
Definition at line 976 of file bq35100.cpp.
bool advancedGetConfig | ( | int32_t | address, |
char * | pData, | ||
int32_t | length | ||
) |
An advanced function to read configuration data from the BQ35100 chip memory.
Please refer to the TI BQ35100 technical reference manual for details of the address space.This function will unseal the device (using the seal codes passed into init()) in order to perform the read from data flash and will restore the previous security state afterwards.
- Parameters:
-
address the address of the data within the class. pData a place to put the read data. length the size of the place to put the data block.
- Returns:
- true if successful, otherwise false.
Definition at line 908 of file bq35100.cpp.
BatteryGaugeBq35100::SecurityMode advancedGetSecurityMode | ( | void | ) |
Advanced function to get the security mode of the chip.
- Returns:
- the security mode.
Definition at line 1004 of file bq35100.cpp.
bool advancedReset | ( | void | ) |
Advanced function to perform a hard reset of the chip, reinitialising RAM data to defaults from ROM.
Note: the security mode of the chip is unaffected.
- Returns:
- true if successful, otherwise false.
Definition at line 1036 of file bq35100.cpp.
bool advancedSendControlWord | ( | uint16_t | controlWord, |
uint16_t * | pDataReturned | ||
) |
Send a control word (see section 11.1 of the BQ35100 technical reference manual).
- Parameters:
-
controlWord the control word to send. pDataReturned a place to put the word of data that could be returned, depending on which control word is used (may be NULL).
- Returns:
- true if successful, otherwise false.
Definition at line 940 of file bq35100.cpp.
bool advancedSetConfig | ( | int32_t | address, |
const char * | pData, | ||
int32_t | length | ||
) |
An advanced function to write configuration data to the BQ35100 chip memory.
Please refer to the TI BQ35100 technical reference manual for details of the address space. This function will unseal the device (using the seal codes passed into init()) in order to perform the write to data flash and will restore the previous security state afterwards. However, if the write operation requires full access (e.g. to change the seal codes) then the security mode of the device must be changed (through a call to advancedGetSecurityMode()) first. If this function is used to change the seal or full access codes for the chip then init() should be called once more to update the codes used by this driver.
- Parameters:
-
address the address to write to. pData a pointer to the data to be written. length the size of the data to be written.
- Returns:
- true if successful, otherwise false.
Definition at line 924 of file bq35100.cpp.
bool advancedSetSecurityMode | ( | SecurityMode | securityMode ) |
Advanced function to set the security mode of the chip.
SECURITY_MODE_UNSEALED mode allows writes to the chip and read access to certain proteced areas while SECURITY_MODE_FULL_ACCESS, in addition, allows the security codes to be updated. All of the functions in this class are able to work with a SEALED chip, provided the correct codes are provided to the init() function. NOTE: it is only possible to move to SECURITY_MODE_FULL_ACCESS from SECURITY_MODE_UNSEALED.
- Returns:
- true if successful, otherwise false.
Definition at line 1020 of file bq35100.cpp.
uint8_t computeChecksum | ( | const char * | pData, |
int32_t | length | ||
) | [protected] |
Compute the checksum of a block of memory in the chip.
- Parameters:
-
pData a pointer to the data block. length the length over which to compute the checksum.
- Returns:
- the checksum value.
Definition at line 74 of file bq35100.cpp.
bool disableGauge | ( | void | ) |
Switch off the battery gauge.
If gauging to non-volatile memory was switched on, the accumulated capacity values will be stored in non-volatile memory. Please see the warning in section 5.1.1 of the TI BQ35100 technical reference manual concerning how frequently this should be done.
- Returns:
- true if successful, otherwise false.
Definition at line 537 of file bq35100.cpp.
bool enableGauge | ( | bool | nonVolatile = false ) |
Switch on the battery gauge.
Battery gauging must be switched on for the battery capacity and percentage readings to be valid. The chip will consume more when battery gauging is switched on.
- Parameters:
-
nonVolatile if set to true then the chip will add the accumulated capacity values to those taken previously in non-volatile memory when disableGauge() is called.
- Returns:
- true if successful, otherwise false.
Definition at line 472 of file bq35100.cpp.
bool getCurrent | ( | int32_t * | pCurrentMA ) |
Read the current flowing from the battery.
- Parameters:
-
pCurrentMA place to put the current reading.
- Returns:
- true if successful, otherwise false.
Definition at line 746 of file bq35100.cpp.
bool getDesignCapacity | ( | uint32_t * | pCapacityMAh ) |
Get the designed capacity of the cell.
- Parameters:
-
pCapacityMAh a place to put the capacity.
- Returns:
- true if successful, otherwise false.
Definition at line 659 of file bq35100.cpp.
bool getRemainingCapacity | ( | uint32_t * | pCapacityUAh ) |
Get the remaining battery capacity in uAh (NOT mAh).
NOTE: this relies on the Design Capacity of the battery having been set correctly.
- Parameters:
-
pCapacityUAh place to put the capacity reading.
- Returns:
- true if successful, otherwise false.
Definition at line 813 of file bq35100.cpp.
bool getRemainingPercentage | ( | int32_t * | pBatteryPercentage ) |
Get the remaining battery capacity in percent.
NOTE: this relies on the Design Capacity of the battery having been set correctly.
- Parameters:
-
pBatteryPercentage place to put the reading.
- Returns:
- true if successful, otherwise false.
Definition at line 846 of file bq35100.cpp.
BatteryGaugeBq35100::SecurityMode getSecurityMode | ( | void | ) | [protected] |
Get the security mode of the chip.
Note: gpI2c should be locked before this is called.
- Returns:
- the security mode.
Definition at line 287 of file bq35100.cpp.
bool getTemperature | ( | int32_t * | pTemperatureC ) |
Read the temperature of the BQ35100 chip.
- Parameters:
-
pTemperatureC place to put the temperature reading.
- Returns:
- true if successful, otherwise false.
Definition at line 687 of file bq35100.cpp.
bool getTwoBytes | ( | uint8_t | registerAddress, |
uint16_t * | pBytes | ||
) | [protected] |
Read two bytes starting at a given address.
Note: gpI2c should be locked before this is called.
- Parameters:
-
registerAddress the register address to start reading from. pBytes place to put the two bytes.
- Returns:
- true if successful, otherwise false.
Definition at line 50 of file bq35100.cpp.
bool getUsedCapacity | ( | uint32_t * | pCapacityUAh ) |
Read the battery capacity used in uAh (NOT mAh).
- Parameters:
-
pCapacityUAh place to put the capacity reading.
- Returns:
- true if successful, otherwise false.
Definition at line 774 of file bq35100.cpp.
bool getVoltage | ( | int32_t * | pVoltageMV ) |
Read the voltage of the battery.
- Parameters:
-
pVoltageMV place to put the voltage reading.
- Returns:
- true if successful, otherwise false.
Definition at line 718 of file bq35100.cpp.
bool init | ( | I2C * | pI2c, |
PinName | gaugeEnable = NC , |
||
uint8_t | address = BATTERY_GAUGE_BQ35100_ADDRESS , |
||
uint32_t | sealCodes = SEAL_CODES_DEFAULT |
||
) |
Initialise the BQ35100 chip.
Once initialised the chip is put into its lowest power state. Any API call will awaken the chip from this state and then return it once more to the lowest possible power state.
- Parameters:
-
pI2c a pointer to the I2C instance to use. gaugeEnable the gauge enable pin (will be set high to enable the chip). address 7-bit I2C address of the battery gauge chip. sealCodes the two 16 bit seal codes (step 1 in the higher word, step 2 in the lower word, NOT byte reversed) that will unseal the device if it is sealed.
- Returns:
- true if successful, otherwise false.
Definition at line 413 of file bq35100.cpp.
bool isGaugeEnabled | ( | void | ) |
Check whether battery gauging is enabled or not.
- Returns:
- true if battery gauging is enabled, otherwise false.
Definition at line 607 of file bq35100.cpp.
bool makeAdcReading | ( | void | ) | [protected] |
Make sure that the chip is awake and has taken a reading.
Note: the function does its own locking of gpI2C so that it isn't held for the entire time we wait for ADC readings to complete.
- Returns:
- true if successful, otherwise false.
Definition at line 378 of file bq35100.cpp.
bool newBattery | ( | uint32_t | capacityMAh ) |
Indicate that a new battery has been inserted.
- Parameters:
-
capacityMAh the capacity of the battery.
- Returns:
- true if successful, otherwise false.
Definition at line 881 of file bq35100.cpp.
bool readExtendedData | ( | int32_t | address, |
char * | pData, | ||
int32_t | length | ||
) | [protected] |
Read data of a given length and class ID.
Note: gpI2c should be locked before this is called.
- Parameters:
-
address the address of the data within the class. pData a place to put the read data. length the size of the place to put the data block.
- Returns:
- true if successful, otherwise false.
Definition at line 115 of file bq35100.cpp.
bool setDesignCapacity | ( | uint32_t | capacityMAh ) |
Set the designed capacity of the cell.
- Parameters:
-
capacityMAh the capacity.
- Returns:
- true if successful, otherwise false.
Definition at line 631 of file bq35100.cpp.
bool setSecurityMode | ( | SecurityMode | securityMode ) | [protected] |
Set the security mode of the chip.
Note: gpI2c should be locked before this is called.
- Parameters:
-
securityMode the security mode to set.
- Returns:
- true if successful, otherwise false.
Definition at line 312 of file bq35100.cpp.
bool writeExtendedData | ( | int32_t | address, |
const char * | pData, | ||
int32_t | length | ||
) | [protected] |
Write an extended data block.
Note: gpI2c should be locked before this is called.
- Parameters:
-
address the address to write to. pData a pointer to the data to be written. length the size of the data to be written.
- Returns:
- true if successful, otherwise false.
Definition at line 202 of file bq35100.cpp.
Field Documentation
uint8_t gAddress [protected] |
The address of the device.
Definition at line 241 of file battery_gauge_bq35100.h.
uint32_t gFullAccessCodes [protected] |
The full access codes for the device (step 1 in the higher word, step 2 the lower word), NOT byte reversed.
Definition at line 247 of file battery_gauge_bq35100.h.
I2C* gpI2c [protected] |
Pointer to the I2C interface.
Definition at line 239 of file battery_gauge_bq35100.h.
bool gReady [protected] |
Flag to indicate device is ready.
Definition at line 249 of file battery_gauge_bq35100.h.
uint32_t gSealCodes [protected] |
The seal codes for the device (step 1 in the higher word, step 2 the lower word), NOT byte reversed.
Definition at line 245 of file battery_gauge_bq35100.h.
DigitalOut* pGaugeEnable [protected] |
The gauge enable pin.
Definition at line 243 of file battery_gauge_bq35100.h.
Generated on Tue Jul 12 2022 19:24:03 by 1.7.2