正文

usb.h + usbdesc.c2006-11-24 22:45:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/378121200/20747.html

分享到:



/*----------------------------------------------------------------------------
 *      U S B  -  K e r n e l
 *----------------------------------------------------------------------------
 *      Name:    usb.h
 *      Purpose: USB definiton file for Philips LPC214x Family Microprocessors
 *      Version: V1.04
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express, 
 *      implied or statutory, including but not limited to the implied 
 *      warranties of fitness for purpose, satisfactory quality and 
 *      noninfringement. Keil extends you a royalty-free right to reproduce and
 *      distribute executable files created using this software for use on 
 *      Philips LPC2xxx microcontroller devices only. Nothing else gives you the 
 *      right to use this software. 
 *
 *      Copyright (c) 2005 Keil Software.
 *        Modified by Philips Semiconductor
 *---------------------------------------------------------------------------*/
#ifndef __USB_H__
#define __USB_H__


#pragma pack(1)


typedef union {
  WORD W;
  struct {
    BYTE L;
    BYTE H;
  } WB;
} WORD_BYTE;


/* bmRequestType.Dir */
#define REQUEST_HOST_TO_DEVICE     0
#define REQUEST_DEVICE_TO_HOST     1

/* bmRequestType.Type */
#define REQUEST_STANDARD           0
#define REQUEST_CLASS              1
#define REQUEST_VENDOR             2
#define REQUEST_RESERVED           3

/* bmRequestType.Recipient */
#define REQUEST_TO_DEVICE          0
#define REQUEST_TO_INTERFACE       1
#define REQUEST_TO_ENDPOINT        2
#define REQUEST_TO_OTHER           3

/* bmRequestType Definition */
typedef union _REQUEST_TYPE {
  struct _BM {
    BYTE Recipient : 5;
    BYTE Type      : 2;
    BYTE Dir       : 1;
  } BM;
  BYTE B;
} REQUEST_TYPE;

/* USB Standard Request Codes */
#define USB_REQUEST_GET_STATUS                 0
#define USB_REQUEST_CLEAR_FEATURE              1
#define USB_REQUEST_SET_FEATURE                3
#define USB_REQUEST_SET_ADDRESS                5
#define USB_REQUEST_GET_DESCRIPTOR             6
#define USB_REQUEST_SET_DESCRIPTOR             7
#define USB_REQUEST_GET_CONFIGURATION          8
#define USB_REQUEST_SET_CONFIGURATION          9
#define USB_REQUEST_GET_INTERFACE              10
#define USB_REQUEST_SET_INTERFACE              11
#define USB_REQUEST_SYNC_FRAME                 12

/* USB GET_STATUS Bit Values */
#define USB_GETSTATUS_SELF_POWERED             0x01
#define USB_GETSTATUS_REMOTE_WAKEUP            0x02
#define USB_GETSTATUS_ENDPOINT_STALL           0x01

/* USB Standard Feature selectors */
#define USB_FEATURE_ENDPOINT_STALL             0
#define USB_FEATURE_REMOTE_WAKEUP              1

/* USB Default Control Pipe Setup Packet */     //设备请求(8Byte):记录请求的内容
typedef struct _USB_SETUP_PACKET {
  REQUEST_TYPE bmRequestType;              //设备请求类型
  BYTE         bRequest;                  //设备请求
  WORD_BYTE    wValue;                      //值
  WORD_BYTE    wIndex;                      //索引
  WORD         wLength;                      //长度
} USB_SETUP_PACKET;


/* USB Descriptor Types */
#define USB_DEVICE_DESCRIPTOR_TYPE             1
#define USB_CONFIGURATION_DESCRIPTOR_TYPE      2
#define USB_STRING_DESCRIPTOR_TYPE             3
#define USB_INTERFACE_DESCRIPTOR_TYPE          4
#define USB_ENDPOINT_DESCRIPTOR_TYPE           5
#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE   6
#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE    8

/* USB Device Classes */
#define USB_DEVICE_CLASS_RESERVED              0x00
#define USB_DEVICE_CLASS_AUDIO                 0x01
#define USB_DEVICE_CLASS_COMMUNICATIONS        0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE       0x03
#define USB_DEVICE_CLASS_MONITOR               0x04
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE    0x05
#define USB_DEVICE_CLASS_POWER                 0x06
#define USB_DEVICE_CLASS_PRINTER               0x07
#define USB_DEVICE_CLASS_STORAGE               0x08
#define USB_DEVICE_CLASS_HUB                   0x09
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC       0xFF

/* bmAttributes in Configuration Descriptor */
#define USB_CONFIG_POWERED_MASK                0xC0
#define USB_CONFIG_BUS_POWERED                 0x80
#define USB_CONFIG_SELF_POWERED                0x40
#define USB_CONFIG_REMOTE_WAKEUP               0x20

