USB state power manager module

The USB state power manager module is a minor, stateless module that imposes the following power state restrictions related to the USB state:

Module events

Source Module

Input Event

This Module

Output Event

Sink Module

Source modules for module_state_event

module_state_event

usb_state_pm

USB state module

usb_state_event

force_power_down_event

Power manager module

power_manager_restrict_event

Power manager 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

To enable the module, use the CONFIG_DESKTOP_USB_PM_ENABLE Kconfig option. It depends on the options CONFIG_DESKTOP_USB_ENABLE and CONFIG_CAF_PM_EVENTS.

The log level is inherited from the USB state module.

System power management integration

Zephyr’s system power management (CONFIG_PM) does not automatically take into account (expect) wakeups related to user input and finalized HID report transfers over USB. This results in entering low power states if no work is scheduled to be done in the nearest future. If you use Zephyr’s system power management, the module automatically requires zero latency in the power management while USB is active. This is done to prevent entering power states that introduce wakeup latency and ensure high performance. You can control this feature using the CONFIG_DESKTOP_USB_PM_REQ_NO_PM_LATENCY Kconfig option.

Implementation details

The module reacts to the usb_state_event. Upon reception of the event and depending on the current USB state, the module requests different power restrictions. For more information about the USB states in nRF Desktop, see the USB state module.

Application power level

The application power level is imposed using the power_manager_restrict_event.

  • If the USB state is set to USB_STATE_POWERED, the module restricts the power down level to the POWER_MANAGER_LEVEL_SUSPENDED.

  • If the USB state is set to USB_STATE_ACTIVE, the POWER_MANAGER_LEVEL_ALIVE is required.

  • If the USB state is set to USB_STATE_SUSPENDED, the POWER_MANAGER_LEVEL_SUSPENDED is imposed. The module restricts the power down level to the POWER_MANAGER_LEVEL_SUSPENDED. The module also submits a force_power_down_event to force a quick power down.

  • If the USB state is set to USB_STATE_DISCONNECTED, any power level is allowed. While disconnecting the USB cable, the USB_STATE_SUSPENDED USB state might be reported before the USB_STATE_DISCONNECTED USB state. For the application to behave consistently regardless of whether the USB_STATE_SUSPENDED USB state was reported, the module also submits a force_power_down_event to force a quick power down. The module initially restricts the power down level to the POWER_MANAGER_LEVEL_SUSPENDED. Then, after the CONFIG_DESKTOP_USB_PM_RESTRICT_REMOVE_DELAY_MS configurable delay, the module removes the power down level restriction. This allows you to take actions, such as restart Bluetooth LE advertising, after disconnecting the USB cable without going through reboot.

System power management latency

The latency requirements of the system power management are updated using the pm_policy_latency_request_add() and pm_policy_latency_request_remove() functions. The zero latency requirement is added when USB state is set to USB_STATE_ACTIVE. The requirement is removed if USB enters another state.