-
大小: 13KB文件類型: .c金幣: 2下載: 1 次發布日期: 2021-04-07
- 語言: 其他
- 標簽: cw2015_batte??
資源簡介
發現網上找不到 cw2015 電池檢測的源代碼,現在補充出來。
代碼片段和文件信息
/*
?*??cw2015_battery.c
?*??fuel-gauge?systems?for?lithium-ion?(Li+)?batteries
?*
?*??Copyright?(C)?2009?Samsung?Electronics
?*??Minkyu?Kang?
?*
?*?This?program?is?free?software;?you?can?redistribute?it?and/or?modify
?*?it?under?the?terms?of?the?GNU?General?Public?License?version?2?as
?*?published?by?the?Free?Software?Foundation.
?*/
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#define?REG_VERSION?????????????0x0
#define?REG_VCELL???????????????0x2
#define?REG_SOC?????????????????0x4
#define?REG_RRT_ALERT???????????0x6
#define?REG_CONFIG??????????????0x8
#define?REG_MODE????????????????0xA
#define?REG_BATINFO?????????????0x10
#define?MODE_SLEEP_MASK?????????(0x3<<6)
#define?MODE_SLEEP??????????????(0x3<<6)
#define?MODE_NORMAL?????????????(0x0<<6)
#define?MODE_QUICK_START????????(0x3<<4)
#define?MODE_RESTART????????????(0xf<<0)
#define?CONFIG_UPDATE_FLG???????(0x1<<1)
#define?ATHD????????????????????(0x0<<3)????????//ATHD?=?0%
#define?cw2015_DELAY 1000
#define?cw2015_BATTERY_FULL 95
static?void?cw2015_reset(struct?i2c_client?*client);
static?void?cw2015_quick_start(struct?i2c_client?*client);
struct?cw2015_chip?{
struct?i2c_client *client;
struct?delayed_work ?work;
struct?power_supply ?battery;
struct?cw_bat_platform_data *plat_data;
/*?State?Of?Connect?*/
int?online;
/*?battery?voltage?*/
int?vcell;
/*?battery?capacity?*/
int?soc;
/*?State?Of?Charge?*/
int?status;
};
static?int?cw2015_get_property(struct?power_supply?*psy
????enum?power_supply_property?psp
????union?power_supply_propval?*val)
{
struct?cw2015_chip?*chip?=?container_of(psy
struct?cw2015_chip?battery);
switch?(psp)?{
case?POWER_SUPPLY_PROP_STATUS:
val->intval?=?chip->status;
break;
case?POWER_SUPPLY_PROP_ONLINE:
val->intval?=?chip->online;
break;
case?POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval?=?chip->vcell;
break;
case?POWER_SUPPLY_PROP_CAPACITY:
val->intval?=?chip->soc;
break;
case?POWER_SUPPLY_PROP_VOLTAGE_MAX:
cw2015_reset(chip->client);
break;
case?POWER_SUPPLY_PROP_VOLTAGE_MIN:
cw2015_quick_start(chip->client);
break;
default:
return?-EINVAL;
}
return?0;
}
static?int?cw_read(struct?i2c_client?*client?u8?reg?u8?buf[])
{
unsigned?char?data;
int?ret;
data?=?(unsigned?char)reg;
ret?=?i2c_master_send(client?&data?1);
if?(ret?0)return?ret;
ret?=?i2c_master_recv(client?buf?1);
if?(ret?0)return?ret;
return?0;
}
static?int?cw_write(struct?i2c_client?*client?u8?reg?u8?const?buf[])
{
u8?data[3];
data[0]?=?reg;
data[1]?=?buf[0];
return?i2c_master_send(client?data?2);
}
static?int?cw_read_word(struct?i
評論
共有 條評論