Unit USB

From Ultibo.org
Revision as of 03:05, 9 June 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



[Expand]
USB device, driver and host specific constants USB_*_PREFIX


[Expand]
USB device type USB_TYPE_*


[Expand]
USB device state USB_STATE_*


[Expand]
USB device status USB_STATUS_*


[Expand]
USB device flag USB_FLAG_*


[Expand]
USB host type USBHOST_TYPE_*


[Expand]
USB host state USBHOST_STATE_*


[Expand]
USB host flag USBHOST_FLAG_*


[Expand]
USB status code USB_STATUS_*


[Expand]
USB request flag USB_REQUEST_FLAG_*


[Expand]
USB control phase USB_CONTROL_PHASE_*


[Expand]
USB control timeout USB_CONTROL_*


[Expand]
USB packet size USB_*_*_PACKET_SIZE


[Expand]
USB frame USB_FRAMES_*


[Expand]
USB microframe USB_UFRAMES_*


[Expand]
USB configuration attribute USB_CONFIGURATION_ATTRIBUTE_*


[Expand]
USB device status USB_DEVICE_STATUS_*


[Expand]
USB endpoint status USB_ENDPOINT_STATUS_*


[Expand]
USB device speed USB_SPEED_*


[Expand]
USB transfer type USB_TRANSFER_TYPE_*


[Expand]
USB transfer size USB_TRANSFER_SIZE_*


[Expand]
USB descriptor type USB_DESCRIPTOR_TYPE_*


[Expand]
USB transfer direction USB_DIRECTION_*


[Expand]
USB request type USB_REQUEST_TYPE_*


[Expand]
USB request recipient USB_REQUEST_RECIPIENT_*


[Expand]
USB bmrequest type USB_BMREQUESTTYPE_*


[Expand]
USB device request USB_DEVICE_REQUEST_*


[Expand]
USB device feature USB_DEVICE_FEATURE_*


[Expand]
USB test mode USB_DEVICE_TEST_MODE_*


[Expand]
USB packet Id value USB_PACKETID_*


[Expand]
USB class code USB_CLASS_CODE_*


[Expand]
USB subclass code USB_SUBCLASS_*


[Expand]
USB protocol code USB_PROTOCOL_*


[Expand]
USB primary language Id USB_LANG_*


[Expand]
USB sublanguage Id USB_SUBLANG_*


[Expand]
USB primary language identifier USB_LANGID_*


[Expand]
USB vendor Id USB_VENDORID_*


[Expand]
USB tree output USB_TREE_*


[Expand]
USB logging USB_LOG_*


[Expand]
USB hub specific constants USB_HUB_*


[Expand]
USB hub type USBHUB_TYPE_*


[Expand]
USB hub state USBHUB_STATE_*


[Expand]
USB hub flag USBHUB_FLAG_*


[Expand]
USB hub thread USBHUB_THREAD_*


[Expand]
USB device USBHUB_DEVICE_*


[Expand]
USB hub driver USBHUB_DRIVER_*


[Expand]
USB port reset USB_PORT_RESET_*


[Expand]
USB hub characteristic USB_HUB_CHARACTERISTIC_*


[Expand]
USB hub feature USB_C_HUB_*


[Expand]
USB port feature USB_PORT_*


[Expand]
USB hub class request USB_HUB_REQUEST_*


[Expand]
USB port status USB_PORT_STATUS_*


[Expand]
USB port change USB_PORT_CHANGE_*


[Expand]
USB hub status USB_HUB_STATUS_*


[Expand]
USB hub change USB_HUB_CHANGE_*


Type definitions



USB device Id

[Expand]

PUSBDeviceId = ^TUSBDeviceId;

TUSBDeviceId = record

USB interface Id

[Expand]

PUSBInterfaceId = ^TUSBInterfaceId;

TUSBInterfaceId = record

USB device and interface Id

[Expand]

PUSBDeviceAndInterfaceId = ^TUSBDeviceAndInterfaceId;

