Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
battery APIs

battery API More...

Macros

#define BATTERY_OCV_TABLE_LEN   11
 
#define BATTERY_CHEMISTRY_DT_GET(node_id)
 Get the battery chemistry enum value.
 
#define BATTERY_OCV_TABLE_DT_GET(node_id, table)
 Get the OCV curve for a given table.
 

Enumerations

enum  battery_chemistry {
  BATTERY_CHEMISTRY_UNKNOWN = 0 , BATTERY_CHEMISTRY_NICKEL_CADMIUM , BATTERY_CHEMISTRY_NICKEL_METAL_HYDRIDE , BATTERY_CHEMISTRY_LITHIUM_ION ,
  BATTERY_CHEMISTRY_LITHIUM_ION_POLYMER , BATTERY_CHEMISTRY_LITHIUM_ION_IRON_PHOSPHATE , BATTERY_CHEMISTRY_LITHIUM_ION_MANGANESE_OXIDE
}
 

Functions

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.
 

Detailed Description

battery API

Macro Definition Documentation

◆ BATTERY_CHEMISTRY_DT_GET

#define BATTERY_CHEMISTRY_DT_GET ( node_id)

#include <zephyr/drivers/sensor/battery.h>

Value:
UTIL_CAT(BATTERY_CHEMISTRY_, DT_STRING_UPPER_TOKEN_OR(node_id, device_chemistry, UNKNOWN))
#define DT_STRING_UPPER_TOKEN_OR(node_id, prop, default_value)
Like DT_STRING_UPPER_TOKEN(), but with a fallback to default_value.
Definition devicetree.h:1182
#define UTIL_CAT(a,...)
Definition util_internal.h:104

Get the battery chemistry enum value.

Parameters
node_idnode identifier

◆ BATTERY_OCV_TABLE_DT_GET

#define BATTERY_OCV_TABLE_DT_GET ( node_id,
table )

#include <zephyr/drivers/sensor/battery.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, table), \
({DT_FOREACH_PROP_ELEM_SEP(node_id, table, DT_PROP_BY_IDX, (,))}), ({-1}))
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition devicetree.h:3677
#define DT_FOREACH_PROP_ELEM_SEP(node_id, prop, fn, sep)
Invokes fn for each element in the value of property prop with separator.
Definition devicetree.h:3260
#define DT_PROP_BY_IDX(node_id, prop, idx)
Get the value at index idx in an array type property.
Definition devicetree.h:891
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195

Get the OCV curve for a given table.

Parameters
node_idnode identifier
tabletable to retrieve

◆ BATTERY_OCV_TABLE_LEN

#define BATTERY_OCV_TABLE_LEN   11

Enumeration Type Documentation

◆ battery_chemistry

#include <zephyr/drivers/sensor/battery.h>

Enumerator
BATTERY_CHEMISTRY_UNKNOWN 
BATTERY_CHEMISTRY_NICKEL_CADMIUM 
BATTERY_CHEMISTRY_NICKEL_METAL_HYDRIDE 
BATTERY_CHEMISTRY_LITHIUM_ION 
BATTERY_CHEMISTRY_LITHIUM_ION_POLYMER 
BATTERY_CHEMISTRY_LITHIUM_ION_IRON_PHOSPHATE 
BATTERY_CHEMISTRY_LITHIUM_ION_MANGANESE_OXIDE 

Function Documentation

◆ battery_soc_lookup()

static int32_t battery_soc_lookup ( const int32_t ocv_table[11],
uint32_t voltage_uv )
inlinestatic

#include <zephyr/drivers/sensor/battery.h>

Convert an OCV table and battery voltage to a charge percentage.

Parameters
ocv_tableOpen circuit voltage curve
voltage_uvBattery voltage in microVolts
Returns
Battery state of charge in milliPercent