sggt/App/APP_WU/Src/ip5310_i2c.c

41 lines
1.3 KiB
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.

/*
* @Author: wujunchao wujunchao@wuxismart.com
* @Date: 2025-03-17 13:35:30
* @LastEditors: wujunchao wujunchao@wuxismart.com
* @LastEditTime: 2025-03-24 17:35:57
* @FilePath: \signal_generator\App\APP_WU\Src\ip5310_i2c.c
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#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;
}