A feature complete driver for the MAX17048 lithium fuel gauge from Maxim.
Dependents: MAX17048_HelloWorld ECGAFE_copy MAX17048_HelloWorld Orion_newPCB_test_LV ... more
Now fully tested!
MAX17048.h@10:4f695111eb54, 2014-05-30 (annotated)
- Committer:
- neilt6
- Date:
- Fri May 30 19:02:51 2014 +0000
- Revision:
- 10:4f695111eb54
- Parent:
- 9:2c1d82ecd63c
Added MBED_OPERATORS check to implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neilt6 | 0:abc480f8eeab | 1 | /* MAX17048 Driver Library |
neilt6 | 0:abc480f8eeab | 2 | * Copyright (c) 2013 Neil Thiessen |
neilt6 | 0:abc480f8eeab | 3 | * |
neilt6 | 0:abc480f8eeab | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
neilt6 | 0:abc480f8eeab | 5 | * you may not use this file except in compliance with the License. |
neilt6 | 0:abc480f8eeab | 6 | * You may obtain a copy of the License at |
neilt6 | 0:abc480f8eeab | 7 | * |
neilt6 | 0:abc480f8eeab | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
neilt6 | 0:abc480f8eeab | 9 | * |
neilt6 | 0:abc480f8eeab | 10 | * Unless required by applicable law or agreed to in writing, software |
neilt6 | 0:abc480f8eeab | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
neilt6 | 0:abc480f8eeab | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
neilt6 | 0:abc480f8eeab | 13 | * See the License for the specific language governing permissions and |
neilt6 | 0:abc480f8eeab | 14 | * limitations under the License. |
neilt6 | 0:abc480f8eeab | 15 | */ |
neilt6 | 0:abc480f8eeab | 16 | |
neilt6 | 0:abc480f8eeab | 17 | #ifndef MAX17048_H |
neilt6 | 0:abc480f8eeab | 18 | #define MAX17048_H |
neilt6 | 0:abc480f8eeab | 19 | |
neilt6 | 0:abc480f8eeab | 20 | #include "mbed.h" |
neilt6 | 0:abc480f8eeab | 21 | |
neilt6 | 0:abc480f8eeab | 22 | /** MAX17048 class. |
neilt6 | 0:abc480f8eeab | 23 | * Used for controlling a MAX17048 fuel gauge connected via I2C. |
neilt6 | 0:abc480f8eeab | 24 | * |
neilt6 | 0:abc480f8eeab | 25 | * Example: |
neilt6 | 0:abc480f8eeab | 26 | * @code |
neilt6 | 0:abc480f8eeab | 27 | * #include "mbed.h" |
neilt6 | 0:abc480f8eeab | 28 | * #include "MAX17048.h" |
neilt6 | 0:abc480f8eeab | 29 | * |
neilt6 | 0:abc480f8eeab | 30 | * MAX17048 gauge(p28, p27); |
neilt6 | 0:abc480f8eeab | 31 | * |
neilt6 | 3:32087cca331f | 32 | * int main() |
neilt6 | 3:32087cca331f | 33 | * { |
neilt6 | 3:32087cca331f | 34 | * //Try to open the MAX17048 |
neilt6 | 3:32087cca331f | 35 | * if (gauge.open()) { |
neilt6 | 3:32087cca331f | 36 | * printf("Device detected!\n"); |
neilt6 | 0:abc480f8eeab | 37 | * |
neilt6 | 7:bf6972a21c61 | 38 | * //Load the default compensation value |
neilt6 | 7:bf6972a21c61 | 39 | * gauge.compensation(MAX17048::RCOMP0); |
neilt6 | 7:bf6972a21c61 | 40 | * |
neilt6 | 3:32087cca331f | 41 | * while (1) { |
neilt6 | 4:e61b2723d2cf | 42 | * //Print the current state of charge |
neilt6 | 4:e61b2723d2cf | 43 | * printf("SOC = %f%%\n", (float)gauge); |
neilt6 | 3:32087cca331f | 44 | * |
neilt6 | 3:32087cca331f | 45 | * //Sleep for 0.5 seconds |
neilt6 | 3:32087cca331f | 46 | * wait(0.5); |
neilt6 | 3:32087cca331f | 47 | * } |
neilt6 | 3:32087cca331f | 48 | * } else { |
neilt6 | 4:e61b2723d2cf | 49 | * error("Device not detected!\n"); |
neilt6 | 0:abc480f8eeab | 50 | * } |
neilt6 | 0:abc480f8eeab | 51 | * } |
neilt6 | 0:abc480f8eeab | 52 | * @endcode |
neilt6 | 0:abc480f8eeab | 53 | */ |
neilt6 | 0:abc480f8eeab | 54 | class MAX17048 |
neilt6 | 0:abc480f8eeab | 55 | { |
neilt6 | 0:abc480f8eeab | 56 | public: |
neilt6 | 7:bf6972a21c61 | 57 | /** The default compensation value for the MAX17048 |
neilt6 | 7:bf6972a21c61 | 58 | */ |
neilt6 | 8:65c889800b3a | 59 | static const char RCOMP0; |
neilt6 | 7:bf6972a21c61 | 60 | |
neilt6 | 0:abc480f8eeab | 61 | /** Represents the different alert flags for the MAX17048 |
neilt6 | 0:abc480f8eeab | 62 | */ |
neilt6 | 0:abc480f8eeab | 63 | enum AlertFlags { |
neilt6 | 0:abc480f8eeab | 64 | ALERT_RI = (1 << 0), /**< Reset indicator */ |
neilt6 | 0:abc480f8eeab | 65 | ALERT_VH = (1 << 1), /**< Voltage high alert */ |
neilt6 | 0:abc480f8eeab | 66 | ALERT_VL = (1 << 2), /**< Voltage low alert */ |
neilt6 | 0:abc480f8eeab | 67 | ALERT_VR = (1 << 3), /**< Voltage reset alert */ |
neilt6 | 0:abc480f8eeab | 68 | ALERT_HD = (1 << 4), /**< SOC low alert */ |
neilt6 | 0:abc480f8eeab | 69 | ALERT_SC = (1 << 5) /**< SOC change alert */ |
neilt6 | 0:abc480f8eeab | 70 | }; |
neilt6 | 0:abc480f8eeab | 71 | |
neilt6 | 0:abc480f8eeab | 72 | /** Create a MAX17048 object connected to the specified I2C pins |
neilt6 | 0:abc480f8eeab | 73 | * |
neilt6 | 1:734b1a089a9c | 74 | * @param sda The I2C data pin. |
neilt6 | 1:734b1a089a9c | 75 | * @param scl The I2C clock pin. |
neilt6 | 9:2c1d82ecd63c | 76 | * @param hz The I2C bus frequency (defaults to 400kHz). |
neilt6 | 0:abc480f8eeab | 77 | */ |
neilt6 | 9:2c1d82ecd63c | 78 | MAX17048(PinName sda, PinName scl, int hz = 400000); |
neilt6 | 0:abc480f8eeab | 79 | |
neilt6 | 7:bf6972a21c61 | 80 | /** Probe for the MAX17048 and indicate if it's present on the bus |
neilt6 | 3:32087cca331f | 81 | * |
neilt6 | 3:32087cca331f | 82 | * @returns |
neilt6 | 3:32087cca331f | 83 | * 'true' if the device exists on the bus, |
neilt6 | 3:32087cca331f | 84 | * 'false' if the device doesn't exist on the bus. |
neilt6 | 3:32087cca331f | 85 | */ |
neilt6 | 5:ffce4fe12ed1 | 86 | bool open(); |
neilt6 | 3:32087cca331f | 87 | |
neilt6 | 0:abc480f8eeab | 88 | /** Command the MAX17048 to perform a power-on reset |
neilt6 | 0:abc480f8eeab | 89 | */ |
neilt6 | 5:ffce4fe12ed1 | 90 | void reset(); |
neilt6 | 0:abc480f8eeab | 91 | |
neilt6 | 0:abc480f8eeab | 92 | /** Command the MAX17048 to perform a QuickStart |
neilt6 | 0:abc480f8eeab | 93 | */ |
neilt6 | 5:ffce4fe12ed1 | 94 | void quickStart(); |
neilt6 | 0:abc480f8eeab | 95 | |
neilt6 | 0:abc480f8eeab | 96 | /** Determine whether sleep mode is enabled on the MAX17048 |
neilt6 | 10:4f695111eb54 | 97 | * |
neilt6 | 10:4f695111eb54 | 98 | * @returns |
neilt6 | 10:4f695111eb54 | 99 | * 'true' if sleep mode is enabled, |
neilt6 | 10:4f695111eb54 | 100 | * 'false' if sleep mode is disabled. |
neilt6 | 10:4f695111eb54 | 101 | */ |
neilt6 | 5:ffce4fe12ed1 | 102 | bool sleepEnabled(); |
neilt6 | 0:abc480f8eeab | 103 | |
neilt6 | 0:abc480f8eeab | 104 | /** Enable or disable sleep mode on the MAX17048 |
neilt6 | 0:abc480f8eeab | 105 | * |
neilt6 | 0:abc480f8eeab | 106 | * @param enabled Whether or not sleep mode is enabled. |
neilt6 | 0:abc480f8eeab | 107 | */ |
neilt6 | 2:0a98e081b48c | 108 | void sleepEnabled(bool enabled); |
neilt6 | 2:0a98e081b48c | 109 | |
neilt6 | 0:abc480f8eeab | 110 | /** Determine whether or not the MAX17048 is hibernating |
neilt6 | 10:4f695111eb54 | 111 | * |
neilt6 | 10:4f695111eb54 | 112 | * @returns |
neilt6 | 10:4f695111eb54 | 113 | * 'true' if hibernating, |
neilt6 | 10:4f695111eb54 | 114 | * 'false' if not hibernating. |
neilt6 | 10:4f695111eb54 | 115 | */ |
neilt6 | 5:ffce4fe12ed1 | 116 | bool hibernating(); |
neilt6 | 2:0a98e081b48c | 117 | |
neilt6 | 0:abc480f8eeab | 118 | /** Get the current hibernate threshold of the MAX17048 |
neilt6 | 10:4f695111eb54 | 119 | * |
neilt6 | 10:4f695111eb54 | 120 | * @returns The current hibernate threshold in \%/hr. |
neilt6 | 10:4f695111eb54 | 121 | */ |
neilt6 | 5:ffce4fe12ed1 | 122 | float hibernateThreshold(); |
neilt6 | 2:0a98e081b48c | 123 | |
neilt6 | 0:abc480f8eeab | 124 | /** Set the hibernate threshold of the MAX17048 |
neilt6 | 0:abc480f8eeab | 125 | * |
neilt6 | 0:abc480f8eeab | 126 | * @param threshold The new hibernate threshold in \%/hr. |
neilt6 | 0:abc480f8eeab | 127 | */ |
neilt6 | 2:0a98e081b48c | 128 | void hibernateThreshold(float threshold); |
neilt6 | 2:0a98e081b48c | 129 | |
neilt6 | 0:abc480f8eeab | 130 | /** Get the current active threshold of the MAX17048 |
neilt6 | 10:4f695111eb54 | 131 | * |
neilt6 | 10:4f695111eb54 | 132 | * @returns The current active threshold in volts. |
neilt6 | 10:4f695111eb54 | 133 | */ |
neilt6 | 5:ffce4fe12ed1 | 134 | float activeThreshold(); |
neilt6 | 2:0a98e081b48c | 135 | |
neilt6 | 0:abc480f8eeab | 136 | /** Set the active threshold of the MAX17048 |
neilt6 | 0:abc480f8eeab | 137 | * |
neilt6 | 0:abc480f8eeab | 138 | * @param threshold The new active threshold in volts. |
neilt6 | 0:abc480f8eeab | 139 | */ |
neilt6 | 2:0a98e081b48c | 140 | void activeThreshold(float threshold); |
neilt6 | 2:0a98e081b48c | 141 | |
neilt6 | 0:abc480f8eeab | 142 | /** Get the production version of the MAX17048 |
neilt6 | 10:4f695111eb54 | 143 | * |
neilt6 | 10:4f695111eb54 | 144 | * @returns The 16-bit production version. |
neilt6 | 10:4f695111eb54 | 145 | */ |
neilt6 | 5:ffce4fe12ed1 | 146 | unsigned short version(); |
neilt6 | 2:0a98e081b48c | 147 | |
neilt6 | 7:bf6972a21c61 | 148 | /** Get the current compensation value of the MAX17048 |
neilt6 | 7:bf6972a21c61 | 149 | * |
neilt6 | 7:bf6972a21c61 | 150 | * @returns The current compensation value as an unsigned char (0 to 255). |
neilt6 | 7:bf6972a21c61 | 151 | */ |
neilt6 | 7:bf6972a21c61 | 152 | char compensation(); |
neilt6 | 7:bf6972a21c61 | 153 | |
neilt6 | 7:bf6972a21c61 | 154 | /** Set the compensation value of the MAX17048 |
neilt6 | 7:bf6972a21c61 | 155 | * |
neilt6 | 7:bf6972a21c61 | 156 | * @param rcomp The new compensation value as an unsigned char (0 to 255). |
neilt6 | 7:bf6972a21c61 | 157 | */ |
neilt6 | 7:bf6972a21c61 | 158 | void compensation(char rcomp); |
neilt6 | 7:bf6972a21c61 | 159 | |
neilt6 | 7:bf6972a21c61 | 160 | /** Set the compensation value of the MAX17048 from the current cell temperature |
neilt6 | 0:abc480f8eeab | 161 | * |
neilt6 | 0:abc480f8eeab | 162 | * @param temp The current cell temperature in °C. |
neilt6 | 0:abc480f8eeab | 163 | */ |
neilt6 | 2:0a98e081b48c | 164 | void tempCompensation(float temp); |
neilt6 | 2:0a98e081b48c | 165 | |
neilt6 | 0:abc480f8eeab | 166 | /** Determine whether or not the MAX17048 is in sleep mode |
neilt6 | 10:4f695111eb54 | 167 | * |
neilt6 | 10:4f695111eb54 | 168 | * @returns |
neilt6 | 10:4f695111eb54 | 169 | * 'true' if in sleep mode, |
neilt6 | 10:4f695111eb54 | 170 | * 'false' if not in sleep mode. |
neilt6 | 10:4f695111eb54 | 171 | */ |
neilt6 | 5:ffce4fe12ed1 | 172 | bool sleeping(); |
neilt6 | 2:0a98e081b48c | 173 | |
neilt6 | 0:abc480f8eeab | 174 | /** Enter or exit sleep mode on the MAX17048 (sleep mode must be enabled first) |
neilt6 | 0:abc480f8eeab | 175 | * |
neilt6 | 0:abc480f8eeab | 176 | * @param sleep Whether or not to sleep. |
neilt6 | 0:abc480f8eeab | 177 | */ |
neilt6 | 2:0a98e081b48c | 178 | void sleep(bool sleep); |
neilt6 | 2:0a98e081b48c | 179 | |
neilt6 | 0:abc480f8eeab | 180 | /** Determine whether or not the SOC 1% change alert is enabled on the MAX17048 |
neilt6 | 10:4f695111eb54 | 181 | * |
neilt6 | 10:4f695111eb54 | 182 | * @returns |
neilt6 | 10:4f695111eb54 | 183 | * 'true' if enabled, |
neilt6 | 10:4f695111eb54 | 184 | * 'false' if not enabled. |
neilt6 | 10:4f695111eb54 | 185 | */ |
neilt6 | 5:ffce4fe12ed1 | 186 | bool socChangeAlertEnabled(); |
neilt6 | 2:0a98e081b48c | 187 | |
neilt6 | 0:abc480f8eeab | 188 | /** Enable or disable the SOC 1% change alert on the MAX17048 |
neilt6 | 0:abc480f8eeab | 189 | * |
neilt6 | 0:abc480f8eeab | 190 | * @param enabled Whether or the SOC 1% change alert is enabled. |
neilt6 | 0:abc480f8eeab | 191 | */ |
neilt6 | 2:0a98e081b48c | 192 | void socChangeAlertEnabled(bool enabled); |
neilt6 | 2:0a98e081b48c | 193 | |
neilt6 | 0:abc480f8eeab | 194 | /** Determine whether or not the MAX17048 is asserting the ALRT pin |
neilt6 | 10:4f695111eb54 | 195 | * |
neilt6 | 10:4f695111eb54 | 196 | * @returns |
neilt6 | 10:4f695111eb54 | 197 | * 'true' if alerting, |
neilt6 | 10:4f695111eb54 | 198 | * 'false' if not alerting. |
neilt6 | 10:4f695111eb54 | 199 | */ |
neilt6 | 5:ffce4fe12ed1 | 200 | bool alerting(); |
neilt6 | 2:0a98e081b48c | 201 | |
neilt6 | 0:abc480f8eeab | 202 | /** Command the MAX17048 to de-assert the ALRT pin |
neilt6 | 10:4f695111eb54 | 203 | */ |
neilt6 | 5:ffce4fe12ed1 | 204 | void clearAlert(); |
neilt6 | 2:0a98e081b48c | 205 | |
neilt6 | 0:abc480f8eeab | 206 | /** Get the current SOC empty alert threshold of the MAX17048 |
neilt6 | 10:4f695111eb54 | 207 | * |
neilt6 | 10:4f695111eb54 | 208 | * @returns The current SOC empty alert threshold in %. |
neilt6 | 10:4f695111eb54 | 209 | */ |
neilt6 | 5:ffce4fe12ed1 | 210 | char emptyAlertThreshold(); |
neilt6 | 2:0a98e081b48c | 211 | |
neilt6 | 0:abc480f8eeab | 212 | /** Set the SOC empty alert threshold of the MAX17048 |
neilt6 | 0:abc480f8eeab | 213 | * |
neilt6 | 0:abc480f8eeab | 214 | * @param threshold The new SOC empty alert threshold in %. |
neilt6 | 0:abc480f8eeab | 215 | */ |
neilt6 | 2:0a98e081b48c | 216 | void emptyAlertThreshold(char threshold); |
neilt6 | 2:0a98e081b48c | 217 | |
neilt6 | 0:abc480f8eeab | 218 | /** Get the current low voltage alert threshold of the MAX17048 |
neilt6 | 10:4f695111eb54 | 219 | * |
neilt6 | 10:4f695111eb54 | 220 | * @returns The current low voltage alert threshold in volts. |
neilt6 | 10:4f695111eb54 | 221 | */ |
neilt6 | 5:ffce4fe12ed1 | 222 | float vAlertMinThreshold(); |
neilt6 | 2:0a98e081b48c | 223 | |
neilt6 | 0:abc480f8eeab | 224 | /** Set the low voltage alert threshold of the MAX17048 |
neilt6 | 0:abc480f8eeab | 225 | * |
neilt6 | 0:abc480f8eeab | 226 | * @param threshold The new low voltage alert threshold in volts. |
neilt6 | 0:abc480f8eeab | 227 | */ |
neilt6 | 2:0a98e081b48c | 228 | void vAlertMinThreshold(float threshold); |
neilt6 | 2:0a98e081b48c | 229 | |
neilt6 | 0:abc480f8eeab | 230 | /** Get the current high voltage alert threshold of the MAX17048 |
neilt6 | 10:4f695111eb54 | 231 | * |
neilt6 | 10:4f695111eb54 | 232 | * @returns The current high voltage alert threshold in volts. |
neilt6 | 10:4f695111eb54 | 233 | */ |
neilt6 | 5:ffce4fe12ed1 | 234 | float vAlertMaxThreshold(); |
neilt6 | 2:0a98e081b48c | 235 | |
neilt6 | 0:abc480f8eeab | 236 | /** Set the high voltage alert threshold of the MAX17048 |
neilt6 | 0:abc480f8eeab | 237 | * |
neilt6 | 0:abc480f8eeab | 238 | * @param threshold The new high voltage alert threshold in volts. |
neilt6 | 0:abc480f8eeab | 239 | */ |
neilt6 | 2:0a98e081b48c | 240 | void vAlertMaxThreshold(float threshold); |
neilt6 | 2:0a98e081b48c | 241 | |
neilt6 | 0:abc480f8eeab | 242 | /** Get the current reset voltage threshold of the MAX17048 |
neilt6 | 10:4f695111eb54 | 243 | * |
neilt6 | 10:4f695111eb54 | 244 | * @returns The current reset voltage threshold in volts. |
neilt6 | 10:4f695111eb54 | 245 | */ |
neilt6 | 5:ffce4fe12ed1 | 246 | float vResetThreshold(); |
neilt6 | 2:0a98e081b48c | 247 | |
neilt6 | 0:abc480f8eeab | 248 | /** Set the reset voltage threshold of the MAX17048 |
neilt6 | 0:abc480f8eeab | 249 | * |
neilt6 | 0:abc480f8eeab | 250 | * @param threshold The new reset voltage threshold in volts. |
neilt6 | 0:abc480f8eeab | 251 | */ |
neilt6 | 2:0a98e081b48c | 252 | void vResetThreshold(float threshold); |
neilt6 | 2:0a98e081b48c | 253 | |
neilt6 | 0:abc480f8eeab | 254 | /** Determine whether or not the reset voltage comparator is enabled on the MAX17048 |
neilt6 | 10:4f695111eb54 | 255 | * |
neilt6 | 10:4f695111eb54 | 256 | * @returns |
neilt6 | 10:4f695111eb54 | 257 | * 'true' if enabled, |
neilt6 | 10:4f695111eb54 | 258 | * 'false' if not enabled. |
neilt6 | 10:4f695111eb54 | 259 | */ |
neilt6 | 5:ffce4fe12ed1 | 260 | bool comparatorEnabled(); |
neilt6 | 2:0a98e081b48c | 261 | |
neilt6 | 0:abc480f8eeab | 262 | /** Enable or disable the reset voltage comparator on the MAX17048 |
neilt6 | 0:abc480f8eeab | 263 | * |
neilt6 | 0:abc480f8eeab | 264 | * @param enabled Whether or not the reset voltage comparator is enabled. |
neilt6 | 0:abc480f8eeab | 265 | */ |
neilt6 | 2:0a98e081b48c | 266 | void comparatorEnabled(bool enabled); |
neilt6 | 2:0a98e081b48c | 267 | |
neilt6 | 0:abc480f8eeab | 268 | /** Get the factory programmed 8-bit ID of the MAX17048 |
neilt6 | 10:4f695111eb54 | 269 | * |
neilt6 | 10:4f695111eb54 | 270 | * @returns The 8-bit ID. |
neilt6 | 10:4f695111eb54 | 271 | */ |
neilt6 | 5:ffce4fe12ed1 | 272 | char id(); |
neilt6 | 2:0a98e081b48c | 273 | |
neilt6 | 0:abc480f8eeab | 274 | /** Determine whether or not the voltage reset alert is enabled on the MAX17048 |
neilt6 | 10:4f695111eb54 | 275 | * |
neilt6 | 10:4f695111eb54 | 276 | * @returns |
neilt6 | 10:4f695111eb54 | 277 | * 'true' if enabled, |
neilt6 | 10:4f695111eb54 | 278 | * 'false' if not enabled. |
neilt6 | 10:4f695111eb54 | 279 | */ |
neilt6 | 5:ffce4fe12ed1 | 280 | bool vResetAlertEnabled(); |
neilt6 | 2:0a98e081b48c | 281 | |
neilt6 | 0:abc480f8eeab | 282 | /** Enable or disable the voltage reset alert on the MAX17048 |
neilt6 | 0:abc480f8eeab | 283 | * |
neilt6 | 0:abc480f8eeab | 284 | * @param enabled Whether or the voltage reset alert is enabled. |
neilt6 | 0:abc480f8eeab | 285 | */ |
neilt6 | 2:0a98e081b48c | 286 | void vResetAlertEnabled(bool enabled); |
neilt6 | 2:0a98e081b48c | 287 | |
neilt6 | 0:abc480f8eeab | 288 | /** Get the current alert flags on the MAX17048 |
neilt6 | 10:4f695111eb54 | 289 | * |
neilt6 | 10:4f695111eb54 | 290 | * @returns The current alert flags as AlertFlags enum values OR'd together. |
neilt6 | 10:4f695111eb54 | 291 | */ |
neilt6 | 5:ffce4fe12ed1 | 292 | char alertFlags(); |
neilt6 | 2:0a98e081b48c | 293 | |
neilt6 | 0:abc480f8eeab | 294 | /** Clear the specified alert flags on the MAX17048 |
neilt6 | 0:abc480f8eeab | 295 | * |
neilt6 | 0:abc480f8eeab | 296 | * @param flags The alert flags to clear as AlertFlags enum values OR'd together. |
neilt6 | 0:abc480f8eeab | 297 | */ |
neilt6 | 0:abc480f8eeab | 298 | void clearAlertFlags(char flags); |
neilt6 | 0:abc480f8eeab | 299 | |
neilt6 | 0:abc480f8eeab | 300 | /** Get the current cell voltage measurement of the MAX17048 |
neilt6 | 10:4f695111eb54 | 301 | * |
neilt6 | 10:4f695111eb54 | 302 | * @returns The cell voltage measurement as a float. |
neilt6 | 10:4f695111eb54 | 303 | */ |
neilt6 | 5:ffce4fe12ed1 | 304 | float vcell(); |
neilt6 | 0:abc480f8eeab | 305 | |
neilt6 | 4:e61b2723d2cf | 306 | /** Get the current state of charge measurement of the MAX17048 as a float |
neilt6 | 0:abc480f8eeab | 307 | * |
neilt6 | 0:abc480f8eeab | 308 | * @returns The state of charge measurement as a float. |
neilt6 | 0:abc480f8eeab | 309 | */ |
neilt6 | 5:ffce4fe12ed1 | 310 | float soc(); |
neilt6 | 0:abc480f8eeab | 311 | |
neilt6 | 4:e61b2723d2cf | 312 | /** Get the current state of charge measurement of the MAX17048 as an int |
neilt6 | 4:e61b2723d2cf | 313 | * |
neilt6 | 4:e61b2723d2cf | 314 | * @returns The state of charge measurement as an int. |
neilt6 | 4:e61b2723d2cf | 315 | */ |
neilt6 | 5:ffce4fe12ed1 | 316 | int soc_int(); |
neilt6 | 4:e61b2723d2cf | 317 | |
neilt6 | 0:abc480f8eeab | 318 | /** Get the current C rate measurement of the MAX17048 |
neilt6 | 0:abc480f8eeab | 319 | * |
neilt6 | 0:abc480f8eeab | 320 | * @returns The C rate measurement as a float. |
neilt6 | 0:abc480f8eeab | 321 | */ |
neilt6 | 5:ffce4fe12ed1 | 322 | float crate(); |
neilt6 | 0:abc480f8eeab | 323 | |
neilt6 | 4:e61b2723d2cf | 324 | #ifdef MBED_OPERATORS |
neilt6 | 4:e61b2723d2cf | 325 | /** A shorthand for soc() |
neilt6 | 4:e61b2723d2cf | 326 | * |
neilt6 | 4:e61b2723d2cf | 327 | * @returns The state of charge measurement as a float. |
neilt6 | 4:e61b2723d2cf | 328 | */ |
neilt6 | 5:ffce4fe12ed1 | 329 | operator float(); |
neilt6 | 4:e61b2723d2cf | 330 | |
neilt6 | 5:ffce4fe12ed1 | 331 | /** A shorthand for soc_int() |
neilt6 | 4:e61b2723d2cf | 332 | * |
neilt6 | 4:e61b2723d2cf | 333 | * @returns The state of charge measurement as an int. |
neilt6 | 4:e61b2723d2cf | 334 | */ |
neilt6 | 5:ffce4fe12ed1 | 335 | operator int(); |
neilt6 | 4:e61b2723d2cf | 336 | #endif |
neilt6 | 4:e61b2723d2cf | 337 | |
neilt6 | 0:abc480f8eeab | 338 | private: |
neilt6 | 2:0a98e081b48c | 339 | //I2C register addresses |
neilt6 | 2:0a98e081b48c | 340 | enum Register { |
neilt6 | 2:0a98e081b48c | 341 | REG_VCELL = 0x02, |
neilt6 | 2:0a98e081b48c | 342 | REG_SOC = 0x04, |
neilt6 | 2:0a98e081b48c | 343 | REG_MODE = 0x06, |
neilt6 | 2:0a98e081b48c | 344 | REG_VERSION = 0x08, |
neilt6 | 2:0a98e081b48c | 345 | REG_HIBRT = 0x0A, |
neilt6 | 2:0a98e081b48c | 346 | REG_CONFIG = 0x0C, |
neilt6 | 2:0a98e081b48c | 347 | REG_VALRT = 0x14, |
neilt6 | 2:0a98e081b48c | 348 | REG_CRATE = 0x16, |
neilt6 | 2:0a98e081b48c | 349 | REG_VRESET_ID = 0x18, |
neilt6 | 2:0a98e081b48c | 350 | REG_STATUS = 0x1A, |
neilt6 | 2:0a98e081b48c | 351 | REG_TABLE = 0x40, |
neilt6 | 2:0a98e081b48c | 352 | REG_CMD = 0xFE |
neilt6 | 2:0a98e081b48c | 353 | }; |
neilt6 | 2:0a98e081b48c | 354 | |
neilt6 | 2:0a98e081b48c | 355 | //Member constants |
neilt6 | 8:65c889800b3a | 356 | static const int m_ADDR; |
neilt6 | 2:0a98e081b48c | 357 | |
neilt6 | 2:0a98e081b48c | 358 | //Member variables |
neilt6 | 2:0a98e081b48c | 359 | I2C m_I2C; |
neilt6 | 2:0a98e081b48c | 360 | |
neilt6 | 2:0a98e081b48c | 361 | //Internal functions |
neilt6 | 2:0a98e081b48c | 362 | unsigned short read(char reg); |
neilt6 | 2:0a98e081b48c | 363 | void write(char reg, unsigned short data); |
neilt6 | 0:abc480f8eeab | 364 | }; |
neilt6 | 0:abc480f8eeab | 365 | |
neilt6 | 0:abc480f8eeab | 366 | #endif |