-
Notifications
You must be signed in to change notification settings - Fork 0
/
BQ24195.h
320 lines (293 loc) · 11.6 KB
/
BQ24195.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#ifndef _SMART_TECH_BQ24195_H_
#define _SMART_TECH_BQ24195_H_
#ifdef NRF52840_XXAA
#include "TWIClass.h"
#else
#include "Wire.h"
#define TWIClass TwoWire
#endif
//Default BQ24195 I2C address
#define BQ24195_ADDRESS 0x6B
// Register address definitions
#define INPUT_SOURCE_REGISTER 0x00
#define POWERON_CONFIG_REGISTER 0x01
#define CHARGE_CURRENT_CONTROL_REGISTER 0x02
#define PRECHARGE_CURRENT_CONTROL_REGISTER 0x03
#define CHARGE_VOLTAGE_CONTROL_REGISTER 0x04
#define CHARGE_TIMER_CONTROL_REGISTER 0x05
#define THERMAL_REG_CONTROL_REGISTER 0x06
#define MISC_CONTROL_REGISTER 0x07
#define SYSTEM_STATUS_REGISTER 0x08
#define FAULT_REGISTER 0x09
#define BQ24195_VERSION_REGISTER 0x0A
class BQ24195 {
public:
BQ24195(TWIClass* _twi);
~BQ24195();
bool begin();
uint8_t getVersion();
uint8_t getSystemStatus();
uint8_t getFault();
// Input source control register
uint8_t readInputSourceRegister(void);
bool enableBuck(void);
bool disableBuck(void);
bool setInputCurrentLimit(uint16_t current);
uint16_t getInputCurrentLimit(void);
bool setInputVoltageLimit(uint16_t voltage);
uint8_t getInputVoltageLimit(void);
// Power ON configuration register
bool enableCharging(void);
bool disableCharging(void);
bool enableOTG(void);
bool disableOTG(void);
bool resetWatchdog(void);
bool setMinimumSystemVoltage(uint16_t voltage);
uint16_t getMinimumSystemVoltage();
uint8_t readPowerONRegister(void);
// Charge current control register
bool setChargeCurrent(bool bit7, bool bit6, bool bit5, bool bit4, bool bit3, bool bit2);
uint8_t getChargeCurrent(void);
//PreCharge/ Termination Current Control Register
bool setPreChargeCurrent();
uint8_t getPreChargeCurrent();
bool setTermChargeCurrent();
uint8_t getTermChargeCurrent();
//Charge Voltage Control Register
bool setChargeVoltage(uint16_t voltage);
uint8_t getChargeVoltage();
uint16_t getChargeVoltageValue();
//CHARGE_TIMER_CONTROL_REGISTER
uint8_t readChargeTermRegister();
bool disableWatchdog(void);
bool setWatchdog(uint8_t time);
//Thermal Regulation Control Register
bool setThermalRegulation();
uint8_t getThermalRegulation();
// Recharge threshold
uint16_t getRechargeThreshold();
bool setRechargeThreshold(uint16_t voltage);
//Misc Operation Control Register
uint8_t readOpControlRegister();
bool enableDPDM(void);
bool disableDPDM(void);
bool enableBATFET(void);
bool disableBATFET(void);
bool safetyTimer(); //slow/ normal
bool enableChargeFaultINT();
bool disableChargeFaultINT();
bool enableBatFaultINT();
bool disableBatFaultINT();
//System Status Register
uint8_t getVbusStat();
uint8_t getChargingStat();
bool getDPMStat();
bool isPowerGood(void);
bool isHot(void);
bool getVsysStat();
//Fault Register
bool isWatchdogFault();
uint8_t getChargeFault();
bool isBatFault();
uint8_t getNTCFault();
TWIClass* twi = NULL;
private:
uint8_t readRegister(uint8_t startAddress);
void writeRegister(uint8_t address, uint8_t DATA);
};
#endif /* _SMART_TECH_BQ24195_H_ */
/*
// List of Registers
//-----------------------------------------------------------------------------
// Input source control register
//-----------------------------------------------------------------------------
REG00
BIT
7 : 0:Enable Buck regulator 1:disable buck regulator (powered only from a LiPo)
--- input volatge limit. this is used to determine if USB source is overloaded
6 : VINDPM[3] 640mV | offset is 3.88V, Range is 3.88 to 5.08
5 : VINDPM[2] 320mV | enabling bits 3 to 6 adds the volatges to 3.88 base value
4 : VINDPM[1] 160mV | Default is 4.36 (0110)
3 : VINDPM[0] 80mV |
--- input current limit
2 : INLIM[2] 000: 100mA, 001: 150mA, 010: 500mA, | Default: 100mA when OTG pin is LOW and
1 : INLIM[1] 011: 900mA, 100: 1.2A, 101: 1.5A | 500mA when OTG pin is HIGH
0 : INLIM[0] 110: 2.0A, 111: 3.0A | when charging port detected, 1.5A
//-----------------------------------------------------------------------------
// Power ON configuration register
//-----------------------------------------------------------------------------
REG01
BIT
7: 0: keep current settings 1:reset register to default
6: 0: normal 1: reset I2C watchdog timer
--- charger config
5: CHG_CONFIG[1] | 00: Disable charging, 01: Charge battery(default)
4: CHG_CONFIG[0] | 10/11: OTG
--- minimum system voltage limit. this is the minimum output feeding the gsm module
3: SYS_MIN[2] 0.4V | offset is 3.0V, Range 3.0V to 3.7V
2: SYS_MIN[1] 0.2V | enabling bits 1 to 3 adds the volatges to 3.0 base value
1: SYS_MIN[0] 0.1V | default is 3.5V (101)
0: Reserved
//-----------------------------------------------------------------------------
// Charge current control register
//-----------------------------------------------------------------------------
REG02
BIT
7: ICHG[5] 2048mA | offset is 512mA
6: ICHG[4] 1024mA | Range: 512 to 4544mA (BQ24195)
5: ICHG[3] 512mA | Range: 512 to 2496mA (BQ24195L)
4: ICHG[2] 256mA | Default: 2048mA (011000) = 512mA+1024mA+512mA
3: ICHG[1] 128mA | enabling bits 2 to 7 adds the current to 512mA base value
2: ICHG[0] 64mA |
1: Reserved (should always be 0)
0: FORCE_20PCT (fill this description)
//-----------------------------------------------------------------------------
//PreCharge/ Termination Current Control Register
//-----------------------------------------------------------------------------
REG03
BIT
--- precharge current limit
7: IPRECHG[3] 1024mA | offset is 128mA
6: IPRECHG[2] 512mA | Range: 128 mA to 2048 mA
5: IPRECHG[1] 256mA | Default: 256 mA (0001) = 128mA+128mA
4: IPRECHG[0] 128mA | enabling bits 4 to 7, adds the current to 128mA base value
--- termination current limit
3: ITERM[3] 1024mA | offset is 128mA
2: ITERM[2] 512mA | Range: 128 mA to 2048 mA
1: ITERM[1] 256mA | Default: 256 mA (0001) = 128mA+128mA
0: ITERM[0] 128mA | enabling bits 0 to 3, adds the current to 128mA base value
//-----------------------------------------------------------------------------
//Charge Voltage Control Register
//-----------------------------------------------------------------------------
REG04
BIT
--- Charge Voltage Limit
7: VREG[5] 512mV | offset os 3.504V
6: VREG[4] 256mV | Range: 3.504V to 4.400V
5: VREG[3] 128mV | Default: 4.208V (101100) = 3.504V+512mV+128mV+64mV
4: VREG[2] 64mV | enabling bits 2 to 7, adds the voltage to 3.504V base value
3: VREG[1] 32mV |
2: VREG[0] 16mV |
--- Battery Precharge to Fast Charge Threshold
1: BATLOWV 0:2.8V, 1:3.0V Default:3.0V(1)
--- Battery Recharge Threshold (below battery regulation voltage)
0: VRECHG 0:100mV, 1:300mV Default:100mV(0)
//-----------------------------------------------------------------------------
//Charge Termination/Timer Control Register
//-----------------------------------------------------------------------------
REG05
BIT
--- Charging Termination Enable
7: EN_TERM 0:Disable
1:Enable
Default: Enable Termination (1)
--- Termination Indicator Threshold
6: TERM_STAT 0:Match ITERM,
1:STAT pin high before actual termination when charge current below 800 mA
Default Match ITERM (0)
--- I2C Watchdog Timer Setting
5: WATCHDOG[1] | 00: disable timer, 01: 40seconds
4: WATCHDOG[0] | 10: 80 seconds, 11: 160 seconds. Default: 40s(01)
--- Charging Safety Timer Enable
3: EN_TIMER 0:Disable
1:Enable
Default:Enable(1)
--- Fast Charge Timer Setting
2: CHG_TIMER[1] | 00: 5hrs, 01: 8hrs, 10: 12hrs, 11: 20hrs
1: CHG_TIMER[0] | Default: 8hrs(01)
0: Reserved
//-----------------------------------------------------------------------------
//Thermal Regulation Control Register
//-----------------------------------------------------------------------------
REG06
BIT
7: Reserved (should always be 0)
6: Reserved (should always be 0)
5: Reserved (should always be 0)
4: Reserved (should always be 0)
3: Reserved (should always be 0)
2: Reserved (should always be 0)
--- Thermal Regulation Threshold
1: TREG[1] | 00: 60°C, 01: 80°C, 10:100°C, 11: 120°C
0: TREG[0] | Default: 120°C (11)
//-----------------------------------------------------------------------------
//Misc Operation Control Register
//-----------------------------------------------------------------------------
REG07
BIT
--- Force DPDM detection
7: DPDM_EN 0: Not in D+/D– detection,
1: Force D+/D– detection.
Default: (0)
--- Safety Timer Setting during Input DPM and Thermal Regulation
6: TMR2X_EN 0: Safety timer not slowed by 2X during input DPM or thermal regulation
1: Safety timer slowed by 2X during input DPM or thermal regulation
Default: (1)
--- Force BATFET Off (this essentially disconnects the battery from the system)
5: BATFET_Disable 0: Allow Q4 turn on
1: Turn off Q4
Default: (0)
4: 0 – Reserved. Must write "0"
3: 1 – Reserved. Must write "1"
2: 0 – Reserved. Must write "0"
1: INT_MASK[1] 0: No INT during CHRG_FAULT
1: INT onCHRG_FAULT
Default(1)
0: INT_MASK[0] 0: No INT during BAT_FAULT
1: INT on BAT_FAULT
Default(1)
//-----------------------------------------------------------------------------
//System Status Register
//-----------------------------------------------------------------------------
//NOTE: This is a read-only register
REG08
BIT
--- VBUS status
7: VBUS_STAT[1] | 00: Unknown (no input, or DPDM detection incomplete), 01: USB host
6: VBUS_STAT[0] | 10: Adapter port, 11: OTG
--- Charging status
5: CHRG_STAT[1] | 00: Not Charging, 01: Pre-charge (<VBATLOWV)
4: CHRG_STAT[0] | 10: Fast Charging, 11: Charge termination done
3: DPM_STAT 0: Not DPM
1: VINDPM or IINDPM
2: PG_STAT 0: Power NO Good :(
1: Power Good :)
1: THERM_STAT 0: Normal
1: In Thermal Regulation (HOT)
0: VSYS_STAT 0: Not in VSYSMIN regulation (BAT > VSYSMIN)
1: In VSYSMIN regulation (BAT < VSYSMIN)
//-----------------------------------------------------------------------------
//Fault Register
//-----------------------------------------------------------------------------
//NOTE: This is a read-only register
REG09
BIT
7: WATCHDOG_FAULT 0: Normal
1: watchdog timer expired
6: Reserved
--- Charge fault status
5: CHRG_FAULT[1] | 00: Normal, 01: Input fault (VBUS OVP or VBAT < VBUS < 3.8 V)
4: CHRG_FAULT[0] | 10: Thermal shutdown, 11: charge safetly timer expiration
--- Battery fault status
3: BAT_FAULT 0: Normal
1: BATOVP battery over threshold
--- NTC thermistor fault status
2: NTC_FAULT[2] | 000: Normal
1: NTC_FAULT[1] | 101: Cold
0: NTC_FAULT[0] | 110: Hot
//-----------------------------------------------------------------------------
//Vender / Part / Revision Status Register
//-----------------------------------------------------------------------------
//NOTE: This is a read-only register
REG0A (reset = 00100011, or 0x23)
BIT
7: Reserved
6: Reserved
--- Device configuration
5: PN[2] 1
4: PN[1] 0
3: PN[0] 0
2: TS_PROFILE 0
1: DEV_REG[0] 1
0: DEV_REG[0] 1
*/