-
題目
: USB 2.0
與
UVC 1.1
在
Webcam
F/W
傳輸設定
尚立
Webcam
高級工程師
Aladdin
前言
:
Webcam
使用
USB Video Class 1.1
以及使用
USB 2.0
的通訊協定將
Webcam
的影像資料傳輸到
PC
或
NB,
如果有支援聲音則使用
USB Audio
Class 1.0
的協定
內容
:
W
ebcam
可以從程式設定了解
USB
協定
(1)
設定
Standard Device
主要設定
USB 2.0 High Speed
的
Standard Device Descriptor,
定義在
USB2.0 Spec. Table 9.8
設定
USB
版本
,
產品的
VID, PID, Serial Number
....
等
0x00, 0x12,
// length of device
decriptor
// Device Descriptor
0x12,
//
bLength: 0x12 byte
0x01,
//
bDescriptorType: DEVICE
0x00, 0x02,
//
bcdUSB: version 2.00
0xEF,
//
bDeviceClass: independent interfaces
0x02,
//
bDeviceSubClass: 2
0x01,
//
bDeviceProtocol: class specific
protocols NOT used on
device basis
0x40,
//
zero
0xF2, 0x04,
//
0xC3, 0xB2,
//
0x27, 0x11,
//
0x01,
//
0x02,
//
0x00,
//
bMaxPacketSize0: maximum packet size
for endpoint
idVendor: vendor ID
idProduct: product ID
bcdDevice: device release
number in BCD
iManufacturer: index of string
iProduct: index of string
iSerialNumber: index of string
0x01,
//
bNumConfigurations: 1 configuration
解釋
Offset 0 -> bLength:
為這個
Descriptor
的長度為
18 Bytes,,
占
1 Byte,
設定為
0x12
Offset 1
->
bDescriptorType,
這個
Descriptor type,
占
1 Byte,
為
0x01
Offset
2->
bcdUSB,
USB
通訊的版本
,
占
2
個
Bytes,
由於是支援
USB2.0 ,
所以要
設定
0x00,
0x02(
傳輸先傳低位元組再傳高位元組
)
Offset 4 ->bDeviceClass, USB_IF
對這
Device
Class
的編碼
, 0xEF
Offset 5 ->bDeviceSubClass,
USB_IF
對這
Device sub Class
編碼
, 0x02
Offset 6
->bDeviceProtocol, USB_IF
對這
Device Protocol
編碼
, 0x01
Offset 7
->bMaxPacketSize,
傳輸最大
數據包的
Size,
只可以定義
8,
16,
32,
64,
這裡定義為
64
Bytes,
為
0x40
Offset 8 -> idVendor,
為產品的
VID
根據
US
B-IF
定義
,
占
2bytes,0xF2,0x40
Offset10->idProduct,
定義產品的
PID,
占
2bytes, 0xC3, 0xB2
Offset12-> bcdDevice,
可定義產品的版本
,
占
2bytes, 0x27,0x11
Offset14-> iManufacturer,
製造廠商
,
利用
index
選擇
Strings, 0x01
Offset15 -> iProduct,
產品名稱
p>
,
利用
index
選擇
Strings,0x02
Offset16-> iSerialNumber,
序號
,
利用
index
選擇
Strings,0x00
Offset 17-> bNumConfigurations,
結構的編號
,
使用
Configuration 1, 0x01
這個
Device
descriptor
傳輸到
NB
或
PC,
在
Windows
的系統的硬體識別碼顯示
VID,
PID,
與
Rev
(2)
其他速率傳輸設定
Device_Qualifier
Descriptor,
設定非
High Speed USB
Device Descriptor ,
如
Webcam
也有支援
Full Speed
傳輸
,
定義在
USB Spec. Table 9.9
F/W
設定為
0x00, 0x0A,
// length of device
qualifier descriptor
// Device
Qualifier Descriptor
0x0A,
//
bLength: 0x0A
byte
0x06,
//
bDescriptorType: DEVICE
QUALIFIER
0x00, 0x02,
//
bcdUSB: version 2.00
0xEF,
//
bDeviceClass: independent
interfaces
0x02,
//
bDeviceSubClass: 2
0x01,
//
bDeviceProtocol: class specific
protocols NOT used on
device basis
0x40,
//
bMaxPacketSize0: maximum packet size
for endpoint
zero
0x01,
//
0x00,
//
bNumConfigurations: 1 configuration
bReserved: 0x00
解釋
Offset0,
為
bLength,
這
Device Qualifier
為
10bytes, 0x0A
Offset1,
為
bDescriptorType,
設定為
0x06
Offset2,
為
bcdUSB,
USB
通訊的版本
,
占
2
個
Bytes,
由於是
USB2.0 ,
所以要設
定
0x00, 0x02
Offset 4,
為
bDeviceClass, USB-IF
對這
Device
的
class
編碼
, 0xEF
Offset5,
為
bDeviceSubClass, USB-IF
對這
Device
的
subclass
編碼
, 0x0x02
Offset6 ,
為
bDeviceProtocol, USB-IF
對這
Device
的
protocol
編碼
, 0x0x01
Offset 7 ->bMaxPacketSize,
傳輸最大數據包的
Size,
只可以定義
8, 16, 32, 64,
< br>這
裡定義為
64,
為
0x40
Offset8->
bNumConfigurations,
結構的編號
,
使用
Configuration 1, 0x01
Offset9-> bReserved,
保留
,
需設定
0x00
(3)
顯示語言編碼
顯示
Webcam
字串的語言編碼
,
定義在
USB 2.0 Spec. Table
9.15
F/W
設定
0x00, 0x04,
//
length of language id string descriptor
// Language ID String Descriptor
0x04,
//
bLength
0x03,
//
bDescriptorType: STRING
0x09, 0x04,
//
bString: English (US)
解釋
Offset0
為
bLength,
因指定義一種語言所以為
0x04
Offset1
為
bbDescriptorType, String
的
Descriptor
為
0x03
Offset2
為
wLANGID[0],
占
2bytes,
英文編碼為
0x09,0x04
參考
USB Language
編
碼
(4)
產品名稱編碼
Webcam
的產品名稱
,
定義在
USB 2.0 Spec. Table 9.16
F/W
設定
0x00,0x32,
//length of product string descriptor
0x32,
//Product String
Descriptor
0x03,
//bLength
0x53,0x00,
0x50,0x00,
0x43,0x00,
0x41,0x00,
0x32,0x00,
0x32,0x00,
0x38,0x00,
0x31,0x00,
0x20,0x00,
0x57,0x00,
0x65,0x00,
0x62,0x00,
0x20,0x00,
0x43,0x00,
0x61,0x00,
0x6D,0x00,
//'W'
//'e'
//'b'
//' '
//'C'
//'a'
//'m'
0x65,0x00,
//'e'
0x72,0x00,
//'r'
0x61,0x00,
//'a'
0x20,0x00,
0x20,0x00,
0x20,0x00,
0x20,0x00,
解釋
Offset0
為
bLength,
更具字串
+2
來定義
Length
Offset1
為
bDescriptorType,
設定字串的
Descriptor
為
0x03
Offset2~OffsetN
設定字串編碼
,
使用
Unicode
碼
,
每個字為
2Bytes
這個
Strings descriptor
傳輸到
NB
或
PC,
在顯示名稱會秀出如
USB Camera
2.
傳輸設定
:
主要設定
USB 2.0
的
Configuration
及
UVC 1.1
的定義處理如
feature,
resolution...
等等
可分為
Full Speed USB
定義及
High Speed USB
定義
,
兩者的
Descriptor
類似只
是參數設定不同
,
(1) USB Configuration
F/W
編碼
//
Configuration Descriptor
0x09,
//
bLength: 0x09
byte
0x02,
//
bDescriptorType: CONFIGURATION
0x81, 0x05,
//
wTotalLength: 0x062d byte
0x04,
//
bNumInterfaces: 2 interfaces
0x01,
//
bConfigurationValue: configuration 1
0x00,
//
iConfiguration: index of string
0x80,
//
bmAttributes: bus powered
0xFA,
//
MaxPower: 500 mA
這定義
USB2.0
傳送
UVC
及
UAC
的型態
,
規範在
USB 2.0 Spec. Table 9.10
解釋
Offset0
為
bLength,
Configuration Descriptor
的長度為
9 bytes, 0x09
Offset1
為
bDescriptorType,
Configuration Descriptor type, 0x02
Offset2
為
wTotalLength,
占
2bytes
為傳送
USB 2.0
的
UVC
或
UAC
定義資料的
全部長度
,
包括
Configuration Descriptor,
0x81,0x05(0x581 bytes)
Offset4
為
bNumInterfaces, Interface
number, SPCA2281
有
Audio
所以設定
0x04,
如沒有
Audio
設定
0x02
Offset5
為
bConfigurationValue,
為設定結構值
,
定義
0x01
Offset6
為
iConfiguration,
為設定這結構的描述字串指標
, 0x00
Offset7
為
bmAttributes,
為設定
bus
的
power
狀況
, D7
為
reserved
必須設定為
1, D6
為是否要
Self Power,
D5
為遠端遙控開機功能
,
D4~D0
為
reserved
設為
0,
所以為
0x80
Offset8
為
bMaxPower,
設定
USB
bus
最大電流
,
每單為為
2mA,
所以
0xfa=250
即為
500mA
(2)Video Interface Association
Descriptor
USB
在
Video
介面接口關連描述
(IAD)
定義在
UVC1.1 Spec. Table 3-1
F/W
設定
0x08,
0x0B,
ASSOCATION
Descriptor
// Video
Interface Association Descriptor
//
bLength: 0x08
byte
//
bDescriptorType: INTERFACE
0x00,
//
bInterfaceNumber: interface 0
0x02,
//
bInterfaceCount: 2
0x0E,
//
bFunctionClass:
0x0E
0x03,
//
bFunctionSubClass: 0x03
0x00,
//
bInterfaceProtocol: class specific
protocol
NOT used on this interface
0x02,
//
iFunction: 2
解釋
Offset0
為
bLength,
IAD
長度為
8bytes, 0x08
Offset1
bDescriptorType ,
Interface Association descriptor type,
Value=11,0x0B
Descriptor Types
編號
Offset2
為
bFirstInterface
為第一個
Video control number,
設定
0x00
Offset3
為
bInterfaceCount
為鄰近的
interface
總數<
/p>
,
設定
0x02(Webcam, NB
or PC)
Offset4
為
bFunctionClass,
Video Interface Class code
的
CC_VIDEO ,0x0E
Offset5
為
bFunctionSubClass,
設定
SC_VIDEO_INTERFACE_COLLECTION
, 0x03
Offset6
為
bFunctionProtocol ,
< br>必須設為
PC_PROTOCOL_UNDEFINED,0x00
Offset7
為
iFunction ,
這界面字串的指標
,0x02
(3)
Standard VC Interface
Descriptor
設定基本
Video Control
介面的
Descriptor,
定義
UVC1.1 Spec Table 3-2
F/W
設定
0x09,
0x04,
0x00,
0x00,
0x01,
0x0E,
0x01,
//
//
//
//
//
//
//
// VideoControl Interface Descriptor
bLength: 0x09 byte
bDescriptorType: INTERFACE
bInterfaceNumber: interface
0
bAlternateSetting:
alternate setting 0
bNumEndpoints: 1 endpoint
bInterfaceClass: 0x0E
bInterfaceSubClass: 0x01
0x00,
//
bInterfaceProtocol: class specific
protocol NOT used on this interface
0x02,
//
iInterface: index of string
解釋
Offset0
為
bLength ,
這
VC interface Descriptor
固定長度為
9Bytes, 0x09
Offset1
為
bDescriptorType,
介面
Descriptor
type, 0x04
Offset2
為
bInterfaceNumber,
介面數
,
設定為
0
Offset3
為
bAlternateSetting ,
間隔數的設定
,
設為
0
間隔
,
0x00
Offset4
為
bNumEndpoints ,
端點的設定
,
需設為
1, 0x01
Offset5
為
bInterfaceClass ,
設定為
CC_VIDEO, 0x0E
Offset6
為
bInterfaceSubClass ,
設定
SC_VIDEOCONTROL,0x01
Offset7
為
bInterfaceProtocol ,
沒使用必須設
PC_PROTOCOL_UNDEFINED
,0x00
Offset8
為
iInterface,
介面
descriptor
描述字串指標
,
設定
0x02
(4) Class-specific VC Interface Header
Descriptor
主要是設定
Class-
specific
的
total length
及
Device clock Frequency,
參考
UVC Spec
Table
3-3
F/W
設定
Header Descriptor
0x0D,
0x24,
0x01,
subtype
0x00, 0x01,
that this device is based upon
0x50, 0x00,
class-specific descriptors
0x00, 0x6C, 0xDC, 0x02,
0x01,
interfaces
0x01,
// Class-
specific VideoControl Interface
bLength: 0x0D byte
bDescriptorType: 0x24
bDescriptorSubType: VC_HEADER
bcdVDC: Revision of class specification
wTotalLength: Total size of
dwClockFrequency: 48MHz
bInCollection: Number of streaming
baInterfaceNr(1): Interface number of
//
//
//
//
//
//
//
//
the first VideoStreaming interface
解釋
Offset0
為
bLength,
基本
Length
為
12,
另外增加
1Byte
的
interface number,
為
13, 0x0D
Offset1
為
bDescriptorType ,
設定
CS_INTERFACE,
為
0x24
Offset2
為
bDescriptorSubType ,
要設
VC_Header, 0x01
Offset3
為
bcdUVC,
定義
Video
Device Class Specification release number,
占
2bytes,
0x00,
0x01
Offset5
為
wTot
alLength,
定義
class-specific VideoControl interface d
escriptor
的全部
長度
,
p>
占
2bytes,
為
0x50, 0x00
Offset7
為
dwClockFrequency ,
裝置的
clock Frequency,
為
48MHz->48000000->02DC6C00,
占
4bytes, 0x00,0x6C,0xDC,0x02
Offset11
為
bInCollection
,
為
VideoStreaming number,
設定
0x01
Offset12
為
baInterfaceNr(1),
為第一個
VideoStreaming
有多少
interface,
為
0x01
(5) Input (Camera)Terminal Descriptor
設定
VideoControl Camera Input
Terminal Descriptor,
參考
UVC
Spec Table 3-6
F/W
設定
0x12,
0x24,
0x02,
VC_INPUT_TERMINAL subtype
0x01,
0x01, 0x02,
0x00,
0x00,
0x00, 0x00,
optional zoom supported
0x00, 0x00,
optional zoom supported
0x00, 0x00,
supported
0x03,
bmControls is
2 bytes
0x0A, 0x00, 0x00,
are
supported
//
VideoControl Camera Terminal Descriptor
//
bLength: 0x12 byte
//
bDescriptorType: 0x24
//
//
//
//
//
//
bDescriptorSubType:
bTerminalID: ID of this input terminal
wTerminalType: ITT_CAMERA type.
bAssocTerminal: No assocation
iTerminal: Unused
wObjectiveFocalLengthMin: No
wObjectiveFocalLengthMax: No
wOcularFocalLength: No optional zoom
bControlSize: The size of the
bmControls: Camera Terminal controls
//
//
//
//
解釋
:
Offset0
為
bLength ,
設定
0x12
Offset1
為
bDescriptorType,
設定
CS_INTERFACE ,
0x24
Offset2
為
bDescriptorSubtype,
設定
VC_INPUT_TERMINAL, 0x02
Offset3
為
bTerminalID ,
為
Input terminal ID, 0x01
Offset4
為
wTerminalType,
占
2bytes, Input Terminal
type
為
Camera,0x01, 0x02
Offset6
為
bAssocTerminal
, no such association exists
設
0, 0x00
Offset7
為
iTerminal, input Terminal
String
指標
, 0x00
Offset8
為
wObjectiveFocalLengthMin ,
The value of L
min
,
因
SPCA2281
沒
Support
control
Focal
設
0x00, 0x00
Offset10
為
wObjectiveFocalLengthMax,
The value of L
Offset12
為
wOcularFocalLength ,
The value of L
Optical
Zoom
公式為
max
,
設
0x00, 0x00
ocular
,
設
0x00, 0x00
Offset14
為
bControlSize,
為
Camera Control bmControls
Size, 0x03
Offset15
為
bmControls ,
Camera Unit control,
設定為
0x0A,0x00,0x00
占
3bytes
表示
0000,0000,0000,0000,0000,1010-> support D3
Exposure Time (Absolute), D1
Auto-Exposure Mode
(6)
Processing
Unit Descriptor
主要設定
Support video stream
及
analog Video
standard
參考
UVC Spec. Table
3-8
F/W
設定
0x0B,
0x24,
0x05,
VC_PROCESSING_UNIT
0x02,
0x01,
//
//
bUnitID: ID of this unit
bSourceID: This input pin of this unit
is
// VideoControl Processing Unit
Descriptor
//
//
//
bLength: 0x0B byte
bDescriptorType: 0x24
bDescriptorSubtype:
connected to the output pin of unit
with ID 0x01
0x00, 0x40,
magnification (4X).
0x02,
bmControls field
0x7F, 0x15,
supported.
0x00,
解釋
Offset0
為
bLength , 0x0B
//
iProcessing: Unused
//
bmControls:
Processing Unit controls
//
bControlSize: Size in bytes
of the
//
wMaxMultiplier: Maximum
digital
Offset1
為
bDescriptorType ,
設定
CS_INTERFACE, 0x24
Offset2
為
bDescriptorSubtype ,
設定
VC_PROCESSING_UNIT,0x05
Offset3
為
bUnitID, Uini ID, 0x02
Offset4
為
bSourceID , Source ID,
輸入為
camera
為
0x01
Offset5
為
wMaxMultiplier, Max
Digital Multiplier
為
4x, 0x00, 0x40
Offset7
為
bControlSize, bmControls
size, 0x02
Offset8
為
bmControls,
設定
0x7F, 0x17,
占
2bytes,
為
0001,0111,0111,1111
表示
Support
White
Balance Temperature( Auto), Power Line
Frequency,
Gain,
Backlight
Compensation
,
White Balance Temperature,
Gamma,
Sharpness,
Hue,
Contrast,
Brightness
Offset10
為
iProcessing ,
Index of a string
descriptor,
設
0x00
(7)
Extension Unit
Descriptor
延伸資料的
Descriptor,
可以將製造商資料
(SunplusIT)
或是客戶
(Dell)
放入
16bytes
的
Extension
unit
中
,
參考
UVC Spec. Table 3-9
F/W
設定
0x1D,
0x24,
0x06,
VC_EXTENSION_UNIT
0x03,
0x99, 0x1D, 0x5A, 0x7D,
Sunplus Extension Unit. */
0x32, 0x5B,
0x8B, 0x42,
0x8C, 0xAD,
0x67, 0x1B,
0x8A, 0x65, 0xF3, 0x7A,
0x00,
0x01,
0x02,
0x04,
0xFF, 0xFF, 0x19,0x00,
0x00,
(8)
Output Terminal Descriptor
參考
UVC SPEC. Table3-5
//
//
//
//
//
//
bNumControls
bNrInPins
bSourceID
bControlSize
bmControls
Unused
//
bUnitID: ID of this unit
//
guidFormat: Globally Unique Identifier for
//
//
//
bLength: 0x1D byte
bDescriptorType: 0x24
bDescriptorSubtype:
F/W
設定
0x09,
0x24,
0x03,
VC_OUTPUT_TERMINAL.
0x04,
0x01, 0x01,
//
//
//
//
//
bTerminalID: ID of this terminal.
wTerminalType: TT_STREAMING type.
bAssocTerminal: No association.
bSourceID: The input pin of this unit
is
iTerminal: Unused
//
VideoControl Output Terminal Descriptor
//
//
//
bLength: 0x09 byte
bDescriptorType: 0x24
bDescriptorSubtype:
This
terminal is a USB streaming terminal.
0x00,
0x04,
0x00,
解釋
Offset0,
為
bLength ,
為
9bytes, 0x09
connected to the output pin of unit 3.
Offset1
為
bDescriptorType ,
設定
CS_INTERFACE , 0x24
Offset2
為
bDescriptorSubtype,
設定
VC_OUTPUT_TERMINAL, 0x03
Offset3
為
bTerminalID ,
為
Terminal ID, 0x04
Offset4
為
wTerminalType, Terminal
type
TT_STREAMING
, 0x01,0x01
-
-
-
-
-
-
-
-
-
上一篇:努力奋斗的英文名言
下一篇:努力奋斗的英文名言【三篇】