Unit HID
Return to Unit Reference
Description
Ultibo Human Interface Device (HID) Interface unit
The Human Interface Device (HID) class is intended to provide a flexible model that allows a wide range of control types to be expressed using a standard set of tags in a report descriptor that each device provides during initialization.
HID devices can represent common items such as mice, keyboards, touchscreens, gamepads and joysticks but can also appear as controls within many other types of devices.
A headset for example will primarily be an audio device but the volume and mute buttons can be defined using the HID standard and easily recognized by software without requiring a custom driver for each and every device.
The Ultibo HID implementation creates an intermediate device layer that is mostly agnostic to both the bus type being used by an underlying provider (such as USB) and the devices recognized by HID consumers such as mice and keyboards.
A provider such as USB HID locates devices from the provider specific bus and creates HID devices to represent them along with obtaining report descriptors and other information.
These HID devices are then passed to registered HID consumers (drivers) to determine if they recognize the collections, reports and usages described by the device. A consumer can accept a device and bind to it during this process and create its own devices to represent the functionality described by the HID device.
While HID itself is intended to be bus agnostic this implementation is based heavily on the USB HID standards as those are the most widely adopted at this time. It is anticipated that HID adoption will expand over time to include a range other bus types, Bluetooth is already using HID and there are existing implementations of HID over I2C, SPI and PCI.
Expanding the Ultibo HID support to other bus types simply requires a new HID provider for that bus to be written along with any necessary changes or extensions to the HID layer itself.
Constants
To be documented
Type definitions
HID descriptor
PHIDDescriptor = ^THIDDescriptor;
THIDDescriptor = packed record
See Section 6.2.1 | |
bLength:Byte;
|
|
bDescriptorType:Byte;
|
|
bcdHID:Word;
|
|
bCountryCode:Byte;
|
|
bNumDescriptors:Byte;
|
|
bHIDDescriptorType:Byte;
|
|
wHIDDescriptorLength:Word;
|
|
Note: Up to two optional bHIDDescriptorType/wHIDDescriptorLength pairs after the Report descriptor details |
HID report descriptor
PHIDReportDescriptor = Pointer;
See Section 6.2.2 | |
HID physical descriptor
PHIDPhysicalDescriptor = ^THIDPhysicalDescriptor;
THIDPhysicalDescriptor = packed record
See Section 6.2.3 | |
bDesignator:Byte;
|
Indicates which part of the body affects the item |
bFlags:Byte;
|
Bits specifying flags (7..5 Qualifier / 4..0 Effort) |
HID physical descriptor set0
PHIDPhysicalDescriptorSet0 = ^THIDPhysicalDescriptorSet0;
THIDPhysicalDescriptorSet0 = packed record
bNumber:Byte;
|
Number of Physical Descriptor sets not including Physical Descriptor set 0 |
wLength:Word;
|
Length of each Physical descriptor set |
HID physical descriptor set
PHIDPhysicalDescriptorSet = ^THIDPhysicalDescriptorSet;
THIDPhysicalDescriptorSet = packed record
bPhysicalInfo:Byte;
|
Bits specifying physical information (7..5 Bias / 4..0 Preference) |
wPhysicalDescriptor:array[0..0] of THIDPhysicalDescriptor;
|
Physical descriptor data |
HID state
PHIDState = ^THIDState;
THIDState = record
Local State | |
Usage:LongWord;
|
|
UsageCount:LongWord;
|
Provides UsageMinimum/UsageMaximum |
DesignatorIndex:LongWord;
|
|
DesignatorCount:LongWord;
|
Provides DesignatorMinimum/DesignatorMaximum |
StringIndex:LongWord;
|
|
StringCount:LongWord;
|
Provides StringMinimum/StringMaximum |
Delimiter:Boolean;
|
|
Global State | |
UsagePage:Word;
|
|
LogicalMinimum:LongInt;
|
|
LogicalMaximum:LongInt;
|
|
PhysicalMinimum:LongInt;
|
|
PhysicalMaximum:LongInt;
|
|
UnitType:LongWord;
|
|
UnitExponent:LongWord;
|
|
ReportSize:LongWord;
|
|
ReportId:LongWord;
|
|
ReportCount:LongWord;
|
HID stack
PHIDStack = ^THIDStack;
THIDStack = record
State:PHIDState;
|
|
Next:PHIDStack;
|
HID usages
PHIDUsages = ^THIDUsages;
THIDUsages = array[0..0] of PHIDUsage;
HID usage
PHIDUsage = ^THIDUsage;
THIDUsage = record
Page:Word;
|
The usage page this usage refers to |
Usage:Word;
|
The usage within the usage page |
Count:Word;
|
The total number of sequential usages where Usage represents the minimum value or 1 for a single usage (Usage range is from Usage to Usage + Count - 1) |
Index:LongWord;
|
The index of this usage in the report (First usage is 0) |
StringIndex:LongWord;
|
The string index for this usage |
StringCount:LongWord;
|
The total number of sequential string index values where string index represents the minimum value or 1 for a single string |
DesignatorIndex:LongWord;
|
The designator index for this usage |
DesignatorCount:LongWord;
|
The total number of sequential designator index values where designator index represents the minimum value or 1 for a single designator |
LogicalMinimum:LongInt;
|
The logical minimum value for this usage |
LogicalMaximum:LongInt;
|
The logical maximum value for this usage |
PhysicalMinimum:LongInt;
|
The physical minimum value for this usage (in Units) |
PhysicalMaximum:LongInt;
|
The physical maximum value for this usage (in Units) |
UnitType:LongWord;
|
The unit type for this usage |
UnitExponent:LongWord;
|
The unit exponent index for this usage |
Aliases:PHIDUsages;
|
The list of aliased usages for this control (See Delimiters in Section 6.2.2.8) |
AliasCount:LongWord;
|
The number of aliased usages contained for this control |
Report:PHIDReport;
|
The report this usage belongs to |
HID reports
PHIDReports = ^THIDReports;
THIDReports = array[0..0] of PHIDReport;
HID report
PHIDReport = ^THIDReport;
THIDReport = record
Id:Byte;
|
The Id of this report |
Kind:Byte;
|
The type of report (Input, Output or Feature) (eg HID_REPORT_INPUT) |
Flags:LongWord;
|
The main item flags for this report (eg HID_MAIN_ITEM_VARIABLE) |
Size:LongWord;
|
The number of bits per field in this report |
Count:LongWord;
|
The number of fields in this report |
Index:LongWord;
|
The index of this report in the collection (First report is 0) |
Usages:PHIDUsages;
|
The list of usages contained in this report |
UsageCount:LongWord;
|
The number of usages contained in this report |
Collection:PHIDCollection;
|
The collection this report belongs to |
HID collections
PHIDCollections = ^THIDCollections;
THIDCollections = array[0..0] of PHIDCollection;
HID collection
PHIDCollection = ^THIDCollection;
THIDCollection = record
Page:Word;
|
The usage page this collection refers to (eg HID_PAGE_GENERIC_DESKTOP) |
Usage:Word;
|
The usage within the usage page (eg HID_DESKTOP_MOUSE) |
Flags:LongWord;
|
The main item flags for this collection (eg HID_MAIN_COLLECTION_APPLICATION) |
Start:LongWord;
|
The first byte of this collection in the report descriptor |
Reports:PHIDReports;
|
The list of reports contained in this collection |
ReportCount:LongWord;
|
The number of reports contained in this collection |
Collections:PHIDCollections;
|
The list of collections contained in this collection |
CollectionCount:LongWord;
|
The number of collections contained in this collection |
Parent:PHIDCollection;
|
The parent collection or nil if this is a top level collection |
Device:PHIDDevice;
|
The device this collection belongs to |
Consumer:PHIDConsumer;
|
The consumer which is bound to this collection (or nil if not bound) |
PrivateData:Pointer;
|
Private data for the consumer of this collection |
HID device enumeration callback
THIDDeviceEnumerate = function(Device:PHIDDevice;Data:Pointer):LongWord;
|
HID device notification callback
THIDDeviceNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
|
HID device get idle
THIDDeviceGetIdle = function(Device:PHIDDevice; var Duration:Word; ReportId:Byte):LongWord;
|
HID device set idle
THIDDeviceSetIdle = function(Device:PHIDDevice; Duration:Word; ReportId:Byte):LongWord;
|
HID device get report
THIDDeviceGetReport = function(Device:PHIDDevice; ReportType,ReportId:Byte; ReportData:Pointer; ReportSize:LongWord):LongWord;
|
HID device set report
THIDDeviceSetReport = function(Device:PHIDDevice; ReportType,ReportId:Byte; ReportData:Pointer; ReportSize:LongWord):LongWord;
|
HID device allocate report
THIDDeviceAllocateReport = function(Device:PHIDDevice; Collection:PHIDCollection; ReportId:Byte; ReportSize:LongWord):LongWord;
|
HID device release report
THIDDeviceReleaseReport = function(Device:PHIDDevice; ReportId:Byte):LongWord;
|
HID device submit report
THIDDeviceSubmitReport = function(Device:PHIDDevice; ReportId:Byte):LongWord;
|
HID device cancel report
THIDDeviceCancelReport = function(Device:PHIDDevice; ReportId:Byte):LongWord;
|
HID device get protocol
THIDDeviceGetProtocol = function(Device:PHIDDevice; var Protocol:Byte):LongWord;
|
HID device set protocol
THIDDeviceSetProtocol = function(Device:PHIDDevice; Protocol:Byte):LongWord;
|
HID device get interval
THIDDeviceGetInterval = function(Device:PHIDDevice; var Interval:LongWord):LongWord;
|
HID device set interval
THIDDeviceSetInterval = function(Device:PHIDDevice; Interval:LongWord):LongWord;
|
HID device get report descriptor
THIDDeviceGetReportDescriptor = function(Device:PHIDDevice; Descriptor:PHIDReportDescriptor; Size:LongWord):LongWord;
|
HID device get physical descriptor set0
THIDDeviceGetPhysicalDescriptorSet0 = function(Device:PHIDDevice; Descriptor:PHIDPhysicalDescriptorSet0):LongWord;
|
HID device get physical descriptor set
THIDDeviceGetPhysicalDescriptorSet = function(Device:PHIDDevice; Descriptor:PHIDPhysicalDescriptorSet; Index:Byte; Size:LongWord):LongWord;
|
HID device
PHIDDevice = ^THIDDevice;
THIDDevice = record
Device Properties | |
Device:TDevice;
|
The Device entry for this HID |
HID Properties | |
HIDId:LongWord;
|
Unique Id of this HID in the HID device table |
HIDState:LongWord;
|
HID device state (eg HID_STATE_ATTACHED) |
Consumer:PHIDConsumer;
|
The consumer which is bound to this device (or nil if not bound) |
DeviceGetIdle:THIDDeviceGetIdle;
|
A device specific GetIdle method (If supported by provider) |
DeviceSetIdle:THIDDeviceSetIdle;
|
A device specific SetIdle method (If supported by provider) |
DeviceGetReport:THIDDeviceGetReport;
|
A device specific GetReport method (If supported by provider) |
DeviceSetReport:THIDDeviceSetReport;
|
A device specific SetReport method (If supported by provider) |
DeviceAllocateReport:THIDDeviceAllocateReport;
|
A device specific AllocateReport method (If supported by provider) |
DeviceReleaseReport:THIDDeviceReleaseReport;
|
A device specific ReleaseReport method (If supported by provider) |
DeviceSubmitReport:THIDDeviceSubmitReport;
|
A device specific SubmitReport method (If supported by provider) |
DeviceCancelReport:THIDDeviceCancelReport;
|
A device specific CancelReport method (If supported by provider) |
DeviceGetProtocol:THIDDeviceGetProtocol;
|
A device specific GetProtocol method (If supported by provider) |
DeviceSetProtocol:THIDDeviceSetProtocol;
|
A device specific SetProtocol method (If supported by provider) |
DeviceGetInterval:THIDDeviceGetInterval;
|
A device specific GetInterval method (If supported by provider) |
DeviceSetInterval:THIDDeviceSetInterval;
|
A device specific SetInterval method (If supported by provider) |
DeviceGetReportDescriptor:THIDDeviceGetReportDescriptor;
|
A device specific GetReportDescriptor method (If supported by provider) |
DeviceGetPhysicalDescriptorSet0:THIDDeviceGetPhysicalDescriptorSet0;
|
A device specific GetPhysicalDescriptorSet0 method (If supported by provider) |
DeviceGetPhysicalDescriptorSet:THIDDeviceGetPhysicalDescriptorSet;
|
A device specific GetPhysicalDescriptorSet method (If supported by provider) |
Driver Properties | |
Lock:TMutexHandle;
|
HID device lock |
PrivateData:Pointer;
|
Private data for the consumer of this HID device (If applicable) |
Collections:PHIDCollections;
|
The parsed report descriptor with collections, reports and usages |
CollectionCount:LongWord;
|
The number of top level collections contained in the report descriptor |
Descriptor:PHIDReportDescriptor;
|
The raw report descriptor obtained from the device |
DescriptorSize:LongWord;
|
The size of the data pointed to by Descriptor |
Statistics Properties | |
ReceiveCount:LongWord;
|
|
ReceiveErrors:LongWord;
|
|
Internal Properties | |
Prev:PHIDDevice;
|
Previous entry in Device table |
Next:PHIDDevice;
|
Next entry in Device table |
HID consumer enumeration callback
THIDConsumerEnumerate = function(Consumer:PHIDConsumer; Data:Pointer):LongWord;
|
HID device bind
THIDDeviceBind = function(Device:PHIDDevice):LongWord;
|
HID device unbind
THIDDeviceUnbind = function(Device:PHIDDevice):LongWord;
|
HID collection bind
THIDCollectionBind = function(Device:PHIDDevice; Collection:PHIDCollection):LongWord;
|
HID collection unbind
THIDCollectionUnbind = function(Device:PHIDDevice; Collection:PHIDCollection):LongWord;
|
HID report receive
THIDReportReceive = function(Collection:PHIDCollection; ReportId:Byte; ReportData:Pointer; ReportSize:LongWord):LongWord;
|
HID consumer
PHIDConsumer = ^THIDConsumer;
THIDConsumer = record
Driver Properties | |
Driver:TDriver;
|
The Driver entry for this HID Consumer |
Consumer Properties | |
DeviceBind:THIDDeviceBind;
|
A Device Bind method to be called when a HID device bind is requested by a provider (Optional) |
DeviceUnbind:THIDDeviceUnbind;
|
A Device Ubind method to be called when a HID device unbind is requested by a provider (Optional) |
CollectionBind:THIDCollectionBind;
|
A Collection Bind method to be called when a HID collection bind is requested by a provider (Mandatory) |
CollectionUnbind:THIDCollectionUnbind;
|
A Collection Unbind method to be called when a HID collection unbind is requested by a provider (Mandatory) |
ReportReceive:THIDReportReceive;
|
A Report Receive method to be called when a HID input report is received by a provider (Mandatory) |
Interface Properties | |
Lock:TMutexHandle;
|
Consumer lock |
Internal Properties | |
Prev:PHIDConsumer;
|
Previous entry in Consumer table |
Next:PHIDConsumer;
|
Next entry in Consumer table |
HID report field
PHIDField = ^THIDField;
THIDField = record
Page:Word;
|
The usage page of this field |
Usage:Word;
|
The usage within the usage page |
Count:LongWord;
|
The total number of sequential usages where Usage represents the minimum value or 1 for a single usage (Usage range is from Usage to Usage + Count - 1) |
Flags:LongWord;
|
The flags for this field |
Size:LongWord;
|
The length in bytes of this field within the input, output or feature report |
Bits:LongWord;
|
The length in bits of this field within the input, output or feature report |
Offset:LongWord;
|
The byte offset of this field within the input, output or feature report |
Shift:LongWord;
|
The number shift bits to access this field in the input, output or feature report |
Minimum:LongInt;
|
The minimum value for this field (either in logical or physical units) |
Maximum:LongInt;
|
The maximum value for this field (either in logical or physical units) |
Multiplier:Double;
|
The conversion multiplier for this field from logical to physical units |
Resolution:Double;
|
The unit resolution for this field in counts per physical unit |
Next:PHIDField;
|
The next field in the list |
HID report definition
PHIDDefinition = ^THIDDefinition;
THIDDefinition = record
Id:Byte;
|
The Id of this report |
Kind:Byte;
|
The type of this report (Input, Output or Feature) |
Size:LongWord;
|
The total length of this input, output or feature report in bytes (Including the Id byte) |
Fields:PHIDField;
|
Linked list of fields in this input, output or feature report |
Next:PHIDDefinition;
|
The next definition in the list |
Public variables
HID logging
HID_DEFAULT_LOG_LEVEL:LongWord = HID_LOG_LEVEL_DEBUG;
|
Minimum level for HID messages. Only messages with level greater than or equal to this will be printed. |
HID_LOG_ENABLED:Boolean;
|
Function declarations
To be documented
Return to Unit Reference