TUSBDeviceAndInterfaceId = record

USB device and interface no

[Expand]

PUSBDeviceAndInterfaceNo = ^TUSBDeviceAndInterfaceNo;

TUSBDeviceAndInterfaceNo = record

USB control setup data

[Expand]

PUSBControlSetupData = ^TUSBControlSetupData;

TUSBControlSetupData = packed record

USB descriptor header

[Expand]

PUSBDescriptorHeader = ^TUSBDescriptorHeader;

TUSBDescriptorHeader = packed record

USB device descriptor

[Expand]

PUSBDeviceDescriptor = ^TUSBDeviceDescriptor;

TUSBDeviceDescriptor = packed record

USB configuration descriptor

[Expand]

PUSBConfigurationDescriptor = ^TUSBConfigurationDescriptor;

TUSBConfigurationDescriptor = packed record

USB interface descriptor

[Expand]

PUSBInterfaceDescriptor = ^TUSBInterfaceDescriptor;

TUSBInterfaceDescriptor = packed record

USB endpoint descriptor

[Expand]

PUSBEndpointDescriptor = ^TUSBEndpointDescriptor;

TUSBEndpointDescriptor = packed record

USB string descriptor

[Expand]

PUSBStringDescriptor = ^TUSBStringDescriptor;

TUSBStringDescriptor = packed record

USB string descriptor string

[Expand]

PUSBStringDescriptorString = ^TUSBStringDescriptorString;

TUSBStringDescriptorString = array[0..125] of Word;

USB string descriptor LANGIDs

[Expand]

PUSBStringDescriptorLANGIDs = ^TUSBStringDescriptorLANGIDs;

USB device status

[Expand]

PUSBDeviceStatus = ^TUSBDeviceStatus;

TUSBDeviceStatus = packed record

USB device bind callback

TUSBDeviceBind = function(Device:PUSBDevice):LongWord;

USB device unbind callback

TUSBDeviceUnbind = function(Device:PUSBDevice; Driver:PUSBDriver):LongWord;

USB device enumeration callback

TUSBDeviceEnumerate = function(Device:PUSBDevice; Data:Pointer):LongWord;

USB device notification callback

TUSBDeviceNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

USB device

[Expand]

PUSBDevice = ^TUSBDevice;

TUSBDevice = record

USB configuration

[Expand]

PUSBConfiguration = ^TUSBConfiguration;

TUSBConfiguration = record

USB interface

[Expand]

PUSBInterface = ^TUSBInterface;

TUSBInterface = record

USB alternate

[Expand]

PUSBAlternate = ^TUSBAlternate;

TUSBAlternate = record

USB driver enumeration callback

TUSBDriverEnumerate = function(Driver:PUSBDriver; Data:Pointer):LongWord;

USB driver bind