/* bMaxPower in Configuration Descriptor */
#define USB_CONFIG_POWER_MA(mA)                ((mA)/2)

/* bEndpointAddress in Endpoint Descriptor */
#define USB_ENDPOINT_DIRECTION_MASK            0x80
#define USB_ENDPOINT_OUT(addr)                 ((addr) | 0x00)
#define USB_ENDPOINT_IN(addr)                  ((addr) | 0x80)

/* bmAttributes in Endpoint Descriptor */
#define USB_ENDPOINT_TYPE_MASK                 0x03
#define USB_ENDPOINT_TYPE_CONTROL              0x00        //控制传输=00H
#define USB_ENDPOINT_TYPE_ISOCHRONOUS          0x01        //同步传输=01H
#define USB_ENDPOINT_TYPE_BULK                 0x02        //批量传输=02H
#define USB_ENDPOINT_TYPE_INTERRUPT            0x03        //中断传输=03H

#define USB_ENDPOINT_SYNC_MASK                 0x0C
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION   0x00
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS         0x04
#define USB_ENDPOINT_SYNC_ADAPTIVE             0x08
#define USB_ENDPOINT_SYNC_SYNCHRONOUS          0x0C

#define USB_ENDPOINT_USAGE_MASK                0x30
#define USB_ENDPOINT_USAGE_DATA                0x00
#define USB_ENDPOINT_USAGE_FEEDBACK            0x10
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK   0x20
#define USB_ENDPOINT_USAGE_RESERVED            0x30


/* USB Standard Device Descriptor */       //设备描述符
typedef struct _USB_DEVICE_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
  WORD  bcdUSB;
  BYTE  bDeviceClass;
  BYTE  bDeviceSubClass;
  BYTE  bDeviceProtocol;
  BYTE  bMaxPacketSize0;
  WORD  idVendor;
  WORD  idProduct;
  WORD  bcdDevice;
  BYTE  iManufacturer;
  BYTE  iProduct;
  BYTE  iSerialNumber;
  BYTE  bNumConfigurations;
} USB_DEVICE_DESCRIPTOR;

/* USB 2.0 Device Qualifier Descriptor */       //设备查询描述符??
typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
  WORD  bcdUSB;
  BYTE  bDeviceClass;
  BYTE  bDeviceSubClass;
  BYTE  bDeviceProtocol;
  BYTE  bMaxPacketSize0;
  BYTE  bNumConfigurations;
  BYTE  bReserved;
} USB_DEVICE_QUALIFIER_DESCRIPTOR;

/* USB Standard Configuration Descriptor */       //配置描述符
typedef struct _USB_CONFIGURATION_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
  WORD  wTotalLength;
  BYTE  bNumInterfaces;
  BYTE  bConfigurationValue;
  BYTE  iConfiguration;
  BYTE  bmAttributes;
  BYTE  MaxPower;
} USB_CONFIGURATION_DESCRIPTOR;

/* USB Standard Interface Descriptor */            //接口描述符
typedef struct _USB_INTERFACE_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
  BYTE  bInterfaceNumber;
  BYTE  bAlternateSetting;
  BYTE  bNumEndpoints;
  BYTE  bInterfaceClass;
  BYTE  bInterfaceSubClass;
  BYTE  bInterfaceProtocol;
  BYTE  iInterface;
} USB_INTERFACE_DESCRIPTOR;

/* USB Standard Endpoint Descriptor */              //端点描述符
typedef struct _USB_ENDPOINT_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
  BYTE  bEndpointAddress;
  BYTE  bmAttributes;
  WORD  wMaxPacketSize;
  BYTE  bInterval;
} USB_ENDPOINT_DESCRIPTOR;
                                                  //字符串描述符
/* USB String Descriptor */
typedef struct _USB_STRING_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
  WORD  bString/*[]*/;
} USB_STRING_DESCRIPTOR;
                                                // 命令描述符??
/* USB Common Descriptor */
typedef struct _USB_COMMON_DESCRIPTOR {
  BYTE  bLength;
  BYTE  bDescriptorType;
} USB_COMMON_DESCRIPTOR;


#pragma pack()


#endif  /* __USB_H__ */





/*----------------------------------------------------------------------------
 *      U S B  -  K e r n e l
 *----------------------------------------------------------------------------
 *      Name:    usbdesc.c
 *      Purpose: USB Descriptors file for Philips LPC214x Family 
 *        Microprocessors
 *      Version: V1.04
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express, 
 *      implied or statutory, including but not limited to the implied 
 *      warranties of fitness for purpose, satisfactory quality and 
 *      noninfringement. Keil extends you a royalty-free right to reproduce and
 *      distribute executable files created using this software for use on 
 *      Philips LPC2xxx microcontroller devices only. Nothing else gives you the 
 *      right to use this software. 
 *
 *      Copyright (c) 2005 Keil Software.
 *        Modified by Philips Semiconductor
 *---------------------------------------------------------------------------*/
