USB HID class modules

nRF5 SDK v13.0.0

This information applies to the nRF52840 SoC only.

The USB HID (Human Interface Device) class modules provided in this SDK implement the HID class and subclasses that have been defined in the following specification:

Device Class Definition for Human Interface Devices (HID)

The specification defines three protocols:

  • Mouse
  • Keyboard
  • Generic

The modules that implement these HID protocols are organized in the same way. All HID protocol implementations use the same parent module in which the common functionality is implemented. The following figure shows how data structures are inherited in HID modules:

Page-1 Sheet.263 Block2 app_usbd_hid_mouse app_usbd_hid_mouse Block2.228 app_usbd_hid_kbd app_usbd_hid_kbd Block2.229 app_usbd_hid_generic app_usbd_hid_generic Block2.230 app_usbd_hid.c app_usbd_hid.c Block2.255 USBD lib base class USBD lib base class Line1 Line1.259 Line1.260 Line1.262
USB data structures in HID modules

HID reports

For more detailed information on the reports for the keyboard and mouse protocol implementations, refer to the Device Class Definition for Human Interface Devices (HID) document.

For all USB HID classes, you must define one IN endpoint for the input reports. Defining an OUT endpoint is optional and if it is not set, output reports are sent through the control endpoint. The following figure shows a typical HID report flow between a USB host and the device:

Page-1 Block2 Host Host Block2.266 Device Device Task Dynamic connector.34 Sheet.273 IN endpoint IN endpoint Task.274 Dynamic connector.34 Sheet.276 OUT endpoint OUT endpoint Sheet.283 OUT control endpoint OUT control endpoint
HID report flow between a USB host and the device

Mouse report

For the mouse protocol, one 4-byte input report is defined:

  • BYTE[0]: Button state bit field.
  • BYTE[1]: Signed 8-b it X-axis offset since the last position.
  • BYTE[2]: Signed 8-bit Y-axis offset since the last position.
  • BYTE[3]: signed 8-bit Wheel offset since the last position.

Keyboard reports

For the keyboard protocol, two reports are defined:

  • IN keyboard state report:
    • BYTE[0]: Keyboard modifier. For example, the Shift key state.
    • BYTE[1]: Reserved.
    • BYTE[2]: Key 0 state.
    • BYTE[3]: Key 1 state.
    • BYTE[4]: Key 2 state.
    • BYTE[5]: Key 3 state.
    • BYTE[6]: Key 4 state.
    • BYTE[7]: Key 5 state.

OUT LED state report:

  • BYTE[0]: LED state, such as CapsLock LED or NumLock LED.

Generic reports

The generic HID protocol implementation does not define any reports. Instead, it allows you to create and handle custom, user-defined report descriptors and reports. All information about the report flow is passed to the user event handler by the APP_USBD_HID_USER_EVT_IN_REPORT_DONE and APP_USBD_HID_USER_EVT_OUT_REPORT_READY events.

For an example on how to use the USB HID mouse and keyboard classes, refer to the USB HID Composite Example .