TUSBDriverBind = function(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;

USB driver unbind

TUSBDriverUnbind = function(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;

USB driver

[Expand]

PUSBDriver = ^TUSBDriver;

TUSBDriver = record

USB host enumeration callback

TUSBHostEnumerate = function(Host:PUSBHost; Data:Pointer):LongWord;

USB host notification callback

TUSBHostNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

USB host start

TUSBHostStart = function(Host:PUSBHost):LongWord;

USB host stop

TUSBHostStop = function(Host:PUSBHost):LongWord;

USB host reset

TUSBHostReset = function(Host:PUSBHost):LongWord;

USB host submit

TUSBHostSubmit = function(Host:PUSBHost; Request:PUSBRequest):LongWord;

USB host cancel

TUSBHostCancel = function(Host:PUSBHost; Request:PUSBRequest):LongWord;

USB host

[Expand]

PUSBHost = ^TUSBHost;

TUSBHost = record

USB request completed

TUSBRequestCompleted = procedure(Request:PUSBRequest);

USB request

[Expand]

PUSBRequest = ^TUSBRequest;

TUSBRequest = record

USB hub descriptor

[Expand]

PUSBHubDescriptor = ^TUSBHubDescriptor;

TUSBHubDescriptor = packed record

USB hub descriptor data

[Expand]

PUSBHubDescriptorData = ^TUSBHubDescriptorData;

TUSBHubDescriptorData = array[0..63] of Byte;

USB port status

[Expand]

PUSBPortStatus = ^TUSBPortStatus;

TUSBPortStatus = packed record

USB hub status

[Expand]

PUSBHubStatus = ^TUSBHubStatus;

TUSBHubStatus = packed record

USB hub data

[Expand]

PUSBHubData = ^TUSBHubData;

TUSBHubData = record

USB port

[Expand]

PUSBPort = ^TUSBPort;

TUSBPort = record

USB hub enumeration callback

TUSBHubEnumerate = function(Hub:PUSBHub; Data:Pointer):LongWord;

USB hub notification callback

TUSBHubNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

USB hub

[Expand]

PUSBHub = ^TUSBHub;

TUSBHub = record


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

[Expand]
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


[Expand]
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.


[Expand]
function USBStop:LongWord;
Description: To be documented


[Expand]
procedure USBAsyncStart(Host:PUSBHost);
Description: To be documented


USB device, driver and host functions

[Expand]
function USBDeviceGetAddress(Device:PUSBDevice):Byte;
Description: Get the bus address for the specified device


[Expand]
function USBDeviceSetAddress(Device:PUSBDevice; Address:Byte):LongWord;
Description: Set the bus address for the specified device


[Expand]
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


[Expand]
function USBDeviceGetDeviceDescriptor(Device:PUSBDevice; Data:Pointer; Length:Word):LongWord;
Description: Read all or part of the device descriptor from the specified device using USBControlRequest


[Expand]
function USBDeviceCreateDeviceDescriptor(Device:PUSBDevice; Length:Word):LongWord;
Description: Allocate a device descriptor for the specified device


[Expand]
function USBDeviceReadDeviceDescriptor(Device:PUSBDevice; Length:Word):LongWord; inline;
Description: Read all or part of the device descriptor from the specified device using USBControlRequest


[Expand]
function USBDeviceReadDeviceDescriptorEx(Device:PUSBDevice; Length:Word; AllowShort:Boolean):LongWord;
Description: Read all or part of the device descriptor from the specified device using USBControlRequest


[Expand]
function USBDeviceCreateConfigurations(Device:PUSBDevice):LongWord;
Description: Allocate the available configurations for this device


[Expand]
function USBDeviceReadConfigurations(Device:PUSBDevice):LongWord;
Description: Read and parse the available configurations for this device


[Expand]
function USBDeviceCreateConfiguration(Device:PUSBDevice; Index:Byte; Size:Word):LongWord;
Description: Allocate the specified configuration for this device


[Expand]
function USBDeviceReadConfiguration(Device:PUSBDevice; Index:Byte):LongWord;
Description: Read and parse the specified configuration for this device


[Expand]
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


[Expand]
function USBDeviceReadStringDescriptor(Device:PUSBDevice; Index:Byte):String;
Description: To be documented


[Expand]
function USBDeviceReadStringDescriptorW(Device:PUSBDevice; Index:Byte):UnicodeString;
Description: To be documented


[Expand]
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


[Expand]
function USBDeviceGetConfiguration(Device:PUSBDevice; var ConfigurationValue:Byte):LongWord;
Description: Get the current configuration for the specified device


[Expand]
function USBDeviceSetConfiguration(Device:PUSBDevice; ConfigurationValue:Byte):LongWord;
Description: Set the configuration for the specified device


[Expand]
function USBDeviceFindConfigurationByValue(Device:PUSBDevice; ConfigurationValue:Byte):PUSBConfiguration;
Description: Find the configuration represented by configuration value for the specified device


[Expand]
function USBDeviceGetInterface(Device:PUSBDevice; Index:Byte; var AlternateSetting:Byte):LongWord;
Description: Get the interface alternate setting for the specified device


[Expand]
function USBDeviceSetInterface(Device:PUSBDevice; Index,AlternateSetting:Byte):LongWord;
Description: Set the interface alternate setting for the specified device


[Expand]
function USBDeviceFindInterfaceByIndex(Device:PUSBDevice; Index:Byte):PUSBInterface;
Description: Find the interface with the specified index on the specified device


[Expand]
function USBDeviceFindInterfaceByClass(Device:PUSBDevice; InterfaceClass,InterfaceSubClass,InterfaceProtocol:Byte):PUSBInterface;
Description: Find an interface of the specified class, subclass and protocol on the specified device


[Expand]
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


[Expand]
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


[Expand]
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


[Expand]
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


[Expand]
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


[Expand]
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


[Expand]
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


[Expand]
function USBDeviceSetFeature(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Feature,Index:Word):LongWord;
Description: Enable a feature on the specified endpoint on the specified device


[Expand]
function USBDeviceClearFeature(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Feature:Word):LongWord;
Description: Disable a feature on the specified endpoint on the specified device


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


[Expand]
function USBDeviceSetStatus(Device:PUSBDevice; Status:LongWord):LongWord;
Description: Set the status of the specified device and send a notification


[Expand]
function USBDeviceBind(Device:PUSBDevice):LongWord;
Description: Attempt to bind a device to one of the registered drivers


[Expand]
function USBDeviceUnbind(Device:PUSBDevice; Driver:PUSBDriver):LongWord;
Description: Unbind a device from a driver


[Expand]
function USBDeviceAttach(Device:PUSBDevice):LongWord;
Description: Configure and initialize a newly attached USB device


[Expand]
function USBDeviceDetach(Device:PUSBDevice):LongWord;
Description: Shutdown and detach a USB device


[Expand]
function USBDeviceAllocate(Host:PUSBHost; Parent:PUSBDevice):PUSBDevice;
Description: Create and Register a new Device entry in the Device table}


[Expand]
function USBDeviceRelease(Device:PUSBDevice):LongWord;
Description: Deregister and Destroy a Device from the Device table


[Expand]
function USBDeviceFind(USBId:LongWord):PUSBDevice;
Description: To be documented


[Expand]
function USBDeviceFindByName(const Name:String):PUSBDevice; inline;
Description: To be documented


[Expand]
function USBDeviceFindByDescription(const Description:String):PUSBDevice; inline;
Description: To be documented


[Expand]
function USBDeviceEnumerate(Callback:TUSBDeviceEnumerate; Data:Pointer):LongWord;
Description: To be documented


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


[Expand]
function USBDriverCreate:PUSBDriver;
Description: Create a new Driver entry


[Expand]
function USBDriverCreateEx(Size:LongWord):PUSBDriver;
Description: Create a new Driver entry}


