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

Power manager module

power_down_event

battery_charger

Source modules for module_state_event

module_state_event

USB state module

usb_state_event

Buttons module

wake_up_event

HID forward module

Motion module

Power manager module

Wheel module

battery_state_event

LED state module

module_state_event

Sink modules for module_state_event

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:

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).