HID Service module
Use the HID Service module to handle the GATT Human Interface Device Service. The GATT Service is used to exchange HID data with the peer connected over Bluetooth®. For this reason, it is mandatory for every nRF Desktop peripheral.
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
Complete the following steps to configure the module:
Complete the basic Bluetooth configuration, as described in nRF Desktop: Bluetooth. Make sure that both CONFIG_DESKTOP_ROLE_HID_PERIPHERAL and CONFIG_DESKTOP_BT_PERIPHERAL options are enabled. The HID Service application module is enabled by the CONFIG_DESKTOP_HIDS_ENABLE option, which is implied by CONFIG_DESKTOP_BT_PERIPHERAL together with other GATT Services that are required for a HID device.
The CONFIG_DESKTOP_HIDS_ENABLE option selects the following Kconfig options:
The
CONFIG_BT_HIDS
option that automatically enables the GATT Human Interface Device (HID) Service.The
CONFIG_BT_CONN_CTX
option that automatically enables the Bluetooth connection context, which is required by the GATT HID Service.
The nRF Desktop application modifies the defaults of Kconfig option values, defined by the GATT Human Interface Device (HID) Service, to tailor the default configuration to application needs. The configuration is tailored for either nRF Desktop mouse (CONFIG_DESKTOP_PERIPHERAL_TYPE_MOUSE) or nRF Desktop keyboard (CONFIG_DESKTOP_PERIPHERAL_TYPE_KEYBOARD). For more details, see the
src/modules/Kconfig.hids
file.Tip
If the HID report configuration is identical to the default configuration of either nRF Desktop mouse or keyboard, you do not need to modify the GATT HID Service configuration. Otherwise, see GATT Human Interface Device (HID) Service documentation for configuration details.
The HID Service application module forwards the information about the enabled HID notifications to other application modules using hid_report_subscription_event
.
These notifications are enabled by the connected Bluetooth® Central.
By default, the hids
application module starts forwarding the subscriptions right after the Bluetooth connection is secured.
You can define additional delay for forwarding the notifications on connection (CONFIG_DESKTOP_HIDS_FIRST_REPORT_DELAY). Sending the first HID report to the connected Bluetooth peer is delayed by this period of time.
Note
The nRF Desktop centrals perform the GATT service discovery and reenable the HID notifications on every reconnection. A HID report that is received before the subscription is reenabled will be dropped before it reaches the application. The CONFIG_DESKTOP_HIDS_FIRST_REPORT_DELAY option is set to 500 ms for nRF Desktop keyboards (CONFIG_DESKTOP_PERIPHERAL_TYPE_KEYBOARD) to make sure that the input is not lost on reconnection with the nRF Desktop dongle.
Implementation details
The HID Service application module initializes and configures the GATT HID Service. The application module registers the HID report map and every HID report that was enabled in the application configuration. For detailed information about the HID-related configuration in the nRF Desktop, see the HID configuration documentation.
Sending HID input reports
After subscriptions are enabled in HID state module, the HID state module sends the HID input reports as hid_report_event
.
The HID Service application module sends the report over Bluetooth LE and submits the hid_report_sent_event
to inform that the given HID input report was sent.
HID keyboard LED output report
The module can receive a HID output report setting state of the keyboard LEDs, for example, state of the Caps Lock.
The report is received from the Bluetooth connected host.
The module forwards the report using hid_report_event
that is handled by HID state module.
Right now, the only board that displays information received in the HID output report using hardware LEDs is the nrf52840dk in keyboard
build type configuration.
The keyboard reference design (nrf52kbd) has only one LED that is used to display the Bluetooth LE peer state.
Detailed information about the usage of LEDs to display information about Bluetooth LE peer state and system state to the user is available in the LED state module documentation.
Detailed information about displaying state of the HID keyboard LEDs using hardware LEDs is available in HID state module documentation.
Bluetooth LE connections and disconnections
The module informs the GATT HID Service about the Bluetooth LE connections and disconnections using bt_hids_connected()
and bt_hids_disconnected()
, respectively.
Registered handlers
The GATT HID Service uses registered handlers to send the following information to the HID Service application module:
Enabling or disabling a HID input report notification.
Incoming HID output or feature reports.
Switching between the boot mode and the report mode.
HID notifications
The hid_notification_event
is used to synchronize the information about enabling or disabling the HID notifications for the HID input report.
The event is submitted when the GATT HID Service calls a callback related to enabling or disabling the notifications and the event is received only by the hids
application module.
Transport for configuration channel
The HID Service application module works as a transport for the Configuration channel and exchanges the Configuration channel HID reports over Bluetooth LE.
The module communicates with the Configuration channel listeners using config_event
.