3.5 HID Keyboard - How to use

Like the mouse stack, the keyboard stack has a USB_HIDKeyboardInitialize function to setup the necessary settings for usage.

The function pair USB_HIDKeyModifierDown and USB_HIDKeyModifierUp manages any press and release of modifier keys on the keyboard, such as the shift, ctrl and alt-buttons.

The USB_HIDKeyCodeIndexGet works through the keyboard array and detects which buttons are currently pressed. After getting this overview, the corresponding keys are sent back to the host in a report, indicating which buttons have been pressed down.

To register the actual key-presses, the function pair USB_HIDKeyPressDown and USB_HIDKeyPressUp are used. The USB_HIDKeyPressDown function scans the current array of pressed keys and records the current set of pressed keys to an array. As long as the array is not full, new keys can be pressed and registered, however if the array is filled up, caused by too many simultaneous keys pressed down at the same time, the keyboard will no longer register any new key-presses beyond what is currently in the array. Otherwise, the key-press is detected and added to the array, and sent back to the host.

The USB_HIDKeyPressUp function works in a similar way, checking the array for keys that are not currently pressed, and making sure to clear out any key that has just been released from the array. After successfully clearing out any released keys, the array is sent to the host.

To handle the sending of reports back to the host, the USB_HIDKeyboardReportInSend function streamlines the process to replace the Get_Report request. It processes the current report and sends to the host, unless the pipeline is busy, in which results in the function setting up the report as the next in line for transmission.