Zephyr API Documentation
4.2.99
A Scalable Open Source RTOS
4.2.99
Toggle main menu visibility
Main Page
Related Pages
Topics
Data Structures
Data Structures
Data Structure Index
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
Enumerator
Files
File List
Globals
All
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
$
a
b
c
d
f
g
h
i
k
l
m
n
o
p
r
s
t
u
x
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Macros
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Zephyr API Documentation
Introduction
Deprecated List
Topics
Data Structures
Files
File List
doc
kernel
lib
modules
subsys
zephyr
acpi
app_memory
arch
audio
bluetooth
canbus
console
crypto
data
debug
devicetree
dfu
display
drivers
adc
bluetooth
can
clock_control
comparator
console
dac
dma
edac
eeprom
ethernet
firmware
flash
gnss
gpio
haptics
i2c
i3c
ieee802154
interrupt_controller
led
led_strip
mfd
mic_privacy
mipi_dsi
misc
mm
modem
mspi
pcie
pinctrl
pm_cpu_ops
power
psi5
pwm
regulator
retained_mem
rtc
sensor
adc_cmp_npcx.h
adltc2990.h
afbr_s50.h
battery.h
bd8lb600fs.h
bmm350.h
bmp581_user.h
ccs811.h
ens160.h
explorir_m.h
f75303.h
fcx_mldx5.h
fdc2x1x.h
grow_r502a.h
icm42688.h
icm42x70.h
it8xxx2_vcmp.h
lm95234.h
max17055.h
max31790.h
max31865.h
mcux_acmp.h
mcux_lpcmp.h
mhz19b.h
mlx90394.h
mmc56x3.h
npm13xx_charger.h
npm2100_vbat.h
paj7620.h
pat9136.h
pzem004t.h
qdec_mcux.h
qdec_nxp_tpm.h
scd4x.h
sgp40.h
sht4x.h
tcs3400.h
tdk_apex.h
tle9104.h
tmag5273.h
tmp108.h
tmp11x.h
tsl2540.h
tsl2591.h
veaa_x_3.h
veml6031.h
veml7700.h
vl53l0x.h
w1_sensor.h
wsen_hids_2525020210002.h
wsen_pads_2511020213301.h
wsen_tids_2521020222501.h
xbr818.h
sent
serial
sip_svc
spi
stepper
timer
uart
usb
usb_c
video
virtio
virtualization
adc.h
auxdisplay.h
bbram.h
bluetooth.h
cache.h
can.h
cellular.h
charger.h
clock_control.h
comparator.h
coredump.h
counter.h
dac.h
dai.h
disk.h
display.h
dma.h
edac.h
eeprom.h
emul.h
emul_bbram.h
emul_fuel_gauge.h
emul_sensor.h
emul_stub_device.h
entropy.h
espi.h
espi_emul.h
espi_saf.h
flash.h
fpga.h
fuel_gauge.h
gnss.h
gpio.h
haptics.h
hwinfo.h
hwspinlock.h
i2c.h
i2c_emul.h
i2s.h
i3c.h
ipm.h
led.h
led_strip.h
loopback_disk.h
lora.h
mbox.h
mdio.h
mipi_dbi.h
mipi_dsi.h
mspi.h
mspi_emul.h
peci.h
pinctrl.h
pm_cpu_ops.h
ps2.h
ptp_clock.h
pwm.h
regulator.h
reset.h
retained_mem.h
rtc.h
sdhc.h
sensor.h
sensor_attribute_types.h
sensor_clock.h
sensor_data_types.h
smbus.h
spi.h
spi_emul.h
stepper.h
swdp.h
syscon.h
tee.h
uart.h
uart_emul.h
uart_pipe.h
video-controls.h
video.h
virtio.h
w1.h
watchdog.h
dsp
dt-bindings
fs
input
internal
ipc
kernel
linker
llext
logging
lorawan
math
mem_mgmt
mgmt
misc
modbus
modem
multi_heap
net
platform
pm
pmci
portability
posix
psa
random
retention
rtio
sd
sensing
settings
shell
sip_svc
stats
storage
sys
task_wdt
timing
toolchain
tracing
usb
usb_c
xen
zbus
zvfs
bindesc.h
cache.h
device.h
devicetree.h
fatal.h
fatal_types.h
init.h
irq.h
irq_multilevel.h
irq_nextlevel.h
irq_offload.h
kernel.h
kernel_includes.h
kernel_structs.h
kernel_version.h
net_buf.h
shared_irq.h
smf.h
spinlock.h
sw_isr_table.h
sys_clock.h
syscall.h
toolchain.h
types.h
Globals
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
battery.h
Go to the documentation of this file.
1
/*
2
* Copyright 2024 Embeint Inc
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_BATTERY_H_
8
#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_BATTERY_H_
9
10
#include <
stdint.h
>
11
#include <
errno.h
>
12
13
#include <
zephyr/devicetree.h
>
14
#include <
zephyr/math/interpolation.h
>
15
#include <
zephyr/sys/util_macro.h
>
16
17
#ifdef __cplusplus
18
extern
"C"
{
19
#endif
20
27
28
/* Battery chemistry enumeration.
29
* Value names must match those from dts/bindings/battery.yaml
30
*/
31
enum
battery_chemistry
{
32
BATTERY_CHEMISTRY_UNKNOWN
= 0,
33
BATTERY_CHEMISTRY_NICKEL_CADMIUM
,
34
BATTERY_CHEMISTRY_NICKEL_METAL_HYDRIDE
,
35
BATTERY_CHEMISTRY_LITHIUM_ION
,
36
BATTERY_CHEMISTRY_LITHIUM_ION_POLYMER
,
37
BATTERY_CHEMISTRY_LITHIUM_ION_IRON_PHOSPHATE
,
38
BATTERY_CHEMISTRY_LITHIUM_ION_MANGANESE_OXIDE
,
39
};
31
enum
battery_chemistry
{
…
};
40
41
/* Length of open circuit voltage table */
42
#define BATTERY_OCV_TABLE_LEN 11
43
49
#define BATTERY_CHEMISTRY_DT_GET(node_id) \
50
UTIL_CAT(BATTERY_CHEMISTRY_, DT_STRING_UPPER_TOKEN_OR(node_id, device_chemistry, UNKNOWN))
49
#define BATTERY_CHEMISTRY_DT_GET(node_id) \
…
51
58
#define BATTERY_OCV_TABLE_DT_GET(node_id, table) \
59
COND_CODE_1(DT_NODE_HAS_PROP(node_id, table), \
60
({DT_FOREACH_PROP_ELEM_SEP(node_id, table, DT_PROP_BY_IDX, (,))}), ({-1}))
58
#define BATTERY_OCV_TABLE_DT_GET(node_id, table) \
…
61
70
static
inline
int32_t
battery_soc_lookup
(
const
int32_t
ocv_table[
BATTERY_OCV_TABLE_LEN
],
71
uint32_t
voltage_uv)
72
{
73
static
const
int32_t
soc_axis[
BATTERY_OCV_TABLE_LEN
] = {
74
0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000};
75
76
/* Convert voltage to SoC */
77
return
linear_interpolate
(ocv_table, soc_axis,
BATTERY_OCV_TABLE_LEN
, voltage_uv);
78
}
70
static
inline
int32_t
battery_soc_lookup
(
const
int32_t
ocv_table[
BATTERY_OCV_TABLE_LEN
], {
…
}
79
83
84
#ifdef __cplusplus
85
}
86
#endif
87
88
#endif
/* ZEPHYR_INCLUDE_DRIVERS_SENSOR_BATTERY_H_ */
devicetree.h
Devicetree main header.
errno.h
System error numbers.
BATTERY_OCV_TABLE_LEN
#define BATTERY_OCV_TABLE_LEN
Definition
battery.h:42
battery_soc_lookup
static int32_t battery_soc_lookup(const int32_t ocv_table[11], uint32_t voltage_uv)
Convert an OCV table and battery voltage to a charge percentage.
Definition
battery.h:70
battery_chemistry
battery_chemistry
Definition
battery.h:31
BATTERY_CHEMISTRY_NICKEL_CADMIUM
@ BATTERY_CHEMISTRY_NICKEL_CADMIUM
Definition
battery.h:33
BATTERY_CHEMISTRY_LITHIUM_ION_MANGANESE_OXIDE
@ BATTERY_CHEMISTRY_LITHIUM_ION_MANGANESE_OXIDE
Definition
battery.h:38
BATTERY_CHEMISTRY_NICKEL_METAL_HYDRIDE
@ BATTERY_CHEMISTRY_NICKEL_METAL_HYDRIDE
Definition
battery.h:34
BATTERY_CHEMISTRY_LITHIUM_ION
@ BATTERY_CHEMISTRY_LITHIUM_ION
Definition
battery.h:35
BATTERY_CHEMISTRY_UNKNOWN
@ BATTERY_CHEMISTRY_UNKNOWN
Definition
battery.h:32
BATTERY_CHEMISTRY_LITHIUM_ION_IRON_PHOSPHATE
@ BATTERY_CHEMISTRY_LITHIUM_ION_IRON_PHOSPHATE
Definition
battery.h:37
BATTERY_CHEMISTRY_LITHIUM_ION_POLYMER
@ BATTERY_CHEMISTRY_LITHIUM_ION_POLYMER
Definition
battery.h:36
linear_interpolate
static int32_t linear_interpolate(const int32_t *x_axis, const int32_t *y_axis, uint8_t len, int32_t x)
Perform a linear interpolation across an arbitrary curve.
Definition
interpolation.h:44
interpolation.h
Provide linear interpolation functions.
stdint.h
uint32_t
__UINT32_TYPE__ uint32_t
Definition
stdint.h:90
int32_t
__INT32_TYPE__ int32_t
Definition
stdint.h:74
util_macro.h
Macro utilities.
zephyr
drivers
sensor
battery.h
Generated on
for Zephyr API Documentation by
1.14.0