Unit HID

From Ultibo.org
Jump to: navigation, search

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



[Expand]
HID specific constants HID_NAME_*


[Expand]
HID device type HID_TYPE_*


[Expand]
HID device state HID_STATE_*


[Expand]
HID device flag HID_FLAG_*


[Expand]
HID interface subclass HID_SUBCLASS_*


[Expand]
HID interface protocol HID_BOOT_PROTOCOL_*


[Expand]
HID class descriptor HID_DESCRIPTOR_TYPE*


[Expand]
HID request HID_REQUEST_*


[Expand]
HID protocol HID_PROTOCOL_*


[Expand]
HID report HID_REPORT_*


[Expand]
HID report ID HID_REPORTID_*


[Expand]
HID item size HID_SIZE_*


[Expand]
HID item type HID_TYPE_*


[Expand]
HID main item tag HID_TAG_MAIN_*


[Expand]
HID global item tag HID_TAG_GLOBAL_*


[Expand]
HID local item tag HID_TAG_LOCAL_*


[Expand]
HID main item input, ouput and feature HID_MAIN_ITEM_*


[Expand]
HID main item collection HID_MAIN_COLLECTION_*


[Expand]
HID global item unit HID_GLOBAL_UNIT_*


[Expand]
HID local item delimiter HID_LOCAL_DELIMITER_*


[Expand]
HID physical descriptor bias HID_PHYSICAL_BIAS_*


[Expand]
HID physical descriptor designator HID_PHYSICAL_DESIGNATOR_*


[Expand]
HID physical descriptor qualifier HID_PHYSICAL_QUALIFIER_*


[Expand]
HID usage page HID_PAGE_*


[Expand]
HID usage table HID_DESKTOP_*


[Expand]
HID keyboard/keypad SCAN_CODE_*


[Expand]
HID LED (Partial) HID_LED_*


[Expand]
HID button (Partial) HID_BUTTON_*


[Expand]
HID digitizers (Partial) HID_DIGITIZERS_*


[Expand]
HID logging HID_LOG_*


Type definitions



HID descriptor

[Expand]

PHIDDescriptor = ^THIDDescriptor;

THIDDescriptor = packed record

HID report descriptor

[Expand]

PHIDReportDescriptor = Pointer;

HID physical descriptor

[Expand]

PHIDPhysicalDescriptor = ^THIDPhysicalDescriptor;

THIDPhysicalDescriptor = packed record

HID physical descriptor set0

[Expand]

PHIDPhysicalDescriptorSet0 = ^THIDPhysicalDescriptorSet0;

THIDPhysicalDescriptorSet0 = packed record

HID physical descriptor set

[Expand]

PHIDPhysicalDescriptorSet = ^THIDPhysicalDescriptorSet;

THIDPhysicalDescriptorSet = packed record

HID state

[Expand]

PHIDState = ^THIDState;

THIDState = record

HID stack

[Expand]

PHIDStack = ^THIDStack;

THIDStack = record

HID usages

[Expand]

PHIDUsages = ^THIDUsages;

THIDUsages = array[0..0] of PHIDUsage;

HID usage

[Expand]

PHIDUsage = ^THIDUsage;

THIDUsage = record

HID reports

[Expand]

PHIDReports = ^THIDReports;

THIDReports = array[0..0] of PHIDReport;

HID report

[Expand]

PHIDReport = ^THIDReport;

THIDReport = record

HID collections

[Expand]

PHIDCollections = ^THIDCollections;

THIDCollections = array[0..0] of PHIDCollection;

HID collection

[Expand]

PHIDCollection = ^THIDCollection;

THIDCollection = record

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

[Expand]

PHIDDevice = ^THIDDevice;

THIDDevice = record

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

[Expand]

PHIDConsumer = ^THIDConsumer;

THIDConsumer = record

HID report extent

[Expand]

PHIDExtent = ^THIDExtent;

THIDExtent = record

HID report field

[Expand]

PHIDField = ^THIDField;

THIDField = record

HID report definition

[Expand]

PHIDDefinition = ^THIDDefinition;

THIDDefinition = record


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



Initialization functions

[Expand]
procedure HIDInit;
Description: Initialize the HID unit, device and consumer tables


HID functions

[Expand]
function HIDParserParseCollections(Device:PHIDDevice; var Collections:PHIDCollections; var Count:LongWord):LongWord;
Description: Parse the HID report descriptor of the provided device and populate the collections, reports and usages


[Expand]
function HIDParserFreeCollections(Collections:PHIDCollections; Count:LongWord):LongWord;
Description: Free the collections, reports and usages parsed from a HID report descriptor


[Expand]
function HIDParserCountCollections(Device:PHIDDevice; Parent:PHIDCollection):LongWord;
Description: Count the number of collections found in the HID report descriptor of the provided device


