Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
charger.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Cirrus Logic, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_
14#define ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_
15
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdint.h>
26
27#include <zephyr/device.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif /* __cplusplus */
32
115
123
131
139
148
160
176
194 /*
195 * Charging is being dynamically adjusted by the charger device
196 */
198 /*
199 * Charging is occurring at a reduced charge rate to preserve
200 * battery health
201 */
203 /*
204 * The charger device is being bypassed and the power conversion
205 * is being handled externally, typically by a "smart" wall adaptor
206 */
208};
209
246
258
270
276typedef void (*charger_status_notifier_t)(enum charger_status status);
277
283typedef void (*charger_online_notifier_t)(enum charger_online online);
284
333
340typedef int (*charger_get_property_t)(const struct device *dev, const charger_prop_t prop,
341 union charger_propval *val);
342
349typedef int (*charger_set_property_t)(const struct device *dev, const charger_prop_t prop,
350 const union charger_propval *val);
351
358typedef int (*charger_charge_enable_t)(const struct device *dev, const bool enable);
359
370
381__syscall int charger_get_prop(const struct device *dev, const charger_prop_t prop,
382 union charger_propval *val);
383
384static inline int z_impl_charger_get_prop(const struct device *dev, const charger_prop_t prop,
385 union charger_propval *val)
386{
387 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
388
389 return api->get_property(dev, prop, val);
390}
391
402__syscall int charger_set_prop(const struct device *dev, const charger_prop_t prop,
403 const union charger_propval *val);
404
405static inline int z_impl_charger_set_prop(const struct device *dev, const charger_prop_t prop,
406 const union charger_propval *val)
407{
408 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
409
410 return api->set_property(dev, prop, val);
411}
412
423__syscall int charger_charge_enable(const struct device *dev, const bool enable);
424
425static inline int z_impl_charger_charge_enable(const struct device *dev, const bool enable)
426{
427 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
428
429 return api->charge_enable(dev, enable);
430}
431
436#ifdef __cplusplus
437}
438#endif /* __cplusplus */
439
440#include <zephyr/syscalls/charger.h>
441
442#endif /* ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_ */
int charger_set_prop(const struct device *dev, const charger_prop_t prop, const union charger_propval *val)
Set a battery charger property.
int charger_get_prop(const struct device *dev, const charger_prop_t prop, union charger_propval *val)
Fetch a battery charger property.
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.
Definition charger.h:340
int32_t charger_custom_value_int_t
Type for custom signed integer property values.
Definition charger.h:130
charger_notification_severity
Charger severity levels for system notifications.
Definition charger.h:250
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.
Definition charger.h:349
charger_status
Charging states.
Definition charger.h:164
int(* charger_charge_enable_t)(const struct device *dev, const bool enable)
Callback API enabling or disabling a charge cycle.
Definition charger.h:358
charger_property
Runtime Dynamic Battery Parameters.
Definition charger.h:36
void(* charger_status_notifier_t)(enum charger_status status)
The charger status change callback to notify the system.
Definition charger.h:276
uint32_t charger_custom_value_uint_t
Type for custom unsigned integer property values.
Definition charger.h:138
charger_health
Charger health conditions.
Definition charger.h:215
void(* charger_online_notifier_t)(enum charger_online online)
The charger online change callback to notify the system.
Definition charger.h:283
int charger_charge_enable(const struct device *dev, const bool enable)
Enable or disable a charge cycle.
uint16_t charger_prop_t
A charger property's identifier.
Definition charger.h:122
charger_online
External supply states.
Definition charger.h:152
charger_charge_type
Charge algorithm types.
Definition charger.h:180
bool charger_custom_value_bool_t
Type for custom boolean property values.
Definition charger.h:147
@ CHARGER_SEVERITY_WARNING
Base severity level.
Definition charger.h:256
@ CHARGER_SEVERITY_PEAK
Most severe level, typically triggered instantaneously.
Definition charger.h:252
@ CHARGER_SEVERITY_CRITICAL
More severe than the warning level, less severe than peak.
Definition charger.h:254
@ CHARGER_STATUS_FULL
The battery is full and the charging device will not attempt charging.
Definition charger.h:174
@ CHARGER_STATUS_NOT_CHARGING
Charging device is not charging a battery.
Definition charger.h:172
@ CHARGER_STATUS_DISCHARGING
Charging device is not able to charge a battery.
Definition charger.h:170
@ CHARGER_STATUS_UNKNOWN
Charging device state is unknown.
Definition charger.h:166
@ CHARGER_STATUS_CHARGING
Charging device is charging a battery.
Definition charger.h:168
@ CHARGER_PROP_PRESENT
Reports whether or not a battery is present.
Definition charger.h:42
@ CHARGER_PROP_ONLINE
Indicates if external supply is present for the charger.
Definition charger.h:39
@ CHARGER_PROP_INPUT_REGULATION_VOLTAGE_UV
Configuration of the input voltage regulation target in µV.
Definition charger.h:73
@ CHARGER_PROP_CUSTOM_BEGIN
Reserved to demark downstream custom properties - use this value as the actual value may change over ...
Definition charger.h:111
@ CHARGER_PROP_HEALTH
Represents the health of the charger.
Definition charger.h:51
@ CHARGER_PROP_ONLINE_NOTIFICATION
Configuration to issue a notification to the system based on the charger online change.
Definition charger.h:104
@ CHARGER_PROP_COMMON_COUNT
Reserved to demark end of common charger properties.
Definition charger.h:106
@ CHARGER_PROP_DISCHARGE_CURRENT_NOTIFICATION
Configuration to issue a notification to the system based on the battery discharge current level and ...
Definition charger.h:87
@ CHARGER_PROP_CONSTANT_CHARGE_VOLTAGE_UV
Configuration of charge voltage regulation target in µV.
Definition charger.h:59
@ CHARGER_PROP_INPUT_REGULATION_CURRENT_UA
Configuration of the input current regulation target in µA.
Definition charger.h:66
@ CHARGER_PROP_INPUT_CURRENT_NOTIFICATION
Configuration to issue a notification to the system based on the input current level and timing.
Definition charger.h:80
@ CHARGER_PROP_STATUS
Represents the charging status of the charger.
Definition charger.h:45
@ CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA
Configuration of current sink used for charging in µA.
Definition charger.h:53
@ CHARGER_PROP_STATUS_NOTIFICATION
Configuration to issue a notification to the system based on the charger status change.
Definition charger.h:98
@ CHARGER_PROP_MAX
Reserved to demark end of valid enum properties.
Definition charger.h:113
@ CHARGER_PROP_PRECHARGE_CURRENT_UA
Configuration of current sink used for conditioning in µA.
Definition charger.h:55
@ CHARGER_PROP_CHARGE_TERM_CURRENT_UA
Configuration of charge termination target in µA.
Definition charger.h:57
@ CHARGER_PROP_SYSTEM_VOLTAGE_NOTIFICATION_UV
Configuration of the falling system voltage threshold where a notification is issued to the system,...
Definition charger.h:92
@ CHARGER_PROP_CHARGE_TYPE
Represents the charging algo type of the charger.
Definition charger.h:48
@ CHARGER_HEALTH_SAFETY_TIMER_EXPIRE
The charger device's safety timer has expired.
Definition charger.h:234
@ CHARGER_HEALTH_CALIBRATION_REQUIRED
The charger device requires calibration.
Definition charger.h:236
@ CHARGER_HEALTH_WARM
The battery temperature is in the "warm" range.
Definition charger.h:238
@ CHARGER_HEALTH_UNKNOWN
Charger health condition is unknown.
Definition charger.h:217
@ CHARGER_HEALTH_COLD
The battery temperature is below the "cold" threshold.
Definition charger.h:230
@ CHARGER_HEALTH_NO_BATTERY
The charger device does not detect a battery.
Definition charger.h:244
@ CHARGER_HEALTH_UNSPEC_FAILURE
The battery or charger device is experiencing an unspecified failure.
Definition charger.h:228
@ CHARGER_HEALTH_GOOD
Charger health condition is good.
Definition charger.h:219
@ CHARGER_HEALTH_HOT
The battery temperature is below the "hot" threshold.
Definition charger.h:242
@ CHARGER_HEALTH_COOL
The battery temperature is in the "cool" range.
Definition charger.h:240
@ CHARGER_HEALTH_WATCHDOG_TIMER_EXPIRE
The charger device's watchdog timer has expired.
Definition charger.h:232
@ CHARGER_HEALTH_OVERVOLTAGE
The battery voltage has exceeded its overvoltage threshold.
Definition charger.h:223
@ CHARGER_HEALTH_OVERHEAT
The charger device is overheated.
Definition charger.h:221
@ CHARGER_ONLINE_FIXED
External supply is present and of fixed output.
Definition charger.h:156
@ CHARGER_ONLINE_PROGRAMMABLE
External supply is present and of programmable output.
Definition charger.h:158
@ CHARGER_ONLINE_OFFLINE
External supply not present.
Definition charger.h:154
@ CHARGER_CHARGE_TYPE_STANDARD
Charging is occurring at a moderate charge rate.
Definition charger.h:193
@ CHARGER_CHARGE_TYPE_NONE
Charging is not occurring.
Definition charger.h:184
@ CHARGER_CHARGE_TYPE_ADAPTIVE
Definition charger.h:197
@ CHARGER_CHARGE_TYPE_UNKNOWN
Charge type is unknown.
Definition charger.h:182
@ CHARGER_CHARGE_TYPE_BYPASS
Definition charger.h:207
@ CHARGER_CHARGE_TYPE_LONGLIFE
Definition charger.h:202
@ CHARGER_CHARGE_TYPE_TRICKLE
Charging is occurring at the slowest desired charge rate, typically for battery detection or precondi...
Definition charger.h:189
@ CHARGER_CHARGE_TYPE_FAST
Charging is occurring at the fastest desired charge rate.
Definition charger.h:191
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
#define UINT16_MAX
Definition stdint.h:28
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
The input current thresholds for the charger to notify the system.
Definition charger.h:262
uint8_t severity
The severity of the notification where CHARGER_SEVERITY_PEAK is the most severe.
Definition charger.h:264
uint32_t duration_us
The duration of excess current before notifying the system.
Definition charger.h:268
uint32_t current_ua
The current threshold to be exceeded.
Definition charger.h:266
Charging device API.
Definition charger.h:365
charger_charge_enable_t charge_enable
Definition charger.h:368
charger_set_property_t set_property
Definition charger.h:367
charger_get_property_t get_property
Definition charger.h:366
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
container for a charger_property value
Definition charger.h:289
struct charger_current_notifier input_current_notification
CHARGER_PROP_INPUT_CURRENT_NOTIFICATION.
Definition charger.h:317
charger_custom_value_int_t custom_int
Generic integer value for downstream custom properties.
Definition charger.h:327
charger_custom_value_bool_t custom_bool
Generic boolean value for downstream custom properties.
Definition charger.h:331
uint32_t precharge_current_ua
CHARGER_PROP_PRECHARGE_CURRENT_UA.
Definition charger.h:307
uint32_t system_voltage_notification
CHARGER_PROP_SYSTEM_VOLTAGE_NOTIFICATION_UV.
Definition charger.h:321
uint32_t const_charge_voltage_uv
CHARGER_PROP_CONSTANT_CHARGE_VOLTAGE_UV.
Definition charger.h:311
charger_custom_value_uint_t custom_uint
Generic unsigned value for downstream custom properties.
Definition charger.h:329
enum charger_status status
CHARGER_PROP_STATUS.
Definition charger.h:299
enum charger_online online
CHARGER_PROP_ONLINE.
Definition charger.h:295
uint32_t charge_term_current_ua
CHARGER_PROP_CHARGE_TERM_CURRENT_UA.
Definition charger.h:309
bool present
CHARGER_PROP_PRESENT.
Definition charger.h:297
charger_online_notifier_t online_notification
CHARGER_PROP_ONLINE_NOTIFICATION.
Definition charger.h:325
enum charger_health health
CHARGER_PROP_HEALTH.
Definition charger.h:303
enum charger_charge_type charge_type
CHARGER_PROP_CHARGE_TYPE.
Definition charger.h:301
charger_status_notifier_t status_notification
CHARGER_PROP_STATUS_NOTIFICATION.
Definition charger.h:323
uint32_t input_current_regulation_current_ua
CHARGER_PROP_INPUT_REGULATION_CURRENT_UA.
Definition charger.h:313
struct charger_current_notifier discharge_current_notification
CHARGER_PROP_DISCHARGE_CURRENT_NOTIFICATION.
Definition charger.h:319
uint32_t const_charge_current_ua
CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA.
Definition charger.h:305
uint32_t input_voltage_regulation_voltage_uv
CHARGER_PROP_INPUT_REGULATION_VOLTAGE_UV.
Definition charger.h:315