Zephyr Project API  3.3.0
A Scalable Open Source RTOS
fuel_gauge.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DRIVERS_BATTERY_H_
8#define ZEPHYR_INCLUDE_DRIVERS_BATTERY_H_
9
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdint.h>
24
25#include <zephyr/device.h>
26
27/* Keep these alphabetized wrt property name */
28
36#define FUEL_GAUGE_AVG_CURRENT 0
37
39#define FUEL_GAUGE_CURRENT FUEL_GAUGE_AVG_CURRENT + 1
41#define FUEL_GAUGE_CHARGE_CUTOFF FUEL_GAUGE_CURRENT + 1
43#define FUEL_GAUGE_CYCLE_COUNT FUEL_GAUGE_CHARGE_CUTOFF + 1
45#define FUEL_GAUGE_CONNECT_STATE FUEL_GAUGE_CYCLE_COUNT + 1
47#define FUEL_GAUGE_FLAGS FUEL_GAUGE_CONNECT_STATE + 1
49#define FUEL_GAUGE_FULL_CHARGE_CAPACITY FUEL_GAUGE_FLAGS + 1
51#define FUEL_GAUGE_PRESENT_STATE FUEL_GAUGE_FULL_CHARGE_CAPACITY + 1
53#define FUEL_GAUGE_REMAINING_CAPACITY FUEL_GAUGE_PRESENT_STATE + 1
55#define FUEL_GAUGE_RUNTIME_TO_EMPTY FUEL_GAUGE_REMAINING_CAPACITY + 1
57#define FUEL_GAUGE_RUNTIME_TO_FULL FUEL_GAUGE_RUNTIME_TO_EMPTY + 1
59#define FUEL_GAUGE_SBS_MFR_ACCESS FUEL_GAUGE_RUNTIME_TO_FULL + 1
61#define FUEL_GAUGE_STATE_OF_CHARGE FUEL_GAUGE_SBS_MFR_ACCESS + 1
63#define FUEL_GAUGE_TEMPERATURE FUEL_GAUGE_STATE_OF_CHARGE + 1
65#define FUEL_GAUGE_VOLTAGE FUEL_GAUGE_TEMPERATURE + 1
66
68#define FUEL_GAUGE_COMMON_COUNT FUEL_GAUGE_VOLTAGE + 1
73#define FUEL_GAUGE_CUSTOM_BEGIN FUEL_GAUGE_COMMON_COUNT + 1
74
76#define FUEL_GAUGE_PROP_MAX UINT16_MAX
77
81
83 int status;
84
86 union {
87 /* Fields have the format: */
88 /* FUEL_GAUGE_PROPERTY_FIELD */
89 /* type property_field; */
90
91 /* Dynamic Battery Info */
95 bool cutoff;
119};
120
124
127
129 union {
130 /* Fields have the format: */
131 /* FUEL_GAUGE_PROPERTY_FIELD */
132 /* type property_field; */
133
134 /* Writable Dynamic Battery Info */
138};
139
152typedef int (*fuel_gauge_get_property_t)(const struct device *dev,
153 struct fuel_gauge_get_property *props, size_t props_len);
154
167typedef int (*fuel_gauge_set_property_t)(const struct device *dev,
168 struct fuel_gauge_set_property *props, size_t props_len);
169
170/* Caching is entirely on the onus of the client */
171
172__subsystem struct battery_driver_api {
175};
176
181#ifdef __cplusplus
182}
183#endif /* __cplusplus */
184
185#endif /* ZEPHYR_INCLUDE_DRIVERS_BATTERY_H_ */
int(* fuel_gauge_get_property_t)(const struct device *dev, struct fuel_gauge_get_property *props, size_t props_len)
Fetch a battery fuel-gauge property.
Definition: fuel_gauge.h:152
int(* fuel_gauge_set_property_t)(const struct device *dev, struct fuel_gauge_set_property *props, size_t props_len)
Set a battery fuel-gauge property.
Definition: fuel_gauge.h:167
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: fuel_gauge.h:172
fuel_gauge_set_property_t set_property
Definition: fuel_gauge.h:174
fuel_gauge_get_property_t get_property
Definition: fuel_gauge.h:173
Runtime device structure (in ROM) per driver instance.
Definition: device.h:378
Definition: fuel_gauge.h:78
uint32_t flags
Definition: fuel_gauge.h:101
uint32_t runtime_to_full
Definition: fuel_gauge.h:109
uint16_t temperature
Definition: fuel_gauge.h:115
uint16_t sbs_mfr_access_word
Definition: fuel_gauge.h:111
int status
Definition: fuel_gauge.h:83
uint16_t property_type
Definition: fuel_gauge.h:80
int current
Definition: fuel_gauge.h:97
int avg_current
Definition: fuel_gauge.h:93
int voltage
Definition: fuel_gauge.h:117
union fuel_gauge_get_property::@117 value
uint32_t remaining_capacity
Definition: fuel_gauge.h:105
bool cutoff
Definition: fuel_gauge.h:95
uint32_t full_charge_capacity
Definition: fuel_gauge.h:103
uint32_t runtime_to_empty
Definition: fuel_gauge.h:107
uint32_t cycle_count
Definition: fuel_gauge.h:99
uint8_t state_of_charge
Definition: fuel_gauge.h:113
Definition: fuel_gauge.h:121
int status
Definition: fuel_gauge.h:126
uint16_t property_type
Definition: fuel_gauge.h:123
union fuel_gauge_set_property::@118 value
uint16_t sbs_mfr_access_word
Definition: fuel_gauge.h:136