[Expand]
function HIDParserCountReports(Device:PHIDDevice; Collection:PHIDCollection):LongWord;
Description: Count the number of reports found in the HID report descriptor of the supplied device and collection


[Expand]
function HIDParserCountUsages(Device:PHIDDevice; Report:PHIDReport):LongWord;
Description: Count the number of usages found in the HID report descriptor for the supplied device and report


[Expand]
function HIDParserAllocateCollection(Device:PHIDDevice; Parent:PHIDCollection; State:PHIDState; Flags,Start:LongWord):PHIDCollection;
Description: Allocate a HID collection to contain a set of reports and usages from a HID report descriptor


[Expand]
function HIDParserAllocateReport(Device:PHIDDevice; Collection:PHIDCollection; State:PHIDState; Kind:Byte; Flags,Index,Sequence:LongWord):PHIDReport;
Description: Allocate a HID report to contain a set of usages from a HID report descriptor


[Expand]
function HIDParserAllocateUsage(Device:PHIDDevice; Report:PHIDReport; State:PHIDState; Index:LongWord):PHIDUsage;
Description: Allocate a HID usage from a HID report descriptor


[Expand]
function HIDParserUpdateUsage(Device:PHIDDevice; Report:PHIDReport; State:PHIDState; Usage:PHIDUsage):Boolean;
Description: Update a HID usage from a HID report descriptor


[Expand]
function HIDParserFreeUsage(Device:PHIDDevice;Usage:PHIDUsage):Boolean;
Description: Free a HID usage and any associated usage aliases


[Expand]
function HIDParserPopStack(var Stack:PHIDStack; var State:PHIDState):LongWord;
Description: Replace the current HID parser state with the top item from the parser stack


[Expand]
function HIDParserPushStack(Stack:PHIDStack):LongWord;
Description: Place a copy of the current HID parser state on top of the parser stack


[Expand]
function HIDParserFreeStack(Stack:PHIDStack):LongWord;
Description: Free the HID parser stack and state


[Expand]
function HIDParserResetState(State:PHIDState):LongWord;
Description: Clear the Local and Global HID parser state


[Expand]
function HIDParserCleanState(State:PHIDState):LongWord;
Description: Clear the Local HID parser state


[Expand]
function HIDFindCollection(Device:PHIDDevice; Page,Usage:Word):PHIDCollection;
Description: Find the first HID collection matching the specified page and usage


[Expand]
function HIDFindReportIds(Device:PHIDDevice; Collection:PHIDCollection; var MinId,MaxId:Byte):LongWord;
Description: Find the minimum and maximum report ids contained in the specified HID collection or all collections


[Expand]
function HIDFindReportSizes(Device:PHIDDevice; Collection:PHIDCollection; Kind:Byte; var MinSize,MaxSize:LongWord):LongWord;
Description: Find the minimum and maximum report sizes contained in the specified HID collection or all collections


[Expand]
function HIDCountReports(Device:PHIDDevice; Collection:PHIDCollection; Kind,Id:Byte; var Count:LongWord):LongWord;
Description: Count the number of HID reports of the specified type and id in the specified collection


[Expand]
function HIDFindReports(Device:PHIDDevice; Collection:PHIDCollection; Kind,Id:Byte; Reports:PHIDReports; Count:LongWord):LongWord;
Description: Find all HID reports of the specified type and id in the specified collection


[Expand]
function HIDAllocateDefinition(Device:PHIDDevice; Collection:PHIDCollection; Kind,Id:Byte):PHIDDefinition;
Description: Allocate a HID definition to describe an input, output or feature report contained in the specified collection


[Expand]
function HIDFreeDefinition(Definition:PHIDDefinition):LongWord;
Description: Free a HID definition describing an input, output or feature report


[Expand]
function HIDInsertBitField(Field:PHIDField; Buffer:Pointer; Size:LongWord; Value:Boolean):LongWord;
Description: Insert a bit field value into a report buffer


[Expand]
function HIDInsertSignedField(Field:PHIDField; Buffer:Pointer; Size:LongWord; Value:LongInt):LongWord;
Description: Insert a signed field value into a report buffer


[Expand]
function HIDInsertUnsignedField(Field:PHIDField; Buffer:Pointer; Size,Value:LongWord):LongWord;
Description: Insert an unsigned field value into a report buffer


[Expand]
function HIDExtractBitField(Field:PHIDField; Buffer:Pointer; Size:LongWord; var Value:Boolean):LongWord;
Description: Extract a bit field value from a report buffer


[Expand]
function HIDExtractSignedField(Field:PHIDField; Buffer:Pointer; Size:LongWord; var Value:LongInt):LongWord;
Description: Extract a signed field value from a report buffer


