SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
BQ25896Regs.hpp
Go to the documentation of this file.
1
92#pragma once
93
94#include <stdint.h>
95
96namespace BQ25896Regs
97{
98
99
100// ==============================================
101// Device Revision Register
102// ==============================================
103static constexpr uint8_t BQ25896_DEV_REV = 0x02;
104
105// ==============================================
106// ADC Voltage Measurement Range Constants
107// ==============================================
112static constexpr uint16_t VBAT_MIN = 2304;
113static constexpr uint16_t VBAT_MAX = 4608;
114static constexpr uint16_t SYS_MIN = 3000;
115static constexpr uint16_t SYS_MAX = 3700;
116static constexpr uint16_t IN_CURRENT_MIN = 100;
117static constexpr uint16_t IN_CURRENT_MAX = 3250;
118static constexpr uint16_t CHG_CURRENT_MAX = 3008;
119static constexpr uint16_t BOOST_VOL_MIN = 4550;
120static constexpr uint16_t BOOST_VOL_MAX = 5510;
121
122// ==============================================
123// USB Port/Adapter Type Definitions
124// ==============================================
125static constexpr uint8_t BUS_STATE_NOINPUT = 0;
126static constexpr uint8_t BUS_STATE_USB_SDP = 1;
127static constexpr uint8_t BUS_STATE_ADAPTER = 2;
128static constexpr uint8_t BUS_STATE_OTG = 7;
129
130// ==============================================
131// Charge State Definitions
132// ==============================================
133static constexpr uint8_t CHARGE_STATE_NO_CHARGE = 0;
134static constexpr uint8_t CHARGE_STATE_PRE_CHARGE = 1;
135static constexpr uint8_t CHARGE_STATE_FAST_CHARGE = 2;
136static constexpr uint8_t CHARGE_STATE_DONE = 3;
137
138// ==============================================
139// ADC Base Values (minimum measurable value)
140// ==============================================
141static constexpr uint16_t VBUS_BASE_VAL = 2600;
142static constexpr uint16_t VBAT_BASE_VAL = 2304;
143static constexpr uint16_t VSYS_BASE_VAL = 2304;
144static constexpr float NTC_BASE_VAL = 21.0f;
145
146// ==============================================
147// ADC Voltage Step Values
148// ==============================================
149static constexpr uint16_t VBUS_VOL_STEP = 100;
150static constexpr uint16_t VBAT_VOL_STEP = 20;
151static constexpr uint16_t VSYS_VOL_STEP = 20;
152static constexpr float NTC_VOL_STEP = 0.465f;
153
154// ==============================================
155// Fast Charge Current Parameters
156// ==============================================
157static constexpr uint16_t CHG_STEP_VAL = 50;
158static constexpr uint16_t FAST_CHG_CUR_STEP = 64;
159static constexpr uint16_t FAST_CHG_CURRENT_MIN = 0;
160static constexpr uint16_t FAST_CHG_CURRENT_MAX = 3008;
161
162// ==============================================
163// Pre-charge Current Parameters
164// @note Formula: IPRECHG = 64mA + [IPRECHG] * 64mA
165// ==============================================
166static constexpr uint16_t PRE_CHG_CUR_BASE = 64;
167static constexpr uint16_t PRE_CHG_CUR_STEP = 64;
168static constexpr uint16_t PRE_CHG_CURRENT_MIN = 64;
169static constexpr uint16_t PRE_CHG_CURRENT_MAX = 1024;
170
171// ==============================================
172// Termination Current Parameters
173// @note Formula: ITERM = 64mA + [ITERM] * 64mA
174// ==============================================
175static constexpr uint16_t TERM_CHG_CUR_BASE = 64;
176static constexpr uint16_t TERM_CHG_CUR_STEP = 64;
177static constexpr uint16_t TERM_CHG_CURRENT_MIN = 64;
178static constexpr uint16_t TERM_CHG_CURRENT_MAX = 1024;
179
180// ==============================================
181// Charge Voltage Parameters
182// @note Formula: VREG = 3.840V + [VREG] * 16mV
183// ==============================================
184static constexpr uint16_t CHG_VOL_BASE = 3840;
185static constexpr uint16_t CHG_VOL_STEP = 16;
186static constexpr uint16_t FAST_CHG_VOL_MIN = 3840;
187static constexpr uint16_t FAST_CHG_VOL_MAX = 4608;
188
189// ==============================================
190// System Voltage Parameters
191// @note Formula: SYS_MIN = 3.0V + [SYS_MIN] * 0.1V
192// ==============================================
193static constexpr uint16_t SYS_VOL_STEPS = 100;
194static constexpr uint16_t SYS_VOFF_VOL_MIN = 3000;
195static constexpr uint16_t SYS_VOFF_VOL_MAX = 3700;
196
197// ==============================================
198// Input Current Limit Parameters
199// @note Formula: IINLIM = 100mA + [IINLIM] * 50mA
200// ==============================================
201static constexpr uint16_t IN_CURRENT_STEP = 50;
202static constexpr uint16_t IN_CURRENT_MIN_VAL = 100;
203static constexpr uint16_t IN_CURRENT_MAX_VAL = 3250;
204
205// ==============================================
206// Boost Mode Parameters
207// @note Formula: VBOOST = 4.55V + [BOOSTV] * 64mV
208// ==============================================
209static constexpr uint16_t BOOST_VOL_BASE = 4550;
210static constexpr uint16_t BOOST_VOL_STEP = 64;
211static constexpr uint16_t BOOST_VOL_MIN_VAL = 4550;
212static constexpr uint16_t BOOST_VOL_MAX_VAL = 5510;
213
214// ==============================================
215// VINDPM Parameters (Absolute Mode)
216// @note Formula: VINDPM = 2.6V + [VINDPM] * 100mV
217// ==============================================
218static constexpr uint16_t VINDPM_VOL_BASE = 2600;
219static constexpr uint16_t VINDPM_VOL_STEPS = 100;
220static constexpr uint16_t VINDPM_VOL_MIN = 3900;
221static constexpr uint16_t VINDPM_VOL_MAX = 15300;
222
223// ==============================================
224// VINDPM Offset Parameters (Relative Mode)
225// @note Used when VBUS <= 6V. Formula: VINDPM_OS = [VINDPM_OS] * 100mV
226// ==============================================
227static constexpr uint16_t VINDPM_OS_STEP = 100;
228static constexpr uint16_t VINDPM_OS_MAX = 3100;
229
230// ==============================================
231// Battery Compensation Parameters
232// @note Formula: BAT_COMP = [BAT_COMP] * 20mohm
233// ==============================================
234static constexpr uint16_t BAT_COMP_STEPS = 20;
235static constexpr uint16_t BAT_COMP_MAX = 140;
236
237// ==============================================
238// Voltage Clamp Parameters (IR Compensation)
239// @note Formula: VCLAMP = [VCLAMP] * 32mV
240// ==============================================
241static constexpr uint16_t VCLAMP_STEP = 32;
242static constexpr uint16_t VCLAMP_MAX = 224;
243
244// ==============================================
245// REG00 (RW) - Input Source Control Register
246// Address: 0x00
247// ==============================================
248static constexpr uint8_t REG_PWR_INPUT = 0x00;
249static constexpr uint8_t MASK_EN_HIZ = 0x80;
250static constexpr uint8_t MASK_EN_ILIM = 0x40;
251static constexpr uint8_t MASK_IINLIM = 0x3F;
252static constexpr uint8_t SHIFT_IINLIM = 0;
253
254// ==============================================
255// REG01 (RW) - VINDPM Control Register
256// Address: 0x01
257// ==============================================
258static constexpr uint8_t REG_PWR_VINDPM = 0x01;
259static constexpr uint8_t MASK_BHOT = 0xC0;
260static constexpr uint8_t SHIFT_BHOT = 6;
261static constexpr uint8_t MASK_BCOLD = 0x20;
262static constexpr uint8_t MASK_VINDPM_OS = 0x1F;
263static constexpr uint8_t SHIFT_VINDPM_OS = 0;
264
265// ==============================================
266// REG02 (RW) - Power On/Off Control Register
267// Address: 0x02
268// ==============================================
269static constexpr uint8_t REG_PWR_ONOFF = 0x02;
270static constexpr uint8_t MASK_CONV_START = 0x80;
271static constexpr uint8_t MASK_CONV_RATE = 0x40;
272static constexpr uint8_t MASK_BOOST_FREQ = 0x20;
273static constexpr uint8_t MASK_ICO_EN = 0x10;
274static constexpr uint8_t MASK_FORCE_DPDM = 0x02;
275static constexpr uint8_t MASK_AUTO_DPDM_EN = 0x01;
276
277// ==============================================
278// REG03 (RW) - Charge Control Register
279// Address: 0x03
280// ==============================================
281static constexpr uint8_t REG_CHG_CTRL = 0x03;
282static constexpr uint8_t MASK_BAT_LOAD_EN = 0x80;
283static constexpr uint8_t MASK_WD_RST = 0x40;
284static constexpr uint8_t MASK_OTG_CONFIG = 0x20;
285static constexpr uint8_t MASK_CHG_CONFIG = 0x10;
286static constexpr uint8_t MASK_SYS_MIN = 0x0E;
287static constexpr uint8_t SHIFT_SYS_MIN = 1;
288static constexpr uint8_t MASK_MIN_VBAT_SEL = 0x01;
289
290// ==============================================
291// REG04 (RW) - Fast Charge Current Control Register
292// Address: 0x04
293// @note ICHG = 0 disables charging
294// ==============================================
295static constexpr uint8_t REG_CHG_CURRENT = 0x04;
296static constexpr uint8_t MASK_EN_PUMPX = 0x80;
297static constexpr uint8_t MASK_ICHG = 0x7F;
298static constexpr uint8_t SHIFT_ICHG = 0;
299
300// ==============================================
301// REG05 (RW) - Pre-charge/Termination Current Control
302// Address: 0x05
303// ==============================================
304static constexpr uint8_t REG_CHG_PRE_CURR = 0x05;
305static constexpr uint8_t MASK_IPRECHG = 0xF0;
306static constexpr uint8_t SHIFT_IPRECHG = 4;
307static constexpr uint8_t MASK_ITERM = 0x0F;
308static constexpr uint8_t SHIFT_ITERM = 0;
309
310// ==============================================
311// REG06 (RW) - Charge Voltage Control Register
312// Address: 0x06
313// ==============================================
314static constexpr uint8_t REG_CHG_VOLT = 0x06;
315static constexpr uint8_t MASK_VREG = 0xFC;
316static constexpr uint8_t SHIFT_VREG = 2;
317static constexpr uint8_t MASK_BATLOWV = 0x02;
318static constexpr uint8_t MASK_VRECHG = 0x01;
319
320// ==============================================
321// REG07 (RW) - Charge Timer/Control Register
322// Address: 0x07
323// ==============================================
324static constexpr uint8_t REG_CHG_TIMER = 0x07;
325static constexpr uint8_t MASK_EN_TERM = 0x80;
326static constexpr uint8_t MASK_STAT_DIS = 0x40;
327static constexpr uint8_t MASK_WATCHDOG = 0x30;
328static constexpr uint8_t SHIFT_WATCHDOG = 4;
329static constexpr uint8_t MASK_EN_TIMER = 0x08;
330static constexpr uint8_t MASK_CHG_TIMER = 0x06;
331static constexpr uint8_t SHIFT_CHG_TIMER = 1;
332static constexpr uint8_t MASK_JEITA_ISET = 0x01;
333
334// ==============================================
335// REG08 (RW) - IR Compensation/Thermal Control
336// Address: 0x08
337// ==============================================
338static constexpr uint8_t REG_CHG_IR_COMP = 0x08;
339static constexpr uint8_t MASK_BAT_COMP = 0xE0;
340static constexpr uint8_t SHIFT_BAT_COMP = 5;
341static constexpr uint8_t MASK_VCLAMP = 0x1C;
342static constexpr uint8_t SHIFT_VCLAMP = 2;
343static constexpr uint8_t MASK_TREG = 0x03;
344static constexpr uint8_t SHIFT_TREG = 0;
345
346// ==============================================
347// REG09 (RW) - Misc Control Register
348// Address: 0x09
349// ==============================================
350static constexpr uint8_t REG_MISC_CTRL = 0x09;
351static constexpr uint8_t MASK_FORCE_ICO = 0x80;
352static constexpr uint8_t MASK_TMR2X_EN = 0x40;
353static constexpr uint8_t MASK_BATFET_DIS = 0x20;
354static constexpr uint8_t MASK_JEITA_VSET = 0x10;
355static constexpr uint8_t MASK_BATFET_DLY = 0x08;
356static constexpr uint8_t MASK_BATFET_RST_EN = 0x04;
357static constexpr uint8_t MASK_PUMPX_UP = 0x02;
358static constexpr uint8_t MASK_PUMPX_DN = 0x01;
359
360// ==============================================
361// REG0A (RW) - Boost Control Register
362// Address: 0x0A
363// ==============================================
364static constexpr uint8_t REG_BOOST_CTRL = 0x0A;
365static constexpr uint8_t MASK_BOOSTV = 0xF0;
366static constexpr uint8_t SHIFT_BOOSTV = 4;
367static constexpr uint8_t MASK_PFM_OTG_DIS = 0x08;
368static constexpr uint8_t MASK_BOOST_LIM = 0x07;
369static constexpr uint8_t SHIFT_BOOST_LIM = 0;
370
371// ==============================================
372// REG0B (RO) - Status Register
373// Address: 0x0B
374// ==============================================
375static constexpr uint8_t REG_STATUS = 0x0B;
376static constexpr uint8_t MASK_VBUS_STAT = 0xE0;
377static constexpr uint8_t SHIFT_VBUS_STAT = 5;
378static constexpr uint8_t MASK_CHRG_STAT = 0x18;
379static constexpr uint8_t SHIFT_CHRG_STAT = 3;
380static constexpr uint8_t MASK_PG_STAT = 0x04;
381static constexpr uint8_t MASK_VSYS_STAT = 0x01;
382
383// ==============================================
384// REG0C (RO) - Fault Register
385// Address: 0x0C
386// ==============================================
387static constexpr uint8_t REG_FAULT = 0x0C;
388static constexpr uint8_t MASK_WD_FAULT = 0x80;
389static constexpr uint8_t MASK_BOOST_FAULT = 0x40;
390static constexpr uint8_t MASK_CHRG_FAULT = 0x30;
391static constexpr uint8_t SHIFT_CHRG_FAULT = 4;
392static constexpr uint8_t MASK_BAT_FAULT = 0x08;
393static constexpr uint8_t MASK_NTC_FAULT = 0x07;
394static constexpr uint8_t SHIFT_NTC_FAULT = 0;
395
396// ==============================================
397// REG0D (RW) - VINDPM Register
398// Address: 0x0D
399// ==============================================
400static constexpr uint8_t REG_VINDPM = 0x0D;
401static constexpr uint8_t MASK_FORCE_VINDPM = 0x80;
402static constexpr uint8_t MASK_VINDPM = 0x7F;
403static constexpr uint8_t SHIFT_VINDPM = 0;
404
405// ==============================================
406// REG0E (RO) - Battery Voltage ADC
407// Address: 0x0E
408// ==============================================
409static constexpr uint8_t REG_ADC_BATV = 0x0E;
410static constexpr uint8_t MASK_THERM_STAT = 0x80;
411static constexpr uint8_t MASK_BATV = 0x7F;
412static constexpr uint8_t SHIFT_BATV = 0;
413
414// ==============================================
415// REG0F (RO) - System Voltage ADC
416// Address: 0x0F
417// ==============================================
418static constexpr uint8_t REG_ADC_SYSV = 0x0F;
419static constexpr uint8_t MASK_SYSV = 0x7F;
420static constexpr uint8_t SHIFT_SYSV = 0;
421
422// ==============================================
423// REG10 (RO) - NTC Percentage ADC
424// Address: 0x10
425// @warning IMPORTANT: This returns NTC percentage, NOT temperature!
426// Formula: NTC/REGN = 21% + [TSPCT] * 0.465%
427// Range: 21% - 80.055%
428// To convert to actual temperature, you need the NTC's Beta value and
429// pull-up resistor configuration from your battery pack specifications.
430// ==============================================
431static constexpr uint8_t REG_ADC_NTC = 0x10;
432static constexpr uint8_t MASK_TSPCT = 0x7F;
433static constexpr uint8_t SHIFT_TSPCT = 0;
434
435// ==============================================
436// REG11 (RO) - VBUS Voltage ADC
437// Address: 0x11
438// ==============================================
439static constexpr uint8_t REG_ADC_BUSV = 0x11;
440static constexpr uint8_t MASK_VBUS_GD = 0x80;
441static constexpr uint8_t MASK_VBUSV = 0x7F;
442static constexpr uint8_t SHIFT_VBUSV = 0;
443
444// ==============================================
445// REG12 (RO) - Charge Current ADC
446// Address: 0x12
447// @note Returns 0 when VBAT < VBATSHORT
448// ==============================================
449static constexpr uint8_t REG_ADC_ICHGR = 0x12;
450static constexpr uint8_t MASK_ICHGR = 0x7F;
451static constexpr uint8_t SHIFT_ICHGR = 0;
452
453// ==============================================
454// REG13 (RO) - Input Current Limit Status
455// Address: 0x13
456// ==============================================
457static constexpr uint8_t REG_IDPM_STATUS = 0x13;
458static constexpr uint8_t MASK_VDPM_STAT = 0x80;
459static constexpr uint8_t MASK_IDPM_STAT = 0x40;
460static constexpr uint8_t MASK_IDPM_LIM = 0x3F;
461static constexpr uint8_t SHIFT_IDPM_LIM = 0;
462
463// ==============================================
464// REG14 (RW) - Device Revision Register
465// Address: 0x14
466// ==============================================
467static constexpr uint8_t REG_DEVICE_REV = 0x14;
468static constexpr uint8_t MASK_REG_RST = 0x80;
469static constexpr uint8_t MASK_ICO_OPTIMIZED = 0x40;
470static constexpr uint8_t MASK_PN = 0x38;
471static constexpr uint8_t SHIFT_PN = 3;
472static constexpr uint8_t MASK_TS_PROFILE = 0x04;
473static constexpr uint8_t MASK_DEV_REV = 0x03;
474static constexpr uint8_t SHIFT_DEV_REV = 0;
475
476}