Unit USB

From Ultibo.org
Revision as of 02:23, 5 January 2017 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


Ultibo USB interface unit

This unit implements the USB core software that does not depend on the specific host controller hardware and is not specific to any single USB device or platform.

Features and limitations:

  • This driver is written to be compatible with USB 2.0. USB 3.0 devices work correctly when operating in USB 2.0 compatible mode, actual support for USB 3.0 host controllers and native super speed modes will require some modification to this driver.
  • Not all USB transfer types and speeds are supported yet. This depends on the Host Controller Driver, see USBRequestSubmit.
  • This driver does not attempt to do any intelligent power management, bandwidth allocation, or transfer scheduling. Devices are always set to their first listed configuration regardless of power requirements. Requests are simply passed to the Host Controller Driver in the order submitted, the Host Controller Driver is responsible for doing any more intelligent scheduling if desired.
  • This driver does not support multiple configurations per USB device.If a device happens to have multiple configurations, the first one will be assigned (see devices below for more information).
  • By design, it is possible to implement a host controller driver for different host controller hardware without changing any of this code, as long as the host controller driver provides the functions declared in TUSBHost (Start, Stop, Reset, Submit and Cancel).
  • By design, this driver has a hard-coded dependency on the USB hub driver because USB is useless without hubs.

To initialize this core USB driver, USBInit must be called by the system startup code. See that function for details.

If the flag USB_AUTOSTART is not set then USBStart must be called to start the USB core. See that function for details.

The other functions exported by this core USB driver are mostly intended to be used by USB device drivers.

Debugging messages in this driver can be enabled by changing the value of USB_DEFAULT_LOG_LEVEL and by enabling the USB_DEBUG define in GlobalDefines.

Be careful when enabling USB debugging as the USB core can generate a lot of messages due to constant polling of interrupt endpoints on devices such as hubs, keyboards and mice.

USB Device

USB devices are the generic implementation of anything that can be connected to the USB bus. All USB devices require a driver to implement the specific behaviour of the device but at the generic level each device will have:

  • One or more configurations available. The USB core will first offer the device to drivers without a configuration being selected, the driver may choose a specific configuration if required otherwise the core will simply select the first available configuration.
  • One or more interfaces available. On devices with multiple interfaces, the USB core supports different drivers binding to different interfaces. This way combination devices are supported.
  • One or more endpoints available. All devices must have a control endpoint and most devices will have one or more bulk, interrupt or isochronous endpoints as well. The USB core will only communicate with the control endpoint to perform generic operations like reading the desriptors and assigning a device addresss.

Drivers are expected to understand which endpoints they need to communicate with to provide the device specific functionality.

Devices are considered dynamic by the USB core and can be connected or disconnected at any time. The hub driver is responsible for attaching and detaching devices in response to hub status change events and for binding or unbinding drivers as devices are added or removed.

USB Driver

USB drivers implement support for specific devices or specific device classes and provide the interfaces to present those devices to other parts of the system. For example the USB Mass Storage driver accepts devices of the mass storage class and presents them to the file system as a disk device.

All drivers must implement the functions defined in TUSBDriver (Bind and Unbind) and must register themselves with the USB core by calling USBDriverRegister. When a new device is detected the hub driver will enumerate all drivers and call their Bind functions until either one of the drivers accepts the device or all drivers have rejected the device. The hub driver first attempts to bind each driver to the device itself and then offers each driver the option to bind to a single interface on the device. In this way devices that have multiple interfaces of different classes (such as a wireless mouse and keyboard dongle) can actually be bound to multiple drivers which each service a specific interface.

When a new driver is registered the USB core will call the drivers Bind function for each device already present to allow the driver an opportunity to bind to any existing devices that are not serviced by other drivers.

When a device is disconnected the hub driver will first call the Unbind function of any driver that is servicing the device to allow the driver to clean up allocated resources and cancel outstanding requests. Drivers must be careful not to block the hub driver during this process, for example trying to send a USB control message to the device at this time will likely be pointless as in many cases the device will have already been disconnected from the system.

USB Host

USB hosts implement the hardware level interface that supports sending USB requests to the hardware and receiving responses. All handling of interrupts, DMA, transaction sequence, errors and resubmitting/retrying requests is done by the USB host driver. All host drivers must implement the functions defined in TUSBHost (Start, Stop, Reset, Submit and Cancel) and must register themselves with the USB core by calling USBHostRegister. When the USB core is started each registered host driver will be called via the Start function so it can initialize itself and allocate locks, buffers and other resources required to interact with the hardware.

A host driver can also be registered after the USB core has been started and it will be given the opportunity to start itself immediately. In this way USB hosts can potentially be hot pluggable.

Each host driver must also implement a root hub which respresents the port or ports that are directly connected to the controller hardware. In many cases this will not be a real hub but will be simulated in the host driver so that the hub driver can interact with it as though it was a standard hub device.

USB Hub

Hubs are one of the fundamental devices in USB and are used to provide connection points (ports) for additional devices. Note that even if no "external" hub is plugged in, the USB still will have at least one logical hub (the root hub) and usually additional "internal" hubs. That is, a USB is a tree of devices where the root node and all non-leaf nodes are hubs. A port on a USB hub may correspond to a port you can physically plug a device into or may correspond to an internal port. USB hubs are commonly based around a design that has 4 ports per hub, so a standard 7 port hub will most often appear as 2 hubs to this driver with one hub connected to a port on the other.

This hub driver is an example of a USB device driver, but it is somewhat special as it mandatory to include this driver if USB is supported at all. This is because it would be impossible to access any USB devices if a hub driver were not available. This hub driver also uses some interfaces in the core driver, such as USBDeviceAttach, that are not useful to any other USB device driver.

The initial entry point of this USB hub driver is USBHubDriverBind, which is called when the USB core has configured a newly attached USB device that may be a hub. USBHubDriverBind is responsible for checking if the device is a hub, and if so, doing hub-specific setup, reading the hub descriptor, powering on the ports, and submitting an asynchronous USB interrupt request to the hub's status change endpoint.

Everything else this hub driver does happens asynchronously as a response to a status change request being completed. Every USB hub has exactly one IN interrupt endpoint called the "status change endpoint". The hub responds on this endpoint whenever the status of the hub or one of the hub's ports has changed, for example when a USB device has been connected or disconnected from a port.

At the hardware level, when a hub has data to send on its status change endpoint, an interrupt will come in from the USB host controller. This eventually will result in the status change transfer being completed and USBHubStatusComplete being called. Thus, the detection of status changes is interrupt-driven and is not implemented by polling at the software level. (At the hardware level, USB is still a polled bus, but the host controller hardware handles that for us). Upon detecting a status change on one or more ports on a hub, the hub driver then must submit one or more control messages to the hub to determine exactly what changed on the affected ports.

Constants



USB device, driver and host specific constants USB_*_PREFIX
USB_DEVICE_PREFIX = 'USB'; Name prefix for USB Devices
USB_DRIVER_PREFIX = 'USB'; Name prefix for USB Drivers
USB_HOST_PREFIX = 'USBHost'; Name prefix for USB Hosts


USB device type constants USB_TYPE_*
USB_TYPE_NONE = 0;  
 
USB_TYPE_MAX = 0;  


USB device state constants USB_STATE_*
USB_STATE_DETACHED = 0;  
USB_STATE_DETACHING = 1;  
USB_STATE_ATTACHING = 2;  
USB_STATE_ATTACHED = 3;  
 
USB_STATE_MAX = 3;  


USB device status constants USB_STATUS_*
USB_STATUS_UNBOUND = 0;  
USB_STATUS_BOUND = 1;  
 
USB_STATUS_MAX = 1;  


USB device flag constants USB_FLAG_*
USB_FLAG_NONE = $00000000;  


USB host type constants USBHOST_TYPE_*
USBHOST_TYPE_NONE = 0;  
USBHOST_TYPE_EHCI = 1;  
USBHOST_TYPE_OHCI = 2;  
USBHOST_TYPE_UHCI = 3;  
USBHOST_TYPE_XHCI = 4;  
USBHOST_TYPE_DWCOTG = 5;  
 
USBHOST_TYPE_MAX = 5;  


USB host state constants USBHOST_STATE_*
USBHOST_STATE_DISABLED = 0;  
USBHOST_STATE_ENABLED = 1;  
 
USBHOST_STATE_MAX = 1;  


USB host flag constants USBHOST_FLAG_*
USBHOST_FLAG_NONE = $00000000;  
USBHOST_FLAG_SHARED = $00000001;  
USBHOST_FLAG_NOCACHE = $00000002;  


USB status code constants USB_STATUS_*
USB_STATUS_SUCCESS = 0; Function successful
USB_STATUS_DEVICE_DETACHED = 1; USB device was detached
USB_STATUS_DEVICE_UNSUPPORTED = 2; USB device is unsupported by the driver
USB_STATUS_HARDWARE_ERROR = 3; Hardware error of some form occurred
USB_STATUS_INVALID_DATA = 4; Invalid data was received
USB_STATUS_INVALID_PARAMETER = 5; An invalid parameter was passed to the function
USB_STATUS_NOT_PROCESSED = 6; The USB request has been submitted but not yet processed
USB_STATUS_OUT_OF_MEMORY = 7; Failed to allocate memory
USB_STATUS_TIMEOUT = 8; The operation timed out
USB_STATUS_UNSUPPORTED_REQUEST = 9; The request is unsupported
USB_STATUS_HARDWARE_STALL = 10; The device reported an endpoint STALL
USB_STATUS_OPERATION_FAILED = 11; The operation was not able to be completed
USB_STATUS_NOT_BOUND = 12; USB device is not bound to a driver
USB_STATUS_ALREADY_BOUND = 13; USB device is already bound to a driver
USB_STATUS_NOT_READY = 14; USB device is not in a ready state
USB_STATUS_NOT_COMPLETED = 15; The USB request has been scheduled but not yet completed
USB_STATUS_CANCELLED = 16; The USB request was cancelled
USB_STATUS_NOT_VALID = 17; The USB request is not valid


USB request flag constants USB_REQUEST_FLAG_*
USB_REQUEST_FLAG_NONE = $00000000;  
USB_REQUEST_FLAG_ALLOCATED = $00000001; Request data has been allocated by USBBufferAllocate (and can be freed by USBBufferRelease)
USB_REQUEST_FLAG_COMPATIBLE = $00000002; Request data is compatible with DMA requirements of host configuration (Can be passed directly to DMA)
USB_REQUEST_FLAG_ALIGNED = $00000004; Request data is aligned according to host configuration
USB_REQUEST_FLAG_SIZED = $00000008; Request data is sized according to host configuration
USB_REQUEST_FLAG_SHARED = $00000010; Request data has been allocated from Shared memory
USB_REQUEST_FLAG_NOCACHE = $00000020; Request data has been allocated from Non Cached memory


USB control phase constants USB_CONTROL_PHASE_*
USB_CONTROL_PHASE_SETUP = 0; Setup phase of a Control request (Using SetupData)
USB_CONTROL_PHASE_DATA = 1; Data phase of a Control request (Using Data buffer)
USB_CONTROL_PHASE_STATUS = 2; Status phase of a Control request (Using StatusData)