#include "type.h"
#include "usb.h"
#include "usbcfg.h"
#include "usbdesc.h"

/* Two interface descriptor for 2 Virtual COM port,, each VCOM uses 3 endpoints */
/* The total number of endpoints are 6, 2 interrupt IN for modem status reading,
2 BULK OUT for COM TX, and 2 BULK IN for COM RX */
 
#define NUM_ENDPOINTS    3 

//////////////////////////////////////////////////////////////////////////////
/* USB Standard Device Descriptor */           //设备描述符
const BYTE USB_DeviceDescriptor[] = {
  USB_DEVICE_DESC_SIZE,              /* bLength */           //设备描述符长度,=12H
  USB_DEVICE_DESCRIPTOR_TYPE,        /* bDescriptorType */   //设备描述符类型,=01H
  WBVAL(0x0100), /* 1.00 */          /* bcdUSB */             //协议版本,=1.00
  0x00,                              /* bDeviceClass */      //测试设备类型,=00H
  0x00,                              /* bDeviceSubClass */   //设备子类,
  0x00,                              /* bDeviceProtocol */    //设备协议
  USB_MAX_PACKET0,                   /* bMaxPacketSize0 */   //端点最大数据包大小
  WBVAL(0xC251), /* 51,C2 */         /* idVendor */          //厂家的设备ID
  WBVAL(0x1305), /* 05,13 */         /* idProduct */        //产品ID
  WBVAL(0x0110), /* 10,01=1.10 */    /* bcdDevice */        //设备序列号
  0x04,                              /* iManufacturer */    //索引 (0x04,0x20,0x4A)
  0x20,                              /* iProduct */
  0x4A,                              /* iSerialNumber */    
  0x01                               /* bNumConfigurations */ //可能配置数
};


