sggt/App/IP5310/ip5310_i2c.c

33 lines
951 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "ip5310_i2c.h"
uint8_t rx_data = 0;
uint8_t tx_data = 0;
uint8_t bat_cpa;
uint8_t charge_flag = 0;
uint8_t charging_flag = 0;
//I2C读取电池电量
void read_battery(void)
{
//读取当前电量5个档位
tx_data = BATTERY_CAPACITY;
HAL_I2C_Master_Transmit(&hi2c3, WRITE_CMD, &tx_data, 1, 0xff);
HAL_I2C_Master_Receive(&hi2c3, READ_CMD, &rx_data, 1, 0xff);
bat_cpa = (rx_data >> 4);
//电池充电是否开始type-C是否接入电源
tx_data = CHARGE_FLAG;
HAL_I2C_Master_Transmit(&hi2c3, WRITE_CMD, &tx_data, 1, 0xff);
HAL_I2C_Master_Receive(&hi2c3, READ_CMD, &rx_data, 1, 0xff);
charge_flag = (rx_data & 0x08)>>3;
//电池充电是否结束type-C可能还处于连接状态
tx_data = CHARGING_FLAG;
HAL_I2C_Master_Transmit(&hi2c3, WRITE_CMD, &tx_data, 1, 0xff);
HAL_I2C_Master_Receive(&hi2c3, READ_CMD, &rx_data, 1, 0xff);
charging_flag = (rx_data & 0x08)>>3;
}