[Expand]
function USBDriverDestroy(Driver:PUSBDriver):LongWord;
Description: Destroy an existing Driver entry


[Expand]
function USBDriverRegister(Driver:PUSBDriver):LongWord;
Description: Register a new Driver in the Driver table


[Expand]
function USBDriverDeregister(Driver:PUSBDriver):LongWord;
Description: Deregister a Driver from the Driver table


[Expand]
function USBDriverFind(DriverId:LongWord):PUSBDriver;
Description: To be documented


[Expand]
function USBDriverFindByName(const Name:String):PUSBDriver; inline;
Description: To be documented


[Expand]
function USBDriverEnumerate(Callback:TUSBDriverEnumerate; Data:Pointer):LongWord;
Description: To be documented


[Expand]
function USBHostSetState(Host:PUSBHost; State:LongWord):LongWord;
Description: Set the state of the specified host and send a notification}


[Expand]
function USBHostCreate:PUSBHost;
Description: Create a new Host entry


[Expand]
function USBHostCreateEx(Size:LongWord):PUSBHost;
Description: Create a new Host entry


[Expand]
function USBHostDestroy(Host:PUSBHost):LongWord;
Description: Destroy an existing Host entry


[Expand]
function USBHostRegister(Host:PUSBHost):LongWord;
Description: Register a new Host in the Host table