[Expand]
function HIDExtractUnsignedField(Field:PHIDField; Buffer:Pointer; Size:LongWord; var Value:LongWord):LongWord;
Description: Extract an unsigned field value from a report buffer


HID Device functions

[Expand]
function HIDDeviceSetState(Device:PHIDDevice; State:LongWord):LongWord;
Description: Set the state of the specified HID device and send a notification


[Expand]
function HIDDeviceGetIdle(Device:PHIDDevice; var Duration:Word; ReportId:Byte):LongWord;
Description: Get the idle rate from a HID device for the specified report id


[Expand]
function HIDDeviceSetIdle(Device:PHIDDevice; Duration:Word; ReportId:Byte):LongWord;
Description: Set the idle rate on a HID device for the specified report id


[Expand]
function HIDDeviceGetReport(Device:PHIDDevice; ReportType,ReportId:Byte; ReportData:Pointer; ReportSize:LongWord):LongWord;
Description: Read a report by type and id from a HID device


[Expand]
function HIDDeviceSetReport(Device:PHIDDevice; ReportType,ReportId:Byte; ReportData:Pointer; ReportSize:LongWord):LongWord;
Description: Write a report by type and id to a HID device


[Expand]
function HIDDeviceAllocateReport(Device:PHIDDevice; Collection:PHIDCollection; ReportId:Byte; ReportSize:LongWord):LongWord;
Description: Allocate and initialize an input report by id on a HID device


[Expand]
function HIDDeviceReleaseReport(Device:PHIDDevice; ReportId:Byte):LongWord;
Description: Release an input report by id from a HID device


[Expand]
function HIDDeviceSubmitReport(Device:PHIDDevice; ReportId:Byte):LongWord;
Description: Submit an input report by id on a HID device


[Expand]
function HIDDeviceCancelReport(Device:PHIDDevice; ReportId:Byte):LongWord;
Description: Cancel an input report by id on a HID device


[Expand]
function HIDDeviceGetProtocol(Device:PHIDDevice; var Protocol:Byte):LongWord;
Description: Get the report protocol from a HID device


[Expand]
function HIDDeviceSetProtocol(Device:PHIDDevice; Protocol:Byte):LongWord;
Description: Set the report protocol for a HID device


[Expand]
function HIDDeviceGetInterval(Device:PHIDDevice; var Interval:LongWord):LongWord;
Description: Get the polling interval from a HID device


[Expand]
function HIDDeviceSetInterval(Device:PHIDDevice; Interval:LongWord):LongWord;
Description: Set the polling interval for a HID device


[Expand]
function HIDDeviceGetReportDescriptor(Device:PHIDDevice; Descriptor:PHIDReportDescriptor; Size:LongWord):LongWord;
Description: Get the Report Descriptor for a HID device


[Expand]
function HIDDeviceGetPhysicalDescriptorSet0(Device:PHIDDevice; Descriptor:PHIDPhysicalDescriptorSet0):LongWord;
Description: Get the HID Physical Descriptor Set 0 for a HID device


[Expand]
function HIDDeviceGetPhysicalDescriptorSet(Device:PHIDDevice; Descriptor:PHIDPhysicalDescriptorSet; Index:Byte; Size:LongWord):LongWord;
Description: Get a HID Physical Descriptor Set for a HID device


[Expand]
function HIDDeviceBindDevice(Device:PHIDDevice):LongWord;
Description: Attempt to bind a HID device to one of the registered consumers


[Expand]
function HIDDeviceUnbindDevice(Device:PHIDDevice; Consumer:PHIDConsumer):LongWord;
Description: Unbind a HID device from a consumer


[Expand]
function HIDDeviceBindCollections(Device:PHIDDevice):LongWord;
Description: Attempt to bind the HID collections in the specified device to one of the registered consumers


[Expand]
function HIDDeviceUnbindCollections(Device:PHIDDevice; Consumer:PHIDConsumer):LongWord;
Description: Unbind the HID collections in the specified device from a consumer


[Expand]
function HIDDeviceCreate:PHIDDevice;
Description: Create a new HID device entry


[Expand]
function HIDDeviceCreateEx(Size:LongWord):PHIDDevice;
Description: Create a new HID device entry


[Expand]
function HIDDeviceDestroy(Device:PHIDDevice):LongWord;
Description: Destroy an existing HID device entry


[Expand]
function HIDDeviceRegister(Device:PHIDDevice):LongWord;
Description: Register a new HID device in the HID device table


[Expand]
function HIDDeviceDeregister(Device:PHIDDevice):LongWord;
Description: Deregister a HID device from the HID device table


[Expand]
function HIDDeviceFind(HIDId:LongWord):PHIDDevice;
Description: Find a HID device by ID in the HID device table


