Unit USBHID

From Ultibo.org
Revision as of 04:23, 31 January 2024 by Ultibo (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Return to Unit Reference


Description


Ultibo USB Human Interface Device (HID) Driver unit

The USB Human Interface Device (HID) class is one of the most widely used classes of USB devices. HID devices can appear as keyboard, mice, touch devices, gamepads, joysticks and many more.

Importantly HID devices can appear as controls within other devices, for example a USB headset can describe the volume and mute buttons as a HID device and a generic driver can recognize it without the need for a custom driver.

Unlike other USB devices where either an entire device or an interface on a device is used to provide a specific function, the HID standard allows multiple devices to coexist on the same interface. So a mouse and keyboard could be defined on a single USB interface and the HID implementation is able to route the reports they generate to the correct consumer.

Some HID devices (such as proprietary game devices) may require more specific handling than can be provided by the generic device infrastructure included in this unit.

In those cases a standard USB driver can be developed which claims the entire device by vendor and product (as USB offers the complete device to all drivers first). The driver can then configure the device as required and is able to use some of the services of both this unit and the HID unit to parse and examine the HID report descriptors.

Alternatively a HID consumer can be developed that claims the HID device during the optional HID DeviceBind callback which prevents other consumers from binding to the HID collections it contains. The consumer can then use some or all of the services of this unit and the HID unit to handle the HID report descriptors when dealing with reports received from the device.

Constants



USB HID specific constants USB_HID_*
USB_HID_DRIVER_NAME = 'USB HID Driver'; Name of USB HID driver


Type definitions



USB HID request

PUSBHIDRequest = ^TUSBHIDRequest;

TUSBHIDRequest = record

Collection:PHIDCollection; The collection this request corresponds to

USB HID requests

PUSBHIDRequests = ^TUSBHIDRequests;

TUSBHIDRequests = array[0..0] of PUSBHIDRequest;

   

USB HID device

PUSBHIDDevice = ^TUSBHIDDevice;

TUSBHIDDevice = record

HID Properties
HID:THIDDevice; The HID entry for this USB Device
USB Properties
USBDevice:PUSBDevice; The USB device
USBInterface:PUSBInterface; The USB interface
HIDDescriptor:PHIDDescriptor; The USB HID descriptor from the interface
Driver Properties
ReportActive:LongWord; The number of currently active report requests
ReportMaxId:LongWord; The maximum report id number this device supports
ReportMaxSize:LongWord; The maximum report size in bytes this device sends
ReportRequests:PUSBHIDRequests; Active input report requests from consumers
ReportEndpoint:PUSBEndpointDescriptor; The USB endpoint for receiving input reports
OutputEndpoint:PUSBEndpointDescriptor; The USB endpoint for receiving ouput reports
PendingCount:LongWord; Number of USB requests pending for this HID device
WaiterThread:TThreadId; Thread waiting for pending requests to complete (for device detachment)


Public variables


None defined

Function declarations



Initialization functions

procedure USBHIDInit;
Description: Initialize the USB HID unit and USB HID driver
Note Called only during system startup


USB HID helper functions

function USBHIDCheckDevice(Device:PUSBDevice):Boolean;
Description: Check if the supplied USB device is suitable for detection as a USB HID Device
Device The USB device to check
Return True if the device is suitable or False if it is not


function USBHIDCheckInterface(Device:PUSBDevice; Interrface:PUSBInterface):Boolean;
Description: Check if the supplied USB device and interface are a USB HID Device
Device The USB device to check
Interrface The USB interface to check
Return True if the device and interface are a USB HID or False if not


function USBHIDGetHIDDescriptor(Device:PUSBDevice; Interrface:PUSBInterface; Descriptor:PHIDDescriptor):LongWord;
Description: Get the HID Descriptor for a USB device and interface
Device The USB device to get the descriptor for
Descriptor Pointer to a USB HID Descriptor structure for the returned data
Return USB_STATUS_SUCCESS if completed or another USB error code on failure


function USBHIDStatusToErrorCode(Status:LongWord):LongWord;
Description: Convert a USB_STATUS_* code to an ERROR_* code
Note None documented


function USBHIDErrorCodeToUSBStatus(Error:LongWord):LongWord;
Description: Convert an ERROR_* code to a USB_STATUS_* code
Note None documented


Return to Unit Reference