[Expand]
function USBHostDeregister(Host:PUSBHost):LongWord;
Description: Deregister a Host from the Host table


[Expand]
function USBHostFind(HostId:LongWord):PUSBHost;
Description: To be documented


[Expand]
function USBHostFindByName(const Name:String):PUSBHost; inline;
Description: To be documented


[Expand]
function USBHostFindByDescription(const Description:String):PUSBHost; inline;
Description: To be documented


[Expand]
function USBHostEnumerate(Callback:TUSBHostEnumerate; Data:Pointer):LongWord;
Description: To be documented


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


[Expand]
function USBBufferAllocate(Device:PUSBDevice; Size:LongWord):Pointer; inline;
Description: Allocate a data buffer for a USB request


[Expand]
function USBBufferAllocateEx(Device:PUSBDevice; Size:LongWord; var Flags:LongWord):Pointer;
Description: Allocate a data buffer for a USB request


[Expand]
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


[Expand]
function USBBufferRelease(Buffer:Pointer):LongWord;
Description: Release a data buffer from a USB request


[Expand]
function USBRequestAllocate(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Callback:TUSBRequestCompleted; Size:LongWord; DriverData:Pointer):PUSBRequest; inline;
Description: Allocate a new USB request


[Expand]
function USBRequestAllocateEx(Device:PUSBDevice; Endpoint:PUSBEndpointDescriptor; Callback:TUSBRequestCompleted; var Data:Pointer; Size:LongWord; DriverData:Pointer):PUSBRequest;
Description: Allocate a new USB request


[Expand]
function USBRequestRelease(Request:PUSBRequest):LongWord;
Description: Release and destroy a USB request


[Expand]
function USBRequestInitialize(Request:PUSBRequest; Callback:TUSBRequestCompleted; Data:Pointer; Size:LongWord; DriverData:Pointer):LongWord;
Description: Initialize or Reinitialize an existing USB request


[Expand]
function USBRequestSubmit(Request:PUSBRequest):LongWord;
Description: Submit a USB request to a host controller for execution


[Expand]
function USBRequestCancel(Request:PUSBRequest):LongWord;
Description: Cancel a USB request previously submitted to a host controller


[Expand]
procedure USBRequestComplete(Request:PUSBRequest);
Description: Called by a host controller when a USB request completes


[Expand]
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


[Expand]
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


[Expand]
procedure USBControlRequestComplete(Request:PUSBRequest);
Description: Called when a USB request from a USB control endpoint completes


USB hub functions

[Expand]
function USBHubCreatePorts(Hub:PUSBHub):LongWord;
Description: Create and initialize the ports for a Hub


[Expand]
function USBHubPowerOnPorts(Hub:PUSBHub):LongWord;
Description: Power on all ports on a Hub


[Expand]
function USBHubCreateHubDescriptor(Hub:PUSBHub):LongWord;
Description: Allocate the hub descriptor for the specified hub


[Expand]
function USBHubReadHubDescriptor(Hub:PUSBHub):LongWord;
Description: Read the hub descriptor for the specified hub


[Expand]
function USBHubLock(Hub:PUSBHub):LongWord;
Description: Lock the specified Hub to prevent changes


[Expand]
function USBHubUnlock(Hub:PUSBHub):LongWord;
Description: Unlock the specified Hub to allow changes


[Expand]
function USBHubSetState(Hub:PUSBHub; State:LongWord):LongWord;
Description: Set the state of the specified hub and send a notification


[Expand]
function USBHubAllocate(Device:PUSBDevice):PUSBHub;
Description: Create and Register a new Hub device


[Expand]
function USBHubRelease(Hub:PUSBHub):LongWord;
Description: Deregister and Destroy a Hub device


