bq25896_reg.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #if BITS_BIG_ENDIAN == 1
  5. #error Bit structures defined in this file is not portable to BE
  6. #endif
  7. #define BQ25896_ADDRESS 0xD6
  8. typedef struct {
  9. uint8_t IINLIM:6; // Input Current Limit, mA, offset: +100mA
  10. bool EN_ILIM:1; // Enable ILIM Pin
  11. bool EN_HIZ:1; // Enable HIZ Mode
  12. } REG00;
  13. #define IILIM_1600 (1<<5)
  14. #define IILIM_800 (1<<4)
  15. #define IILIM_400 (1<<3)
  16. #define IILIM_200 (1<<2)
  17. #define IILIM_100 (1<<1)
  18. #define IILIM_50 (1<<0)
  19. typedef struct {
  20. uint8_t VINDPM_OS:5; // Input Voltage Limit Offset, mV
  21. bool BCOLD:1; // Boost Mode Cold Temperature Monitor Threshold
  22. uint8_t BHOT:2; // Boost Mode Hot Temperature Monitor Threshold
  23. } REG01;
  24. #define VINDPM_OS_1600 (1<<4)
  25. #define VINDPM_OS_800 (1<<3)
  26. #define VINDPM_OS_400 (1<<2)
  27. #define VINDPM_OS_200 (1<<1)
  28. #define VINDPM_OS_100 (1<<0)
  29. typedef struct {
  30. bool AUTO_DPDM_EN:1; // Automatic Input Detection Enable
  31. bool FORCE_DPDM:1; // Force Input Detection
  32. uint8_t RES:2; // Reserved
  33. bool ICO_EN:1; // Input Current Optimizer (ICO) Enable
  34. bool BOOST_FREQ:1; // Boost Mode Frequency Selection
  35. bool CONV_RATE:1; // ADC Conversion Rate Selection
  36. bool CONV_START:1; // ADC Conversion Start Control
  37. } REG02;
  38. typedef struct {
  39. bool MIN_VBAT_SEL:1; // Minimum Battery Voltage (falling) to exit boost mode
  40. uint8_t SYS_MIN:3; // Minimum System Voltage Limit, mV, offset: +3000mV
  41. bool CHG_CONFIG:1; // Charge Enable Configuration
  42. bool OTG_CONFIG:1; // Boost (OTG) Mode Configuration
  43. bool WD_RST:1; // I2C Watchdog Timer Reset
  44. bool BAT_LOADEN:1; // Battery Load (IBATLOAD) Enable
  45. } REG03;
  46. #define SYS_MIN_400 (1<<2)
  47. #define SYS_MIN_200 (1<<1)
  48. #define SYS_MIN_100 (1<<0)
  49. typedef struct {
  50. uint8_t ICHG:7; // Fast Charge Current Limit, mA
  51. bool EN_PUMPX:1; // Current pulse control Enable
  52. } REG04;
  53. #define ICHG_4096 (1<<6)
  54. #define ICHG_2048 (1<<5)
  55. #define ICHG_1024 (1<<4)
  56. #define ICHG_512 (1<<3)
  57. #define ICHG_256 (1<<2)
  58. #define ICHG_128 (1<<1)
  59. #define ICHG_64 (1<<0)
  60. typedef struct {
  61. uint8_t ITERM:4; // Termination Current Limit, offset: +64mA
  62. uint8_t IPRECHG:4; // Precharge Current Limit, offset: +64mA
  63. } REG05;
  64. #define IPRETERM_512 (1<<3)
  65. #define IPRETERM_256 (1<<2)
  66. #define IPRETERM_128 (1<<1)
  67. #define IPRETERM_64 (1<<0)
  68. typedef struct {
  69. bool VRECHG:1; // Battery Recharge Threshold Offset
  70. bool BATLOWV:1; // Battery Precharge to Fast Charge Threshold
  71. uint8_t VREG:6; // Charge Voltage Limit, offset: +3840mV
  72. } REG06;
  73. #define VREG_512 (1<<5)
  74. #define VREG_256 (1<<4)
  75. #define VREG_128 (1<<3)
  76. #define VREG_64 (1<<2)
  77. #define VREG_32 (1<<1)
  78. #define VREG_16 (1<<0)
  79. typedef struct {
  80. bool JEITA_ISET:1; // JEITA Low Temperature Current Setting
  81. uint8_t CHG_TIMER:2; // Fast Charge Timer Setting
  82. bool EN_TIMER:1; // Charging Safety Timer Enable
  83. uint8_t WATCHDOG:2; // I2C Watchdog Timer Setting
  84. bool STAT_DIS:1; // STAT Pin Disable
  85. bool EN_TERM:1; // Charging Termination Enable
  86. } REG07;
  87. #define WATCHDOG_DIS (0b00)
  88. #define WATCHDOG_40 (0b01)
  89. #define WATCHDOG_80 (0b10)
  90. #define WATCHDOG_160 (0b11)
  91. #define CHG_TIMER_5 (0b00)
  92. #define CHG_TIMER_8 (0b01)
  93. #define CHG_TIMER_12 (0b10)
  94. #define CHG_TIMER_20 (0b11)
  95. typedef struct {
  96. uint8_t TREG:2; // Thermal Regulation Threshold
  97. uint8_t VCLAMP:3; // IR Compensation Voltage Clamp
  98. uint8_t BAT_COMP:3; // IR Compensation Resistor Setting
  99. } REG08;
  100. #define BAT_COMP_80 (1<<2)
  101. #define BAT_COMP_40 (1<<1)
  102. #define BAT_COMP_20 (1<<0)
  103. #define VCLAMP_128 (1<<2)
  104. #define VCLAMP_64 (1<<1)
  105. #define VCLAMP_32 (1<<0)
  106. #define TREG_60 (0b00)
  107. #define TREG_80 (0b01)
  108. #define TREG_100 (0b10)
  109. #define TREG_120 (0b11)
  110. typedef struct {
  111. bool PUMPX_DN:1; // Current pulse control voltage down enable
  112. bool PUMPX_UP:1; // Current pulse control voltage up enable
  113. bool BATFET_RST_EN:1; // BATFET full system reset enable
  114. bool BATFET_DLY:1; // BATFET turn off delay control
  115. bool JEITA_VSET:1; // JEITA High Temperature Voltage Setting
  116. bool BATFET_DIS:1; // Force BATFET off to enable ship mode
  117. bool TMR2X_EN:1; // Safety Timer Setting during DPM or Thermal Regulation
  118. bool FORCE_ICO:1; // Force Start Input Current Optimizer
  119. } REG09;
  120. typedef struct {
  121. uint8_t BOOST_LIM:3; // Boost Mode Current Limit
  122. bool PFM_OTG_DIS:1; // PFM mode allowed in boost mode
  123. uint8_t BOOSTV:4; // Boost Mode Voltage Regulation, offset: +4550mV
  124. } REG0A;
  125. #define BOOSTV_512 (1<<3)
  126. #define BOOSTV_256 (1<<2)
  127. #define BOOSTV_128 (1<<1)
  128. #define BOOSTV_64 (1<<0)
  129. #define BOOST_LIM_500 (0b000)
  130. #define BOOST_LIM_750 (0b001)
  131. #define BOOST_LIM_1200 (0b010)
  132. #define BOOST_LIM_1400 (0b011)
  133. #define BOOST_LIM_1650 (0b100)
  134. #define BOOST_LIM_1875 (0b101)
  135. #define BOOST_LIM_2150 (0b110)
  136. #define BOOST_LIM_RSVD (0b111)
  137. typedef enum {
  138. VBusStatNo = 0b000,
  139. VBusStatUSB = 0b001,
  140. VBusStatExternal = 0b010,
  141. VBusStatOTG = 0b111,
  142. } VBusStat;
  143. typedef enum {
  144. ChrgStatNo = 0b00,
  145. ChrgStatPre = 0b01,
  146. ChrgStatFast = 0b10,
  147. ChrgStatDone = 0b11,
  148. } ChrgStat;
  149. typedef struct {
  150. bool VSYS_STAT:1; // VSYS Regulation Status
  151. bool RES:1; // Reserved: Always reads 1
  152. bool PG_STAT:1; // Power Good Status
  153. ChrgStat CHRG_STAT:2; // Charging Status
  154. VBusStat VBUS_STAT:3; // VBUS Status register
  155. } REG0B;
  156. typedef enum {
  157. ChrgFaultNO = 0b00,
  158. ChrgFaultIN = 0b01,
  159. ChrgFaultTH = 0b10,
  160. ChrgFaultTIM = 0b11,
  161. } ChrgFault;
  162. typedef enum {
  163. NtcFaultNo = 0b000,
  164. NtcFaultWarm = 0b010,
  165. NtcFaultCool = 0b011,
  166. NtcFaultCold = 0b101,
  167. NtcFaultHot = 0b110,
  168. } NtcFault;
  169. typedef struct {
  170. NtcFault NTC_FAULT:3; // NTC Fault Status
  171. bool BAT_FAULT:1; // Battery Fault Status
  172. ChrgFault CHRG_FAULT:2; // Charge Fault Status
  173. bool BOOST_FAULT:1; // Boost Mode Fault Status
  174. bool WATCHDOG_FAULT:1; // Watchdog Fault Status
  175. } REG0C;
  176. typedef struct {
  177. uint8_t VINDPM:7; // Absolute VINDPM Threshold, offset: +2600mV
  178. bool FORCE_VINDPM:1; // VINDPM Threshold Setting Method
  179. } REG0D;
  180. #define VINDPM_6400 (1<<6)
  181. #define VINDPM_3200 (1<<5)
  182. #define VINDPM_1600 (1<<4)
  183. #define VINDPM_800 (1<<3)
  184. #define VINDPM_400 (1<<2)
  185. #define VINDPM_200 (1<<1)
  186. #define VINDPM_100 (1<<0)
  187. typedef struct {
  188. uint8_t BATV:7; // ADC conversion of Battery Voltage (VBAT), offset: +2304mV
  189. bool THERM_STAT:1; // Thermal Regulation Status
  190. } REG0E;
  191. typedef struct {
  192. uint8_t SYSV:7; // ADDC conversion of System Voltage (VSYS), offset: +2304mV
  193. uint8_t RES:1; // Reserved: Always reads 0
  194. } REG0F;
  195. typedef struct {
  196. uint8_t TSPCT:7; // ADC conversion of TS Voltage (TS) as percentage of REGN, offset: +21%
  197. uint8_t RES:1; // Reserved: Always reads 0
  198. } REG10;
  199. typedef struct {
  200. uint8_t VBUSV:7; // ADC conversion of VBUS voltage (VBUS), offset: +2600mV
  201. bool VBUS_GD:1; // VBUS Good Status
  202. } REG11;
  203. typedef struct {
  204. uint8_t ICHGR:7; // ADC conversion of Charge Current (IBAT) when VBAT > VBATSHORT
  205. uint8_t RES:1; // Reserved: Always reads 0
  206. } REG12;
  207. typedef struct {
  208. uint8_t IDPM_LIM:6; // Input Current Limit in effect while Input Current Optimizer (ICO) is enabled, offset: 100mA (default)
  209. bool IDPM_STAT:1; // IINDPM Status
  210. bool VDPM_STAT:1; // VINDPM Status
  211. } REG13;
  212. typedef struct {
  213. uint8_t DEV_REV:2; // Device Revision
  214. bool TS_PROFILE:1; // Temperature Profile
  215. uint8_t PN:3; // Device Configuration
  216. bool ICO_OPTIMIZED:1; // Input Current Optimizer (ICO) Status
  217. bool REG_RST:1; // Register Reset
  218. } REG14;