KT25-1015_AC695x_SDK310/apps/kaotings/kt_battery.h
2026-05-07 22:11:18 +08:00

30 lines
1.1 KiB
C
Raw Permalink 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.

#ifndef __KT_BATTERY_H__
#define __KT_BATTERY_H__
#include "kt.h"
/*
* KT_CFG_VBAT_DET_PIN(IO_PORTA_12 / AD_CH_PA12) 经 100K/100K 分压采集电池电压。
* 采样路径: ADC(mV) × KT_BAT_DIVIDER_NUM = 电池真实电压(mV)
*
* 锂电池满电 4.2V,SDK 的 get_vbat_percent() 测试不准,这里独立做百分比换算 + 滤波 + 滞回。
*/
#define KT_BAT_FULL_MV 4200u /* 100% 对应电压 (mV) */
#define KT_BAT_EMPTY_MV 3200u /* 0% 对应电压 (mV);留 0.2V 余量避免低电关机抖 */
#define KT_BAT_DIVIDER_NUM 2u /* 100K/100K 分压,实际电压 = ADC 读数 × 2 */
void kt_battery_init(void);
/* 当前电池百分比(0~100),已经过滑动平均 + 单向滞回平滑,可以直接喂 UI */
u8 kt_get_vbat_percent(void);
/* 当前平滑后的电池电压(mV),调试/上报用 */
u16 kt_get_vbat_mv(void);
/* 由 USB 插拔检测路径调用(kt.c::vbus_detect),用来切换滞回方向: */
/* charging=1 → 只允许百分比上升; charging=0 → 只允许百分比下降 */
void kt_set_charging(u8 charging);
#endif