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
battery_gauge_bq35100.h@0:cec745c014b7, 2017-07-03 (annotated)
- Committer:
- RobMeades
- Date:
- Mon Jul 03 16:12:22 2017 +0000
- Revision:
- 0:cec745c014b7
- Child:
- 1:ee7cc8d75283
Initial commit, work in progress.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobMeades | 0:cec745c014b7 | 1 | /* mbed Microcontroller Library |
RobMeades | 0:cec745c014b7 | 2 | * Copyright (c) 2017 u-blox |
RobMeades | 0:cec745c014b7 | 3 | * |
RobMeades | 0:cec745c014b7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
RobMeades | 0:cec745c014b7 | 5 | * you may not use this file except in compliance with the License. |
RobMeades | 0:cec745c014b7 | 6 | * You may obtain a copy of the License at |
RobMeades | 0:cec745c014b7 | 7 | * |
RobMeades | 0:cec745c014b7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
RobMeades | 0:cec745c014b7 | 9 | * |
RobMeades | 0:cec745c014b7 | 10 | * Unless required by applicable law or agreed to in writing, software |
RobMeades | 0:cec745c014b7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
RobMeades | 0:cec745c014b7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
RobMeades | 0:cec745c014b7 | 13 | * See the License for the specific language governing permissions and |
RobMeades | 0:cec745c014b7 | 14 | * limitations under the License. |
RobMeades | 0:cec745c014b7 | 15 | */ |
RobMeades | 0:cec745c014b7 | 16 | |
RobMeades | 0:cec745c014b7 | 17 | #ifndef BATTERY_GAUGE_BQ35100_H |
RobMeades | 0:cec745c014b7 | 18 | #define BATTERY_GAUGE_BQ35100_H |
RobMeades | 0:cec745c014b7 | 19 | |
RobMeades | 0:cec745c014b7 | 20 | /** |
RobMeades | 0:cec745c014b7 | 21 | * @file battery_gauge_bq35100.h |
RobMeades | 0:cec745c014b7 | 22 | * This file defines the API to the TI BQ35100 battery gauge chip. |
RobMeades | 0:cec745c014b7 | 23 | */ |
RobMeades | 0:cec745c014b7 | 24 | |
RobMeades | 0:cec745c014b7 | 25 | /* ---------------------------------------------------------------- |
RobMeades | 0:cec745c014b7 | 26 | * COMPILE-TIME MACROS |
RobMeades | 0:cec745c014b7 | 27 | * -------------------------------------------------------------- */ |
RobMeades | 0:cec745c014b7 | 28 | |
RobMeades | 0:cec745c014b7 | 29 | /** Device I2C address. */ |
RobMeades | 0:cec745c014b7 | 30 | #define BATTERY_GAUGE_BQ35100_ADDRESS 0x55 |
RobMeades | 0:cec745c014b7 | 31 | |
RobMeades | 0:cec745c014b7 | 32 | /** The default seal code. */ |
RobMeades | 0:cec745c014b7 | 33 | #define SEAL_CODE_DEFAULT 0x8000 |
RobMeades | 0:cec745c014b7 | 34 | |
RobMeades | 0:cec745c014b7 | 35 | /* ---------------------------------------------------------------- |
RobMeades | 0:cec745c014b7 | 36 | * CLASSES |
RobMeades | 0:cec745c014b7 | 37 | * -------------------------------------------------------------- */ |
RobMeades | 0:cec745c014b7 | 38 | |
RobMeades | 0:cec745c014b7 | 39 | /** BQ35100 battery gauge driver. */ |
RobMeades | 0:cec745c014b7 | 40 | class BatteryGaugeBq35100 { |
RobMeades | 0:cec745c014b7 | 41 | public: |
RobMeades | 0:cec745c014b7 | 42 | |
RobMeades | 0:cec745c014b7 | 43 | /** Constructor. */ |
RobMeades | 0:cec745c014b7 | 44 | BatteryGaugeBq35100(void); |
RobMeades | 0:cec745c014b7 | 45 | /** Destructor. */ |
RobMeades | 0:cec745c014b7 | 46 | ~BatteryGaugeBq35100(void); |
RobMeades | 0:cec745c014b7 | 47 | |
RobMeades | 0:cec745c014b7 | 48 | /** Initialise the BQ35100 chip. Once initialised |
RobMeades | 0:cec745c014b7 | 49 | * the chip is put into its lowest power state. Any API call |
RobMeades | 0:cec745c014b7 | 50 | * will awaken the chip from this state and then return it once |
RobMeades | 0:cec745c014b7 | 51 | * more to the lowest possible power state. |
RobMeades | 0:cec745c014b7 | 52 | * @param pI2c a pointer to the I2C instance to use. |
RobMeades | 0:cec745c014b7 | 53 | * @param address 7-bit I2C address of the battery gauge chip. |
RobMeades | 0:cec745c014b7 | 54 | * @param sealCode the 16 bit seal code that will unseal the device if it is sealed. |
RobMeades | 0:cec745c014b7 | 55 | * @return true if successful, otherwise false. |
RobMeades | 0:cec745c014b7 | 56 | */ |
RobMeades | 0:cec745c014b7 | 57 | bool init (I2C * pI2c, uint8_t address = BATTERY_GAUGE_BQ35100_ADDRESS, uint16_t sealCode = SEAL_CODE_DEFAULT); |
RobMeades | 0:cec745c014b7 | 58 | |
RobMeades | 0:cec745c014b7 | 59 | protected: |
RobMeades | 0:cec745c014b7 | 60 | /** Pointer to the I2C interface. */ |
RobMeades | 0:cec745c014b7 | 61 | I2C * gpI2c; |
RobMeades | 0:cec745c014b7 | 62 | /** The address of the device. */ |
RobMeades | 0:cec745c014b7 | 63 | uint8_t gAddress; |
RobMeades | 0:cec745c014b7 | 64 | /** The seal code for the device. */ |
RobMeades | 0:cec745c014b7 | 65 | uint16_t gSealCode; |
RobMeades | 0:cec745c014b7 | 66 | /** Flag to indicate device is ready. */ |
RobMeades | 0:cec745c014b7 | 67 | bool gReady; |
RobMeades | 0:cec745c014b7 | 68 | |
RobMeades | 0:cec745c014b7 | 69 | /** Read two bytes starting at a given address. |
RobMeades | 0:cec745c014b7 | 70 | * Note: gpI2c should be locked before this is called. |
RobMeades | 0:cec745c014b7 | 71 | * @param registerAddress the register address to start reading from. |
RobMeades | 0:cec745c014b7 | 72 | * @param pBytes place to put the two bytes. |
RobMeades | 0:cec745c014b7 | 73 | * @return true if successful, otherwise false. |
RobMeades | 0:cec745c014b7 | 74 | */ |
RobMeades | 0:cec745c014b7 | 75 | bool getTwoBytes (uint8_t registerAddress, uint16_t *pBytes); |
RobMeades | 0:cec745c014b7 | 76 | |
RobMeades | 0:cec745c014b7 | 77 | }; |
RobMeades | 0:cec745c014b7 | 78 | |
RobMeades | 0:cec745c014b7 | 79 | #endif |
RobMeades | 0:cec745c014b7 | 80 | |
RobMeades | 0:cec745c014b7 | 81 | /* End Of File */ |