USB control timeout constants USB_CONTROL_*
USB_CONTROL_GET_TIMEOUT = 5000;  
USB_CONTROL_SET_TIMEOUT = 5000;  


USB packet size constants USB_*_*_PACKET_SIZE
USB_DEFAULT_MAX_PACKET_SIZE = 8; Default maximum packet size for unconfigured Endpoints
USB_ALTERNATE_MAX_PACKET_SIZE = 64;  
 
USB_MAX_PACKET_SIZE = 1024; Maximum packet size of any USB Endpoint (1024 is the maximum allowed by USB 2.0)


USB frame constants USB_FRAMES_*
USB_FRAMES_PER_MS = 1; Number of USB frames per millisecond


USB microframe constants USB_UFRAMES_*
USB_UFRAMES_PER_MS = 8; Number of USB microframes per millisecond


USB configuration attribute constants USB_CONFIGURATION_ATTRIBUTE_*
Values for bmAttributes in type TUSBConfigurationDescriptor
 
USB_CONFIGURATION_ATTRIBUTE_RESERVED_HIGH = $80;  
USB_CONFIGURATION_ATTRIBUTE_SELF_POWERED = $40;  
USB_CONFIGURATION_ATTRIBUTE_REMOTE_WAKEUP = $20;  
USB_CONFIGURATION_ATTRIBUTE_RESERVED_LOW = $1f;  


USB device status constants USB_DEVICE_STATUS_*
See Figure 9-4 of Section 9.4 of the USB 2.0 specification
Values for wStatus in type TUSBDeviceStatus (Device Recipient)
 
USB_DEVICE_STATUS_SELF_POWERED = (1 shl 0);  
USB_DEVICE_STATUS_REMOTE_WAKEUP = (1 shl 1);  


USB endpoint status constants USB_ENDPOINT_STATUS_*
See Figure 9-6 of Section 9.4 of the USB 2.0 specification
Values for vStatus in type TUSBDeviceStatus (Endpoint Recipient)
 
USB_ENDPOINT_STATUS_HALT = (1 shl 0);  


USB device speed constants USB_SPEED_*
USB_SPEED_HIGH = 0; {480 Mb/s}  
USB_SPEED_FULL = 1; {12 Mb/s}  
USB_SPEED_LOW = 2; {1.5 Mb/s}  
USB_SPEED_SUPER = 3; {5 Gb/s}  
USB_SPEED_SUPERPLUS = 4; {10 Gb/s}  


USB transfer type constants USB_TRANSFER_TYPE_*
Values for bmAttributes (bits 1..0) in type TUSBEndpointDescriptor
 
USB_TRANSFER_TYPE_CONTROL = 0;  
USB_TRANSFER_TYPE_ISOCHRONOUS = 1;  
USB_TRANSFER_TYPE_BULK = 2;  
USB_TRANSFER_TYPE_INTERRUPT = 3;  
USB_TRANSFER_TYPE_MASK = $03;  


USB transfer size constants USB_TRANSFER_SIZE_*
USB_TRANSFER_SIZE_8_BIT = 0;  
USB_TRANSFER_SIZE_16_BIT = 1;  
USB_TRANSFER_SIZE_32_BIT = 2;  
USB_TRANSFER_SIZE_64_BIT = 3;  


USB descriptor type constants USB_DESCRIPTOR_TYPE_*
See Table 9-5 in Section 9.4 of the USB 2.0 specification
Values for bDescriptorType in types TUSBDescriptorHeader and TUSBDeviceDescriptor
 
USB_DESCRIPTOR_TYPE_DEVICE = 1;  
USB_DESCRIPTOR_TYPE_CONFIGURATION = 2;  
USB_DESCRIPTOR_TYPE_STRING = 3;  
USB_DESCRIPTOR_TYPE_INTERFACE = 4;  
USB_DESCRIPTOR_TYPE_ENDPOINT = 5;  
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER = 6;  
USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION = 7;  
USB_DESCRIPTOR_TYPE_INTERFACE_POWER = 8;  
USB_DESCRIPTOR_TYPE_CLASS_DEVICE = $21; (USB_REQUEST_TYPE_CLASS shl 5) or USB_DESCRIPTOR_TYPE_DEVICE (See USB Device Class Definition for Audio Devices Specification)
USB_DESCRIPTOR_TYPE_CLASS_CONFIGURATION = $22; (USB_REQUEST_TYPE_CLASS shl 5) or USB_DESCRIPTOR_TYPE_CONFIGURATION
USB_DESCRIPTOR_TYPE_CLASS_STRING = $23; (USB_REQUEST_TYPE_CLASS shl 5) or USB_DESCRIPTOR_TYPE_STRING
USB_DESCRIPTOR_TYPE_CLASS_INTERFACE = $24; (USB_REQUEST_TYPE_CLASS shl 5) or USB_DESCRIPTOR_TYPE_INTERFACE
USB_DESCRIPTOR_TYPE_CLASS_ENDPOINT = $25; (USB_REQUEST_TYPE_CLASS shl 5) or USB_DESCRIPTOR_TYPE_ENDPOINT
USB_DESCRIPTOR_TYPE_HUB = $29;  


USB transfer direction constants USB_DIRECTION_*
See Table 9-2 of Section 9.3 of the USB 2.0 specification
Values for bmRequestType (bit 7) in type TUSBControlSetupData
 
USB_DIRECTION_OUT = 0; Host to Device
USB_DIRECTION_IN = 1; Device to Host


USB request type constants USB_REQUEST_TYPE_*
See Table 9-2 of Section 9.3 of the USB 2.0 specification
bits 6..5 of bmRequestType in type TUSBControlSetupData
 
USB_REQUEST_TYPE_STANDARD = 0;  
USB_REQUEST_TYPE_CLASS = 1;  
USB_REQUEST_TYPE_VENDOR = 2;  
USB_REQUEST_TYPE_RESERVED = 3;  


USB request recipient constants USB_REQUEST_RECIPIENT_*
See Table 9-2 of Section 9.3 of the USB 2.0 specification
bits 4..0 of bmRequestType in type TUSBControlSetupData
 
USB_REQUEST_RECIPIENT_DEVICE = 0;  
USB_REQUEST_RECIPIENT_INTERFACE = 1;  
USB_REQUEST_RECIPIENT_ENDPOINT = 2;  
USB_REQUEST_RECIPIENT_OTHER = 3;  


USB bmrequest type constants USB_BMREQUESTTYPE_*
See Table 9-2 of Section 9.3 of the USB 2.0 specification
Values of the bitfields within the bmRequestType member of TUSBControlSetupData
 
USB_BMREQUESTTYPE_DIR_OUT = (USB_DIRECTION_OUT shl 7);  
USB_BMREQUESTTYPE_DIR_IN = (USB_DIRECTION_IN shl 7);  
USB_BMREQUESTTYPE_DIR_MASK = ($01 shl 7);  
USB_BMREQUESTTYPE_TYPE_STANDARD = (USB_REQUEST_TYPE_STANDARD shl 5);  
USB_BMREQUESTTYPE_TYPE_CLASS = (USB_REQUEST_TYPE_CLASS shl 5);  
USB_BMREQUESTTYPE_TYPE_VENDOR = (USB_REQUEST_TYPE_VENDOR shl 5);  
USB_BMREQUESTTYPE_TYPE_RESERVED = (USB_REQUEST_TYPE_RESERVED shl 5);  
USB_BMREQUESTTYPE_TYPE_MASK = ($03 shl 5);  
USB_BMREQUESTTYPE_RECIPIENT_DEVICE = (USB_REQUEST_RECIPIENT_DEVICE shl 0);  
USB_BMREQUESTTYPE_RECIPIENT_INTERFACE = (USB_REQUEST_RECIPIENT_INTERFACE shl 0);  
USB_BMREQUESTTYPE_RECIPIENT_ENDPOINT = (USB_REQUEST_RECIPIENT_ENDPOINT shl 0);  
USB_BMREQUESTTYPE_RECIPIENT_OTHER = (USB_REQUEST_RECIPIENT_OTHER shl 0);  
USB_BMREQUESTTYPE_RECIPIENT_MASK = ($1f shl 0);  


USB device request constants USB_DEVICE_REQUEST_*
See Table 9-3 in Section 9.4 of the USB 2.0 specification
Values for bRequest in type TUSBControlSetupData
 
USB_DEVICE_REQUEST_GET_STATUS = 0;  
USB_DEVICE_REQUEST_CLEAR_FEATURE = 1;  
USB_DEVICE_REQUEST_SET_FEATURE = 3;  
USB_DEVICE_REQUEST_SET_ADDRESS = 5;  
USB_DEVICE_REQUEST_GET_DESCRIPTOR = 6;  
USB_DEVICE_REQUEST_SET_DESCRIPTOR = 7;  
USB_DEVICE_REQUEST_GET_CONFIGURATION = 8;  
USB_DEVICE_REQUEST_SET_CONFIGURATION = 9;  
USB_DEVICE_REQUEST_GET_INTERFACE = 10;  
USB_DEVICE_REQUEST_SET_INTERFACE = 11;  
USB_DEVICE_REQUEST_SYNCH_FRAME = 12;  


USB device feature constants USB_DEVICE_FEATURE_*
See Table 9-6 in Section 9.4 of the USB 2.0 specification
Values for wValue in type TUSBControlSetupData
 
USB_DEVICE_FEATURE_ENDPOINT_HALT = 0; Endpoint Only
USB_DEVICE_FEATURE_REMOTE_WAKEUP = 1; Device Only
USB_DEVICE_FEATURE_TEST_MODE = 2; Device Only


USB test mode constants USB_DEVICE_TEST_MODE_*
See Table 9-7 in Section 9.4 of the USB 2.0 specification
Values for wIndex in type TUSBControlSetupData
 
USB_DEVICE_TEST_MODE_J = $01;  
USB_DEVICE_TEST_MODE_K = $02;  
USB_DEVICE_TEST_MODE_SE0_NAK = $03;  
USB_DEVICE_TEST_MODE_PACKET = $04;  
USB_DEVICE_TEST_MODE_FORCE_ENABLE = $05;  


USB packet ID value constants USB_PACKETID_*
See ????????
 
USB_PACKETID_UNDEF_0 = $f0;  
USB_PACKETID_OUT = $e1;  
USB_PACKETID_ACK = $d2;  
USB_PACKETID_DATA0 = $c3;  
USB_PACKETID_UNDEF_4 = $b4;  
USB_PACKETID_SOF = $a5;  
USB_PACKETID_UNDEF_6 = $96;  
USB_PACKETID_UNDEF_7 = $87;  
USB_PACKETID_UNDEF_8 = $78;  
USB_PACKETID_IN = $69;  
USB_PACKETID_NAK = $5a;  
USB_PACKETID_DATA1 = $4b;  
USB_PACKETID_PREAMBLE = $3c;  
USB_PACKETID_SETUP = $2d;  
USB_PACKETID_STALL = $1e;  
USB_PACKETID_UNDEF_F = $0f;  


USB class code constants USB_CLASS_CODE_*
bDeviceClass / bInterfaceClass
Note that only the hub class is defined in the USB 2.0 specification itself the other standard class codes are defined in additional specifications
 
