hal_sy6970.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #include "hal_sy6970.h"
  2. #define READ_SDA4 GPIO_ReadInputPins(GPIO_PORT_A,GPIO_PIN_12)
  3. #define IIC_SDA4(n) (n?GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_12):GPIO_ResetPins(GPIO_PORT_A, GPIO_PIN_12))
  4. #define IIC_SCL4(n) (n?GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_11):GPIO_ResetPins(GPIO_PORT_A, GPIO_PIN_11))
  5. #define sy6970_speed 5
  6. //需要示波器调1us的时间
  7. static void delay_us(uint16_t time)
  8. {
  9. uint16_t i;
  10. for(i=time;i>0;i--)
  11. {
  12. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  13. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  14. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  15. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  16. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  17. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  18. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  19. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  20. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  21. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  22. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  23. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  24. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  25. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  26. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  27. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  28. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  29. __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
  30. }
  31. }
  32. static void iic4_init(void)
  33. {
  34. stc_gpio_init_t pstcGpioInit1;
  35. GPIO_StructInit(&pstcGpioInit1);
  36. pstcGpioInit1.u16PinDir = PIN_DIR_OUT;
  37. pstcGpioInit1.u16PinState = PIN_STAT_RST;
  38. GPIO_Init(GPIO_PORT_A, GPIO_PIN_11,&pstcGpioInit1);
  39. GPIO_Init(GPIO_PORT_A, GPIO_PIN_12,&pstcGpioInit1);
  40. GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_11);
  41. GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_12);
  42. }
  43. void sy6970_init(void)
  44. {
  45. iic4_init();
  46. }
  47. static void SDA_IN4(void)
  48. {
  49. stc_gpio_init_t pstcGpioInit3;//iic的引脚
  50. pstcGpioInit3.u16PinDir = PIN_DIR_IN;
  51. //pstcGpioInit3.u16PinInputType = PIN_PU_ON;
  52. GPIO_Init(GPIO_PORT_A, GPIO_PIN_12,&pstcGpioInit3);
  53. }
  54. static void SDA_OUT4(void)
  55. {
  56. stc_gpio_init_t pstcGpioInit3;
  57. pstcGpioInit3.u16PinDir = PIN_DIR_OUT;
  58. pstcGpioInit3.u16PinOutputType=PIN_OUT_TYPE_NMOS;
  59. GPIO_Init(GPIO_PORT_A, GPIO_PIN_12,&pstcGpioInit3);
  60. }
  61. static void iic_start(void)
  62. {
  63. SDA_OUT4();
  64. IIC_SDA4(1);
  65. IIC_SCL4(1);
  66. delay_us(sy6970_speed);
  67. IIC_SDA4(0);
  68. delay_us(sy6970_speed);
  69. IIC_SCL4(0);
  70. }
  71. static void iic_stop(void)
  72. {
  73. SDA_OUT4();
  74. IIC_SCL4(0);
  75. IIC_SDA4(0);
  76. delay_us(sy6970_speed);
  77. IIC_SCL4(1);
  78. IIC_SDA4(1);
  79. delay_us(sy6970_speed);
  80. }
  81. static void iic_ack(void)
  82. {
  83. SDA_OUT4();
  84. IIC_SCL4(0);
  85. IIC_SDA4(0);
  86. delay_us(sy6970_speed);
  87. IIC_SCL4(1);
  88. delay_us(sy6970_speed);
  89. IIC_SCL4(0);
  90. }
  91. static void iic_nack(void)
  92. {
  93. SDA_OUT4();
  94. IIC_SCL4(0);
  95. IIC_SDA4(1);
  96. delay_us(sy6970_speed);
  97. IIC_SCL4(1);
  98. delay_us(sy6970_speed);
  99. IIC_SCL4(0);
  100. }
  101. static uint8_t iic_wait_ack(void)
  102. {
  103. uint16_t t =200;
  104. SDA_OUT4();
  105. IIC_SDA4(1);delay_us(1);
  106. IIC_SCL4(1);delay_us(1);
  107. SDA_IN4();
  108. while(READ_SDA4)
  109. {
  110. t--;
  111. if(t==0)
  112. {
  113. iic_stop();
  114. return 1;
  115. }
  116. delay_us(1);
  117. }
  118. IIC_SCL4(0);
  119. return 0;
  120. }
  121. static void iic_send_byte(uint8_t byte)
  122. {
  123. uint8_t bit_cnt;
  124. SDA_OUT4();
  125. IIC_SCL4(0);
  126. for(bit_cnt=0;bit_cnt<8;bit_cnt++)
  127. {
  128. if(byte&0x80)
  129. IIC_SDA4(1);
  130. else
  131. IIC_SDA4(0);
  132. byte<<=1;
  133. delay_us(sy6970_speed);
  134. IIC_SCL4(1);
  135. delay_us(sy6970_speed);
  136. IIC_SCL4(0);
  137. }
  138. }
  139. static uint8_t iic_recive_byte(unsigned char ack)
  140. {
  141. uint8_t retc = 0;
  142. uint8_t bit_cnt;
  143. SDA_IN4();
  144. delay_us(1);
  145. for(bit_cnt=0;bit_cnt<8;bit_cnt++)
  146. {
  147. IIC_SCL4(0);
  148. delay_us(sy6970_speed);
  149. IIC_SCL4(1);
  150. retc=retc<<1;
  151. if(READ_SDA4)
  152. retc++;
  153. delay_us(sy6970_speed);
  154. }
  155. return(retc);
  156. }
  157. static void sy6970_write_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t WData)
  158. {
  159. iic_start();
  160. iic_send_byte(dev_addr);
  161. iic_wait_ack();
  162. iic_send_byte(RAddr);
  163. iic_wait_ack();
  164. iic_send_byte(WData);
  165. iic_wait_ack();
  166. iic_stop();
  167. }
  168. static void sy6970_read_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t *RData)
  169. {
  170. iic_start();
  171. iic_send_byte(dev_addr);
  172. iic_wait_ack();
  173. iic_send_byte(RAddr);
  174. iic_wait_ack();
  175. iic_start();
  176. iic_send_byte(dev_addr|0x01);
  177. iic_wait_ack();
  178. *RData = iic_recive_byte(0);
  179. iic_stop();
  180. }
  181. _Bool sy6970_write_bytes ( unsigned char SlaveAddr, unsigned char RegAddr, unsigned char *Buf, unsigned char Num )
  182. {
  183. iic_start(); //起始信号
  184. //发送设备地址(写)
  185. iic_send_byte ( SlaveAddr ); //等待应答
  186. iic_wait_ack();
  187. //发送寄存器地址
  188. iic_send_byte ( RegAddr ) ; //等待应答
  189. iic_wait_ack();
  190. while ( Num-- ) //循环写入数据
  191. {
  192. //发送数据
  193. iic_send_byte ( *Buf ); //等待应答
  194. iic_wait_ack();
  195. Buf++; //数据指针偏移到下一个
  196. delay_us(10);
  197. }
  198. iic_stop(); //停止信号
  199. return 0;
  200. }
  201. _Bool sy6970_read_bytes ( unsigned char SlaveAddr, unsigned char RegAddr, unsigned char *Buf, unsigned char Num )
  202. {
  203. iic_start(); //起始信号
  204. //发送设备地址(写)
  205. iic_send_byte ( SlaveAddr ); //等待应答
  206. iic_wait_ack();
  207. //发送寄存器地址
  208. iic_send_byte ( RegAddr ); //等待应答
  209. iic_wait_ack();
  210. iic_start(); //重启信号
  211. //发送设备地址(读)
  212. iic_send_byte ( SlaveAddr + 1 ); //等待应答
  213. iic_wait_ack();
  214. while ( Num-- )
  215. {
  216. //偏移到下一个数据存储地址
  217. if ( Num == 0 )
  218. {
  219. *Buf = iic_recive_byte ( 0 ); //最后一个数据需要回NOACK
  220. }
  221. else
  222. {
  223. *Buf = iic_recive_byte ( 1 ); //回应ACK
  224. }
  225. Buf++;
  226. }
  227. iic_stop();
  228. return 0;
  229. }
  230. #if 0
  231. /**********************************************SY6970 操作函数****************************************************/
  232. /*
  233. * 设置sy6970输入电流的大小
  234. *
  235. * set_val 需要操作的从机设备
  236. Fast Charge Current Limit:
  237. ICHG=[ICHG]*64mA
  238. Range:0mA(0000000)-5056mA(1001111)
  239. 0000000=0mA(Disable Charge)
  240. 0000001=64mA
  241. 0100000=2048mA(Default)
  242. 1001111~1111111=5056mA
  243. *
  244. * 返回值:void
  245. * */
  246. void sy6970_set_input_current_limit(uint8_t set_val)
  247. {
  248. set_val&= 0x7F;
  249. sy6970_write_byte(SY6970_ADDR,0x04,set_val);
  250. }
  251. /*
  252. * 设置sy6970输入电压的大小
  253. *
  254. * set_val 需要操作的从机设备
  255. Charge Voltage Limit:
  256. VREG=3.840V+[VREG]*16mV
  257. Range:3.840V-4.608V(110000)
  258. 000000=3.840V
  259. 000001=3.856V
  260. 010111=4.208V(Default)
  261. 110000~111111=4.608V
  262. *
  263. * 返回值:void
  264. * */
  265. void sy6970_set_input_voltage_limit(uint8_t set_val)
  266. {
  267. set_val&= 0xFC;
  268. sy6970_write_byte(SY6970_ADDR,0x06,set_val);
  269. }
  270. /*充电使能*/
  271. void sy6970_charge_enable(void)
  272. {
  273. uint8_t set_val = 0x00;
  274. set_val&= 0x01<<4;
  275. sy6970_write_byte(SY6970_ADDR,0x03,set_val);
  276. }
  277. /*充电不使能*/
  278. void sy6970_charge_disable(void)
  279. {
  280. uint8_t set_val = 0x00;
  281. set_val&= 0x00<<4;
  282. sy6970_write_byte(SY6970_ADDR,0x03,set_val);
  283. }
  284. /*充电状态查询
  285. 返回值:
  286. 00-Not Charging
  287. 01-Pre-charge (VBAT <VBATLOWV)
  288. 10-Fast Charging
  289. 11-Charge Termination Done
  290. */
  291. uint8_t sy6970_charge_status(void)
  292. {
  293. uint8_t status = 0;
  294. sy6970_read_byte(SY6970_ADDR,0x0b,&status);
  295. status >>=3;
  296. status &=0x03;
  297. return status;
  298. }
  299. uint8_t statusx = 0;
  300. #endif
  301. #include "FreeRTOS.h"
  302. #include "task.h"
  303. uint16 batt_voltage = 0, sys_voltage = 0;
  304. uint8 charge_status = 0;
  305. uint8 charge_ctl = 0;
  306. REG_SYS_CONFIG reg[0X15];
  307. REG_SYS_CONFIG regRead;
  308. uint8 ntc_error = 0, bus_state = 0, current_limit = 0;
  309. uint16 charge_voltage = 0, charge_current = 0, inutcharg = 0, charge_current_read = 0;
  310. uint8 charge_flag = 0;
  311. /**********************************************SY6970 操作函数****************************************************/
  312. /*
  313. * 设置sy6970输入电流的大小
  314. *
  315. * set_val 需要操作的从机设备
  316. Fast Charge Current Limit:
  317. ICHG=[ICHG]*64mA
  318. Range:0mA(0000000)-5056mA(1001111)
  319. 0000000=0mA(Disable Charge)
  320. 0000001=64mA
  321. 0100000=2048mA(Default)
  322. 1001111~1111111=5056mA
  323. *
  324. * 返回值:void
  325. * */
  326. void sy6970_set_input_current_limit(uint8_t set_val)
  327. {
  328. set_val&= 0x7F;
  329. sy6970_write_byte(SY6970_ADDR,0x04,set_val);
  330. }
  331. /*
  332. * 设置sy6970输入电压的大小
  333. *
  334. * set_val 需要操作的从机设备
  335. Charge Voltage Limit:
  336. VREG=3.840V+[VREG]*16mV
  337. Range:3.840V-4.608V(110000)
  338. 000000=3.840V
  339. 000001=3.856V
  340. 010111=4.208V(Default)
  341. 110000~111111=4.608V
  342. *
  343. * 返回值:void
  344. * */
  345. void sy6970_set_input_voltage_limit(uint8_t set_val)
  346. {
  347. set_val &= 0xFC;
  348. sy6970_write_byte(SY6970_ADDR,0x06,set_val);
  349. }
  350. /*充电使能*/
  351. void sy6970_set_reg03_charge(void)
  352. {
  353. REG_SYS_CONFIG bat_config = {0};
  354. bat_config.reg03_config.bat_load_en = 0;
  355. bat_config.reg03_config.wd_rst = 1;
  356. bat_config.reg03_config.otg_config = 0;
  357. bat_config.reg03_config.chg_config = 1;
  358. bat_config.reg03_config.sys_min = 5;
  359. sy6970_write_byte(SY6970_ADDR,0x03, bat_config.data_uint8);
  360. }
  361. /*获取 */
  362. REG_SYS_CONFIG sy6970_get_reg_config(uint8_t cmd)
  363. {
  364. REG_SYS_CONFIG bat_read = {0};
  365. sy6970_read_byte(SY6970_ADDR, cmd, &bat_read.data_uint8);
  366. return bat_read;
  367. }
  368. /*获取REG02配置*/
  369. REG_SYS_CONFIG sy6970_get_reg02_config(void)
  370. {
  371. REG_SYS_CONFIG bat_read = {0};
  372. sy6970_read_byte(SY6970_ADDR,0x02, &bat_read.data_uint8);
  373. return bat_read;
  374. }
  375. /*获取充电配置*/
  376. REG_SYS_CONFIG sy6970_get_reg03_config(void)
  377. {
  378. REG_SYS_CONFIG bat_read = {0};
  379. sy6970_read_byte(SY6970_ADDR,0x03, &bat_read.data_uint8);
  380. return bat_read;
  381. }
  382. /*配置reg0D*/
  383. void sy6970_reg0d_vindpm_config(void)
  384. {
  385. REG_SYS_CONFIG bat_config = {0};
  386. bat_config.reg0D_config.VINDPM_MODE = 1;
  387. bat_config.reg0D_config.VINDPM = 100;
  388. sy6970_write_byte(SY6970_ADDR,0x0D, bat_config.data_uint8);
  389. }
  390. /*获取reg0D配置*/
  391. REG_SYS_CONFIG sy6970_get_reg0d_vindpm_config(void)
  392. {
  393. REG_SYS_CONFIG bat_read = {0};
  394. sy6970_read_byte(SY6970_ADDR,0x0D, &bat_read.data_uint8);
  395. return bat_read;
  396. }
  397. /*
  398. *
  399. * 获取reg11数据
  400. * 包括
  401. * bus状态
  402. * BUSV
  403. * */
  404. REG_SYS_CONFIG sy6970_get_reg11_bus_status(void)
  405. {
  406. REG_SYS_CONFIG bat_status = {0};
  407. sy6970_read_byte(SY6970_ADDR, 0x11, &(bat_status.data_uint8));
  408. return bat_status;
  409. }
  410. /*充电不使能*/
  411. void sy6970_reg03_charge_disable(void)
  412. {
  413. REG_SYS_CONFIG bat_status = {0};
  414. //bat_status.reg03_config.
  415. //sy6970_read_byte(SY6970_ADDR, 0x11, &(bat_status.data));
  416. //return bat_status;
  417. }
  418. /*
  419. */
  420. REG_SYS_CONFIG sy6970_get_reg0b_charge_status(void)
  421. {
  422. REG_SYS_CONFIG bat_read = {0};
  423. sy6970_read_byte(SY6970_ADDR,0x0b, &bat_read.data_uint8);
  424. return bat_read;
  425. }
  426. /*
  427. * 电池电压查询
  428. 返回值:
  429. 电池电压
  430. 单位mv
  431. */
  432. uint16_t sy6970_get_batv(void)
  433. {
  434. uint8_t data = 0;
  435. sy6970_read_byte(SY6970_ADDR,0x0E,&data);
  436. return 2304 + 20 * (data & 0X7F);
  437. }
  438. uint16_t sy6970_set_reg(uint8 cmd, uint16 cmd_data)
  439. {
  440. REG_SYS_CONFIG bat_config = {0};
  441. switch(cmd)
  442. {
  443. case 0X00:
  444. bat_config.re00_config.EN_HIZ = 0;
  445. bat_config.re00_config.EN_ILIM = 1;
  446. bat_config.re00_config.IINLIM = (cmd_data - 100) / 50;
  447. break;
  448. case 0X02:
  449. bat_config.reg02_config.conv_start = 1;
  450. bat_config.reg02_config.conv_rate = 0;
  451. bat_config.reg02_config.boost_freq = 0;
  452. bat_config.reg02_config.aicl_en = 1;
  453. bat_config.reg02_config.hvdcp_en = 1;
  454. bat_config.reg02_config.hv_type = 1;
  455. bat_config.reg02_config.force_dpdm = 0;
  456. bat_config.reg02_config.auto_dpdm_en = 0;
  457. break;
  458. case 0X03:
  459. switch(cmd_data)
  460. {
  461. case 0X00:
  462. bat_config.reg03_config.bat_load_en = 0;
  463. bat_config.reg03_config.wd_rst = 0;
  464. bat_config.reg03_config.otg_config = 0;
  465. bat_config.reg03_config.chg_config = 0;
  466. bat_config.reg03_config.sys_min = 5;
  467. break;
  468. case 0X01:
  469. bat_config.reg03_config.bat_load_en = 0;
  470. bat_config.reg03_config.wd_rst = 0;
  471. bat_config.reg03_config.otg_config = 0;
  472. bat_config.reg03_config.chg_config = 1;
  473. bat_config.reg03_config.sys_min = 5;
  474. break;
  475. default:
  476. return 1;
  477. }
  478. break;
  479. case 0X04://充电电流设置
  480. cmd_data = cmd_data/64;
  481. bat_config.reg04_config.EN_PUMPX = 0;
  482. bat_config.reg04_config.ICHG = cmd_data;
  483. break;
  484. case 0X06:
  485. if(cmd_data < 3804)
  486. return 0;
  487. else
  488. {}
  489. cmd_data = (cmd_data - 4208) >= 0 ? (cmd_data - 3840)/16 : 23;
  490. //bat_config.
  491. bat_config.reg06_config.VREG = cmd_data;
  492. bat_config.reg06_config.BATLOWV = 1;
  493. bat_config.reg06_config.VRECHG = 0;
  494. break;
  495. default:
  496. return 1;
  497. }
  498. sy6970_write_byte(SY6970_ADDR, cmd ,bat_config.data_uint8);
  499. return 0;
  500. }
  501. /*
  502. * system电压查询
  503. 返回值:
  504. system电压
  505. 单位mv
  506. */
  507. uint16_t sy6970_get_sysv(void)
  508. {
  509. uint8_t data = 0;
  510. sy6970_read_byte(SY6970_ADDR,0x0F,&data);
  511. return 2304 + 20 * (data & 0X7F);
  512. }
  513. void sy6970_task(void *argv)
  514. {
  515. /*Buck Mode:
  516. 000-Normal
  517. 010-NTC Warm
  518. 011-NTC Cool
  519. 101-NTC Cold
  520. 110-NTC Hot
  521. Boost Mode:
  522. 000-NTC Normal
  523. 101-NTC Cold
  524. 110-NTC Hot*/
  525. //charge_status = sy6970_charge_status();// value_v = data * 0.02 + 2.304;
  526. charge_current = 1024;
  527. charge_voltage = 4208;
  528. inutcharg = 1000;
  529. sy6970_set_reg(REG_ADC_START_CTR, 0);
  530. sy6970_set_reg(REG_INPUT_CURRENT_CTR, inutcharg);
  531. sy6970_set_reg(REG_CURRENT_CHARGE_CTR, charge_current);
  532. sy6970_set_reg(REG_VOLTAGE_CHARGE_CTR, charge_voltage);
  533. //sy6970_set_reg(REG_ADC_START_CTR, inutcharg);
  534. while(1)
  535. {
  536. regRead = sy6970_get_reg_config(REG_VOLTAGE_READ);
  537. batt_voltage = regRead.reg0e_batt_info.BATV * 20 + 2304;
  538. regRead = sy6970_get_reg_config(REG_SYS_VOLTAGE_READ);
  539. sys_voltage = regRead.reg0f_sysv_info.SYSV * 20 + 2304;
  540. regRead = sy6970_get_reg_config(REG_CHARGE_STATUS_READ);
  541. charge_status = regRead.reg0b_onre_status.charg_stat;
  542. regRead = sy6970_get_reg_config(REG_NTC_STATUS_READ);
  543. ntc_error = regRead.reg0c_tem_info.NTC_FAULT;
  544. regRead = sy6970_get_reg_config(REG_CHARGE_CURRENT_READ);
  545. charge_current_read = regRead.reg12_charge_info.ICHGR * 50;
  546. regRead = sy6970_get_reg_config(REG_CURRENT_STATUS_READ);
  547. current_limit = regRead.reg13_current_input_info.CurrentInputLimit;
  548. if(batt_voltage > 4224 && 1 == charge_flag)
  549. {
  550. sy6970_set_reg(REG_CHARGE_CTR, DISABLE);
  551. charge_flag = 0;
  552. }
  553. else if(batt_voltage < 4000 && 0 == charge_flag)
  554. {
  555. sy6970_set_reg(REG_CHARGE_CTR, ENABLE);
  556. charge_flag = 1;
  557. }
  558. else{;}
  559. sy6970_set_reg(REG_ADC_START_CTR, 0);
  560. vTaskDelay(pdMS_TO_TICKS(1000));
  561. //3.872 ** xian 3884
  562. for(uint8 i = 0; i <= 0X14; i++)
  563. {
  564. reg[i] = sy6970_get_reg_config(i);
  565. }
  566. //
  567. // batt_voltage = reg[0X0E].reg0e_batt_info.BATV * 20 + 2304;
  568. // sys_voltage = reg[0X0F].reg0f_sysv_info.SYSV * 20 + 2304;
  569. // charge_status = reg[0X0B].reg0b_onre_status.charg_stat;
  570. // bus_state = reg[0X11].r11_bus_info.bus_gd;
  571. // bus_v = reg[0X11].reg11_bus_info.busv * 100 + 2600;
  572. // charge_current = reg[0X12].reg12_charge_info.ICHGR;
  573. // ntc_error = reg[0X0C].reg0c_tem_info.NTC_FAULT;
  574. }
  575. }