Zephyr API Documentation 4.0.0
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
12#ifndef ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_
13#define ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_
14
22#include <stdbool.h>
23#include <stddef.h>
24#include <stdint.h>
25
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cplusplus */
31
114
122
134
150
168 /*
169 * Charging is being dynamically adjusted by the charger device
170 */
172 /*
173 * Charging is occurring at a reduced charge rate to preserve
174 * battery health
175 */
177 /*
178 * The charger device is being bypassed and the power conversion
179 * is being handled externally, typically by a "smart" wall adaptor
180 */
182};
183
220
232
244
250typedef void (*charger_status_notifier_t)(enum charger_status status);
251
257typedef void (*charger_online_notifier_t)(enum charger_online online);
258
301
308typedef int (*charger_get_property_t)(const struct device *dev, const charger_prop_t prop,
309 union charger_propval *val);
310
317typedef int (*charger_set_property_t)(const struct device *dev, const charger_prop_t prop,
318 const union charger_propval *val);
319
326typedef int (*charger_charge_enable_t)(const struct device *dev, const bool enable);
327
338
349__syscall int charger_get_prop(const struct device *dev, const charger_prop_t prop,
350 union charger_propval *val);
351
352static inline int z_impl_charger_get_prop(const struct device *dev, const charger_prop_t prop,
353 union charger_propval *val)
354{
355 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
356
357 return api->get_property(dev, prop, val);
358}
359
370__syscall int charger_set_prop(const struct device *dev, const charger_prop_t prop,
371 const union charger_propval *val);
372
373static inline int z_impl_charger_set_prop(const struct device *dev, const charger_prop_t prop,
374 const union charger_propval *val)
375{
376 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
377
378 return api->set_property(dev, prop, val);
379}
380
391__syscall int charger_charge_enable(const struct device *dev, const bool enable);
392
393static inline int z_impl_charger_charge_enable(const struct device *dev, const bool enable)
394{
395 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
396
397 return api->charge_enable(dev, enable);
398}
399
404#ifdef __cplusplus
405}
406#endif /* __cplusplus */
407
408#include <zephyr/syscalls/charger.h>
409
410#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.
charger_notification_severity
Charger severity levels for system notifications.
Definition charger.h:224
charger_status
Charging states.
Definition charger.h:138
uint16_t charger_prop_t
A charger property's identifier.
Definition charger.h:121
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:317
charger_property
Runtime Dynamic Battery Parameters.
Definition charger.h:35
void(* charger_status_notifier_t)(enum charger_status status)
The charger status change callback to notify the system.
Definition charger.h:250
charger_health
Charger health conditions.
Definition charger.h:189
void(* charger_online_notifier_t)(enum charger_online online)
The charger online change callback to notify the system.
Definition charger.h:257
int charger_charge_enable(const struct device *dev, const bool enable)
Enable or disable a charge cycle.
charger_online
External supply states.
Definition charger.h:126
charger_charge_type
Charge algorithm types.
Definition charger.h:154
int(* charger_charge_enable_t)(const struct device *dev, const bool enable)
Callback API enabling or disabling a charge cycle.
Definition charger.h:326
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:308
@ CHARGER_SEVERITY_WARNING
Base severity level.
Definition charger.h:230
@ CHARGER_SEVERITY_PEAK
Most severe level, typically triggered instantaneously.
Definition charger.h:226
@ CHARGER_SEVERITY_CRITICAL
More severe than the warning level, less severe than peak.
Definition charger.h:228
@ CHARGER_STATUS_FULL
The battery is full and the charging device will not attempt charging.
Definition charger.h:148
@ CHARGER_STATUS_NOT_CHARGING
Charging device is not charging a battery.
Definition charger.h:146
@ CHARGER_STATUS_DISCHARGING
Charging device is not able to charge a battery.
Definition charger.h:144
@ CHARGER_STATUS_UNKNOWN
Charging device state is unknown.
Definition charger.h:140
@ CHARGER_STATUS_CHARGING
Charging device is charging a battery.
Definition charger.h:142
@ CHARGER_PROP_PRESENT
Reports whether or not a battery is present.
Definition charger.h:41
@ CHARGER_PROP_ONLINE
Indicates if external supply is present for the charger.
Definition charger.h:38
@ CHARGER_PROP_INPUT_REGULATION_VOLTAGE_UV
Configuration of the input voltage regulation target in µV.
Definition charger.h:72
@ CHARGER_PROP_CUSTOM_BEGIN
Reserved to demark downstream custom properties - use this value as the actual value may change over ...
Definition charger.h:110
@ CHARGER_PROP_HEALTH
Represents the health of the charger.
Definition charger.h:50
@ CHARGER_PROP_ONLINE_NOTIFICATION
Configuration to issue a notification to the system based on the charger online change.
Definition charger.h:103
@ CHARGER_PROP_COMMON_COUNT
Reserved to demark end of common charger properties.
Definition charger.h:105
@ CHARGER_PROP_DISCHARGE_CURRENT_NOTIFICATION
Configuration to issue a notification to the system based on the battery discharge current level and ...
Definition charger.h:86
@ CHARGER_PROP_CONSTANT_CHARGE_VOLTAGE_UV
Configuration of charge voltage regulation target in µV.
Definition charger.h:58
@ CHARGER_PROP_INPUT_REGULATION_CURRENT_UA
Configuration of the input current regulation target in µA.
Definition charger.h:65
@ CHARGER_PROP_INPUT_CURRENT_NOTIFICATION
Configuration to issue a notification to the system based on the input current level and timing.
Definition charger.h:79
@ CHARGER_PROP_STATUS
Represents the charging status of the charger.
Definition charger.h:44
@ CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA
Configuration of current sink used for charging in µA.
Definition charger.h:52
@ CHARGER_PROP_STATUS_NOTIFICATION
Configuration to issue a notification to the system based on the charger status change.
Definition charger.h:97
@ CHARGER_PROP_MAX
Reserved to demark end of valid enum properties.
Definition charger.h:112
@ CHARGER_PROP_PRECHARGE_CURRENT_UA
Configuration of current sink used for conditioning in µA.
Definition charger.h:54
@ CHARGER_PROP_CHARGE_TERM_CURRENT_UA
Configuration of charge termination target in µA.
Definition charger.h:56
@ CHARGER_PROP_SYSTEM_VOLTAGE_NOTIFICATION_UV
Configuration of the falling system voltage threshold where a notification is issued to the system,...
Definition charger.h:91
@ CHARGER_PROP_CHARGE_TYPE
Represents the charging algo type of the charger.
Definition charger.h:47
@ CHARGER_HEALTH_SAFETY_TIMER_EXPIRE
The charger device's safety timer has expired.
Definition charger.h:208
@ CHARGER_HEALTH_CALIBRATION_REQUIRED
The charger device requires calibration.
Definition charger.h:210
@ CHARGER_HEALTH_WARM
The battery temperature is in the "warm" range.
Definition charger.h:212
@ CHARGER_HEALTH_UNKNOWN
Charger health condition is unknown.
Definition charger.h:191
@ CHARGER_HEALTH_COLD
The battery temperature is below the "cold" threshold.
Definition charger.h:204
@ CHARGER_HEALTH_NO_BATTERY
The charger device does not detect a battery.
Definition charger.h:218
@ CHARGER_HEALTH_UNSPEC_FAILURE
The battery or charger device is experiencing an unspecified failure.
Definition charger.h:202
@ CHARGER_HEALTH_GOOD
Charger health condition is good.
Definition charger.h:193
@ CHARGER_HEALTH_HOT
The battery temperature is below the "hot" threshold.
Definition charger.h:216
@ CHARGER_HEALTH_COOL
The battery temperature is in the "cool" range.
Definition charger.h:214
@ CHARGER_HEALTH_WATCHDOG_TIMER_EXPIRE
The charger device's watchdog timer has expired.
Definition charger.h:206
@ CHARGER_HEALTH_OVERVOLTAGE
The battery voltage has exceeded its overvoltage threshold.
Definition charger.h:197
@ CHARGER_HEALTH_OVERHEAT
The charger device is overheated.
Definition charger.h:195
@ CHARGER_ONLINE_FIXED
External supply is present and of fixed output.
Definition charger.h:130
@ CHARGER_ONLINE_PROGRAMMABLE
External supply is present and of programmable output.
Definition charger.h:132
@ CHARGER_ONLINE_OFFLINE
External supply not present.
Definition charger.h:128
@ CHARGER_CHARGE_TYPE_STANDARD
Charging is occurring at a moderate charge rate.
Definition charger.h:167
@ CHARGER_CHARGE_TYPE_NONE
Charging is not occurring.
Definition charger.h:158
@ CHARGER_CHARGE_TYPE_ADAPTIVE
Definition charger.h:171
@ CHARGER_CHARGE_TYPE_UNKNOWN
Charge type is unknown.
Definition charger.h:156
@ CHARGER_CHARGE_TYPE_BYPASS
Definition charger.h:181
@ CHARGER_CHARGE_TYPE_LONGLIFE
Definition charger.h:176
@ CHARGER_CHARGE_TYPE_TRICKLE
Charging is occurring at the slowest desired charge rate, typically for battery detection or precondi...
Definition charger.h:163
@ CHARGER_CHARGE_TYPE_FAST
Charging is occurring at the fastest desired charge rate.
Definition charger.h:165
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__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:236
uint8_t severity
The severity of the notification where CHARGER_SEVERITY_PEAK is the most severe.
Definition charger.h:238
uint32_t duration_us
The duration of excess current before notifying the system.
Definition charger.h:242
uint32_t current_ua
The current threshold to be exceeded.
Definition charger.h:240
Charging device API.
Definition charger.h:333
charger_charge_enable_t charge_enable
Definition charger.h:336
charger_set_property_t set_property
Definition charger.h:335
charger_get_property_t get_property
Definition charger.h:334
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
container for a charger_property value
Definition charger.h:263
struct charger_current_notifier input_current_notification
CHARGER_PROP_INPUT_CURRENT_NOTIFICATION.
Definition charger.h:291
uint32_t precharge_current_ua
CHARGER_PROP_PRECHARGE_CURRENT_UA.
Definition charger.h:281
uint32_t system_voltage_notification
CHARGER_PROP_SYSTEM_VOLTAGE_NOTIFICATION_UV.
Definition charger.h:295
uint32_t const_charge_voltage_uv
CHARGER_PROP_CONSTANT_CHARGE_VOLTAGE_UV.
Definition charger.h:285
enum charger_status status
CHARGER_PROP_STATUS.
Definition charger.h:273
enum charger_online online
CHARGER_PROP_ONLINE.
Definition charger.h:269
uint32_t charge_term_current_ua
CHARGER_PROP_CHARGE_TERM_CURRENT_UA.
Definition charger.h:283
bool present
CHARGER_PROP_PRESENT.
Definition charger.h:271
charger_online_notifier_t online_notification
CHARGER_PROP_ONLINE_NOTIFICATION.
Definition charger.h:299
enum charger_health health
CHARGER_PROP_HEALTH.
Definition charger.h:277
enum charger_charge_type charge_type
CHARGER_PROP_CHARGE_TYPE.
Definition charger.h:275
charger_status_notifier_t status_notification
CHARGER_PROP_STATUS_NOTIFICATION.
Definition charger.h:297
uint32_t input_current_regulation_current_ua
CHARGER_PROP_INPUT_REGULATION_CURRENT_UA.
Definition charger.h:287
struct charger_current_notifier discharge_current_notification
CHARGER_PROP_DISCHARGE_CURRENT_NOTIFICATION.
Definition charger.h:293
uint32_t const_charge_current_ua
CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA.
Definition charger.h:279
uint32_t input_voltage_regulation_voltage_uv
CHARGER_PROP_INPUT_REGULATION_VOLTAGE_UV.
Definition charger.h:289