USB_CLASS_CODE_INTERFACE_SPECIFIC = $00; Use class code info from Interface Descriptors
USB_CLASS_CODE_AUDIO = $01; Audio device
USB_CLASS_CODE_COMMUNICATIONS_AND_CDC_CONTROL = $02; Communication device class
USB_CLASS_CODE_HID = $03; HID device class
USB_CLASS_CODE_PHYSICAL = $05; Physical device class
USB_CLASS_CODE_IMAGE = $06; Still Imaging device
USB_CLASS_CODE_PRINTER = $07; Printer device
USB_CLASS_CODE_MASS_STORAGE = $08; Mass Storage device
USB_CLASS_CODE_HUB = $09; Hub Device
USB_CLASS_CODE_CDC_DATA = $0a; CDC data device
USB_CLASS_CODE_SMART_CARD = $0b; Smart Card device
USB_CLASS_CODE_CONTENT_SECURITY = $0d; Content Security device
USB_CLASS_CODE_VIDEO = $0e; Video device
USB_CLASS_CODE_PERSONAL_HEALTHCARE = $0f; Personal Healthcare device
USB_CLASS_CODE_AUDIO_VIDEO = $10; Audio/Video Devices
USB_CLASS_CODE_BILLBOARD = $11; Billboard Device
USB_CLASS_CODE_DIAGNOSTIC = $DC; Diagnostic Device
USB_CLASS_CODE_WIRELESS_CONTROLLER = $e0; Wireless Controller
USB_CLASS_CODE_MISCELLANEOUS = $ef; Miscellaneous
USB_CLASS_CODE_APPLICATION_SPECIFIC = $fe; Application Specific
USB_CLASS_CODE_VENDOR_SPECIFIC = $ff; Vendor Specific


USB subclass code constants USB_SUBCLASS_*
bInterfaceSubClass
See: http://www.usb.org/developers/defined_class/
 
Communications Devices
USB_SUBCLASS_CDC_DLCM = $01; Direct Line Control Model (USBPSTN1.2)
USB_SUBCLASS_CDC_ACM = $02; Abstract Control Model (USBPSTN1.2)
USB_SUBCLASS_CDC_TCM = $03; Telephone Control Model (USBPSTN1.2)
USB_SUBCLASS_CDC_MCCM = $04; Multi-Channel Control Model (USBISDN1.2)
USB_SUBCLASS_CDC_CCM = $05; CAPI Control Model (USBISDN1.2)
USB_SUBCLASS_CDC_ETHERNET = $06; Ethernet Networking Control Model (USBECM1.2)
USB_SUBCLASS_CDC_WHCM = $08; Wireless Handset Control Model (USBWMC1.1)
USB_SUBCLASS_CDC_DMM = $09; Device Management Model (USBWMC1.1)
USB_SUBCLASS_CDC_MDLM = $0a; Mobile Direct Line Model (USBWMC1.1)
USB_SUBCLASS_CDC_OBEX = $0b; OBEX (USBWMC1.1)
USB_SUBCLASS_CDC_EEM = $0c; Ethernet Emulation Model (USBEEM1.0)
USB_SUBCLASS_CDC_NCM = $0d; Network Control Model (USBNCM1.0)
USB_SUBCLASS_CDC_MBIM = $0e;  
Still Image Devices
USB_SUBCLASS_IMAGE_DEFAULT = $01;  
Mass Storage Devices
USB_SUBCLASS_MASS_STORAGE_DEFAULT = $00; SCSI command set not reported, De facto use
USB_SUBCLASS_MASS_STORAGE_RBC = $01; Reduced Block Commands (RBC), INCITS 330:2000, available at http://www.t10.org
USB_SUBCLASS_MASS_STORAGE_MMC5 = $02; Multi-Media Command Set 5 (MMC-5), T10/1675-D available at http://www.t10.org
USB_SUBCLASS_MASS_STORAGE_QIC157 = $03; Obsolete was QIC-157
USB_SUBCLASS_MASS_STORAGE_UFI = $04; UFI Specifies how to interface Floppy Disk Drives to USB
USB_SUBCLASS_MASS_STORAGE_SFF8070I = $05; Obsolete Was SFF-8070i
USB_SUBCLASS_MASS_STORAGE_SCSI = $06; SCSI transparent command set
USB_SUBCLASS_MASS_STORAGE_LSDFS = $07; {LSD FS }  
USB_SUBCLASS_MASS_STORAGE_IEEE1667 = $08; IEEE 1667 Standard Protocol for Authentication in Host Attachments of Transient Storage Devices (IEEE 1667) available at www.ieee1667.com
USB_SUBCLASS_MASS_STORAGE_VENDOR_SPECIFIC = $ff; Specific to device vendor, De facto use
Content Security Devices
USB_SUBCLASS_CONTENT_SECURITY_DEFAULT = $00;  
Audio/Video Devices
USB_SUBCLASS_AUDIO_VIDEO_CONTROL = $01; Audio/Video Device ? AVControl Interface
USB_SUBCLASS_AUDIO_VIDEO_DATA_VIDEO = $02; Audio/Video Device ? AVData Video Streaming Interface
USB_SUBCLASS_AUDIO_VIDEO_DATA_AUDIO = $03; Audio/Video Device ? AVData Audio Streaming Interface
Billboard Devices
USB_SUBCLASS_BILLBOARD_DEFAULT = $00;  
Diagnostic Device
USB_SUBCLASS_DIAGNOSTIC_DEFAULT = $01;  
Wireless Controller
USB_SUBCLASS_WIRELESS_CONTROLLER_BLUETOOTH = $01;  
USB_SUBCLASS_WIRELESS_CONTROLLER_USB = $02;  
Miscellaneous
USB_SUBCLASS_MISCELLANEOUS_SYNC = $01;  
USB_SUBCLASS_MISCELLANEOUS_IAD_WAMP = $02; Interface Association Descriptor / Wire Adapter Multifunction Peripheral
USB_SUBCLASS_MISCELLANEOUS_CBAF = $03; Cable Based Association Framework
USB_SUBCLASS_MISCELLANEOUS_RNDIS = $04;  
USB_SUBCLASS_MISCELLANEOUS_USB3VISION = $05;  
Application Specific
USB_SUBCLASS_APPLICATION_SPECIFIC_DFU = $01;  
USB_SUBCLASS_APPLICATION_SPECIFIC_IRDA = $02;  
USB_SUBCLASS_APPLICATION_SPECIFIC_TMC = $02;  
Vendor Specific
USB_SUBCLASS_VENDOR_SPECIFIC = $ff; Vendor Specific


USB protocol code constants USB_PROTOCOL_*
bInterfaceProtocol
See: http://www.usb.org/developers/defined_class/
 
Communications Devices
USB_PROTOCOL_CDC_ACM_NONE = 0; Abstract Control Model - No class specific protocol required
USB_PROTOCOL_CDC_ACM_AT_V25TER = 1; Abstract Control Model - AT Commands: V.250 etc
USB_PROTOCOL_CDC_ACM_AT_PCCA101 = 2; Abstract Control Model - AT Commands defined by PCCA-101
USB_PROTOCOL_CDC_ACM_AT_PCCA101_WAKE = 3; Abstract Control Model - AT Commands defined by PCCA-101 & Annex O
USB_PROTOCOL_CDC_ACM_AT_GSM = 4; Abstract Control Model - AT Commands defined by GSM 07.07
USB_PROTOCOL_CDC_ACM_AT_3G = 5; Abstract Control Model - AT Commands defined by 3GPP 27.007
USB_PROTOCOL_CDC_ACM_AT_CDMA = 6; Abstract Control Model - AT Commands defined by TIA for CDMA
USB_PROTOCOL_CDC_ACM_VENDOR = $ff; Abstract Control Model - Vendor-specific
USB_PROTOCOL_CDC_EEM = 7; Ethernet Emulation Model
USB_PROTOCOL_CDC_NCM_NTB = 1; Network Control Model - Network Transfer Block
USB_PROTOCOL_CDC_MBIM_NTB = 2; Network Transfer Block
Still Image Devices
USB_PROTOCOL_IMAGE_DEFAULT = $01;  
Mass Storage Devices
USB_PROTOCOL_MASS_STORAGE_CBI = $00; CBI (with command completion interrupt) USB Mass Storage Class Control/Bulk/Interrupt Transport
USB_PROTOCOL_MASS_STORAGE_CB = $01; CBI (with no command completion interrupt) USB Mass Storage Class Control/Bulk/Interrupt Transport
USB_PROTOCOL_MASS_STORAGE_BBB = $50; BBB USB Mass Storage Class Bulk-Only Transport
USB_PROTOCOL_MASS_STORAGE_UAS = $62; UAS
USB_PROTOCOL_MASS_STORAGE_VENDOR_SPECIFIC = $ff; Specific to device vendor, De facto use
Hub Devices
USB_PROTOCOL_HUB_FULLSPEED = $00; Full speed Hub
USB_PROTOCOL_HUB_HIGHSPEED_SINGLE_TT = $01; Hi-speed hub with single Transaction Translator
USB_PROTOCOL_HUB_HIGHSPEED_MULTI_TT = $02; Hi-speed hub with multiple Transaction Translators
Content Security Devices
USB_PROTOCOL_CONTENT_SECURITY_DEFAULT = $00;  
Audio/Video Devices
USB_PROTOCOL_AUDIO_VIDEO_DEFAULT = $00;  
Billboard Devices
USB_PROTOCOL_BILLBOARD_DEFAULT = $00;  
Diagnostic Device
USB_PROTOCOL_DIAGNOSTIC_DEFAULT = $01;  
Wireless Controller
USB_PROTOCOL_WIRELESS_CONTROLLER_BLUETOOTH = $01; See: http://www.bluetooth.com/
USB_PROTOCOL_WIRELESS_CONTROLLER_UWB = $02; See: Wireless USB Specification in Chapter 8
USB_PROTOCOL_WIRELESS_CONTROLLER_NDIS = $03; See: http://www.microsoft.com/windowsmobile/mobileoperators/default.mspx
USB_PROTOCOL_WIRELESS_CONTROLLER_BLUETOOTH_AMP = $04; See: http://www.bluetooth.com/
USB_PROTOCOL_WIRELESS_CONTROLLER_USB_HOST = $01; Host Wire Adapter Control/Data interface. Definition can be found in the Wireless USB Specification in Chapter 8
USB_PROTOCOL_WIRELESS_CONTROLLER_USB_DEVICE = $02; Device Wire Adapter Control/Data interface. Definition can be found in the Wireless USB Specification in Chapter 8
USB_PROTOCOL_WIRELESS_CONTROLLER_USB_DEVOCE_ISOC = $03; Device Wire Adapter Isochronous interface. Definition can be found in the Wireless USB Specification in Chapter 8
Miscellaneous
USB_PROTOCOL_MISCELLANEOUS_ACTIVESYNC = $01; Active Sync device
USB_PROTOCOL_MISCELLANEOUS_PALMSYNC = $02; Palm Sync
USB_PROTOCOL_MISCELLANEOUS_IAD = $01; Interface Association Descriptor. The usage of this class code triple is defined in the Interface Association Descriptor ECN
USB_PROTOCOL_MISCELLANEOUS_WAMP = $02; Wire Adapter Multifunction Peripheral programming interface. Definition can be found in the Wireless USB Specification in Chapter 8.
USB_PROTOCOL_MISCELLANEOUS_CBAF = $01; Cable Based Association Framework. This is defined in the Association Model addendum to the Wireless USB specification.
USB_PROTOCOL_MISCELLANEOUS_RNDIS_ETHERNET = $01; RNDIS over Ethernet
USB_PROTOCOL_MISCELLANEOUS_RNDIS_WIFI = $02; RNDIS over WiFi
USB_PROTOCOL_MISCELLANEOUS_RNDIS_WIMAX = $03; RNDIS over WiMAX
USB_PROTOCOL_MISCELLANEOUS_RNDIS_WWAN = $04; RNDIS over WWAN
USB_PROTOCOL_MISCELLANEOUS_RNDIS_IPV4 = $05; RNDIS for Raw IPv4
USB_PROTOCOL_MISCELLANEOUS_RNDIS_IPV6 = $06; RNDIS for Raw IPv6
USB_PROTOCOL_MISCELLANEOUS_RNDIS_GPRS = $07; RNDIS for GPRS
USB_PROTOCOL_MISCELLANEOUS_USB3VISION_CONTROL = $00; USB3 Vision Control Interface
USB_PROTOCOL_MISCELLANEOUS_USB3VISION_EVENT = $01; USB3 Vision Event Interface
USB_PROTOCOL_MISCELLANEOUS_USB3VISION_STREAM = $02; USB3 Vision Streaming Interface
Application Specific
USB_PROTOCOL_APPLICATION_SPECIFIC_DFU_DEFAULT = $01; Device Firmware Upgrade
USB_PROTOCOL_APPLICATION_SPECIFIC_IRDA_DEFAULT = $00; IRDA Bridge device
USB_PROTOCOL_APPLICATION_SPECIFIC_TMC_DEFAULT = $00; USB Test and Measurement Device
USB_PROTOCOL_APPLICATION_SPECIFIC_TMC_488 = $01; USB Test and Measurement Device conforming to the USBTMC USB488 Subclass Specification


