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@2:4c699a813451, 2017-11-10 (annotated)
- Committer:
- RobMeades
- Date:
- Fri Nov 10 17:07:06 2017 +0000
- Revision:
- 2:4c699a813451
- Parent:
- 1:ee7cc8d75283
Functionality at equivalent level to the BQ27411 battery driver. Good enough for now.
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 | 1:ee7cc8d75283 | 32 | /** I2C clock frequency. |
RobMeades | 1:ee7cc8d75283 | 33 | * NOTE: the battery shield board on the C030 platform will not work |
RobMeades | 1:ee7cc8d75283 | 34 | * at the default I2C clock frequency. |
RobMeades | 1:ee7cc8d75283 | 35 | */ |
RobMeades | 2:4c699a813451 | 36 | #define I2C_CLOCK_FREQUENCY 100 |
RobMeades | 1:ee7cc8d75283 | 37 | |
RobMeades | 1:ee7cc8d75283 | 38 | /** Settling time after gaugeEnable is set high */ |
RobMeades | 1:ee7cc8d75283 | 39 | #define GAUGE_ENABLE_SETTLING_TIME_MS 10 |
RobMeades | 1:ee7cc8d75283 | 40 | |
RobMeades | 1:ee7cc8d75283 | 41 | /** The default seal codes (step 1 in the higher word, step 2 the lower word), NOT byte reversed. */ |
RobMeades | 1:ee7cc8d75283 | 42 | #define SEAL_CODES_DEFAULT 0x04143672 |
RobMeades | 1:ee7cc8d75283 | 43 | |
RobMeades | 1:ee7cc8d75283 | 44 | /** The default full access codes (step 1 in the higher word, step 2 the lower word). */ |
RobMeades | 1:ee7cc8d75283 | 45 | #define FULL_ACCESS_CODES_DEFAULT 0xFFFFFFFF |
RobMeades | 0:cec745c014b7 | 46 | |
RobMeades | 0:cec745c014b7 | 47 | /* ---------------------------------------------------------------- |
RobMeades | 0:cec745c014b7 | 48 | * CLASSES |
RobMeades | 0:cec745c014b7 | 49 | * -------------------------------------------------------------- */ |
RobMeades | 0:cec745c014b7 | 50 | |
RobMeades | 0:cec745c014b7 | 51 | /** BQ35100 battery gauge driver. */ |
RobMeades | 0:cec745c014b7 | 52 | class BatteryGaugeBq35100 { |
RobMeades | 0:cec745c014b7 | 53 | public: |
RobMeades | 0:cec745c014b7 | 54 | |
RobMeades | 1:ee7cc8d75283 | 55 | /** The security mode of the BQ35100 chip. */ |
RobMeades | 1:ee7cc8d75283 | 56 | typedef enum { |
RobMeades | 1:ee7cc8d75283 | 57 | SECURITY_MODE_UNKNOWN = 0x00, |
RobMeades | 1:ee7cc8d75283 | 58 | SECURITY_MODE_FULL_ACCESS = 0x01, //!< Allows writes to all of memory. |
RobMeades | 1:ee7cc8d75283 | 59 | SECURITY_MODE_UNSEALED = 0x02, //!< Allows writes to all of memory apart from the security codes area. |
RobMeades | 1:ee7cc8d75283 | 60 | SECURITY_MODE_SEALED = 0x03 //!< Normal operating mode, prevents accidental writes. |
RobMeades | 1:ee7cc8d75283 | 61 | } SecurityMode; |
RobMeades | 1:ee7cc8d75283 | 62 | |
RobMeades | 0:cec745c014b7 | 63 | /** Constructor. */ |
RobMeades | 0:cec745c014b7 | 64 | BatteryGaugeBq35100(void); |
RobMeades | 0:cec745c014b7 | 65 | /** Destructor. */ |
RobMeades | 0:cec745c014b7 | 66 | ~BatteryGaugeBq35100(void); |
RobMeades | 0:cec745c014b7 | 67 | |
RobMeades | 0:cec745c014b7 | 68 | /** Initialise the BQ35100 chip. Once initialised |
RobMeades | 2:4c699a813451 | 69 | * the chip is put into its lowest power state. Any API call |
RobMeades | 2:4c699a813451 | 70 | * will awaken the chip from this state and then return it once |
RobMeades | 2:4c699a813451 | 71 | * more to the lowest possible power state. |
RobMeades | 2:4c699a813451 | 72 | * @param pI2c a pointer to the I2C instance to use. |
RobMeades | 2:4c699a813451 | 73 | * @param gaugeEnable the gauge enable pin (will be set high to enable the chip). |
RobMeades | 2:4c699a813451 | 74 | * @param address 7-bit I2C address of the battery gauge chip. |
RobMeades | 2:4c699a813451 | 75 | * @param sealCodes the two 16 bit seal codes (step 1 in the higher word, step 2 in the |
RobMeades | 2:4c699a813451 | 76 | * lower word, NOT byte reversed) that will unseal the device if it is sealed. |
RobMeades | 2:4c699a813451 | 77 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 78 | */ |
RobMeades | 2:4c699a813451 | 79 | bool init(I2C * pI2c, PinName gaugeEnable = NC, uint8_t address = BATTERY_GAUGE_BQ35100_ADDRESS, |
RobMeades | 1:ee7cc8d75283 | 80 | uint32_t sealCodes = SEAL_CODES_DEFAULT); |
RobMeades | 1:ee7cc8d75283 | 81 | |
RobMeades | 1:ee7cc8d75283 | 82 | /** Switch on the battery gauge. Battery gauging must be switched on |
RobMeades | 2:4c699a813451 | 83 | * for the battery capacity and percentage readings to be valid. The |
RobMeades | 2:4c699a813451 | 84 | * chip will consume more when battery gauging is switched on. |
RobMeades | 2:4c699a813451 | 85 | * @param nonVolatile if set to true then the chip will add the |
RobMeades | 2:4c699a813451 | 86 | * accumulated capacity values to those taken |
RobMeades | 2:4c699a813451 | 87 | * previously in non-volatile memory when |
RobMeades | 2:4c699a813451 | 88 | * disableGauge() is called. |
RobMeades | 2:4c699a813451 | 89 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 90 | */ |
RobMeades | 2:4c699a813451 | 91 | bool enableGauge(bool nonVolatile = false); |
RobMeades | 1:ee7cc8d75283 | 92 | |
RobMeades | 2:4c699a813451 | 93 | /** Switch off the battery gauge. If gauging to non-volatile |
RobMeades | 2:4c699a813451 | 94 | * memory was switched on, the accumulated capacity values |
RobMeades | 2:4c699a813451 | 95 | * will be stored in non-volatile memory. Please see the warning |
RobMeades | 2:4c699a813451 | 96 | * in section 5.1.1 of the TI BQ35100 technical reference manual |
RobMeades | 2:4c699a813451 | 97 | * concerning how frequently this should be done. |
RobMeades | 2:4c699a813451 | 98 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 99 | */ |
RobMeades | 1:ee7cc8d75283 | 100 | bool disableGauge(void); |
RobMeades | 1:ee7cc8d75283 | 101 | |
RobMeades | 1:ee7cc8d75283 | 102 | /** Check whether battery gauging is enabled or not. |
RobMeades | 2:4c699a813451 | 103 | * @return true if battery gauging is enabled, otherwise false. |
RobMeades | 2:4c699a813451 | 104 | */ |
RobMeades | 1:ee7cc8d75283 | 105 | bool isGaugeEnabled(void); |
RobMeades | 1:ee7cc8d75283 | 106 | |
RobMeades | 1:ee7cc8d75283 | 107 | /** Set the designed capacity of the cell. |
RobMeades | 2:4c699a813451 | 108 | * @param capacityMAh the capacity. |
RobMeades | 2:4c699a813451 | 109 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 110 | */ |
RobMeades | 1:ee7cc8d75283 | 111 | bool setDesignCapacity(uint32_t capacityMAh); |
RobMeades | 1:ee7cc8d75283 | 112 | |
RobMeades | 1:ee7cc8d75283 | 113 | /** Get the designed capacity of the cell. |
RobMeades | 2:4c699a813451 | 114 | * @param pCapacityMAh a place to put the capacity. |
RobMeades | 2:4c699a813451 | 115 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 116 | */ |
RobMeades | 1:ee7cc8d75283 | 117 | bool getDesignCapacity(uint32_t *pCapacityMAh); |
RobMeades | 1:ee7cc8d75283 | 118 | |
RobMeades | 1:ee7cc8d75283 | 119 | /** Read the temperature of the BQ35100 chip. |
RobMeades | 2:4c699a813451 | 120 | * @param pTemperatureC place to put the temperature reading. |
RobMeades | 2:4c699a813451 | 121 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 122 | */ |
RobMeades | 1:ee7cc8d75283 | 123 | bool getTemperature(int32_t *pTemperatureC); |
RobMeades | 1:ee7cc8d75283 | 124 | |
RobMeades | 1:ee7cc8d75283 | 125 | /** Read the voltage of the battery. |
RobMeades | 2:4c699a813451 | 126 | * @param pVoltageMV place to put the voltage reading. |
RobMeades | 2:4c699a813451 | 127 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 128 | */ |
RobMeades | 1:ee7cc8d75283 | 129 | bool getVoltage(int32_t *pVoltageMV); |
RobMeades | 1:ee7cc8d75283 | 130 | |
RobMeades | 1:ee7cc8d75283 | 131 | /** Read the current flowing from the battery. |
RobMeades | 2:4c699a813451 | 132 | * @param pCurrentMA place to put the current reading. |
RobMeades | 2:4c699a813451 | 133 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 134 | */ |
RobMeades | 1:ee7cc8d75283 | 135 | bool getCurrent(int32_t *pCurrentMA); |
RobMeades | 1:ee7cc8d75283 | 136 | |
RobMeades | 1:ee7cc8d75283 | 137 | /** Read the battery capacity used in uAh (NOT mAh). |
RobMeades | 2:4c699a813451 | 138 | * @param pCapacityUAh place to put the capacity reading. |
RobMeades | 2:4c699a813451 | 139 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 140 | */ |
RobMeades | 1:ee7cc8d75283 | 141 | bool getUsedCapacity(uint32_t *pCapacityUAh); |
RobMeades | 1:ee7cc8d75283 | 142 | |
RobMeades | 1:ee7cc8d75283 | 143 | /** Get the remaining battery capacity in uAh (NOT mAh). |
RobMeades | 1:ee7cc8d75283 | 144 | * NOTE: this relies on the Design Capacity of the battery |
RobMeades | 1:ee7cc8d75283 | 145 | * having been set correctly. |
RobMeades | 1:ee7cc8d75283 | 146 | * @param pCapacityUAh place to put the capacity reading. |
RobMeades | 1:ee7cc8d75283 | 147 | * @return true if successful, otherwise false. |
RobMeades | 1:ee7cc8d75283 | 148 | */ |
RobMeades | 1:ee7cc8d75283 | 149 | bool getRemainingCapacity(uint32_t *pCapacityUAh); |
RobMeades | 1:ee7cc8d75283 | 150 | |
RobMeades | 1:ee7cc8d75283 | 151 | /** Get the remaining battery capacity in percent. |
RobMeades | 2:4c699a813451 | 152 | * NOTE: this relies on the Design Capacity of the battery |
RobMeades | 2:4c699a813451 | 153 | * having been set correctly. |
RobMeades | 2:4c699a813451 | 154 | * @param pBatteryPercentage place to put the reading. |
RobMeades | 2:4c699a813451 | 155 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 156 | */ |
RobMeades | 1:ee7cc8d75283 | 157 | bool getRemainingPercentage(int32_t *pBatteryPercentage); |
RobMeades | 1:ee7cc8d75283 | 158 | |
RobMeades | 2:4c699a813451 | 159 | /** Indicate that a new battery has been inserted. |
RobMeades | 2:4c699a813451 | 160 | * @param capacityMAh the capacity of the battery. |
RobMeades | 2:4c699a813451 | 161 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 162 | */ |
RobMeades | 2:4c699a813451 | 163 | bool newBattery(uint32_t capacityMAh); |
RobMeades | 2:4c699a813451 | 164 | |
RobMeades | 2:4c699a813451 | 165 | /** An advanced function to read configuration data from the BQ35100 chip memory. |
RobMeades | 2:4c699a813451 | 166 | * Please refer to the TI BQ35100 technical reference manual for details of the |
RobMeades | 2:4c699a813451 | 167 | * address space.This function will unseal the device (using the seal codes |
RobMeades | 2:4c699a813451 | 168 | * passed into init()) in order to perform the read from data flash and will |
RobMeades | 2:4c699a813451 | 169 | * restore the previous security state afterwards. |
RobMeades | 2:4c699a813451 | 170 | * @param address the address of the data within the class. |
RobMeades | 2:4c699a813451 | 171 | * @param pData a place to put the read data. |
RobMeades | 2:4c699a813451 | 172 | * @param length the size of the place to put the data block. |
RobMeades | 2:4c699a813451 | 173 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 174 | */ |
RobMeades | 2:4c699a813451 | 175 | bool advancedGetConfig(int32_t address, char * pData, int32_t length); |
RobMeades | 2:4c699a813451 | 176 | |
RobMeades | 2:4c699a813451 | 177 | /** An advanced function to write configuration data to the BQ35100 chip memory. |
RobMeades | 2:4c699a813451 | 178 | * Please refer to the TI BQ35100 technical reference manual for details of the |
RobMeades | 2:4c699a813451 | 179 | * address space. This function will unseal the device (using the seal codes |
RobMeades | 2:4c699a813451 | 180 | * passed into init()) in order to perform the write to data flash and will |
RobMeades | 2:4c699a813451 | 181 | * restore the previous security state afterwards. However, if the write |
RobMeades | 2:4c699a813451 | 182 | * operation requires full access (e.g. to change the seal codes) then |
RobMeades | 2:4c699a813451 | 183 | * the security mode of the device must be changed (through a call to |
RobMeades | 2:4c699a813451 | 184 | * advancedGetSecurityMode()) first. If this function is used to change the seal |
RobMeades | 2:4c699a813451 | 185 | * or full access codes for the chip then init() should be called once more to |
RobMeades | 2:4c699a813451 | 186 | * update the codes used by this driver. |
RobMeades | 2:4c699a813451 | 187 | * @param address the address to write to. |
RobMeades | 2:4c699a813451 | 188 | * @param pData a pointer to the data to be written. |
RobMeades | 2:4c699a813451 | 189 | * @param length the size of the data to be written. |
RobMeades | 2:4c699a813451 | 190 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 191 | */ |
RobMeades | 2:4c699a813451 | 192 | bool advancedSetConfig(int32_t address, const char * pData, int32_t length); |
RobMeades | 2:4c699a813451 | 193 | |
RobMeades | 2:4c699a813451 | 194 | /** Send a control word (see section 11.1 of the BQ35100 technical reference manual). |
RobMeades | 2:4c699a813451 | 195 | * @param controlWord the control word to send. |
RobMeades | 2:4c699a813451 | 196 | * @param pDataReturned a place to put the word of data that could be returned, |
RobMeades | 2:4c699a813451 | 197 | * depending on which control word is used (may be NULL). |
RobMeades | 2:4c699a813451 | 198 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 199 | */ |
RobMeades | 2:4c699a813451 | 200 | bool advancedSendControlWord(uint16_t controlWord, uint16_t *pDataReturned); |
RobMeades | 2:4c699a813451 | 201 | |
RobMeades | 2:4c699a813451 | 202 | /** Read two bytes starting at a given address on the chip. |
RobMeades | 2:4c699a813451 | 203 | * See sections 11.3 to 11.18 of the BQ35100 technical reference manual for the list |
RobMeades | 2:4c699a813451 | 204 | * of addresses. |
RobMeades | 2:4c699a813451 | 205 | * NOTE: this is not a read from data flash, for that you need the advancedGetConfig() |
RobMeades | 2:4c699a813451 | 206 | * method. |
RobMeades | 2:4c699a813451 | 207 | * @param address the start address to read from. For instance, for temperature this is 0x06. |
RobMeades | 2:4c699a813451 | 208 | * @param pDataReturned a place to put the word of data returned. |
RobMeades | 2:4c699a813451 | 209 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 210 | */ |
RobMeades | 2:4c699a813451 | 211 | bool advancedGet(uint8_t address, uint16_t *pDataReturned); |
RobMeades | 2:4c699a813451 | 212 | |
RobMeades | 1:ee7cc8d75283 | 213 | /** Advanced function to get the security mode of the chip. |
RobMeades | 2:4c699a813451 | 214 | * @return the security mode. |
RobMeades | 2:4c699a813451 | 215 | */ |
RobMeades | 1:ee7cc8d75283 | 216 | SecurityMode advancedGetSecurityMode(void); |
RobMeades | 1:ee7cc8d75283 | 217 | |
RobMeades | 2:4c699a813451 | 218 | /** Advanced function to set the security mode of the chip. |
RobMeades | 2:4c699a813451 | 219 | * SECURITY_MODE_UNSEALED mode allows writes to the chip and read access to |
RobMeades | 2:4c699a813451 | 220 | * certain proteced areas while SECURITY_MODE_FULL_ACCESS, in addition, |
RobMeades | 2:4c699a813451 | 221 | * allows the security codes to be updated. All of the functions in this |
RobMeades | 2:4c699a813451 | 222 | * class are able to work with a SEALED chip, provided the correct codes |
RobMeades | 2:4c699a813451 | 223 | * are provided to the init() function. |
RobMeades | 2:4c699a813451 | 224 | * NOTE: it is only possible to move to SECURITY_MODE_FULL_ACCESS from |
RobMeades | 2:4c699a813451 | 225 | * SECURITY_MODE_UNSEALED. |
RobMeades | 2:4c699a813451 | 226 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 227 | */ |
RobMeades | 1:ee7cc8d75283 | 228 | bool advancedSetSecurityMode(SecurityMode securityMode); |
RobMeades | 1:ee7cc8d75283 | 229 | |
RobMeades | 2:4c699a813451 | 230 | /** Advanced function to perform a hard reset of the chip, reinitialising RAM |
RobMeades | 2:4c699a813451 | 231 | * data to defaults from ROM. |
RobMeades | 2:4c699a813451 | 232 | * Note: the security mode of the chip is unaffected. |
RobMeades | 2:4c699a813451 | 233 | * @return true if successful, otherwise false. |
RobMeades | 2:4c699a813451 | 234 | */ |
RobMeades | 1:ee7cc8d75283 | 235 | bool advancedReset(void); |
RobMeades | 0:cec745c014b7 | 236 | |
RobMeades | 0:cec745c014b7 | 237 | protected: |
RobMeades | 0:cec745c014b7 | 238 | /** Pointer to the I2C interface. */ |
RobMeades | 0:cec745c014b7 | 239 | I2C * gpI2c; |
RobMeades | 0:cec745c014b7 | 240 | /** The address of the device. */ |
RobMeades | 0:cec745c014b7 | 241 | uint8_t gAddress; |
RobMeades | 1:ee7cc8d75283 | 242 | /** The gauge enable pin. */ |
RobMeades | 1:ee7cc8d75283 | 243 | DigitalOut *pGaugeEnable; |
RobMeades | 1:ee7cc8d75283 | 244 | /** The seal codes for the device (step 1 in the higher word, step 2 the lower word), NOT byte reversed. . */ |
RobMeades | 1:ee7cc8d75283 | 245 | uint32_t gSealCodes; |
RobMeades | 1:ee7cc8d75283 | 246 | /** The full access codes for the device (step 1 in the higher word, step 2 the lower word), NOT byte reversed. . */ |
RobMeades | 1:ee7cc8d75283 | 247 | uint32_t gFullAccessCodes; |
RobMeades | 0:cec745c014b7 | 248 | /** Flag to indicate device is ready. */ |
RobMeades | 0:cec745c014b7 | 249 | bool gReady; |
RobMeades | 0:cec745c014b7 | 250 | |
RobMeades | 0:cec745c014b7 | 251 | /** Read two bytes starting at a given address. |
RobMeades | 1:ee7cc8d75283 | 252 | * Note: gpI2c should be locked before this is called. |
RobMeades | 1:ee7cc8d75283 | 253 | * @param registerAddress the register address to start reading from. |
RobMeades | 1:ee7cc8d75283 | 254 | * @param pBytes place to put the two bytes. |
RobMeades | 1:ee7cc8d75283 | 255 | * @return true if successful, otherwise false. |
RobMeades | 1:ee7cc8d75283 | 256 | */ |
RobMeades | 1:ee7cc8d75283 | 257 | bool getTwoBytes(uint8_t registerAddress, uint16_t *pBytes); |
RobMeades | 1:ee7cc8d75283 | 258 | |
RobMeades | 1:ee7cc8d75283 | 259 | /** Compute the checksum of a block of memory in the chip. |
RobMeades | 1:ee7cc8d75283 | 260 | * @param pData a pointer to the data block. |
RobMeades | 1:ee7cc8d75283 | 261 | * @parm length the length over which to compute the checksum. |
RobMeades | 1:ee7cc8d75283 | 262 | * @return the checksum value. |
RobMeades | 1:ee7cc8d75283 | 263 | */ |
RobMeades | 1:ee7cc8d75283 | 264 | uint8_t computeChecksum(const char * pData, int32_t length); |
RobMeades | 1:ee7cc8d75283 | 265 | |
RobMeades | 1:ee7cc8d75283 | 266 | /** Read data of a given length and class ID. |
RobMeades | 1:ee7cc8d75283 | 267 | * Note: gpI2c should be locked before this is called. |
RobMeades | 1:ee7cc8d75283 | 268 | * @param address the address of the data within the class. |
RobMeades | 1:ee7cc8d75283 | 269 | * @param pData a place to put the read data. |
RobMeades | 1:ee7cc8d75283 | 270 | * @param length the size of the place to put the data block. |
RobMeades | 1:ee7cc8d75283 | 271 | * @return true if successful, otherwise false. |
RobMeades | 1:ee7cc8d75283 | 272 | */ |
RobMeades | 2:4c699a813451 | 273 | bool readExtendedData(int32_t address, char * pData, int32_t length); |
RobMeades | 1:ee7cc8d75283 | 274 | |
RobMeades | 1:ee7cc8d75283 | 275 | /** Write an extended data block. |
RobMeades | 1:ee7cc8d75283 | 276 | * Note: gpI2c should be locked before this is called. |
RobMeades | 1:ee7cc8d75283 | 277 | * @param address the address to write to. |
RobMeades | 1:ee7cc8d75283 | 278 | * @param pData a pointer to the data to be written. |
RobMeades | 1:ee7cc8d75283 | 279 | * @param length the size of the data to be written. |
RobMeades | 1:ee7cc8d75283 | 280 | * @return true if successful, otherwise false. |
RobMeades | 1:ee7cc8d75283 | 281 | */ |
RobMeades | 2:4c699a813451 | 282 | bool writeExtendedData(int32_t address, const char * pData, int32_t length); |
RobMeades | 1:ee7cc8d75283 | 283 | |
RobMeades | 1:ee7cc8d75283 | 284 | /** Get the security mode of the chip. |
RobMeades | 1:ee7cc8d75283 | 285 | * Note: gpI2c should be locked before this is called. |
RobMeades | 1:ee7cc8d75283 | 286 | * @return the security mode. |
RobMeades | 1:ee7cc8d75283 | 287 | */ |
RobMeades | 1:ee7cc8d75283 | 288 | SecurityMode getSecurityMode(void); |
RobMeades | 1:ee7cc8d75283 | 289 | |
RobMeades | 1:ee7cc8d75283 | 290 | /** Set the security mode of the chip. |
RobMeades | 1:ee7cc8d75283 | 291 | * Note: gpI2c should be locked before this is called. |
RobMeades | 1:ee7cc8d75283 | 292 | * @param securityMode the security mode to set. |
RobMeades | 1:ee7cc8d75283 | 293 | * @return true if successful, otherwise false. |
RobMeades | 1:ee7cc8d75283 | 294 | */ |
RobMeades | 1:ee7cc8d75283 | 295 | bool setSecurityMode(SecurityMode securityMode); |
RobMeades | 1:ee7cc8d75283 | 296 | |
RobMeades | 1:ee7cc8d75283 | 297 | /** Make sure that the chip is awake and has taken a reading. |
RobMeades | 1:ee7cc8d75283 | 298 | * Note: the function does its own locking of gpI2C so that it isn't |
RobMeades | 1:ee7cc8d75283 | 299 | * held for the entire time we wait for ADC readings to complete. |
RobMeades | 0:cec745c014b7 | 300 | * @return true if successful, otherwise false. |
RobMeades | 0:cec745c014b7 | 301 | */ |
RobMeades | 1:ee7cc8d75283 | 302 | bool makeAdcReading(void); |
RobMeades | 0:cec745c014b7 | 303 | }; |
RobMeades | 0:cec745c014b7 | 304 | |
RobMeades | 0:cec745c014b7 | 305 | #endif |
RobMeades | 0:cec745c014b7 | 306 | |
RobMeades | 0:cec745c014b7 | 307 | /* End Of File */ |