[Expand]
function USBHubFind(HubId:LongWord):PUSBHub;
Description: To be documented


[Expand]
function USBHubFindByName(const Name:String):PUSBHub; inline;
Description: To be documented


[Expand]
function USBHubFindByDescription(const Description:String):PUSBHub; inline;
Description: To be documented


[Expand]
function USBHubEnumerate(Callback:TUSBHubEnumerate; Data:Pointer):LongWord;
Description: To be documented


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


[Expand]
procedure USBHubBindDevices(Device:PUSBDevice; Callback:TUSBDeviceBind);
Description: Enumerate each device in the USB tree and call a bind callback for each one


[Expand]
procedure USBHubUnbindDevices(Device:PUSBDevice; Driver:PUSBDriver; Callback:TUSBDeviceUnbind);
Description: Enumerate each device in the USB tree and call an unbind callback for each one


[Expand]
procedure USBHubEnumerateDevices(Device:PUSBDevice; Callback:TUSBDeviceEnumerate; Data:Pointer);
Description: Enumerate each device in the USB tree and call an enumerate callback for each one


[Expand]
function USBHubPortReset(Port:PUSBPort):LongWord;
Description: Reset a the specified USB port


[Expand]
function USBHubPortGetStatus(Port:PUSBPort):LongWord;
Description: Read the status of the specified USB port


[Expand]
function USBHubPortSetFeature(Port:PUSBPort; Feature:Word):LongWord;
Description: Enable a feature on the specified USB port


[Expand]
function USBHubPortClearFeature(Port:PUSBPort; Feature:Word):LongWord;
Description: Disable a feature on the specified USB port


[Expand]
function USBHubPortChangeFeature(Port:PUSBPort; Feature:Word; Enable:Boolean):LongWord;
Description: Enable or disable a feature on the specified USB port


[Expand]
function USBHubPortAttachDevice(Port:PUSBPort):LongWord;
Description: Attach a newly connected USB device to the specified USB port


[Expand]
function USBHubPortDetachDevice(Port:PUSBPort):LongWord;
Description: Detach a disconnected USB device from the specified USB port


[Expand]
function USBHubPortStatusChanged(Port:PUSBPort):LongWord;
Description: Process a status change for the specified USB port


[Expand]
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


[Expand]
procedure USBHubStatusComplete(Request:PUSBRequest);
Description: Called when the USB request from a USB hub IN interrupt endpoint completes


[Expand]
function USBHubDriverBind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Description: Bind the Hub driver to a USB device if it is suitable}


[Expand]
function USBHubDriverUnbind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Description: Unbind the Hub driver from a USB device


USB device, driver and host helper functions

[Expand]
function USBDeviceGetCount:LongWord; inline;
Description: Get the current device count


[Expand]
function USBDeviceCheck(Device:PUSBDevice):PUSBDevice;
Description: Check if the supplied Device is in the device table


[Expand]
function USBDriverGetCount:LongWord; inline;
Description: Get the current driver count


[Expand]
function USBDriverCheck(Driver:PUSBDriver):PUSBDriver;
Description: Check if the supplied Driver is in the driver table


[Expand]
function USBHostGetCount:LongWord; inline;
Description: Get the current host count


[Expand]
function USBHostCheck(Host:PUSBHost):PUSBHost;
Description: Check if the supplied Host is in the host table


[Expand]
function USBIsHub(Device:PUSBDevice):Boolean;
Description: Returns True if Device is a Hub or False if not


[Expand]
function USBIsRootHub(Device:PUSBDevice):Boolean;
Description: Returns True if Device is a Root Hub or False if not


[Expand]
function USBIsControlRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is a control request or False if not


[Expand]
function USBIsBulkRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is a bulk request or False if not


[Expand]
function USBIsInterruptRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is an interrupt request or False if not


[Expand]
function USBIsIsochronousRequest(Request:PUSBRequest):Boolean;
Description: Returns True if Request is an isochronous request or False if not