USB primary language ID constants USB_LANG_*
See Language Identifiers supplement to the USB 2.0 specification
These are the first 10 bits of the 16-bit language identifier
 
Reserved $00
USB_LANG_ARABIC = $01; Arabic
USB_LANG_BULGARIAN = $02; Bulgarian
USB_LANG_CATALAN = $03; Catalan
USB_LANG_CHINESE = $04; Chinese
USB_LANG_CZECH = $05; Czech
USB_LANG_DANISH = $06; Danish
USB_LANG_GERMAN = $07; German
USB_LANG_GREEK = $08; Greek
USB_LANG_ENGLISH = $09; English
USB_LANG_SPANISH = $0a; Spanish
USB_LANG_FINNISH = $0b; Finnish
USB_LANG_FRENCH = $0c; French
USB_LANG_HEBREW = $0d; Hebrew
USB_LANG_HUNGARIAN = $0e; Hungarian
USB_LANG_ICELANDIC = $0f; Icelandic
USB_LANG_ITALIAN = $10; Italian
USB_LANG_JAPANESE = $11; Japanese
USB_LANG_KOREAN = $12; Korean
USB_LANG_DUTCH = $13; Dutch
USB_LANG_NORWEGIAN = $14; Norwegian
USB_LANG_POLISH = $15; Polish
USB_LANG_PORTUGUESE = $16; Portuguese
USB_LANG_ROMANIAN = $18; Romanian
USB_LANG_RUSSIAN = $19; Russian
USB_LANG_CROATIAN = $1a; Croatian
USB_LANG_SERBIAN = $1a; Serbian
USB_LANG_SLOVAK = $1b; Slovak
USB_LANG_ALBANIAN = $1c; Albanian
USB_LANG_SWEDISH = $1d; Swedish
USB_LANG_THAI = $1e; Thai
USB_LANG_TURKISH = $1f; Turkish
USB_LANG_URDU = $20; Urdu
USB_LANG_INDONESIAN = $21; Indonesian
USB_LANG_UKRANIAN = $22; Ukrainian
USB_LANG_BELARUSIAN = $23; Belarusian
USB_LANG_SLOVENIAN = $24; Slovenian
USB_LANG_ESTONIAN = $25; Estonian
USB_LANG_LATVIAN = $26; Latvian
USB_LANG_LITHUANIAN = $27; Lithuanian
USB_LANG_FARSI = $29; Farsi
USB_LANG_VIETNAMESE = $2a; Vietnamese
USB_LANG_ARMENIAN = $2b; Armenian
USB_LANG_AZERI = $2c; Azeri
USB_LANG_BASQUE = $2d; Basque
USB_LANG_MACEDONIAN = $2f; Macedonian
USB_LANG_AFRIKAANS = $36; Afrikaans
USB_LANG_GEORGIAN = $37; Georgian
USB_LANG_FAEROESE = $38; Faeroese
USB_LANG_HINDI = $39; Hindi
USB_LANG_MALAY = $3e; Malay
USB_LANG_KAZAK = $3f; Kazak
USB_LANG_SWAHILI = $41; Swahili
USB_LANG_UZBEK = $43; Uzbek
USB_LANG_TATAR = $44; Tatar
USB_LANG_BENGALI = $45; Bengali
USB_LANG_PUNJABI = $46; Punjabi
USB_LANG_GUJARATI = $47; Gujarati
USB_LANG_ORIYA = $48; Oriya
USB_LANG_TAMIL = $49; Tamil
USB_LANG_TELUGU = $4a; Telugu
USB_LANG_KANNADA = $4b; Kannada
USB_LANG_MALAYALAM = $4c; Malayalam
USB_LANG_ASSAMESE = $4d; Assamese
USB_LANG_MARATHI = $4e; Marathi
USB_LANG_SANSKRIT = $4f; Sanskrit
USB_LANG_KONKANI = $57; Konkani
USB_LANG_MANIPURI = $58; Manipuri
USB_LANG_SINDHI = $59; Sindhi
USB_LANG_KASHMIRI = $60; Kashmiri
USB_LANG_NEPALI = $61; Nepali
Reserved $62-$fe
USB_LANG_HID = $ff; Reserved for USB HID Class use
Reserved $100-$3ff
USB_PRIMARY_LANGUAGE_MASK = $3ff;  


USB sublanguage ID constants USB_SUBLANG_*
See Language Identifiers supplement to the USB 2.0 specification
These are the upper 6 bits of the 16-bit language identifier
 
Reserved $00-$02
USB_SUBLANG_ARABIC_SAUDI_ARABIA = $01; Arabic (Saudi Arabia)
USB_SUBLANG_ARABIC_IRAQ = $02; Arabic (Iraq)
USB_SUBLANG_ARABIC_EGYPT = $03; Arabic (Egypt)
USB_SUBLANG_ARABIC_LIBYA = $04; Arabic (Libya)
USB_SUBLANG_ARABIC_ALGERIA = $05; Arabic (Algeria)
USB_SUBLANG_ARABIC_MOROCCO = $06; Arabic (Morocco)
USB_SUBLANG_ARABIC_TUNISIA = $07; Arabic (Tunisia)
USB_SUBLANG_ARABIC_OMAN = $08; Arabic (Oman)
USB_SUBLANG_ARABIC_YEMEN = $09; Arabic (Yemen)
USB_SUBLANG_ARABIC_SYRIA = $10; Arabic (Syria)
USB_SUBLANG_ARABIC_JORDAN = $11; Arabic (Jordan)
USB_SUBLANG_ARABIC_LEBANON = $12; Arabic (Lebanon)
USB_SUBLANG_ARABIC_KUWAIT = $13; Arabic (Kuwait)
USB_SUBLANG_ARABIC_UAE = $14; Arabic (U.A.E.)
USB_SUBLANG_ARABIC_BAHRAIN = $15; Arabic (Bahrain)
USB_SUBLANG_ARABIC_QATAR = $16; Arabic (Qatar)
USB_SUBLANG_AZERI_CYRILLIC = $01; Azeri (Cyrillic)
USB_SUBLANG_AZERI_LATIN = $02; Azeri (Latin)
USB_SUBLANG_CHINESE_TRADITIONAL = $01; Chinese (Traditional)
USB_SUBLANG_CHINESE_SIMPLIFIED = $02; Chinese (Simplified)
USB_SUBLANG_CHINESE_HONGKONG = $03; Chinese (Hong Kong SAR, PRC)
USB_SUBLANG_CHINESE_SINGAPORE = $04; Chinese (Singapore)
USB_SUBLANG_CHINESE_MACAU = $05; Chinese (Macau SAR)
USB_SUBLANG_DUTCH = $01; Dutch
USB_SUBLANG_DUTCH_BELGIAN = $02; Dutch (Belgian)
USB_SUBLANG_ENGLISH_US = $01; English (US)
USB_SUBLANG_ENGLISH_UK = $02; English (UK)
USB_SUBLANG_ENGLISH_AUS = $03; English (Australian)
USB_SUBLANG_ENGLISH_CAN = $04; English (Canadian)
USB_SUBLANG_ENGLISH_NZ = $05; English (New Zealand)
USB_SUBLANG_ENGLISH_EIRE = $06; English (Ireland)
USB_SUBLANG_ENGLISH_SOUTH_AFRICA = $07; English (South Africa)
USB_SUBLANG_ENGLISH_JAMAICA = $08; English (Jamaica)
USB_SUBLANG_ENGLISH_CARIBBEAN = $09; English (Caribbean)
USB_SUBLANG_ENGLISH_BELIZE = $0a; English (Belize)
USB_SUBLANG_ENGLISH_TRINIDAD = $0b; English (Trinidad)
USB_SUBLANG_ENGLISH_PHILIPPINES = $0c; English (Zimbabwe)
USB_SUBLANG_ENGLISH_ZIMBABWE = $0d; English (Philippines)
USB_SUBLANG_FRENCH = $01; French
USB_SUBLANG_FRENCH_BELGIAN = $02; French (Belgian)
USB_SUBLANG_FRENCH_CANADIAN = $03; French (Canadian)
USB_SUBLANG_FRENCH_SWISS = $04; French (Swiss)
USB_SUBLANG_FRENCH_LUXEMBOURG = $05; French (Luxembourg)
USB_SUBLANG_FRENCH_MONACO = $06; French (Monaco)
USB_SUBLANG_GERMAN = $01; German
USB_SUBLANG_GERMAN_SWISS = $02; German (Swiss)
USB_SUBLANG_GERMAN_AUSTRIAN = $03; German (Austrian)
USB_SUBLANG_GERMAN_LUXEMBOURG = $04; German (Luxembourg)
USB_SUBLANG_GERMAN_LIECHTENSTEIN = $05; German (Liechtenstein)
USB_SUBLANG_ITALIAN = $01; Italian
USB_SUBLANG_ITALIAN_SWISS = $02; Italian (Swiss)
USB_SUBLANG_KASHMIRI_INDIA = $02; Kashmiri (India)
USB_SUBLANG_KOREAN = $01; Korean
USB_SUBLANG_LITHUANIAN = $01; Lithuanian
USB_SUBLANG_MALAY_MALAYSIA = $01; Malay (Malaysia)
USB_SUBLANG_MALAY_BRUNEI_DARUSSALAM = $02; Malay (Brunei Darassalam)
USB_SUBLANG_NEPALI_INDIA = $02; Nepali (India)
USB_SUBLANG_NORWEGIAN_BOKMAL = $01; Norwegian (Bokmal)
USB_SUBLANG_NORWEGIAN_NYNORSK = $02; Norwegian (Nynorsk)
USB_SUBLANG_PORTUGUESE = $01; Portuguese (Brazilian)
USB_SUBLANG_PORTUGUESE_BRAZILIAN = $02; Portuguese
USB_SUBLANG_SERBIAN_LATIN = $02; Serbian (Latin)
USB_SUBLANG_SERBIAN_CYRILLIC = $03; Serbian (Cyrillic)
USB_SUBLANG_SPANISH = $01; Spanish (Castilian)
USB_SUBLANG_SPANISH_MEXICAN = $02; Spanish (Mexican)
USB_SUBLANG_SPANISH_MODERN = $03; Spanish (Modern)
USB_SUBLANG_SPANISH_GUATEMALA = $04; Spanish (Guatemala)
USB_SUBLANG_SPANISH_COSTA_RICA = $05; Spanish (Costa Rica)
USB_SUBLANG_SPANISH_PANAMA = $06; Spanish (Panama)
USB_SUBLANG_SPANISH_DOMINICAN_REPUBLIC = $07; Spanish (Dominican Republic)
USB_SUBLANG_SPANISH_VENEZUELA = $08; Spanish (Venezuela)
USB_SUBLANG_SPANISH_COLOMBIA = $09; Spanish (Colombia)
USB_SUBLANG_SPANISH_PERU = $0a; Spanish (Peru)
USB_SUBLANG_SPANISH_ARGENTINA = $0b; Spanish (Argentina)
USB_SUBLANG_SPANISH_ECUADOR = $0c; Spanish (Ecuador)
USB_SUBLANG_SPANISH_CHILE = $0d; Spanish (Chile)
USB_SUBLANG_SPANISH_URUGUAY = $0e; Spanish (Uruguay)
USB_SUBLANG_SPANISH_PARAGUAY = $0f; Spanish (Paraguay)
USB_SUBLANG_SPANISH_BOLIVIA = $10; Spanish (Bolivia)
USB_SUBLANG_SPANISH_EL_SALVADOR = $11; Spanish (El Salvador)
USB_SUBLANG_SPANISH_HONDURAS = $12; Spanish (Honduras)
USB_SUBLANG_SPANISH_NICARAGUA = $13; Spanish (Nicaragua)
USB_SUBLANG_SPANISH_PUERTO_RICO = $14; Spanish (Puerto Rico)
USB_SUBLANG_SWEDISH = $01; Swedish
USB_SUBLANG_SWEDISH_FINLAND = $02; Swedish (Finland)
USB_SUBLANG_URDU_PAKISTAN = $01; Urdu (Pakistan)
USB_SUBLANG_URDU_INDIA = $02; Urdu (India)
USB_SUBLANG_UZBEK_LATIN = $01; Uzbek (Latin)
USB_SUBLANG_UZBEK_CYRILLIC = $02; Uzbek (Cyrillic)
USB_SUBLANG_HID_USAGE_DATA_DESCRIPTOR = $01; HID (Usage Data Descriptor)
USB_SUBLANG_HID_VENDOR_DEFINED_1 = $3c; HID (Vendor Defined 1)
USB_SUBLANG_HID_VENDOR_DEFINED_2 = $3d; HID (Vendor Defined 2)
USB_SUBLANG_HID_VENDOR_DEFINED_3 = $3e; HID (Vendor Defined 3)
USB_SUBLANG_HID_VENDOR_DEFINED_4 = $3f; HID (Vendor Defined 4)


