1 /*
2 file: sc8812.c
3 auth: youcp
4 date: 2022.11.17
5 email: 1739666569@qq.com
6 */
7
8 #include "sc8812a.h"
9 u8 test_reg[0x1A]={0};
10 /*Implement by user*/
11 void sc8812a_write_reg(u8 reg_addr,u8 value)
12 {
13 u8 buf[2]=0;
14 buf[0]=reg_addr;
15 buf[1]=value;
16 //print_hex("-->", buf, 2);
17 test_reg[reg_addr] = value;
18 }
19 /*Implement by user*/
20 u8 sc8812a_read_reg(u8 reg_addr)
21 {
22 return test_reg[reg_addr];
23 }
24 /*
25 brief: before set this register ,please check battery harware infomation
26 ircomp: Battery Inter Resistor compensation setting
27 csel: Battery cell selection, only valid for internal VBAT voltage setting
28 vcell: Battery voltage setting per cell, only valid for internal VBAT voltage setting
29 */
30 void sc8812a_vbat_set(
31 IRCOMP_e ircomp,
32 CSEL_e csel,
33 VCELL_e vcell)
34 {
35 u8 value = 0;
36 value = sc8812a_read_reg(Reg_VBAT_SET_rw);
37
38 value &= ~(3<<6);
39 value |= (ircomp<<6);
40
41 value &= ~(3<<3);
42 value |= (csel<<3);
43
44 value &= ~(7<<0);
45 value |= (vcell<<0);
46
47 sc8812a_write_reg(Reg_VBAT_SET_rw,value);
48 return;
49 }
50 void sc8812a_ratio_set(
51 RATIO_IBAT_LIM_e ratio_ibat_lim,
52 RATIO_IBUS_LIM_e ratio_ibus_lim,
53 RATIO_VBAT_MON_e ratio_vbat_mon,
54 RATIO_VBUS_e ratio_vbus)
55 {
56 u8 value = 0;
57 value = sc8812a_read_reg(Reg_RATIO_rw);
58
59 value &= ~(1<<4);
60 value |= (ratio_ibat_lim<<4);
61
62 value &= ~(3<<2);
63 value |= (ratio_ibus_lim<<2);
64
65 value &= ~(1<<1);
66 value |= (ratio_vbat_mon<<1);
67
68 value &= ~(1<<0);
69 value |= (ratio_vbus<<0);
70
71 value &= ~(3<<6);//reseverd
72 value |= (1<<5);//reseverd
73
74 sc8812a_write_reg(Reg_RATIO_rw,value);
75 return;
76 }
77
78 u8 sc8812a_ratio_get(RATIO_GET_e which)
79 {
80 u8 value=0;
81 u8 ratio=0;
82 value = sc8812a_read_reg(Reg_RATIO_rw);
83 switch(which)
84 {
85 case R_IBAT_LIM:
86 ratio = (value&(1<<4))?12:6;
87 break;
88 case R_IBUS_LIM:
89 ratio = (((value&0x0C)>>2)== RATIO_IBUS_LIM_3x)?3:6;
90 break;
91 case R_VBAT_MON:
92 ratio = (value&(1<<1))?5:125;
93 break;
94 case R_VBUS:
95 ratio = (value&(1<<0))?5:125;
96 break;
97 default:
98 break;
99 }
100 return ratio;
101 }
102
103 /*
104 输出vbus 来自于内部
105 VBUSREF_I = (4 x VBUSREF_I_SET + VBUSREF_I_SET2 + 1) x 2 mV
106 VBUS = VBUSREF_I x VBUS_RATIO
107
108 */
109 void sc8812a_vbus_i_set(u16 voltage)
110 {
111 u16 value=0;
112 u8 ratio=0;
113 ratio = (sc8812a_ratio_get(R_VBUS)==5)?10:25;
114 value = voltage/25-1;
115 sc8812a_write_reg(Reg_VBUSREF_I_SET_rw,(u8)(value>>2));
116 sc8812a_write_reg(Reg_VBUSREF_I_SET2_rw,(u8)(value&0x03));
117 return;
118 }
119
120 /*
121 输出vbus 来自于外部电阻和内部寄存器共同调节
122 VBUSREF_E = (4 x VBUSREF_E_SET+VBUSREF_E_SET2+1) x 2mV
123 VBUS = VBUSREF_E x (1+RUP/RDOWM )
124 */
125 void sc8812a_vbus_e_set(u16 voltage,u8 r_up,u8 r_down)
126 {
127 u16 value=0;
128 value = voltage/2/(1+r_up/r_down);
129 sc8812a_write_reg(Reg_VBUSREF_E_SET_rw,(u8)(value>>2));
130 sc8812a_write_reg(Reg_VBUSREF_E_SET2_rw,(u8)(value&0x03));
131 return;
132 }
133 /*
134 Set IBUS current limit, which is valid for both charging and discharging modes.
135 IBUS_LIM (A) = (IBUS_LIM_SET +1) / 256 × IBUS_RATIO ×10 mΩ/RS1
136 RS1 is the current sense resistor at VBUS side
137 */
138 void sc8812a_ibus_lim_set(u32 mA,u8 RS1_mOhm)
139 {
140 u32 value=0;
141 u8 ratio=0;
142 ratio = sc8812a_ratio_get(R_IBUS_LIM);
143 value = mA*256*RS1_mOhm/ratio/10/1000 - 1;
144 sc8812a_write_reg(Reg_IBUS_LIM_SET_rw,(u8)(value));
145 return;
146 }
147 /*
148 Set IBAT current limit, which is valid for both charging and discharging modes.
149 IBAT_LIM (A) = (IBAT_LIM_SET+1) /256 × IBAT_RATIO ×10 mΩ/ RS2
150 RS2 is the current sense resistor at VBAT side.
151
152 */
153 void sc8812a_ibat_lim_set(u32 mA,u8 RS2_mOhm)
154 {
155 u32 value=0;
156 u8 ratio=0;
157 ratio = sc8812a_ratio_get(R_IBAT_LIM);
158 value = mA*256*RS2_mOhm/ratio/10/1000 - 1;
159 sc8812a_write_reg(Reg_IBAT_LIM_SET_rw,(u8)(value));
160 return;
161 }
162
163 void sc8812a_ctrl0_set(CTRL0_SET_INIT_s* s)
164 {
165 u8 value =0;
166 value = sc8812a_read_reg(Reg_CTRL0_SET_rw);
167
168 value &= ~(1<<7);
169 value |= (s->otg<<7);
170
171 value &= ~(1<<4);
172 value |= (s->vinreg_ratio<<4);
173
174 value &= ~(3<<2);
175 value |= (s->freq_set<<2);
176
177 value &= ~(3<<0);
178 value |= (s->deadtime<<0);
179
180 value &= ~(3<<5);//reseverd
181
182 sc8812a_write_reg(Reg_CTRL0_SET_rw,value);
183 return;
184 }
185
186 void sc8812a_ctrl0_otg(u8 otg)
187 {
188 u8 value =0;
189 value = sc8812a_read_reg(Reg_CTRL0_SET_rw);
190
191 value &= ~(1<<7);
192 value |= (otg<<7);
193
194 sc8812a_write_reg(Reg_CTRL0_SET_rw,value);
195 return;
196 }
197
198 void sc8812a_ctrl1_set(CTRL1_SET_INIT_s * s)
199 {
200 u8 value =0;
201 value = sc8812a_read_reg(Reg_CTRL1_SET_rw);
202
203 value &= ~(1<<7);
204 value |= (s->ichar_sel<<7);
205
206 value &= ~(1<<6);
207 value |= (s->trickle_en<<6);
208
209 value &= ~(1<<5);
210 value |= (s->term_en<<5);
211
212 value &= ~(1<<4);
213 value |= (s->fb_sel<<4);
214
215 value &= ~(1<<3);
216 value |= (s->trickle_set<<3);
217
218 value &= ~(1<<2);
219 value |= (s->ovp<<2);
220
221
222 value &= ~(1<<1);//reseverd
223 value |= (1<<0);//reseverd
224
225 sc8812a_write_reg(Reg_CTRL1_SET_rw,value);
226 return;
227 }
228
229 void sc8812a_ctrl2_set(CTRL2_SET_INIT_s * s)
230 {
231 u8 value =0;
232 value = sc8812a_read_reg(Reg_CTRL2_SET_rw);
233
234
235 value &= ~(3<<6);//reseverd
236 value |= (1<<3);//factory
237
238 value &= ~(1<<4);
239 value |= (s->softstart_set<<4);
240
241 value &= ~(1<<2);
242 value |= (s->dither_en<<2);
243
244 value &= ~(1<<0);
245 value |= (s->vbus_slew<<0);
246
247 sc8812a_write_reg(Reg_CTRL2_SET_rw,value);
248 return;
249 }
250
251 void sc8812a_ctrl3_set(CTRL3_SET_INIT_s * s)
252 {
253 u8 value =0;
254 value = sc8812a_read_reg(Reg_CTRL3_SET_rw);
255
256 value &= ~(1<<7);
257 value |= (s->en_pgate<<7);
258
259 value &= ~(1<<6);
260 value |= (s->gpo_ctrl<<6);
261
262 value &= ~(1<<5);
263 value |= (s->adc_ctrl<<5);
264
265 value &= ~(1<<4);
266 value |= (s->ilim_bw_sel<<4);
267
268 value &= ~(1<<3);
269 value |= (s->loop_set<<3);
270
271 value &= ~(1<<2);
272 value |= (s->discharge_foldback<<2);
273
274 value &= ~(1<<1);
275 value |= (s->eoc_set<<1);
276
277 value &= ~(1<<0);
278 value |= (s->pfm<<0);
279
280 sc8812a_write_reg(Reg_CTRL3_SET_rw,value);
281 return;
282 }
283 void sc8812a_ctrl3_adc(u8 s)
284 {
285
286 u8 value =0;
287 value = sc8812a_read_reg(Reg_CTRL3_SET_rw);
288
289 value &= ~(1<<5);
290 value |= (s<<5);
291
292 sc8812a_write_reg(Reg_CTRL3_SET_rw,value);
293 return;
294 }
295
296 /*
297 The highest 8-bit of the ADC reading of VBUS voltage (total 10-bit).
298 VBUS voltage is calculated as
299 VBUS = (4 x VBUS_FB_VALUE + VBUS_FB_VALUE2 + 1) x VBUS_RATIO x 2 mV
300
301 */
302 u16 sc8812a_vbus_fb_get(void)
303 {
304 u16 voltage=0;
305 u8 ratio=0;
306 ratio = (sc8812a_ratio_get(R_VBUS)==5)?10:25;
307 voltage = (u16)sc8812a_read_reg(Reg_VBUS_FB_VALUE_r)<<2;
308 voltage |= (u16)sc8812a_read_reg(Reg_VBUS_FB_VALUE2_r);
309 voltage = (voltage+1)*ratio;
310 return voltage;
311
312 }
313
314 /*
315 The highest 8-bit of the ADC reading of VBAT voltage (total 10-bit).
316 VBAT voltage is calculated as
317 VBAT = (4 x VBAT_FB_VALUE + VBAT_FB_VALUE2 + 1) x VBAT_MON_RATIO x 2 mV
318
319 */
320 u16 sc8812a_vbat_fb_get(void)
321 {
322 u16 voltage=0;
323 u8 ratio=0;
324 ratio = (sc8812a_ratio_get(R_VBAT_MON)==5)?10:25;
325 voltage = (u16)sc8812a_read_reg(Reg_VBAT_FB_VALUE_r)<<2;
326 voltage |= (u16)sc8812a_read_reg(Reg_VBAT_FB_VALUE2_r);
327 voltage = (voltage+1)*ratio;
328 return voltage;//mv
329
330 }
331 /*
332 The highest 8-bit of the ADC reading of IBUS current (total 10-bit).
333 IBUS current is calculated as
334 IBUS (A) =(4 x IBUS_VALUE + IBUS_VALUE2 + 1)×2/1200 × IBUS_RATIO × 10 m /RS1
335
336 */
337 u16 sc8812a_ibus_get(u8 RS1_mOhm)
338 {
339 u16 current=0;
340 u8 ratio=0;
341 ratio = sc8812a_ratio_get(R_IBUS_LIM);
342 current = (u16)sc8812a_read_reg(Reg_IBUS_VALUE_r)<<2;
343 current |= (u16)sc8812a_read_reg(Reg_IBUS_VALUE2_r);
344 current = (current+1)*2/12/RS1_mOhm;
345 return current;//mA
346
347 }
348
349 /*
350 The highest 8-bit of the ADC reading of IBAT current (total 10-bit).
351 IBAT current is calculated as
352 IBAT (A) =(4 x IBAT_VALUE + IBAT_VALUE2 + 1)×2/1200 × IBAT_RATIO × 10 m /RS2
353
354 */
355 u16 sc8812a_ibat_get(u8 RS2_mOhm)
356 {
357 u16 current=0;
358 u8 ratio=0;
359 ratio = sc8812a_ratio_get(R_IBAT_LIM);
360 current = (u16)sc8812a_read_reg(Reg_IBAT_VALUE_r)<<2;
361 current |= (u16)sc8812a_read_reg(Reg_IBAT_VALUE2_r);
362 current = (current+1)*2/12/RS2_mOhm;
363 return current;//mA
364 }
365 u8 sc8812a_status_get(void)
366 {
367 return sc8812a_read_reg(Reg_STATUS_r);
368 }
369
370 /********************************************************************************/
371 void example_init(void)
372 {
373 CTRL0_SET_INIT_s ctrl0;
374 CTRL1_SET_INIT_s ctrl1;
375 CTRL2_SET_INIT_s ctrl2;
376 CTRL3_SET_INIT_s ctrl3;
377
378 sc8812a_vbat_set(IRCOMP_0mOhm,CSEL_4S,VCELL_SET_4P2V);
379 sc8812a_ratio_set(RATIO_IBAT_LIM_12x,RATIO_IBUS_LIM_6x,RATIO_VBAT_MON_12P5x,RATIO_VBUS_12P5x);
380 sc8812a_vbus_e_set(12089,100,11);
381 sc8812a_ibus_lim_set(5438,10);//放电
382 sc8812a_ibat_lim_set(8250,5);//放电
383
384 ctrl0.otg = EN_OTG_DISCHARGE;
385 ctrl0.vinreg_ratio = VINREG_RATIO_100x;
386 ctrl0.freq_set = FREQ_SET_300HZ;
387 ctrl0.deadtime = DT_SET_20ns;
388 sc8812a_ctrl0_set(&ctrl0);
389
390 ctrl1.ichar_sel = ICHAR_SEL_IBUS;
391 ctrl1.trickle_en = TRICKLE_ENABLE;
392 ctrl1.term_en = TERM_ENABLE;
393 ctrl1.fb_sel = VBUS_EXTERNAL;
394 ctrl1.trickle_set = VBAT_70_PERCENT;
395 ctrl1.ovp = OVP_ENABLE;
396 sc8812a_ctrl1_set(&ctrl1);
397
398 ctrl2.softstart_set = SS_RATE_0P0625mV_per_us;
399 ctrl2.dither_en = DITHER_ENABLE;
400 ctrl2.vbus_slew = SLEW_2mV_per_us;
401 sc8812a_ctrl2_set(&ctrl2);
402
403 ctrl3.en_pgate = PGATE_HIGH_OFF;
404 ctrl3.gpo_ctrl = GPO_LOW;
405 ctrl3.adc_ctrl = ADC_START;
406 ctrl3.ilim_bw_sel = BW_5KHZ;
407 ctrl3.loop_set = RESPONSE_NORMAL;
408 ctrl3.discharge_foldback = FOLDBACK_ENABLE;
409 ctrl3.eoc_set = EOC_10_PERCENT_OF_CURRENT;
410 sc8812a_ctrl3_set(&ctrl3);
411
412 for(u8 i=0;i<sizeof(test_reg);i++)
413 {
414 printf("reg=%02X, %02X\n",i,test_reg[i]);
415 }
416 }
417
418 //函数需配合PSTOP引脚
419 void example_charge(void)
420 {
421 sc8812a_ibus_lim_set(3000,10);//充电
422 sc8812a_ibat_lim_set(2550,5);//充电
423 sc8812a_ctrl0_otg(EN_OTG_CHARGE);
424 return;
425 }
426
427 //函数需配合PSTOP引脚
428 void example_discharge(void)
429 {
430 sc8812a_ibus_lim_set(5438,10);//放电
431 sc8812a_ibat_lim_set(8250,5);//放电
432 sc8812a_ctrl0_otg(EN_OTG_DISCHARGE);
433 return;
434 }
435
436 //函数需配合PSTOP引脚
437 void example_sleep(void)
438 {
439 sc8812a_ctrl3_adc(ADC_STOP);
440 return;
441 }
1 /*
2 file: sc8812a.h
3 auth: youcp
4 date: 2022.11.17
5 email: 1739666569@qq.com
6 */
7
8 #ifndef _SC8812A_H_
9 #define _SC8812A_H_
10 #include "main.h"
11 /*
12 Device Address
13 */
14 #define SC8812A_DEVICE_ADDRESS (0x74) //7-bit address ,0xE8(8bits-Write),0xE9(8bits-Read)
15
16 /*
17 Register Address
18 */
19 #define Reg_VBAT_SET_rw (0x00)
20 #define Reg_VBUSREF_I_SET_rw (0x01)
21 #define Reg_VBUSREF_I_SET2_rw (0x02)
22 #define Reg_VBUSREF_E_SET_rw (0x03)
23 #define Reg_VBUSREF_E_SET2_rw (0x04)
24 #define Reg_IBUS_LIM_SET_rw (0x05)
25 #define Reg_IBAT_LIM_SET_rw (0x06)
26 #define Reg_VINREG_SET_rw (0x07)
27 #define Reg_RATIO_rw (0x08)
28 #define Reg_CTRL0_SET_rw (0x09)
29 #define Reg_CTRL1_SET_rw (0x0A)
30 #define Reg_CTRL2_SET_rw (0x0B)
31 #define Reg_CTRL3_SET_rw (0x0C)
32 #define Reg_VBUS_FB_VALUE_r (0x0D)
33 #define Reg_VBUS_FB_VALUE2_r (0x0E)
34 #define Reg_VBAT_FB_VALUE_r (0x0F)
35 #define Reg_VBAT_FB_VALUE2_r (0x10)
36 #define Reg_IBUS_VALUE_r (0x11)
37 #define Reg_IBUS_VALUE2_r (0x12)
38 #define Reg_IBAT_VALUE_r (0x13)
39 #define Reg_IBAT_VALUE2_r (0x14)
40 #define Reg_Reserved0_r (0x15)
41 #define Reg_Reserved1_r (0x16)
42 #define Reg_STATUS_r (0x17)
43 #define Reg_Reserved2_r (0x18)
44 #define Reg_MASK_rw (0x19)
45 #define Reg_DPDM_CTRL_rw (0x1A)
46 #define Reg_DPDM_READ_rw (0x1B)
47
48 /*
49 Register Value enum
50 */
51 /********************************************************************(0x00)*/
52 //VBAT_SET
53 typedef enum
54 {
55 IRCOMP_0mOhm = 0,
56 IRCOMP_20mOhm = 1,
57 IRCOMP_40mOhm = 2,
58 IRCOMP_80mOhm = 3,
59
60 }IRCOMP_e;
61
62 typedef enum
63 {
64 CSEL_1S = 0,
65 CSEL_2S = 1,
66 CSEL_3S = 2,
67 CSEL_4S = 3,//4串
68 }CSEL_e;
69
70 typedef enum
71 {
72
73 VCELL_SET_4P1V = 0,
74 VCELL_SET_4P2V = 1,
75 VCELL_SET_4P25V = 2,
76 VCELL_SET_4P3V = 3,
77 VCELL_SET_4P35V = 4,
78 VCELL_SET_4P4V = 5,
79 VCELL_SET_4P45V = 6,
80 VCELL_SET_4P5V = 7,
81 }VCELL_e;
82
83 /********************************************************************(0x08)*/
84 //RATIO
85 typedef enum
86 {
87 RATIO_IBAT_LIM_6x = 0,
88 RATIO_IBAT_LIM_12x = 1,
89 }RATIO_IBAT_LIM_e;
90
91 typedef enum
92 {
93 RATIO_IBUS_LIM_6x = 1,
94 RATIO_IBUS_LIM_3x = 2,
95 }RATIO_IBUS_LIM_e;
96
97
98 typedef enum
99 {
100 RATIO_VBAT_MON_12P5x = 0,
101 RATIO_VBAT_MON_5x = 1,
102 }RATIO_VBAT_MON_e;
103
104
105 typedef enum
106 {
107 RATIO_VBUS_12P5x = 0,
108 RATIO_VBUS_5x = 1,
109 }RATIO_VBUS_e;
110
111 typedef enum
112 {
113 R_IBAT_LIM =0,
114 R_IBUS_LIM,
115 R_VBAT_MON,
116 R_VBUS,
117 }RATIO_GET_e;
118
119
120 /********************************************************************(0x09)*/
121 //CTRL0_SET
122 typedef enum
123 {
124 EN_OTG_CHARGE = 0,
125 EN_OTG_DISCHARGE = 1,
126 }EN_OTG_e;
127
128 typedef enum
129 {
130 VINREG_RATIO_100x = 0,
131 VINREG_RATIO_40x = 1,
132 }VINREG_RATIO_e;
133
134 typedef enum
135 {
136 FREQ_SET_150HZ = 0,
137 FREQ_SET_300HZ = 1,
138 FREQ_SET_Reserved = 2,
139 FREQ_SET_450HZ = 3,
140 }FREQ_SET_e;
141
142 typedef enum
143 {
144 DT_SET_20ns = 0,
145 DT_SET_40ns = 1,
146 DT_SET_60ns = 2,
147 DT_SET_80ns = 3,
148 }DeadTime_SET_e;
149 typedef struct
150 {
151 EN_OTG_e otg;
152 VINREG_RATIO_e vinreg_ratio;
153 FREQ_SET_e freq_set;
154 DeadTime_SET_e deadtime;
155 }CTRL0_SET_INIT_s;
156 /********************************************************************(0x0A)*/
157 //CTRL1_SET
158 typedef enum
159 {
160 ICHAR_SEL_IBUS = 0, /*涓流充电电流和满电充电电流以IBUS为基准,涓流=ibus*22%,满电=ibus*(10% or 25%,by EOC_SET bit)*/
161 ICHAR_SEL_IBAT = 1, //涓流充电电流和满电充电电流以IBAT为基准,涓流=ibat*10%,满电=ibat*(10% or 25%,by EOC_SET bit)
162 }ICHAR_SEL_e;
163
164 typedef enum
165 {
166 TRICKLE_ENABLE = 0,//使能涓流充电
167 TRICKLE_DISENABLE = 1,//不使能涓流充电
168 }TRICKLE_EN_e;
169
170 typedef enum
171 {
172 TERM_ENABLE = 0,//充满停止充电
173 TERM_DISENABLE = 1,//充满不停止,自动维持满电电压
174 }TERM_EN_e;
175 typedef enum
176 {
177 VBUS_INTERNAL = 0,//vbus输出来自内部寄存器设置
178 VBUS_EXTERNAL = 1,//vbus输出来自内部寄存器设置和外部电阻
179 }FB_SEL_e;
180 typedef enum
181 {
182 VBAT_70_PERCENT = 0,//涓流充电阈值,低于70%VBAT电压为涓流充电阶段
183 VBAT_60_PERCENT = 1,//涓流充电阈值,低于60%VBAT电压为涓流充电阶段
184 }Trickle_SET_e;
185
186 typedef enum
187 {
188 OVP_ENABLE = 0,
189 OVP_DISENABLE = 1,
190 }DISCHARGE_OVP_e;
191
192 typedef struct
193 {
194 ICHAR_SEL_e ichar_sel;
195 TRICKLE_EN_e trickle_en;
196 TERM_EN_e term_en;
197 FB_SEL_e fb_sel;
198 Trickle_SET_e trickle_set;
199 DISCHARGE_OVP_e ovp;
200 }CTRL1_SET_INIT_s;
201 /********************************************************************(0x0B)*/
202 //CTRL2_SET
203 typedef enum
204 {
205 SS_RATE_0P0625mV_per_us = 0,
206 SS_RATE_0P125mV_per_us = 1,
207 SS_RATE_0P25mV_per_us = 2,
208 SS_RATE_0P5mV_per_us = 3
209 }SoftStart_SET_e;//缓启动速率
210 typedef enum
211 {
212 DITHER_ENABLE = 0,//PGATE输出不变频
213 DITHER_DISENABLE = 1,//PGATE输出变频
214 }DITHER_EN_e;
215 typedef enum
216 {
217 SLEW_1mV_per_us = 0,
218 SLEW_2mV_per_us = 1,
219 SLEW_4mV_per_us = 2,
220 SLEW_8mV_per_us = 3
221 }VBUS_SLEW_SET_e;//VBUS输出动态调整电压速率
222 typedef struct
223 {
224 SoftStart_SET_e softstart_set;
225 DITHER_EN_e dither_en;
226 VBUS_SLEW_SET_e vbus_slew;
227 }CTRL2_SET_INIT_s;
228
229 /********************************************************************(0x0C)*/
230 //CTRL3_SET
231 typedef enum
232 {
233 PGATE_HIGH_OFF = 0,//PGATE输出高关MOS,根据外部MOS类型选择
234 PGATE_LOW_OFF = 1,//PGATE输出低关MOS
235 }EN_PGATE_e;
236 typedef enum
237 {
238 GPO_OD = 0,
239 GPO_LOW = 1,
240 }GPO_CTRL_e;
241 typedef enum
242 {
243 ADC_STOP = 0,
244 ADC_START = 1,
245 }ADC_CTRL_e;
246 typedef enum
247 {
248 BW_5KHZ = 0,
249 BW_1P25KHZ = 1,
250 }ILIM_BW_SEL_e;
251 typedef enum
252 {
253 RESPONSE_NORMAL = 0,
254 RESPONSE_IMPROVE = 1,
255 }LOOP_SET_e;
256 typedef enum
257 {
258 FOLDBACK_ENABLE = 0,
259 FOLDBACK_DISABLE = 1,
260 }DISCHARGE_FOLDBACK_e;
261 typedef enum
262 {
263 EOC_25_PERCENT_OF_CURRENT = 0,
264 EOC_10_PERCENT_OF_CURRENT = 1,
265 }EOC_SET_e;//充满的电流阈值,当电池电压达到98%且同时满足电流充满条件,则表示已充满,同时STATUS寄存器EOC标志置位
266 typedef enum
267 {
268 PFM_DISABLE = 0,
269 PFM_ENABLE = 1,
270 }PFM_e;
271
272 typedef struct
273 {
274 EN_PGATE_e en_pgate;
275 GPO_CTRL_e gpo_ctrl;
276 ADC_CTRL_e adc_ctrl;
277 ILIM_BW_SEL_e ilim_bw_sel;
278 LOOP_SET_e loop_set;
279 DISCHARGE_FOLDBACK_e discharge_foldback;
280 EOC_SET_e eoc_set;
281 PFM_e pfm;
282 }CTRL3_SET_INIT_s;
283 /****************************************************************************functions*/
284 void example_init(void);
285
286 #endif