[Expand]
function HIDDeviceFindByName(const Name:String):PHIDDevice; inline;
Description: Find a HID device by name in the device table


[Expand]
function HIDDeviceFindByDescription(const Description:String):PHIDDevice; inline;
Description: Find a HID device by description in the device table


[Expand]
function HIDDeviceEnumerate(Callback:THIDDeviceEnumerate; Data:Pointer):LongWord;
Description: Enumerate all HID devices in the HID device table


[Expand]
function HIDDeviceNotification(Device:PHIDDevice; Callback:THIDDeviceNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for HID device changes


HID consumer functions

[Expand]
function HIDConsumerCreate:PHIDConsumer;
Description: Create a new HID Consumer entry


[Expand]
function HIDConsumerCreateEx(Size:LongWord):PHIDConsumer;
Description: Create a new HID Consumer entry


[Expand]
function HIDConsumerDestroy(Consumer:PHIDConsumer):LongWord;
Description: Destroy an existing HID Consumer entry


[Expand]
function HIDConsumerRegister(Consumer:PHIDConsumer):LongWord;
Description: Register a new Consumer in the HID Consumer table


[Expand]
function HIDConsumerDeregister(Consumer:PHIDConsumer):LongWord;
Description: Deregister a Consumer from the HID Consumer table


[Expand]
function HIDConsumerFind(ConsumerId:LongWord):PHIDConsumer;
Description: Find a consumer by Id in the HID Consumer table


[Expand]
function HIDConsumerFindByName(const Name:String):PHIDConsumer; inline;
Description: Find a consumer by name in the Driver table


[Expand]
function HIDConsumerEnumerate(Callback:THIDConsumerEnumerate; Data:Pointer):LongWord;
Description: Enumerate all consumers in the HID Consumer table


HID helper functions

[Expand]
function HIDIsBitField(Field:PHIDField):Boolean;
Description: Return True if the supplied field contains a 1 bit value


[Expand]
function HIDIsByteField(Field:PHIDField):Boolean;
Description: Return True if the supplied HID field contains a 1 byte value


[Expand]
function HIDIsWordField(Field:PHIDField):Boolean;
Description: Return True if the supplied HID field contains a 2 byte value


[Expand]
function HIDIsLongField(Field:PHIDField):Boolean;
Description: Return True if the supplied HID field contains a 3 or 4 byte value


[Expand]
function HIDIsSignedField(Field:PHIDField):Boolean;
Description: Return True if the supplied HID field contains a signed value


[Expand]
function HIDPageToString(Page:Word):String;
Description: Return a string describing a HID usage page


[Expand]
function HIDUsageToString(Page,Usage,Count:Word):String;
Description: Return a string describing a HID usage within the given page


[Expand]
function HIDUnitTypeToString(UnitType:LongWord):String;
Description: Return a string describing a HID unit type


[Expand]
function HIDReportKindToString(Kind:Byte):String;
Description: Return a string describing a HID report type


[Expand]
function HIDReportFlagsToString(Flags:LongWord):String;
Description: Return a string describing the flags of a HID report


[Expand]
function HIDCollectionFlagsToString(Flags:LongWord):String;
Description: Return a string describing the flags of a HID collection


[Expand]
procedure HIDLog(Level:LongWord; Device:PHIDDevice; const AText:String);
Description: To be documented


[Expand]
procedure HIDLogInfo(Device:PHIDDevice; const AText:String);
Description: To be documented


[Expand]
procedure HIDLogWarn(Device:PHIDDevice; const AText:String);
Description: To be documented


[Expand]
procedure HIDLogError(Device:PHIDDevice; const AText:String);
Description: To be documented


[Expand]
procedure HIDLogDebug(Device:PHIDDevice; const AText:String);
Description: To be documented


HID device helper functions

[Expand]
function HIDDeviceGetCount:LongWord;
Description: Get the current HID Device count


[Expand]
function HIDDeviceCheck(Device:PHIDDevice):PHIDDevice;
Description: Check if the supplied HID Device is in the device table


[Expand]
function HIDDeviceTypeToString(HIDType:LongWord):String;
Description: Return a string describing the HID device type (eg HID_TYPE_USB)


[Expand]
function HIDDeviceStateToString(HIDState:LongWord):String;
Description: Return a string describing the HID device state (eg HID_STATE_ATTACHED)


[Expand]
function HIDDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Device state value into the notification code for device notifications


HID consumer helper functions

[Expand]
function HIDConsumerGetCount:LongWord;
Description: Get the current HID Consumer count


[Expand]
function HIDConsumerCheck(Consumer:PHIDConsumer):PHIDConsumer;
Description: Check if the supplied HID Consumer is in the consumer table


Return to Unit Reference