USB primary language identifier constants USB_LANGID_*
See Language Identifiers supplement to the USB 2.0 specification
 
USB_LANGID_US_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_US shl 10)); English (US)
USB_LANGID_UK_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_UK shl 10)); English (UK)
USB_LANGID_AUS_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_AUS shl 10)); English (Australian)
USB_LANGID_CAN_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_CAN shl 10)); English (Canadian)
USB_LANGID_NZ_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_NZ shl 10)); English (New Zealand)
USB_LANGID_EIRE_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_EIRE shl 10)); English (Ireland)
USB_LANGID_SOUTH_AFRICA_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_SOUTH_AFRICA shl 10)); English (South Africa)
USB_LANGID_JAMAICA_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_JAMAICA shl 10)); English (Jamaica)
USB_LANGID_CARIBBEAN_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_CARIBBEAN shl 10)); English (Caribbean)
USB_LANGID_BELIZE_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_BELIZE shl 10)); English (Belize)
USB_LANGID_TRINIDAD_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_TRINIDAD shl 10)); English (Trinidad)
USB_LANGID_PHILIPPINES_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_PHILIPPINES shl 10)); English (Philippines)
USB_LANGID_ZIMBABWE_ENGLISH = (USB_LANG_ENGLISH or (USB_SUBLANG_ENGLISH_ZIMBABWE shl 10)); English (Zimbabwe)
 
USB_LANGID_USAGE_HID = (USB_LANG_HID or (USB_SUBLANG_HID_USAGE_DATA_DESCRIPTOR shl 10));  
USB_LANGID_VENDOR1_HID = (USB_LANG_HID or (USB_SUBLANG_HID_VENDOR_DEFINED_1 shl 10));  
USB_LANGID_VENDOR2_HID = (USB_LANG_HID or (USB_SUBLANG_HID_VENDOR_DEFINED_2 shl 10));  
USB_LANGID_VENDOR3_HID = (USB_LANG_HID or (USB_SUBLANG_HID_VENDOR_DEFINED_3 shl 10));  
USB_LANGID_VENDOR4_HID = (USB_LANG_HID or (USB_SUBLANG_HID_VENDOR_DEFINED_4 shl 10));  


USB vendor ID constants USB_VENDORID_*
USB_VENDORID_REALTEK = $0BDA; Realtek


USB tree output constants USB_TREE_*
USB_TREE_SPACES_PER_LEVEL = 6;  
USB_TREE_LINES_PER_PORT = 2;  


USB logging constants USB_LOG_*
USB_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; USB debugging messages
USB_LOG_LEVEL_INFO = LOG_LEVEL_INFO; USB informational messages, such as a device being attached or detached
USB_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; USB error messages
USB_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No USB messages


USB hub specific constants USB_HUB_*
USB_HUB_PREFIX = 'USBHub'; Name prefix for USB Hubs


USB hub type constants USBHUB_TYPE_*
USBHUB_TYPE_NONE = 0;  


USB hub state constants USBHUB_STATE_*
USBHUB_STATE_DETACHED = 0;  
USBHUB_STATE_DETACHING = 1;  
USBHUB_STATE_ATTACHING = 2;  
USBHUB_STATE_ATTACHED = 3;  


USB hub flag constants USBHUB_FLAG_*
USBHUB_FLAG_NONE = $00000000;  


USB hub thread constants USBHUB_THREAD_*
USBHUB_THREAD_STACK_SIZE = SIZE_32K; Stack size of USB hub thread}
USBHUB_THREAD_PRIORITY = THREAD_PRIORITY_HIGHEST; Priority of USB hub thread
USBHUB_THREAD_NAME = 'USB Hub'; Name of USB hub thread


USB hub driver constants USBHUB_DRIVER_*
USBHUB_DRIVER_NAME = 'USB Hub Driver'; Name of USB hub driver


USB port reset constants USB_PORT_RESET_*
USB_PORT_RESET_TIMEOUT = 800; Maximum milliseconds to wait for a port to reset (800 is the same value that Linux uses)
USB_PORT_RESET_DELAY = 10; Milliseconds between each status check on the port while waiting for it to finish being reset (Linux uses several values, but 10 is the default case)
USB_PORT_RESET_RECOVERY = 30; Milliseconds to wait after port reset to allow the device attached to the port to recover before any data transfers. USB 2.0 spec says 10ms


USB hub characteristic constants USB_HUB_CHARACTERISTIC_*
Values for wHubCharacteristics in type TUSBHubDescriptor
 
USB_HUB_CHARACTERISTIC_IS_COMPOUND_DEVICE = (1 shl 2);  


USB hub feature constants USB_C_HUB_*
See Table 11-17 in Section 11.24.2 of the USB 2.0 specification
 
USB_C_HUB_LOCAL_POWER = 0;  
USB_C_HUB_OVER_CURRENT = 1;  


USB port feature constants USB_PORT_*
See Table 11-17 in Section 11.24.2 of the USB 2.0 specification
 
USB_PORT_CONNECTION = 0;  
USB_PORT_ENABLE = 1;  
USB_PORT_SUSPEND = 2;  
USB_PORT_OVER_CURRENT = 3;  
USB_PORT_RESET = 4;  
USB_PORT_POWER = 8;  
USB_PORT_LOW_SPEED = 9;  
USB_C_PORT_CONNECTION = 16;  
USB_C_PORT_ENABLE = 17;  
USB_C_PORT_SUSPEND = 18;  
USB_C_PORT_OVER_CURRENT = 19;  
USB_C_PORT_RESET = 20;  
USB_PORT_TEST = 21;  
USB_PORT_INDICATOR = 22;  


USB hub class request constants USB_HUB_REQUEST_*
See Table 11-16 in Section 11.24.2 of the USB 2.0 specification
 
USB_HUB_REQUEST_GET_STATUS = 0;  
USB_HUB_REQUEST_CLEAR_FEATURE = 1;  
USB_HUB_REQUEST_SET_FEATURE = 3;  
USB_HUB_REQUEST_GET_DESCRIPTOR = 6;  
USB_HUB_REQUEST_SET_DESCRIPTOR = 7;  
USB_HUB_REQUEST_CLEAR_TT_BUFFER = 8;  
USB_HUB_REQUEST_RESET_TT = 9;  
USB_HUB_REQUEST_GET_TT_STATE = 10;  
USB_HUB_REQUEST_STOP_TT = 11;  


USB port status constants USB_PORT_STATUS_*
See Table 11-21 in Section 11.24.2.7.1 of the USB 2.0 specification
Values for wPortStatus in type TUSBPortStatus
 
USB_PORT_STATUS_CONNNECTED = (1 shl 0);  
USB_PORT_STATUS_ENABLED = (1 shl 1);  
USB_PORT_STATUS_SUSPENDED = (1 shl 2);  
USB_PORT_STATUS_OVERCURRENT = (1 shl 3);  
USB_PORT_STATUS_RESET = (1 shl 4);  
USB_PORT_STATUS_POWERED = (1 shl 8);  
USB_PORT_STATUS_LOW_SPEED_ATTACHED = (1 shl 9);  
USB_PORT_STATUS_HIGH_SPEED_ATTACHED = (1 shl 10);  
USB_PORT_STATUS_TEST_MODE = (1 shl 11);  
USB_PORT_STATUS_INDICATOR_CONTROL = (1 shl 12);  


