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 Overview: Firmware architecture 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 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 following module configuration options are available:
CONFIG_DESKTOP_BATTERY_CHARGER_CSO_PIN - Configures the pin to which the charge status output (CSO) from the charger is connected.
CONFIG_DESKTOP_BATTERY_CHARGER_CSO_PULL_NONE - CSO pin pull disabled (default setting).
CONFIG_DESKTOP_BATTERY_CHARGER_CSO_PULL_UP - CSO pin pull up.
CONFIG_DESKTOP_BATTERY_CHARGER_CSO_PULL_DOWN - CSO pin pull down.
CONFIG_DESKTOP_BATTERY_CHARGER_ENABLE_PIN - Configures the pin that enables the battery charging.
CONFIG_DESKTOP_BATTERY_CHARGER_ENABLE_INVERSED - Option for inversing the charging enable signal.
CONFIG_DESKTOP_BATTERY_CHARGER_CSO_FREQ - Set this Kconfig option to the CSO pin state switching frequency (in Hz) for when a charging error occurs.
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).