[Expand]
function USBIsInEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is an IN endpoint or False if not


[Expand]
function USBIsOutEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is an OUT endpoint or False if not


[Expand]
function USBIsBulkEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is a BULK endpoint or False if not


[Expand]
function USBIsInterruptEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is a INTERRUPT endpoint or False if not


[Expand]
function USBIsIsochronousEndpoint(Endpoint:PUSBEndpointDescriptor):Boolean;
Description: Returns True is Endpoint is a ISOCHRONOUS endpoint or False if not


[Expand]
function USBDeviceToString(Device:PUSBDevice):String;
Description: Return a description of a USB device


[Expand]
function USBStatusToString(Status:LongWord):String;
Description: Translates a USB status code into a string


[Expand]
function USBClassCodeToString(ClassCode:Integer):String;
Description: Translates a USB class code into a string


[Expand]
function USBSubClassCodeToString(ClassCode,SubClassCode:Integer):String;
Description: Translates a USB sub class code into a string


[Expand]
function USBProtocolCodeToString(ClassCode,ProtocolCode:Integer):String;
Description: Translates a USB protocol code into a string


[Expand]
function USBSpeedToString(Speed:Integer):String;
Description: Translates a USB speed constant into a string


[Expand]
function USBTransferTypeToString(TransferType:Integer):String;
Description: Translates a USB transfer type constant into a string


[Expand]
function USBDirectionToString(Direction:Integer):String;
Description: Translates a USB direction constant into a string


[Expand]
function USBBCDVersionToString(BCDVersion:Word):String;
Description: Translates a bcdUSB (binary-coded-decimal USB version) value into a human-readable string


[Expand]
function USBPortStatusConnectedToString(Status:Word):String;
Description: To be documented


[Expand]
function USBHubCharacteristicsToString(HubCharacteristics:Word):String;
Description: To be documented


[Expand]
function USBDeviceTypeToString(USBType:LongWord):String;
Description: To be documented


[Expand]
function USBDeviceStateToString(USBState:LongWord):String;
Description: To be documented


[Expand]
function USBDeviceStatusToString(USBStatus:LongWord):String;
Description: To be documented


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


[Expand]
function USBDeviceStatusToNotification(Status:LongWord):LongWord;
Description: Convert a Device status value into the notification code for device notifications


[Expand]
function USBHostTypeToString(HostType:LongWord):String;
Description: To be documented


[Expand]
function USBHostStateToString(HostState:LongWord):String;
Description: To be documented


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


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


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


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


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


[Expand]
procedure USBLogDeviceConfiguration(Device:PUSBDevice);
Description: To be documented


[Expand]
procedure USBLogDeviceDescriptor(Device:PUSBDevice; Descriptor:PUSBDeviceDescriptor);
Description: To be documented


[Expand]
procedure USBLogConfigurationDescriptor(Device:PUSBDevice; Descriptor:PUSBConfigurationDescriptor);
Description: To be documented


[Expand]
procedure USBLogInterfaceDescriptor(Device:PUSBDevice; Descriptor:PUSBInterfaceDescriptor);
Description: To be documented


[Expand]
procedure USBLogEndpointDescriptor(Device:PUSBDevice; Descriptor:PUSBEndpointDescriptor);
Description: To be documented


[Expand]
function USBLogDevices:LongWord;
Description: Print information about all devices attached to the USB


[Expand]
function USBLogDeviceCallback(Device:PUSBDevice; Data:Pointer):LongWord;
Description: To be documented


[Expand]
function USBLogTreeCallback(Device:PUSBDevice; Data:Pointer):LongWord;
Description: To be documented


USB hub helper functions

[Expand]
function USBHubGetCount:LongWord; inline;
Description: Get the current hub count


[Expand]
function USBHubCheck(Hub:PUSBHub):PUSBHub;
Description: Check if the supplied Hub is in the hub table


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


Return to Unit Reference