UVC摄像头USB配置描述符实现
2022-03-09
1308
3
USB配置描述符用于根据设备类和端点设置配置设备。配置下描述符的层次结构包括接口关联描述符,接口描述符、类特定描述符和端点描述符。
当主机请求配置描述符时,将返回整个主机层次结构时相关描述符。
/* USB Configuration Descriptor */
static unsigned char cfgDesc[] = {
0x09, /* 0 bLength */
USB_DESCTYPE_CONFIGURATION, /* 1 bDescriptorType - Configuration*/
0xAE,00, /* 2 wTotalLength */
0x02, /* 4 bNumInterfaces */
0x01, /* 5 bConfigurationValue */
0x03, /* 6 iConfiguration - index of string */
0x80, /* 7 bmAttributes - Bus powered */
0xFA, /* 8 bMaxPower (in 2mA units) - 500mA */
/* Interface Association Descriptor */
0x08, /* 0 bLength */
USB_DESCTYPE_INTERFACE_ASSOCIATION, /* 1 bDescriptorType - Interface Association */
0x00, /* 2 bFirstInterface - VideoControl i/f */
0x02, /* 3 bInterfaceCount - 2 Interfaces */
USB_CLASS_VIDEO, /* 4 bFunctionClass - Video Class */
USB_VIDEO_INTERFACE_COLLECTION, /* 5 bFunctionSubClass - Video Interface Collection */
0x00, /* 6 bFunctionProtocol - No protocol */
0x02, /* 7 iFunction - index of string */
/* Video Control (VC) Interface Descriptor */
0x09, /* 0 bLength */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType - Interface */
0x00, /* 2 bInterfaceNumber - Interface 0 */
0x00, /* 3 bAlternateSetting */
0x01, /* 4 bNumEndpoints */
USB_CLASS_VIDEO, /* 5 bInterfaceClass - Video Class */
USB_VIDEO_CONTROL, /* 6 bInterfaceSubClass - VideoControl Interface */
0x00, /* 7 bInterfaceProtocol - No protocol */
0x02, /* 8 iInterface - Index of string (same as iFunction of IAD) */
/* Class-specific VC Interface Header Descriptor */
0x0D, /* 0 bLength */
USB_DESCTYPE_CS_INTERFACE, /* 1 bDescriptorType - Class-specific Interface */
USB_VC_HEADER, /* 2 bDescriptorSubType - HEADER */
0x10, 0x01, /* 3 bcdUVC - Video class revision 1.1 */
0x28, 0x00, /* 5 wTotalLength - till output terminal */
WORD_CHARS(100000000), /* 7 dwClockFrequency - 100MHz (Deprecated) */
0x01, /* 11 bInCollection - One Streaming Interface */
0x01, /* 12 baInterfaceNr - Number of the Streaming interface */
/* Input Terminal (Camera) Descriptor - Represents the CCD sensor (Simulated here in this demo) */
0x12, /* 0 bLength */
USB_DESCTYPE_CS_INTERFACE, /* 1 bDescriptorType - Class-specific Interface */
USB_VC_INPUT_TERMINAL, /* 2 bDescriptorSubType - INPUT TERMINAL */
0x01, /* 3 bTerminalID */
0x01, 0x02, /* 4 wTerminalType - ITT_CAMERA type (CCD Sensor) */
0x00, /* 6 bAssocTerminal - No association */
0x00, /* 7 iTerminal - Unused */
0x00, 0x00, /* 8 wObjectiveFocalLengthMin - No optical zoom supported */
0x00, 0x00, /* 10 wObjectiveFocalLengthMax - No optical zoom supported*/
0x00, 0x00, /* 12 wOcularFocalLength - No optical zoom supported */
0x03, /* 14 bControlSize - 3 bytes */
0x00, 0x00, 0x00, /* 15 bmControls - No controls are supported */
/* Output Terminal Descriptor */
0x09, /* 0 bLength */
USB_DESCTYPE_CS_INTERFACE, /* 1 bDescriptorType - Class-specific Interface */
USB_VC_OUPUT_TERMINAL, /* 2 bDescriptorSubType - OUTPUT TERMINAL */
0x02, /* 3 bTerminalID */
0x01, 0x01, /* 4 wTerminalType - TT_STREAMING type */
0x00, /* 6 bAssocTerminal - No association */
0x01, /* 7 bSourceID - Source is Input terminal 1 */
0x00, /* 8 iTerminal - Unused */
/* Standard Interrupt Endpoint Descriptor */
0x07, /* 0 bLength */
USB_DESCTYPE_ENDPOINT, /* 1 bDescriptorType */
(VIDEO_STATUS_EP_NUM | 0x80), /* 2 bEndpointAddress - IN endpoint*/
0x03, /* 3 bmAttributes - Interrupt transfer */
0x40, 0x00, /* 4 wMaxPacketSize - 64 bytes */
0x09, /* 6 bInterval - 2^(9-1) microframes = 32ms */
/* Class-specific Interrupt Endpoint Descriptor */
0x05, /* 0 bLength */
USB_DESCTYPE_CS_ENDPOINT, /* 1 bDescriptorType - Class-specific Endpoint */
0x03, /* 2 bDescriptorSubType - Interrupt Endpoint */
0x40, 0x00, /* 3 wMaxTransferSize - 64 bytes */
/* Video Streaming Interface Descriptor */
/* Zero-bandwidth Alternate Setting 0 */
0x09, /* 0 bLength */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType - Interface */
0x01, /* 2 bInterfaceNumber - Interface 1 */
0x00, /* 3 bAlternateSetting - 0 */
0x00, /* 4 bNumEndpoints - No bandwidth used */
USB_CLASS_VIDEO, /* 5 bInterfaceClass - Video Class */
USB_VIDEO_STREAMING, /* 6 bInterfaceSubClass - VideoStreaming Interface */
0x00, /* 7 bInterfaceProtocol - No protocol */
0x00, /* 8 iInterface - Unused */
/* Class-specific VS Interface Input Header Descriptor */
0x0E, /* 0 bLength */
USB_DESCTYPE_CS_INTERFACE, /* 1 bDescriptorType - Class-specific Interface */
USB_VS_INPUT_HEADER, /* 2 bDescriptorSubType - INPUT HEADER */
0x01, /* 3 bNumFormats - One format supported */
0x47, 0x00, /* 4 wTotalLength - Size of class-specific VS descriptors */
(VIDEO_DATA_EP_NUM | 0x80), /* 6 bEndpointAddress - Iso EP for video streaming */
0x00, /* 7 bmInfo - No dynamic format change */
0x02, /* 8 bTerminalLink - Denotes the Output Terminal */
0x01, /* 9 bStillCaptureMethod - Method 1 supported */
0x00, /* 10 bTriggerSupport - No Hardware Trigger */
0x00, /* 11 bTriggerUsage */
0x01, /* 12 bControlSize - 1 byte */
0x00, /* 13 bmaControls - No Controls supported */
/* Class-specific VS Format Descriptor */
0x1B, /* 0 bLength */
USB_DESCTYPE_CS_INTERFACE, /* 1 bDescriptorType - Class-specific Interface */
USB_VS_FORMAT_UNCOMPRESSED, /* 2 bDescriptorSubType - FORMAT UNCOMPRESSED */
0x01, /* 3 bFormatIndex */
0x01, /* 4 bNumFrameDescriptors - 1 Frame descriptor followed */
0x59,0x55,0x59,0x32,
0x00,0x00,0x10,0x00,
0x80,0x00,0x00,0xAA,
0x00,0x38,0x9B,0x71, /* 5 guidFormat - YUY2 Video format */
BITS_PER_PIXEL, /* 21 bBitsPerPixel - 16 bits */
0x01, /* 22 bDefaultFrameIndex */
0x00, /* 23 bAspectRatioX */
0x00, /* 24 bAspectRatioY */
0x00, /* 25 bmInterlaceFlags - No interlaced mode */
0x00, /* 26 bCopyProtect - No restrictions on duplication */
/* Class-specific VS Frame Descriptor */
0x1E, /* 0 bLength */
USB_DESCTYPE_CS_INTERFACE, /* 1 bDescriptorType - Class-specific Interface */
USB_VS_FRAME_UNCOMPRESSED, /* 2 bDescriptorSubType */
0x01, /* 3 bFrameIndex */
0x01, /* 4 bmCapabilities - Still image capture method 1 */
SHORT_CHARS(WIDTH), /* 5 wWidth - 480 pixels */
SHORT_CHARS(HEIGHT), /* 7 wHeight - 320 pixels */
WORD_CHARS(MIN_BIT_RATE), /* 9 dwMinBitRate */
WORD_CHARS(MAX_BIT_RATE), /* 13 dwMaxBitRate */
WORD_CHARS(MAX_FRAME_SIZE), /* 17 dwMaxVideoFrameBufSize */
WORD_CHARS(FRAME_INTERVAL), /* 21 dwDefaultFrameInterval (in 100ns units) */
0x01, /* 25 bFrameIntervalType */
WORD_CHARS(FRAME_INTERVAL), /* 26 dwFrameInterval (in 100ns units) */
/* Video Streaming Interface Descriptor */
/* Alternate Setting 1 */
0x09, /* 0 bLength */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType - Interface */
0x01, /* 2 bInterfaceNumber - Interface 1 */
0x01, /* 3 bAlternateSetting - 1 */
0x01, /* 4 bNumEndpoints */
USB_CLASS_VIDEO, /* 5 bInterfaceClass - Video Class */
USB_VIDEO_STREAMING, /* 6 bInterfaceSubClass - VideoStreaming Interface */
0x00, /* 7 bInterfaceProtocol - No protocol */
0x00, /* 8 iInterface - Unused */
/* Standard VS Isochronous Video Data Endpoint Descriptor */
0x07, /* 0 bLength */
USB_DESCTYPE_ENDPOINT, /* 1 bDescriptorType */
(VIDEO_DATA_EP_NUM | 0x80), /* 2 bEndpointAddress - IN Endpoint */
0x05, /* 3 bmAttributes - Isochronous EP (Asynchronous) */
0x00, 0x04, /* 4 wMaxPacketSize 1x 1024 bytes*/
0x01, /* 6 bInterval */
};
配置描述符告诉主机设备的电源需求及其支持的接口数量。
多个接口一起提供视频功能。这组接口称为视频接口集合。视频接口集合由接口关联描述符(IAD)描述。
在示例应用程序中,IAD定义接口0和1分组以形成USB视频设备。这两个接口是:
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936