Muokkaa

Jaa


Getting started with USB development

A Universal Serial Bus (USB) device defines its capabilities and features through configurations, interfaces, alternate settings, and endpoints. This topic provides a high-level overview of those concepts. For details, see the USB specifications at Universal Serial Bus Documents.

In this section

Topic Description
USB device layout A USB device defines its capabilities and features through configurations, interfaces, alternate settings, and endpoints. This topic provides a high-level overview of those concepts.
Standard USB descriptors A USB device provides information about itself in data structures called USB descriptors. This section provides information about device, configuration, interface, and endpoint descriptors and ways to retrieve them from a USB device.
USB endpoints and their pipes A USB device has endpoints that are used to for data transfers. On the host side, endpoints are represented by pipes. This topic differentiates between those two terms.
USB in Windows - FAQ This topic presents frequently asked questions for driver developers who are new to developing and integrating USB devices and drivers with Windows operating systems.

Common USB scenarios

1—Get the device handle for communication and use the retrieved handle or object to send data transfers.

Client driver UWP app Windows desktop app
KMDF:
WdfUsbTargetDeviceCreateWithParameters

UMDF:
IWDFUsbTargetDevice
UsbDevice

How to connect to a USB device
WinUsb_Initialize

Write a Windows desktop app based on the WinUSB template

USB descriptor retrieval to get information about the device's configuration(s), interface(s), setting(s), and their endpoint(s).

Client driver UWP app Windows desktop app
KMDF:

WdfUsbTargetDeviceGetDeviceDescriptor
WdfUsbTargetDeviceRetrieveConfigDescriptor

UMDF:

IWDFUsbTargetDevice::RetrieveDescriptor

USB descriptors
UsbDevice.DeviceDescriptor
UsbConfiguration.Descriptors
UsbInterface.Descriptors
UsbInterfaceSetting.Descriptors

How to get USB descriptors
WinUsb_GetDescriptor
WinUsb_QueryInterfaceSettings
WinUsb_QueryPipe

Query the Device for USB Descriptors

2—Configure the device to select an active USB configuration and setting per interface.

Client driver UWP app Windows desktop app
KMDF:
WdfUsbTargetDeviceSelectConfig
WdfUsbTargetDeviceCreateUrb
USBD_SelectConfigUrbAllocateAndBuild
WdfUsbInterfaceSelectSetting

How to select a configuration for a USB device.

How to select an alternate setting in a USB interface.

UMDF:
Configuration selection is not supported

IWDFUsbInterface::SelectSetting
UsbInterfaceSetting.SelectSettingAsync

How to select a USB interface setting
WinUsb_SetCurrentAlternateSetting

3—Send control transfers for configuring the device and performing vendor commands that are specific to particular device.

Client driver UWP app Windows desktop app
KMDF:
WdfUsbTargetDeviceSendControlTransferSynchronously
WdfUsbTargetDeviceFormatRequestForControlTransfer
USBD_SelectConfigUrbAllocateAndBuild

UMDF:
IWDFUsbTargetDevice::FormatRequestForControlTransfer

How to send a USB control transfer
SendControlInTransferAsync
SendControlOutTransferAsync

How to send a USB control transfer
WinUsb_ControlTransfer

Send Control Transfer to the Default Endpoint

4—Send bulk transfers, typically used by mass storage devices that transfer large amount of data.

Client driver UWP app Windows desktop app
KMDF:
WdfUsbTargetPipeReadSynchronously
WdfUsbTargetPipeWriteSynchronously
WdfUsbTargetPipeFormatRequestForRead
WdfUsbTargetPipeFormatRequestForWrite

How to send USB bulk transfer requests

How to use the continuous reader for reading data from a USB pipe

UMDF:
IUsbTargetPipeContinuousReaderCallbackReadComplete
IWDFUsbTargetPipe
IWDFUsbTargetPipe2
UsbBulkInPipe.InputStream
UsbBulkOutPipe.OutputStream

How to send a USB bulk transfer request
WinUsb_WritePipe
WinUsb_ReadPipe

Issue I/O Requests

5—Send interrupt transfers. Data is read to retrieve hardware interrupt data.

Client driver UWP app Windows desktop app
Same as bulk transfers UsbInterruptInPipe.DataReceived
UsbInterruptOutPipe.OutputStream

How to send a USB interrupt transfer request
Same as bulk transfers

6—Send isochronous transfers, mostly used for media streaming devices.

Client driver UWP app Windows desktop app
KMDF:
WdfUsbTargetDeviceCreateIsochUrb

How to transfer data to USB isochronous endpoints

UMDF:
Not supported
Not supported WinUsb_RegisterIsochBuffer
WinUsb_UnregisterIsochBuffer
WinUsb_WriteIsochPipeAsap
WinUsb_ReadIsochPipeAsap
WinUsb_WriteIsochPipe
WinUsb_ReadIsochPipe
WinUsb_GetCurrentFrameNumber
WinUsb_GetAdjustedFrameNumber

Sending USB isochronous transfers from a WinUSB desktop app

7—USB selective suspend to allow the device to enter a low power state and bring the device back to working state.

Client driver UWP app Windows desktop app
KMDF:
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS
WdfDeviceAssignS0IdleSettings

UMDF:
IWDFUsbTargetDevice::SetPowerPolicy
IWDFDevice2::AssignS0IdleSettings
IWDFDevice3::AssignS0IdleSettingsEx

How to send a device to selective suspend
Not supported WinUsb_SetPowerPolicy

WinUSB Power Management

See also