bq25896_reg.h 8.6 KB

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