Battery charger module
The battery charger module is responsible for battery charging control.
Module events
Source Module |
Input Event |
This Module |
Output Event |
Sink Module |
---|---|---|---|---|
|
|
|||
|
||||
|
||||
|
||||
|
||||
|
Note
See the Application overview for more information about the event-based communication in the nRF Desktop application and about how to read this table.
Configuration
The module implemented in battery_charger.c
uses Zephyr’s General-Purpose Input/Output (GPIO) driver to control and monitor battery charging.
For this reason, you should set CONFIG_GPIO
option.
By default, the module is disabled and the CONFIG_DESKTOP_BATTERY_CHARGER_NONE option is selected. Set the option CONFIG_DESKTOP_BATTERY_CHARGER_DISCRETE to enable the module.
The module requires a node labeled battery_charger
with a battery-charger
compatible set in devicetree.
The charge status output (CSO) GPIO spec, the Enable GPIO spec, and the CSO switching frequency properties are also required.
See the following snippet for an example:
battery_charger: battery-charger {
compatible = "battery-charger";
cso-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
enable-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
cso-switching-freq = <1000>;
};
Implementation details
As required by the USB specification, the module disables the battery charging when USB is suspended to reduce the power consumption. In addition, it also disables charging when USB is disconnected. The module enables charging when USB is powered or active.
Note
Make sure that the hardware configuration enables charging by default (for example, when the pin to enable charging is not configured). Otherwise, it will be impossible to enable charging when the battery is empty.
The module checks the battery state using k_work_delayable
.
The check is based on the edge interrupt count on the CSO pin in a period of time defined in ERROR_CHECK_TIMEOUT_MS
, and on the CSO pin state while the work is processed.
On a battery state change, the new state is sent using battery_state_event
.
The battery state can have one of the following values:
BATTERY_STATE_IDLE
- Battery is not being charged (CSO pin set to logical high).BATTERY_STATE_CHARGING
- Battery is being charged (CSO pin set to logical low).BATTERY_STATE_ERROR
- Battery charger reported an error (a signal with the CONFIG_DESKTOP_BATTERY_CHARGER_CSO_FREQ frequency and a 50% duty cycle on the CSO pin).