USB port change constants USB_PORT_CHANGE_*
See Table 11-20 in Section 11.24.2.6 of the USB 2.0 specification
Values for wPortChange in type TUSBPortStatus
 
USB_PORT_CHANGE_CONNECTED = (1 shl 0);  
USB_PORT_CHANGE_ENABLED = (1 shl 1);  
USB_PORT_CHANGE_SUSPENDED = (1 shl 2);  
USB_PORT_CHANGE_OVERCURRENT = (1 shl 3);  
USB_PORT_CHANGE_RESET = (1 shl 4);  


USB hub status constants USB_HUB_STATUS_*
See Table 11-19 in Section 11.24.2.6 of the USB 2.0 specification
Values for wHubStatus in type TUSBHubStatus
 
USB_HUB_STATUS_LOCAL_POWER = (1 shl 0);  
USB_HUB_STATUS_OVERCURRENT = (1 shl 1);  


USB hub change constants USB_HUB_CHANGE_*
See Table 11-20 in Section 11.24.2.6 of the USB 2.0 specification
Values for wHubChange in type TUSBHubStatus
 
USB_HUB_CHANGE_LOCAL_POWER = (1 shl 0);  
USB_HUB_CHANGE_OVERCURRENT = (1 shl 1);  


Type definitions


To be documented

Public variables



USB logging

USB_DEFAULT_LOG_LEVEL:LongWord = USB_LOG_LEVEL_DEBUG; Minimum level for USB messages. Only messages with level greater than or equal to this will be printed.
USB_LOG_ENABLED:Boolean;


Function declarations



Initialization functions

procedure USBInit;
Description: Performs basic initialization of the USB core driver, after this devices, hosts and drivers can be registered however nothing will work until USBStart is called
Note None documented


function USBStart:LongWord;
Description: Starts all registered USB hosts, starts the USB hub thread and begins the USB enumeration process. USB enumeration will continue after this function returns as devices are discovered by changes in hub status.
Note None documented


function USBStop:LongWord;
Description: To be documented
Note None documented


procedure USBAsyncStart(Host:PUSBHost);
Description: To be documented
Note None documented


USB device, driver and host functions

function USBDeviceGetAddress(Device:PUSBDevice):Byte;
Description: Get the bus address for the specified device
Device The USB device to get the address for
Return Device address or 0 on failure


function USBDeviceSetAddress(Device:PUSBDevice; Address:Byte):LongWord;
Description: Set the bus address for the specified device
Device The USB device to set the address for
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceGetDescriptor(Device:PUSBDevice; bRequest,bmRequestType:Byte; wValue,wIndex:Word; Data:Pointer; Length:Word):LongWord;
Description: Read any descriptor from the specified device using USBControlRequest
Device The USB device to read the descriptor from
bRequest See USBControlRequest
bmRequestType See USBControlRequest
wValue See USBControlRequest
wIndex See USBControlRequest
Data See USBControlRequest
Length See USBControlRequest
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceGetDeviceDescriptor(Device:PUSBDevice; Data:Pointer; Length:Word):LongWord;
Description: Read all or part of the device descriptor from the specified device using USBControlRequest
Device The USB device to read the device descriptor from
Data See USBControlRequest
Length See USBControlRequest
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceCreateDeviceDescriptor(Device:PUSBDevice; Length:Word):LongWord;
Description: Allocate a device descriptor for the specified device
Device The USB device to create the device descriptor for
Length The length of the descriptor to create
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceReadDeviceDescriptor(Device:PUSBDevice; Length:Word):LongWord; inline;
Description: Read all or part of the device descriptor from the specified device using USBControlRequest
Device The USB device to read the device descriptor from
Length The amount of the descriptor to read which may be less than the full size
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceReadDeviceDescriptorEx(Device:PUSBDevice; Length:Word; AllowShort:Boolean):LongWord;
Description: Read all or part of the device descriptor from the specified device using USBControlRequest
Device The USB device to read the device descriptor from
Length The amount of the descriptor to read which may be less than the full size
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceCreateConfigurations(Device:PUSBDevice):LongWord;
Description: Allocate the available configurations for this device
Device The USB device to create the configurations for
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceReadConfigurations(Device:PUSBDevice):LongWord;
Description: Read and parse the available configurations for this device
Device The USB device to read the configurations for
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceCreateConfiguration(Device:PUSBDevice; Index:Byte; Size:Word):LongWord;
Description: Allocate the specified configuration for this device
Device The USB device to create the configuration for
Index The index of the configuration to create
Size The size of the configuration descriptor to create
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceReadConfiguration(Device:PUSBDevice; Index:Byte):LongWord;
Description: Read and parse the specified configuration for this device
Device The USB device to read the configuration for
Index The index of the configuration to read
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceGetStringDescriptor(Device:PUSBDevice; Index:Byte; Data:Pointer; Length:Word):LongWord;
Description: Read all or part of the specified string descriptor from the specified device using USBControlRequest
Device The USB device to read the string descriptor from
Index The index of the string descriptor to read
Data See USBControlRequest
Length See USBControlRequest
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceReadStringDescriptor(Device:PUSBDevice; Index:Byte):String;
Description: To be documented
Note None documented


function USBDeviceReadStringDescriptorW(Device:PUSBDevice; Index:Byte):UnicodeString;
Description: To be documented
Note None documented


function USBDeviceGetConfigurationDescriptor(Device:PUSBDevice; Index:Byte;Data:Pointer; Length:Word):LongWord;
Description: Read all or part of the specified configuration descriptor from the specified device using USBControlRequest
Device The USB device to read the configuration descriptor from
Index The index of the configuration descriptor to read
Data See USBControlRequest
Length See USBControlRequest
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceGetConfiguration(Device:PUSBDevice; var ConfigurationValue:Byte):LongWord;
Description: Get the current configuration for the specified device
Device The USB device to get the current configuration for
ConfigurationValue The current configuration (As per bConfigurationValue in the configuration descriptor)
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceSetConfiguration(Device:PUSBDevice; ConfigurationValue:Byte):LongWord;
Description: Set the configuration for the specified device
Device The USB device to set the configuration for
ConfigurationValue The configuration to set (As per bConfigurationValue in the configuration descriptor)
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceFindConfigurationByValue(Device:PUSBDevice; ConfigurationValue:Byte):PUSBConfiguration;
Description: Find the configuration represented by configuration value for the specified device
Device The USB device to find the configuration for
ConfigurationValue The configuration value to find (As per bConfigurationValue in the configuration descriptor)
Return USB Configuration if completed or nil on failure


function USBDeviceGetInterface(Device:PUSBDevice; Index:Byte; var AlternateSetting:Byte):LongWord;
Description: Get the interface alternate setting for the specified device
Device The USB device to get the interface alternate setting for
Index The index of the interface to get (As per bInterfaceNumber in the interface descriptor)
AlternateSetting The current alternate setting of the specified interface (As per bAlternateSetting in the interface descriptor)
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceFindInterfaceByIndex(Device:PUSBDevice; Index:Byte):PUSBInterface;
Description: Find the interface with the specified index on the specified device
Device The USB device to find the interface from
Index The index of the interface to find (As per bInterfaceNumber in the interface descriptor)
Return The interface for the matching interface of nil if no interface matched


function USBDeviceFindInterfaceByClass(Device:PUSBDevice; InterfaceClass,InterfaceSubClass,InterfaceProtocol:Byte):PUSBInterface;
Description: Find an interface of the specified class, subclass and protocol on the specified device
Device The USB device to find the interface from
InterrfaceClass The interface class to match
InterfaceSubClass The interface subclass to match
InterfaceProtocol The interface protocol to match
Return The interface for the matching interface of nil if no interface matched


function USBDeviceFindEndpointByIndex(Device:PUSBDevice; Interrface:PUSBInterface; Index:Byte):PUSBEndpointDescriptor;
Description: Find the endpoint with the specified index on the specified interface of the specified device
Device The USB device to find the endpoint from
Interrface The interface to find the endpoint from
Index The index of the endpoint to find (First endpoint is zero)
Return The endpoint for the matching endpoint of nil if no endpoint matched


function USBDeviceFindEndpointByType(Device:PUSBDevice; Interrface:PUSBInterface; Direction,TransferType:Byte):PUSBEndpointDescriptor;
Description: Find an endpoint of the specified type and direction on the specified interface of the specified device
Device The USB device to find the endpoint from
Interrface The interface to find the endpoint from
Direction The direction of the endpoint to find (eg USB_DIRECTION_OUT)
TransferType The transfer type of the endpoint to find (eg USB_TRANSFER_TYPE_BULK)
Return The endpoint for the matching endpoint of nil if no endpoint matched


function USBDeviceFindEndpointByTypeEx(Device:PUSBDevice; Interrface:PUSBInterface; Direction,TransferType:Byte; var Index:Byte):PUSBEndpointDescriptor;
Description: Find the next endpoint of the specified type and direction on the specified interface of the specified device
Device The USB device to find the endpoint from
Interrface The interface to find the endpoint from
Direction The direction of the endpoint to find (eg USB_DIRECTION_OUT)
TransferType The transfer type of the endpoint to find (eg USB_TRANSFER_TYPE_BULK)
Index The index returned from the last call, pass 0 on the first call
Return The endpoint for the matching endpoint of nil if no endpoint matched


function USBDeviceCountEndpointsByType(Device:PUSBDevice; Interrface:PUSBInterface; Direction,TransferType:Byte):Byte;
Description: Count the number of endpoints of the specified type and direction on the specified interface of the specified device
Device The USB device to find the endpoint from
Interrface The interface to find the endpoint from
Direction The direction of the endpoint to find (eg USB_DIRECTION_OUT)
TransferType The transfer type of the endpoint to find (eg USB_TRANSFER_TYPE_BULK)
Return The number of matching endpoints on the specified interface


function USBDeviceFindAlternateByIndex(Device:PUSBDevice; Interrface:PUSBInterface; Index:Byte):PUSBAlternate;
Description: Find the alternate setting with the specified index on the specified interface of the specified device
Device The USB device to find the alternate setting from
Interrface The interface to find the alternate setting from
Index The index of the alternate setting to find (First alternate setting is zero)
Return The alternate setting for the matching alternate setting of nil if no alternate setting matched


function USBDeviceFindAlternateEndpointByIndex(Device:PUSBDevice; Interrface:PUSBInterface; Alternate:PUSBAlternate; Index:Byte):PUSBEndpointDescriptor;
Description: Find the endpoint with the specified index on the specified alternate setting interface of the specified device
Device The USB device to find the endpoint from
Interrface The interface to find the endpoint from
Alternate The alternate setting to find the endpoint from
Index The index of the endpoint to find (First endpoint is zero)
Return The endpoint for the matching endpoint of nil if no endpoint matched


function USBDeviceFindAlternateEndpointByType(Device:PUSBDevice; Interrface:PUSBInterface; Alternate:PUSBAlternate; Direction,TransferType:Byte):PUSBEndpointDescriptor;
Description: Find an endpoint of the specified type and direction on the specified alternate setting interface of the specified device
Device The USB device to find the endpoint from
Interrface The interface to find the endpoint from
Alternate The alternate setting to find the endpoint from
Direction The direction of the endpoint to find (eg USB_DIRECTION_OUT)
TransferType The transfer type of the endpoint to find (eg USB_TRANSFER_TYPE_BULK)
Return The endpoint for the matching endpoint of nil if no endpoint matched


