8#ifndef ZEPHYR_INCLUDE_DRIVERS_BATTERY_H_
9#define ZEPHYR_INCLUDE_DRIVERS_BATTERY_H_
182#define SBS_GAUGE_MANUFACTURER_NAME_MAX_SIZE 20
183#define SBS_GAUGE_DEVICE_NAME_MAX_SIZE 20
184#define SBS_GAUGE_DEVICE_CHEMISTRY_MAX_SIZE 4
227 void *dst,
size_t dst_len);
269 if (api->get_property == NULL) {
273 return api->get_property(dev, prop, val);
293static inline int z_impl_fuel_gauge_get_props(
const struct device *dev,
299 for (
size_t i = 0; i < len; i++) {
300 int ret = api->get_property(dev, props[i], vals + i);
327 if (api->set_property == NULL) {
331 return api->set_property(dev, prop, val);
348static inline int z_impl_fuel_gauge_set_props(
const struct device *dev,
352 for (
size_t i = 0; i < len; i++) {
375 void *dst,
size_t dst_len);
377static inline int z_impl_fuel_gauge_get_buffer_prop(
const struct device *dev,
379 void *dst,
size_t dst_len)
383 if (api->get_buffer_property == NULL) {
387 return api->get_buffer_property(dev, prop_type, dst, dst_len);
400static inline int z_impl_fuel_gauge_battery_cutoff(
const struct device *dev)
404 if (api->battery_cutoff == NULL) {
408 return api->battery_cutoff(dev);
419#include <zephyr/syscalls/fuel_gauge.h>
#define SBS_GAUGE_DEVICE_NAME_MAX_SIZE
Definition fuel_gauge.h:183
uint16_t fuel_gauge_prop_t
Definition fuel_gauge.h:116
int(* fuel_gauge_battery_cutoff_t)(const struct device *dev)
Callback API for doing a battery cutoff.
Definition fuel_gauge.h:235
int fuel_gauge_battery_cutoff(const struct device *dev)
Have fuel gauge cutoff its associated battery.
int fuel_gauge_get_buffer_prop(const struct device *dev, fuel_gauge_prop_t prop_type, void *dst, size_t dst_len)
Fetch a battery fuel-gauge buffer property.
#define SBS_GAUGE_MANUFACTURER_NAME_MAX_SIZE
Data structures for reading SBS buffer properties.
Definition fuel_gauge.h:182
int fuel_gauge_set_prop(const struct device *dev, fuel_gauge_prop_t prop, union fuel_gauge_prop_val val)
Set a battery fuel-gauge property.
int fuel_gauge_get_prop(const struct device *dev, fuel_gauge_prop_t prop, union fuel_gauge_prop_val *val)
Fetch a battery fuel-gauge property.
int fuel_gauge_set_props(const struct device *dev, const fuel_gauge_prop_t *props, const union fuel_gauge_prop_val *vals, size_t len)
Set a battery fuel-gauge property.
fuel_gauge_prop_type
Definition fuel_gauge.h:31
int(* fuel_gauge_set_property_t)(const struct device *dev, fuel_gauge_prop_t prop, union fuel_gauge_prop_val val)
Callback API for setting a fuel_gauge property.
Definition fuel_gauge.h:216
int(* fuel_gauge_get_property_t)(const struct device *dev, fuel_gauge_prop_t prop, union fuel_gauge_prop_val *val)
Callback API for getting a fuel_gauge property.
Definition fuel_gauge.h:207
int(* fuel_gauge_get_buffer_property_t)(const struct device *dev, fuel_gauge_prop_t prop_type, void *dst, size_t dst_len)
Callback API for getting a fuel_gauge buffer property.
Definition fuel_gauge.h:225
int fuel_gauge_get_props(const struct device *dev, const fuel_gauge_prop_t *props, union fuel_gauge_prop_val *vals, size_t len)
Fetch multiple battery fuel-gauge properties.
#define SBS_GAUGE_DEVICE_CHEMISTRY_MAX_SIZE
Definition fuel_gauge.h:184
@ FUEL_GAUGE_CURRENT
Battery current (uA); negative=discharging.
Definition fuel_gauge.h:44
@ FUEL_GAUGE_STATUS
Alarm, Status and Error codes (flags)
Definition fuel_gauge.h:80
@ FUEL_GAUGE_SBS_MFR_ACCESS
Retrieve word from SBS1.1 ManufactuerAccess.
Definition fuel_gauge.h:64
@ FUEL_GAUGE_CONNECT_STATE
Connect state of battery.
Definition fuel_gauge.h:50
@ FUEL_GAUGE_FLAGS
General Error/Runtime Flags.
Definition fuel_gauge.h:52
@ FUEL_GAUGE_CYCLE_COUNT
Cycle count in 1/100ths (number of charge/discharge cycles)
Definition fuel_gauge.h:48
@ FUEL_GAUGE_COMMON_COUNT
Reserved to demark end of common fuel gauge properties.
Definition fuel_gauge.h:105
@ FUEL_GAUGE_MANUFACTURER_NAME
Manufacturer of pack (1 byte length + 20 bytes data)
Definition fuel_gauge.h:98
@ FUEL_GAUGE_SBS_MODE
Battery Mode (flags)
Definition fuel_gauge.h:74
@ FUEL_GAUGE_SBS_ATRATE
AtRate (mA or 10 mW)
Definition fuel_gauge.h:86
@ FUEL_GAUGE_DESIGN_VOLTAGE
Design Voltage (mV)
Definition fuel_gauge.h:84
@ FUEL_GAUGE_AVG_CURRENT
Runtime Dynamic Battery Parameters.
Definition fuel_gauge.h:39
@ FUEL_GAUGE_RUNTIME_TO_FULL
Remaining time in minutes until battery reaches full charge.
Definition fuel_gauge.h:62
@ FUEL_GAUGE_CHARGE_CURRENT
Battery desired Max Charging Current (uA)
Definition fuel_gauge.h:76
@ FUEL_GAUGE_CUSTOM_BEGIN
Reserved to demark downstream custom properties - use this value as the actual value may change over ...
Definition fuel_gauge.h:110
@ FUEL_GAUGE_DEVICE_CHEMISTRY
Chemistry (1 byte length + 4 bytes data)
Definition fuel_gauge.h:102
@ FUEL_GAUGE_PROP_MAX
Reserved to demark end of valid enum properties.
Definition fuel_gauge.h:113
@ FUEL_GAUGE_SBS_ATRATE_TIME_TO_EMPTY
AtRateTimeToEmpty (minutes)
Definition fuel_gauge.h:90
@ FUEL_GAUGE_DESIGN_CAPACITY
Design Capacity (mAh or 10mWh)
Definition fuel_gauge.h:82
@ FUEL_GAUGE_VOLTAGE
Battery voltage (uV)
Definition fuel_gauge.h:72
@ FUEL_GAUGE_SBS_REMAINING_TIME_ALARM
Remaining Time Alarm (minutes)
Definition fuel_gauge.h:96
@ FUEL_GAUGE_CHARGE_CUTOFF
Whether the battery underlying the fuel-gauge is cut off from charge.
Definition fuel_gauge.h:46
@ FUEL_GAUGE_CHARGE_VOLTAGE
Battery desired Max Charging Voltage (uV)
Definition fuel_gauge.h:78
@ FUEL_GAUGE_ABSOLUTE_STATE_OF_CHARGE
Absolute state of charge (percent, 0-100) - expressed as % of design capacity.
Definition fuel_gauge.h:66
@ FUEL_GAUGE_DEVICE_NAME
Name of pack (1 byte length + 20 bytes data)
Definition fuel_gauge.h:100
@ FUEL_GAUGE_SBS_ATRATE_TIME_TO_FULL
AtRateTimeToFull (minutes)
Definition fuel_gauge.h:88
@ FUEL_GAUGE_TEMPERATURE
Temperature in 0.1 K.
Definition fuel_gauge.h:70
@ FUEL_GAUGE_FULL_CHARGE_CAPACITY
Full Charge Capacity in uAh (might change in some implementations to determine wear)
Definition fuel_gauge.h:54
@ FUEL_GAUGE_RUNTIME_TO_EMPTY
Remaining battery life time in minutes.
Definition fuel_gauge.h:60
@ FUEL_GAUGE_PRESENT_STATE
Is the battery physically present.
Definition fuel_gauge.h:56
@ FUEL_GAUGE_REMAINING_CAPACITY
Remaining capacity in uAh.
Definition fuel_gauge.h:58
@ FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM
Remaining Capacity Alarm (mAh or 10mWh)
Definition fuel_gauge.h:94
@ FUEL_GAUGE_BATTERY_CUTOFF
Used to cutoff the battery from the system - useful for storage/shipping of devices.
Definition fuel_gauge.h:42
@ FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE
Relative state of charge (percent, 0-100) - expressed as % of full charge capacity.
Definition fuel_gauge.h:68
@ FUEL_GAUGE_SBS_ATRATE_OK
AtRateOK (boolean)
Definition fuel_gauge.h:92
#define ENOSYS
Function not implemented.
Definition errno.h:82
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
#define UINT16_MAX
Definition stdint.h:28
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
Definition fuel_gauge.h:239
fuel_gauge_battery_cutoff_t battery_cutoff
Definition fuel_gauge.h:249
fuel_gauge_set_property_t set_property
Definition fuel_gauge.h:247
fuel_gauge_get_property_t get_property
Note: Historically this API allowed drivers to implement a custom multi-get/set property function,...
Definition fuel_gauge.h:246
fuel_gauge_get_buffer_property_t get_buffer_property
Definition fuel_gauge.h:248
Definition fuel_gauge.h:196
char device_chemistry[4]
Definition fuel_gauge.h:198
uint8_t device_chemistry_length
Definition fuel_gauge.h:197
Definition fuel_gauge.h:191
uint8_t device_name_length
Definition fuel_gauge.h:192
char device_name[20]
Definition fuel_gauge.h:193
Definition fuel_gauge.h:186
uint8_t manufacturer_name_length
Definition fuel_gauge.h:187
char manufacturer_name[20]
Definition fuel_gauge.h:188
Property field to value/type union.
Definition fuel_gauge.h:119
uint16_t design_volt
FUEL_GAUGE_DESIGN_VOLTAGE.
Definition fuel_gauge.h:164
uint16_t design_cap
FUEL_GAUGE_DESIGN_CAPACITY.
Definition fuel_gauge.h:162
uint32_t runtime_to_full
FUEL_GAUGE_RUNTIME_TO_FULL.
Definition fuel_gauge.h:142
uint8_t absolute_state_of_charge
FUEL_GAUGE_ABSOLUTE_STATE_OF_CHARGE.
Definition fuel_gauge.h:146
uint16_t temperature
FUEL_GAUGE_TEMPERATURE.
Definition fuel_gauge.h:150
uint8_t relative_state_of_charge
FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE.
Definition fuel_gauge.h:148
uint16_t fg_status
FUEL_GAUGE_STATUS.
Definition fuel_gauge.h:160
uint32_t chg_current
FUEL_GAUGE_CHARGE_CURRENT.
Definition fuel_gauge.h:156
uint16_t sbs_at_rate_time_to_empty
FUEL_GAUGE_SBS_ATRATE_TIME_TO_EMPTY
Definition fuel_gauge.h:170
uint16_t sbs_mode
FUEL_GAUGE_SBS_MODE.
Definition fuel_gauge.h:154
uint16_t sbs_remaining_capacity_alarm
FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM.
Definition fuel_gauge.h:174
uint32_t chg_voltage
FUEL_GAUGE_CHARGE_VOLTAGE.
Definition fuel_gauge.h:158
uint16_t sbs_mfr_access_word
FUEL_GAUGE_SBS_MFR_ACCESS.
Definition fuel_gauge.h:144
bool sbs_at_rate_ok
FUEL_GAUGE_SBS_ATRATE_OK.
Definition fuel_gauge.h:172
int current
FUEL_GAUGE_CURRENT.
Definition fuel_gauge.h:130
uint16_t sbs_remaining_time_alarm
FUEL_GAUGE_SBS_REMAINING_TIME_ALARM.
Definition fuel_gauge.h:176
uint32_t full_charge_capacity
FUEL_GAUGE_FULL_CHARGE_CAPACITY.
Definition fuel_gauge.h:136
int16_t sbs_at_rate
FUEL_GAUGE_SBS_ATRATE.
Definition fuel_gauge.h:166
int voltage
FUEL_GAUGE_VOLTAGE.
Definition fuel_gauge.h:152
uint32_t cycle_count
FUEL_GAUGE_CYCLE_COUNT.
Definition fuel_gauge.h:132
bool cutoff
FUEL_GAUGE_CHARGE_CUTOFF.
Definition fuel_gauge.h:128
int avg_current
FUEL_GAUGE_AVG_CURRENT.
Definition fuel_gauge.h:126
uint32_t flags
FUEL_GAUGE_FLAGS.
Definition fuel_gauge.h:134
uint32_t remaining_capacity
FUEL_GAUGE_REMAINING_CAPACITY.
Definition fuel_gauge.h:138
uint32_t runtime_to_empty
FUEL_GAUGE_RUNTIME_TO_EMPTY.
Definition fuel_gauge.h:140
uint16_t sbs_at_rate_time_to_full
FUEL_GAUGE_SBS_ATRATE_TIME_TO_FULL.
Definition fuel_gauge.h:168