///////////////////////////////////////////////////////////////////////////////////
/* USB Configuration Descriptor */
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const BYTE USB_ConfigDescriptor[] = {              //[ 配置描述符 ]
/* Configuration 1 */
  USB_CONFIGUARTION_DESC_SIZE,       /* bLength */          //配置描述符长度,=09H
  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */  //配置描述符类型,=02H
  WBVAL(                             /* wTotalLength */      //描述符总长度,=2EH
    USB_CONFIGUARTION_DESC_SIZE +
    USB_INTERFACE_DESC_SIZE     +
    NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE +
    USB_INTERFACE_DESC_SIZE     +
    NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE
  ),
  0x02,                              /* bNumInterfaces */     //支持接口数,=2(接口0,接口1)
  0x01,                              /* bConfigurationValue */  //配置值,=1
  0x00,                              /* iConfiguration */      //字符串描述符指针(无)
  USB_CONFIG_BUS_POWERED |           /* bmAttributes */        //总线供电
  USB_CONFIG_REMOTE_WAKEUP,                                    //支持远程唤醒
  USB_CONFIG_POWER_MA(100),          /* bMaxPower */           //最大功耗,


/* Interface 0, Alternate Setting 0, Class Code Unknown */    //[ 接口描述符:接口0,可变设置0 ]
  USB_INTERFACE_DESC_SIZE,           /* bLength */             //接口描述符长度,=09H
  USB_INTERFACE_DESCRIPTOR_TYPE,     /* bDescriptorType */     //接口描述符类型,=04H
  0x00,                              /* bInterfaceNumber */    //接口数,0个
  0x00,                              /* bAlternateSetting */   //可选配制,0个
  NUM_ENDPOINTS,                     /* bNumEndpoints */       //除端点0的端点索引数目,=3个
  USB_DEVICE_CLASS_VENDOR_SPECIFIC,  /* bInterfaceClass, USB_CLASS_VENDOR_SPECIFIC */     //测试设备类型
  0xFF,                              /* bInterfaceSubClass, USB_SUBCLASS_CODE_UNKNOWN */  //子类代码
  0xFF,                              /* bInterfaceProtocol, USB_PROTOCOL_CODE_UNKNOWN */  //协议代码
  0x00,                              /* iInterface, STR_INDEX_INTERFACE = no_string */    //字符串描述符索引


/* Endpoint, EP1 Interrupt In */        //[ 端点描述符: 端点1,中断传输,IN ]
  USB_ENDPOINT_DESC_SIZE,            /* bLength */             //端点描述符长度,=07H
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */     //端点描述符类型,=05H
  USB_ENDPOINT_IN(1),                /* bEndpointAddress */    //端点1 IN,=0X81
  USB_ENDPOINT_TYPE_INTERRUPT,       /* bmAttributes */        //中断传输,=03H
  WBVAL(0x0004),                     /* wMaxPacketSize */      //端点最大包的大小,=
  0x20,          /* 32ms */          /* bInterval */            //传输间隔时间,=32ms

/* Endpoint, EP2 Bulk Out */            //[ 端点描述符: 端点2,批量传输,OUT ]
  USB_ENDPOINT_DESC_SIZE,            /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
  USB_ENDPOINT_OUT(2),               /* bEndpointAddress */
  USB_ENDPOINT_TYPE_BULK,            /* bmAttributes */
  WBVAL(0x0040),                     /* wMaxPacketSize */
  0x20,          /* 32ms */

/* Endpoint, EP2 Bulk In */             //[ 端点描述符: 端点2,批量传输,IN ]
  USB_ENDPOINT_DESC_SIZE,            /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
  USB_ENDPOINT_IN(2),                /* bEndpointAddress */
  USB_ENDPOINT_TYPE_BULK,            /* bmAttributes */
  WBVAL(0x0040),                     /* wMaxPacketSize */
  0x20,          /* 32ms */

/* Interface 1, Alternate Setting 0, Class Code Unknown */    //[ 接口描述符:接口1,可变设置0 ]
  USB_INTERFACE_DESC_SIZE,           /* bLength */
  USB_INTERFACE_DESCRIPTOR_TYPE,     /* bDescriptorType */
  0x01,                              /* bInterfaceNumber */
  0x00,                              /* bAlternateSetting */
  NUM_ENDPOINTS,                     /* bNumEndpoints */
  USB_DEVICE_CLASS_VENDOR_SPECIFIC,  /* bInterfaceClass, USB_CLASS_CODE_UNKNOWN */
  0xFF,                              /* bInterfaceSubClass, USB_SUBCLASS_CODE_UNKNOWN */
  0xFF,                              /* bInterfaceProtocol, USB_PROTOCOL_CODE_UNKNOWN */
  0x00,                              /* iInterface, STR_INDEX_INTERFACE = no_string */

/* Endpoint, EP4 Interrupt In */
  USB_ENDPOINT_DESC_SIZE,            /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
  USB_ENDPOINT_IN(4),                /* bEndpointAddress */
  USB_ENDPOINT_TYPE_INTERRUPT,       /* bmAttributes */
  WBVAL(0x0004),                     /* wMaxPacketSize */
  0x20,          /* 32ms */          /* bInterval */

/* Endpoint, EP5 Bulk Out */
  USB_ENDPOINT_DESC_SIZE,            /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
  USB_ENDPOINT_OUT(5),               /* bEndpointAddress */
  USB_ENDPOINT_TYPE_BULK,            /* bmAttributes */
  WBVAL(0x0040),                     /* wMaxPacketSize */
  0x20,          /* 32ms */

/* Endpoint, EP5 Bulk In */
  USB_ENDPOINT_DESC_SIZE,            /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
  USB_ENDPOINT_IN(5),                /* bEndpointAddress */
  USB_ENDPOINT_TYPE_BULK,            /* bmAttributes */
  WBVAL(0x0040),                     /* wMaxPacketSize */
  0x20,          /* 32ms */
/* Terminator */
  0                                  /* bLength */
};

/////////////////////////////////////////////////////////////////////////////////
/* USB String Descriptor (optional) */
const BYTE USB_StringDescriptor[] = { 
/* Index 0x00: LANGID Codes */
  0x04,                              /* bLength */
  USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  WBVAL(0x0409), /* US English */    /* wLANGID */

/* Index 0x04: Manufacturer */
  0x1C,                              /* bLength */
  USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  'K',0,
  'e',0,
  'i',0,
  'l',0,
  ' ',0,
  'S',0,
  'o',0,
  'f',0,
  't',0,
  'w',0,
  'a',0,
  'r',0,
  'e',0,

/* Index 0x20: Product */
  0x2A,                              /* bLength */
  USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  'P',0,
  'h',0,
  'i',0,
  'l',0,
  'i',0,
  'p',0,
  's',0,
  ' ',0,
  'L',0,
  'P',0,
  'C',0,
  '2',0,
  '1',0,
  '4',0,
  '8',0,
  ' ',0,
  'V',0,
  'C',0,
  'O',0,
  'M',0,

/* Index 0x4A: Serial Number */
  0x1C,                              /* bLength */
  USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '-',0,
  'D',0,
  'E',0,
  'M',0,
  'O',0,

/* Index 0x66: Interface 0, Alternate Setting 0 */
  0x0A,                              /* bLength */
  USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  'V',0,
  'C',0,
  'O',0,
  'M',0,
};



阅读(224) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册