USBディスクリプタ

8828 ワード


標準的なUSBデバイスには、デバイス記述子、構成記述子、文字列記述子、インタフェース記述子、エンドポイント記述子の5種類があります.
 1 // Standard Device Descriptor

 2 typedef struct

 3 {

 4     u8   bLength;

 5     u8   bDescriptorType;

 6     u16  bcdUSB;

 7     u8   bDeviceClass;

 8     u8   bDeviceSubClass;

 9     u8   bDeviceProtocol;

10     u8   bMaxPacketSize0;

11     u16  idVendor;

12     u16  idProduct;

13     u16  bcdDevice;

14     u8   iManufacturer;

15     u8   iProduct;

16     u8   iSerialNumber;

17     u8   bNumConfigurations;

18 } __attribute__((__packed__)) sDevDesc, *pDevDesc;

19 

20 /* Standard Configuration Descriptor */

21 typedef struct

22 {    

23     u8   bLength;                 // Size of descriptor in Byte

24     u8   bType;                   // Configuration

25     u16  wLength;                 // Total length

26     u8   bNumIntf;                // Number of interface

27     u8   bCV;                     // bConfigurationValue

28     u8   bIndex;                  // iConfiguration

29     u8   bAttr;                   // Configuration Characteristic

30     u8   bMaxPower;               // Power config

31 } __attribute__((__packed__)) sCfgDesc, *pCfgDesc;

32 

33 // Standard Interface Descriptor

34 typedef struct

35 {    u8   bLength;

36     u8   bType;

37     u8   iNum;

38     u8   iAltString;

39     u8   bEndPoints;

40     u8   iClass;

41     u8   iSub; 

42     u8   iProto;

43     u8   iIndex; 

44 } __attribute__((__packed__)) sIntfDesc, *pIntfDesc;

45 

46 // Standard EndPoint Descriptor

47 typedef struct

48 {    u8   bLength;

49     u8   bType;

50     u8   bEPAdd;

51     u8   bAttr;

52     u16  wPayLoad;               // low-speed this must be 0x08

53     u8   bInterval;

54 } __attribute__((__packed__)) sEPDesc, *pEPDesc;

55 

56 // Standard String Descriptor

57 typedef struct

58 {    u8   bLength;

59     u8   bType;

60     u16  wLang;

61 } __attribute__((__packed__)) sStrDesc, *pStrDesc;

 
HID記述子:
 1 struct hid_class_descriptor {

 2     u8  bDescriptorType;

 3     u16 wDescriptorLength;

 4 } __attribute__ ((packed));

 5 

 6 struct hid_descriptor {

 7     u8  bLength;

 8     u8  bDescriptorType;

 9     u16 bcdHID;

10     u8  bCountryCode;

11     u8  bNumDescriptors;

12     struct hid_class_descriptor desc[1];

13 } __attribute__ ((packed));

 
 
関連リンク:
http://wiki.osdev.org/Universal_Serial_Bus#Introduction
http://blog.csdn.net/alien75/article/details/4622319
http://blog.csdn.net/mcgrady_tracy/article/details/8129992