bq25896_reg.h 7.9 KB

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