The latest development version of this page may be more current than this released 3.5.0 version.

Chargers

The charger subsystem exposes an API to uniformly access battery charger devices. Currently, only reading data is supported.

Basic Operation

Properties

Fundamentally, a property is a configurable setting, state, or quantity that a charger device can measure.

Chargers typically support multiple properties, such as temperature readings of the battery-pack or present-time current/voltage.

Properties are fetched using a client allocated array of charger_get_property. This array is then populated by values as according to its property_type field.

API Reference

group charger_interface

Charger Interface.

Typedefs

typedef uint16_t charger_prop_t

A charger property’s identifier.

See charger_property for a list of identifiers

typedef int (*charger_get_property_t)(const struct device *dev, const charger_prop_t prop, union charger_propval *val)

Callback API for getting a charger property.

See charger_get_property() for argument description

typedef int (*charger_set_property_t)(const struct device *dev, const charger_prop_t prop, const union charger_propval *val)

Callback API for setting a charger property.

See charger_set_property() for argument description

Enums

enum charger_property

Runtime Dynamic Battery Parameters.

Values:

enumerator CHARGER_PROP_ONLINE = 0

Indicates if external supply is present for the charger.

Value should be of type enum charger_online

enumerator CHARGER_PROP_PRESENT

Reports whether or not a battery is present.

Value should be of type bool

enumerator CHARGER_PROP_STATUS

Represents the charging status of the charger.

Value should be of type enum charger_status

enumerator CHARGER_PROP_COMMON_COUNT

Reserved to demark end of common charger properties.

enumerator CHARGER_PROP_CUSTOM_BEGIN = CHARGER_PROP_COMMON_COUNT + 1

Reserved to demark downstream custom properties - use this value as the actual value may change over future versions of this API.

enumerator CHARGER_PROP_MAX = UINT16_MAX

Reserved to demark end of valid enum properties.

enum charger_online

External supply states.

Values:

enumerator CHARGER_ONLINE_OFFLINE = 0

External supply not present.

enumerator CHARGER_ONLINE_FIXED

External supply is present and of fixed output.

enumerator CHARGER_ONLINE_PROGRAMMABLE

External supply is present and of programmable output.

enum charger_status

Charging states.

Values:

enumerator CHARGER_STATUS_UNKNOWN = 0

Charging device state is unknown.

enumerator CHARGER_STATUS_CHARGING

Charging device is charging a battery.

enumerator CHARGER_STATUS_DISCHARGING

Charging device is not able to charge a battery.

enumerator CHARGER_STATUS_NOT_CHARGING

Charging device is not charging a battery.

enumerator CHARGER_STATUS_FULL

The battery is full and the charging device will not attempt charging.

Functions

int charger_get_prop(const struct device *dev, const charger_prop_t prop, union charger_propval *val)

Fetch a battery charger property.

Parameters:
  • dev – Pointer to the battery charger device

  • prop – Charger property to get

  • val – Pointer to charger_propval union

Return values:
  • 0 – if successful

  • < – 0 if getting property failed

int charger_set_prop(const struct device *dev, const charger_prop_t prop, const union charger_propval *val)

Set a battery charger property.

Parameters:
  • dev – Pointer to the battery charger device

  • prop – Charger property to set

  • val – Pointer to charger_propval union

Return values:
  • 0 – if successful

  • < – 0 if setting property failed

union charger_propval
#include <charger.h>

container for a charger_property value

Public Members

enum charger_online online

CHARGER_PROP_ONLINE.

bool present

CHARGER_PROP_PRESENT.

enum charger_status status

CHARGER_PROP_STATUS.

struct charger_driver_api
#include <charger.h>

Charging device API.

Caching is entirely on the onus of the client