Feature settings and custom HID layouts

USB Library ›› Device ›› Use HID ››
… visits
Parent Previous Next

Start with a built-in profile if it fits your project. This page covers two extra tasks: sharing settings through a feature report, and describing your own report layout.

Share a small settings block

A feature report is a separate block for settings or status. Use it when the PC needs to read or change a small set of settings without mixing them into normal data reports. Its size is fixed, and it travels through HID control requests.

  1. Select HID data or Custom descriptor.
  2. Set Feature report bytes (USB_HID_FEATURE_SIZE) to 1–64. Zero disables it. The fixed keyboard, mouse, joystick and consumer profiles require zero.
  3. Agree with the PC application on each feature byte's meaning.
  4. After USB_Init(), fill the library-supplied USB_Feature[] array with the values the PC should read.
  5. Let the PC read or write it through its HID feature-report API. A successful host write raises USB_EV_FEATURE.

Call USB_GetEvents(), then test the USB_EV_FEATURE bit in USB_LastEvents. Check the received bytes before using them. A PC write replaces the feature array only: your code must apply the settings, save them to Flash if needed, or change the hardware. If you need separate command and status fields, decide their byte layout with the PC program.


In polling mode, read or update the array between service calls. In interrupt mode, use the shared-data protection when copying several bytes, so an interrupt cannot see a half-finished update. Copy received settings into your own variables before doing slow work. The feature event is a flag; it does not keep a list of every earlier write.

What the PC reads back

The stack also answers host queries for the current reports. An input query returns the saved input state. For the mouse profile, relative X/Y bytes are cleared after queuing motion, so queries and idle repeats do not repeat that motion. An output query returns the last output delivered to the application; a feature query reads USB_Feature[]. Editing an unfinished TXReport does not change the saved input snapshot.


The host controls HID idle repetition. A zero idle rate disables automatic repetition; other values use 4 ms units. The library handles the timer and resends the saved state as required. Your own USB_Write() calls still send reports even when unchanged. Keyboard and mouse accept boot/report-protocol requests; the supplied layouts work with both.

Use a custom report layout

For a custom descriptor, select profile 5 and paste hexadecimal bytes into Custom descriptor. Spaces, commas or semicolons may separate bytes; $05, 0x05 and 05 are accepted forms. Then:

  1. Keep one balanced Application collection and no Report IDs.
  2. Make input, output and optional feature bit counts match USB_TX_SIZE, USB_RX_SIZE and USB_HID_FEATURE_SIZE, including padding.
  3. Read and correct the tool's validation messages. The editor does not accept long HID items or global PUSH/POP items.
  4. Copy the generated definitions, including USB_HID_CUSTOM_DATA and calculated USB_HID_CUSTOM_LEN, before the library include.

The editor accepts up to 4096 descriptor bytes. Do not change only a buffer size while leaving the descriptor unchanged. Use a built-in profile when it already fits: a custom descriptor describes your data layout; it does not implement the application behaviour for you.

See also

Created with the Personal Edition of HelpNDoc: Leave the tedious WinHelp HLP to CHM conversion process behind with HelpNDoc