function USBDeviceSetInterface(Device:PUSBDevice; Index,AlternateSetting:Byte):LongWord;
Description: Set the interface alternate setting for the specified device
Device The USB device to set the interface alternate setting for
Index The index of the interface to set (As per bInterfaceNumber in the interface descriptor)
AlternateSetting The alternate setting to set on the specified interface (As per bAlternateSetting in the interface descriptor)
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceSetFeature(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Feature,Index:Word):LongWord;
Description: Enable a feature on the specified endpoint on the specified device
Device The USB device to enable the feature for
Endpoint The endpoint to enable the feature on
Feature The feature to enable
Index To be documented
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceClearFeature(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Feature:Word):LongWord;
Description: Disable a feature on the specified endpoint on the specified device
Device The USB device to disable the feature for
Endpoint The endpoint to disable the feature on
Feature The feature to disable
Index To be documented
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceSetState(Device:PUSBDevice; State:LongWord):LongWord;
Description: Set the state of the specified device and send a notification
Device The USB device to set the state for
Status The new state to set and notify
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceSetStatus(Device:PUSBDevice; Status:LongWord):LongWord;
Description: Set the status of the specified device and send a notification
Device The USB device to set the status for
Status The new status to set and notify
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceBind(Device:PUSBDevice):LongWord;
Description: Attempt to bind a device to one of the registered drivers
Device The device to attempt to bind a driver to
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceUnbind(Device:PUSBDevice; Driver:PUSBDriver):LongWord;
Description: Unbind a device from a driver
Device The device to unbind a driver from
Driver The driver to unbind the device from (nil to unbind from current driver)
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceAttach(Device:PUSBDevice):LongWord;
Description: Configure and initialize a newly attached USB device
Device New USB device to configure and initialize
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceDetach(Device:PUSBDevice):LongWord;
Description: Shutdown and detach a USB device
Device The USB device to shutdown and detach
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBDeviceAllocate(Host:PUSBHost; Parent:PUSBDevice):PUSBDevice;
Description: Create and Register a new Device entry in the Device table}
Host The Host this device is attached to
Parent The Parent device (Hub) this device is attached to (nil if this device is a root hub)
Return Pointer to new Device entry or nil if device could not be created


function USBDeviceRelease(Device:PUSBDevice):LongWord;
Description: Deregister and Destroy a Device from the Device table
Device The device to deregister and destroy
Return ERROR_SUCCESS if completed or another error code on failure


function USBDeviceFind(USBId:LongWord):PUSBDevice;
Description: To be documented
Note None documented


function USBDeviceFindByName(const Name:String):PUSBDevice; inline;
Description: To be documented
Note None documented


function USBDeviceFindByDescription(const Description:String):PUSBDevice; inline;
Description: To be documented
Note None documented


function USBDeviceEnumerate(Callback:TUSBDeviceEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function USBDeviceNotification(Device:PUSBDevice; Callback:TUSBDeviceNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


function USBDriverCreate:PUSBDriver;
Description: Create a new Driver entry
Return Pointer to new Driver entry or nil if driver could not be created


function USBDriverCreateEx(Size:LongWord):PUSBDriver;
Description: Create a new Driver entry}
Size Size in bytes to allocate for new driver (Including the driver entry)
Return Pointer to new Driver entry or nil if driver could not be created


function USBDriverDestroy(Driver:PUSBDriver):LongWord;
Description: Destroy an existing Driver entry
Note None documented


function USBDriverRegister(Driver:PUSBDriver):LongWord;
Description: Register a new Driver in the Driver table
Note None documented


function USBDriverDeregister(Driver:PUSBDriver):LongWord;
Description: Deregister a Driver from the Driver table
Note None documented


function USBDriverFind(DriverId:LongWord):PUSBDriver;
Description: To be documented
Note None documented


function USBDriverFindByName(const Name:String):PUSBDriver; inline;
Description: To be documented
Note None documented


function USBDriverEnumerate(Callback:TUSBDriverEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function USBHostSetState(Host:PUSBHost; State:LongWord):LongWord;
Description: Set the state of the specified host and send a notification}
Host The USB host to set the state for
State The new state to set and notify
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBHostCreate:PUSBHost;
Description: Create a new Host entry
Return Pointer to new Host entry or nil if host could not be created


function USBHostCreateEx(Size:LongWord):PUSBHost;
Description: Create a new Host entry
Size Size in bytes to allocate for new host (Including the host entry)
Return Pointer to new Host entry or nil if host could not be created


function USBHostDestroy(Host:PUSBHost):LongWord;
Description: Destroy an existing Host entry
Note None documented


function USBHostRegister(Host:PUSBHost):LongWord;
Description: Register a new Host in the Host table
Note None documented


function USBHostDeregister(Host:PUSBHost):LongWord;
Description: Deregister a Host from the Host table
Note None documented


function USBHostFind(HostId:LongWord):PUSBHost;
Description: To be documented
Note None documented


function USBHostFindByName(const Name:String):PUSBHost; inline;
Description: To be documented
Note None documented


function USBHostFindByDescription(const Description:String):PUSBHost; inline;
Description: To be documented
Note None documented


function USBHostEnumerate(Callback:TUSBHostEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function USBHostNotification(Host:PUSBHost; Callback:TUSBHostNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


function USBBufferAllocate(Device:PUSBDevice; Size:LongWord):Pointer; inline;
Description: Allocate a data buffer for a USB request
Device The device that the request will be sent to
Size The size of the data buffer to allocate
Return The newly allocated buffer or nil on failure


function USBBufferAllocateEx(Device:PUSBDevice; Size:LongWord; var Flags:LongWord):Pointer;
Description: Allocate a data buffer for a USB request
Device The device that the request will be sent to
Size The size of the data buffer to allocate
Flags The returned flags for the allocated buffer (eg USB_REQUEST_FLAG_SHARED)
Return The newly allocated buffer or nil on failure


function USBBufferValidate(Device:PUSBDevice; Buffer:Pointer; Size:LongWord; var Flags:LongWord):LongWord;
Description: Validate a data buffer for a USB request against the USB host requirements
Device The device that the request will be sent to
Buffer The data buffer to validate
Size The size of the data buffer
Flags The returned flags for the validated buffer (eg USB_REQUEST_FLAG_SHARED)
Return USB_STATUS_SUCCESS on success or another error code on failure


function USBBufferRelease(Buffer:Pointer):LongWord;
Description: Release a data buffer from a USB request
Data The buffer to be released
Return USB_STATUS_SUCCESS on success or another error code on failure


function USBRequestAllocate(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Callback:TUSBRequestCompleted; Size:LongWord; DriverData:Pointer):PUSBRequest; inline;
Description: Allocate a new USB request
Device The USB device this request will be sent to
Endpoint The Endpoint descriptor this request will be sent to (Or nil for the default control endpoint)
Callback The callback function to be called on completion of the request
Size The size of the data buffer for the request
DriverData Device driver private data for the callback (Optional)
Return The newly allocated request or nil on failure


function USBRequestAllocateEx(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Callback:TUSBRequestCompleted; var Data:Pointer; Size:LongWord; DriverData:Pointer):PUSBRequest;
Description: Allocate a new USB request
Device The USB device this request will be sent to
Endpoint The Endpoint descriptor this request will be sent to (Or nil for the default control endpoint)
Callback The callback function to be called on completion of the request
Data The returned data buffer allocated for the request (Or nil if size is zero)(Pass an existing buffer to prevent allocation)
Size The size of the data buffer for the request
DriverData Device driver private data for the callback (Optional)
Return The newly allocated request or nil on failure


function USBRequestRelease(Request:PUSBRequest):LongWord;
Description: Release and destroy a USB request
Request The request to be released
Return USB_STATUS_SUCCESS on success or another error code on failure


function USBRequestInitialize(Request:PUSBRequest; Callback:TUSBRequestCompleted; Data:Pointer; Size:LongWord; DriverData:Pointer):LongWord;
Description: Initialize or Reinitialize an existing USB request
Request The request to be initialized
Callback The callback function to be called on completion of the request
Data The returned data buffer allocated for the request (Or nil if size is zero)
Size The size of the data buffer for the request
DriverData Device driver private data for the callback (Optional)
Return USB_STATUS_SUCCESS on success or another error code on failure


function USBRequestSubmit(Request:PUSBRequest):LongWord;
Description: Submit a USB request to a host controller for execution
Request The request to be submitted
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note The request will be completed asynchronously by the host controller and the completion callback will be called when the request has either succeeded or failed


function USBRequestCancel(Request:PUSBRequest):LongWord;
Description: Cancel a USB request previously submitted to a host controller
Request The request to be cancelled
Return USB_STATUS_SUCCESS if completed or another error code on failure


procedure USBRequestComplete(Request:PUSBRequest);
Description: Called by a host controller when a USB request completes
Request The USB request which has completed


function USBControlRequest(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; bRequest,bmRequestType:Byte; wValue,wIndex:Word; Data:Pointer; wLength:Word):LongWord; inline;
Description: Send of USB control request to the specified device and wait for the request to complete
Device The USB device to send the control request to
Endpoint The Endpoint to use for the control request (or nil for the default control endpoint)
bRequest The request to send (See Section 9.4 of the USB 2.0 specification for Standard requests)
bmRequest Type of request to send (See Section 9.3.1 of the USB 2.0 specification for Standard request types)
wValue Request specific data
wIndex Request specific data
Data Buffer for the data to be sent or received from the request (Ignored if wLength is 0)
wLength Length of the Data buffer in bytes
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBControlRequestEx(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; bRequest,bmRequestType:Byte; wValue,wIndex:Word; Data:Pointer; wLength:Word; Timeout:LongWord; AllowShort:Boolean):LongWord;
Description: Send of USB control request to the specified device and wait for the request to complete
Device The USB device to send the control request to
Endpoint The Endpoint to use for the control request (or nil for the default control endpoint)
bRequest The request to send (See Section 9.4 of the USB 2.0 specification for Standard requests)
bmRequest Type of request to send (See Section 9.3.1 of the USB 2.0 specification for Standard request types)
wValue Request specific data
wIndex Request specific data
Data Buffer for the data to be sent or received from the request (Ignored if wLength is 0)
wLength Length of the Data buffer in bytes
Timeout Milliseconds to wait for request to complete (INFINITE to wait forever)
AllowShort Allow the return size to be less than the requested size
Return USB_STATUS_SUCCESS if completed or another error code on failure


procedure USBControlRequestComplete(Request:PUSBRequest);
Description: Called when a USB request from a USB control endpoint completes
Request The USB request which has completed


USB hub functions

function USBHubCreatePorts(Hub:PUSBHub):LongWord;
Description: Create and initialize the ports for a Hub
Hub The hub to initialize ports for
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBHubPowerOnPorts(Hub:PUSBHub):LongWord;
Description: Power on all ports on a Hub
Hub The hub to power on ports for
Return USB_STATUS_SUCCESS if completed or another error code on failure


function USBHubCreateHubDescriptor(Hub:PUSBHub):LongWord;
Description: Allocate the hub descriptor for the specified hub
Hub The hub to create the descriptor for
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note The class specific hub descriptor is not the same as the device descriptor


function USBHubReadHubDescriptor(Hub:PUSBHub):LongWord;
Description: Read the hub descriptor for the specified hub
Hub The hub to read the descriptor for
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note The class specific hub descriptor is not the same as the device descriptor


function USBHubLock(Hub:PUSBHub):LongWord;
Description: Lock the specified Hub to prevent changes
Hub The hub to lock
Return ERROR_SUCCESS if completed or another error code on failure


function USBHubUnlock(Hub:PUSBHub):LongWord;
Description: Unlock the specified Hub to allow changes
Hub The hub to unlock
Return ERROR_SUCCESS if completed or another error code on failure


function USBHubSetState(Hub:PUSBHub; State:LongWord):LongWord;
Description: Set the state of the specified hub and send a notification
Hub The hub to set the state for
State The new state to set and notify
Return ERROR_SUCCESS if completed or another error code on failure


function USBHubAllocate(Device:PUSBDevice):PUSBHub;
Description: Create and Register a new Hub device
Device The USB device that represents this hub
Return Pointer to new Hub entry or nil if hub could not be created


function USBHubRelease(Hub:PUSBHub):LongWord;
Description: Deregister and Destroy a Hub device
Hub The hub to deregister and destroy
Return ERROR_SUCCESS if completed or another error code on failure


function USBHubFind(HubId:LongWord):PUSBHub;
Description: To be documented
Note None documented


function USBHubFindByName(const Name:String):PUSBHub; inline;
Description: To be documented
Note None documented


function USBHubFindByDescription(const Description:String):PUSBHub; inline;
Description: To be documented
Note None documented


function USBHubEnumerate(Callback:TUSBHubEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function USBHubNotification(Hub:PUSBHub; Callback:TUSBHubNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


procedure USBHubBindDevices(Device:PUSBDevice; Callback:TUSBDeviceBind);
Description: Enumerate each device in the USB tree and call a bind callback for each one
Device USB device at which to start the enueration
Callback Bind callback function to execute for each device


procedure USBHubUnbindDevices(Device:PUSBDevice; Driver:PUSBDriver; Callback:TUSBDeviceUnbind);
Description: Enumerate each device in the USB tree and call an unbind callback for each one
Device USB device at which to start the enumeration
Callback Unbind callback function to execute for each device


procedure USBHubEnumerateDevices(Device:PUSBDevice; Callback:TUSBDeviceEnumerate; Data:Pointer);
Description: Enumerate each device in the USB tree and call an enumerate callback for each one
Device USB device at which to start the enumeration
Callback Enumerate callback function to execute for each device


function USBHubPortReset(Port:PUSBPort):LongWord;
Description: Reset a the specified USB port
Port USB port to reset
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock


function USBHubPortGetStatus(Port:PUSBPort):LongWord;
Description: Read the status of the specified USB port
Port USB port to read status for
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock


function USBHubPortSetFeature(Port:PUSBPort; Feature:Word):LongWord;
Description: Enable a feature on the specified USB port
Port USB port to enable the feature on
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock


function USBHubPortClearFeature(Port:PUSBPort; Feature:Word):LongWord;
Description: Disable a feature on the specified USB port
Port USB port to disable the feature on
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock


function USBHubPortChangeFeature(Port:PUSBPort; Feature:Word; Enable:Boolean):LongWord;
Description: Enable or disable a feature on the specified USB port
Port USB port to enable or disable the feature on
Feature The feature to enable or disable
Enable True to enable the feature or False to disable the feature
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock


function USBHubPortAttachDevice(Port:PUSBPort):LongWord;
Description: Attach a newly connected USB device to the specified USB port
Port USB port to attach the new device to
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock. Only called in response to a status change on the hub.


function USBHubPortDetachDevice(Port:PUSBPort):LongWord;
Description: Detach a disconnected USB device from the specified USB port
Port USB port to detach the device from
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock. Only called in response to a status change on the hub.


function USBHubPortStatusChanged(Port:PUSBPort):LongWord;
Description: Process a status change for the specified USB port
Port USB port to process the status change for
Return USB_STATUS_SUCCESS if completed or another error code on failure
Note Caller must hold the hub lock. Only called in response to a status change on the hub.


function USBHubExecute(Parameter:Pointer):PtrInt;
Description: The Hub thread procedure which is responsible for receiving completed hub status change requests, processing them for changes and then resubmitting the request
Note One status change request exists for each hub currently connected and is created and submitted by the hub driver when it binds to a new hub device. When a hub is disconnected the hub driver will remove the request when the hub is detached and destroyed.


procedure USBHubStatusComplete(Request:PUSBRequest);
Description: Called when the USB request from a USB hub IN interrupt endpoint completes
Request The USB request which has completed


function USBHubDriverBind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Description: Bind the Hub driver to a USB device if it is suitable}
Device The USB device to attempt to bind to
Interrface The USB interface to attempt to bind to (or nil for whole device)
Return USB_STATUS_SUCCESS if completed, USB_STATUS_DEVICE_UNSUPPORTED if unsupported or another error code on failure


function USBHubDriverUnbind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Description: Unbind the Hub driver from a USB device
Device The USB device to unbind from
Interrface The USB interface to unbind from (or nil for whole device)
Return USB_STATUS_SUCCESS if completed or another error code on failure


USB device, driver and host helper functions

function USBDeviceGetCount:LongWord; inline;
Description: Get the current device count
Note None documented


function USBDeviceCheck(Device:PUSBDevice):PUSBDevice;
Description: Check if the supplied Device is in the device table
Note None documented


function USBDriverGetCount:LongWord; inline;
Description: Get the current driver count
Note None documented


function USBDriverCheck(Driver:PUSBDriver):PUSBDriver;
Description: Check if the supplied Driver is in the driver table
Note None documented


function USBHostGetCount:LongWord; inline;
Description: Get the current host count
Note None documented


function USBHostCheck(Host:PUSBHost):PUSBHost;
Description: Check if the supplied Host is in the host table
Note None documented


function USBIsHub(Device:PUSBDevice):Boolean;
Description: Returns True if Device is a Hub or False if not
Note None documented


function USBIsRootHub(Device:PUSBDevice):Boolean;
Description: Returns True if Device is a Root Hub or False if not
Note None documented


function USBIsControlRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is a control request or False if not
Note None documented


function USBIsBulkRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is a bulk request or False if not
Note None documented


function USBIsInterruptRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is an interrupt request or False if not
Note None documented


function USBIsIsochronousRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is an isochronous request or False if not
Note None documented


function USBIsInEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is an IN endpoint or False if not
Note None documented


function USBIsOutEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is an OUT endpoint or False if not
Note None documented


function USBIsBulkEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is a BULK endpoint or False if not
Note None documented


function USBIsInterruptEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is a INTERRUPT endpoint or False if not
Note None documented


function USBIsIsochronousEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is a ISOCHRONOUS endpoint or False if not
Note None documented


function USBDeviceToString(Device:PUSBDevice):String;
Description: Return a description of a USB device
Device USB device to get a description of
Return A string describing the device


function USBStatusToString(Status:LongWord):String;
Description: Translates a USB status code into a string
Note None documented


function USBClassCodeToString(ClassCode:Integer):String;
Description: Translates a USB class code into a string
Note None documented


function USBSubClassCodeToString(ClassCode,SubClassCode:Integer):String;
Description: Translates a USB sub class code into a string
Note None documented


function USBProtocolCodeToString(ClassCode,ProtocolCode:Integer):String;
Description: Translates a USB protocol code into a string
Note None documented


function USBSpeedToString(Speed:Integer):String;
Description: Translates a USB speed constant into a string
Note None documented


function USBTransferTypeToString(TransferType:Integer):String;
Description: Translates a USB transfer type constant into a string
Note None documented


function USBDirectionToString(Direction:Integer):String;
Description: Translates a USB direction constant into a string
Note None documented


function USBBCDVersionToString(BCDVersion:Word):String;
Description: Translates a bcdUSB (binary-coded-decimal USB version) value into a human-readable string
BCDVersion The bcdUSB value (e.g. from a USB device descriptor) to translate
Return String describing the USB version


function USBPortStatusConnectedToString(Status:Word):String;
Description: To be documented
Note None documented


function USBHubCharacteristicsToString(HubCharacteristics:Word):String;
Description: To be documented
Note None documented


function USBDeviceTypeToString(USBType:LongWord):String;
Description: To be documented
Note None documented


function USBDeviceStateToString(USBState:LongWord):String;
Description: To be documented
Note None documented


function USBDeviceStatusToString(USBStatus:LongWord):String;
Description: To be documented
Note None documented


function USBDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Device state value into the notification code for device notifications
Note None documented


function USBDeviceStatusToNotification(Status:LongWord):LongWord;
Description: Convert a Device status value into the notification code for device notifications
Note None documented


function USBHostTypeToString(HostType:LongWord):String;
Description: To be documented
Note None documented


function USBHostStateToString(HostState:LongWord):String;
Description: To be documented
Note None documented


function USBHostStateToNotification(State:LongWord):LongWord;
Description: Convert a Host state value into the notification code for device notifications
Note None documented


procedure USBLog(Level:LongWord; Device:PUSBDevice; const AText:String);
Description: To be documented
Note None documented


procedure USBLogInfo(Device:PUSBDevice;const AText:String);
Description: To be documented
Note None documented


procedure USBLogError(Device:PUSBDevice;const AText:String);
Description: To be documented
Note None documented


procedure USBLogDebug(Device:PUSBDevice;const AText:String);
Description: To be documented
Note None documented


procedure USBLogDeviceConfiguration(Device:PUSBDevice);
Description: To be documented
Note None documented


procedure USBLogDeviceDescriptor(Device:PUSBDevice; Descriptor:PUSBDeviceDescriptor);
Description: To be documented
Note None documented


procedure USBLogConfigurationDescriptor(Device:PUSBDevice; Descriptor:PUSBConfigurationDescriptor);
Description: To be documented
Note None documented


procedure USBLogInterfaceDescriptor(Device:PUSBDevice; Descriptor:PUSBInterfaceDescriptor);
Description: To be documented
Note None documented


procedure USBLogEndpointDescriptor(Device:PUSBDevice; Descriptor:PUSBEndpointDescriptor);
Description: To be documented
Note None documented


function USBLogDevices:LongWord;
Description: Print information about all devices attached to the USB
Return ERROR_SUCCESS if completed or another error code on failure


function USBLogDeviceCallback(Device:PUSBDevice; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function USBLogTreeCallback(Device:PUSBDevice; Data:Pointer):LongWord;
Description: To be documented
Note None documented


USB hub helper functions

function USBHubGetCount:LongWord; inline;
Description: Get the current hub count
Note None documented


function USBHubCheck(Hub:PUSBHub):PUSBHub;
Description: Check if the supplied Hub is in the hub table
Note None documented


function USBHubStateToNotification(State:LongWord):LongWord;
Description: Convert a Hub state value into the notification code for device notifications
Note None documented


Return to Unit Reference