RT-AICHIP-sample
usbdesc.c
[詳解]
1 /*----------------------------------------------------------------------------
2  * U S B - K e r n e l
3  *----------------------------------------------------------------------------
4  * Name: usbdesc.c
5  * Purpose: USB Descriptors
6  * Version: V1.20
7  *----------------------------------------------------------------------------
8  * This software is supplied "AS IS" without any warranties, express,
9  * implied or statutory, including but not limited to the implied
10  * warranties of fitness for purpose, satisfactory quality and
11  * noninfringement. Keil extends you a royalty-free right to reproduce
12  * and distribute executable files created using this software for use
13  * on NXP Semiconductors LPC microcontroller devices only. Nothing else
14  * gives you the right to use this software.
15  *
16  * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
17  *----------------------------------------------------------------------------
18  * History:
19  * V1.20 Changed string descriptor handling
20  * V1.00 Initial Version
21  *---------------------------------------------------------------------------*/
22 #include "type.h"
23 #include "usb.h"
24 #include "cdc.h"
25 #include "usbcfg.h"
26 #include "usbdesc.h"
27 #include "config.h"
28 
29 
30 /* USB Standard Device Descriptor */
32  USB_DEVICE_DESC_SIZE, /* bLength */
33  USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
34  WBVAL(0x0200), /* 2.0 */ /* bcdUSB */
35  USB_DEVICE_CLASS_COMMUNICATIONS, /* bDeviceClass CDC*/
36  0x00, /* bDeviceSubClass */
37  0x00, /* bDeviceProtocol */
38  USB_MAX_PACKET0, /* bMaxPacketSize0 */
39  WBVAL(USB_VENDOR_ID), /* idVendor */
40  WBVAL(USB_PROD_ID), /* idProduct */
41  WBVAL(USB_DEVICE), /* 1.00 */ /* bcdDevice */
42  0x01, /* iManufacturer */
43  0x02, /* iProduct */
44  0x03, /* iSerialNumber */
45  0x01 /* bNumConfigurations: one possible configuration*/
46 };
47 
48 /* USB Configuration Descriptor */
49 /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
51 /* Configuration 1 */
52  USB_CONFIGUARTION_DESC_SIZE, /* bLength */
53  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
54  WBVAL( /* wTotalLength */
56  1*USB_INTERFACE_DESC_SIZE + /* communication interface */
57  0x0013 + /* CDC functions */
58  1*USB_ENDPOINT_DESC_SIZE + /* interrupt endpoint */
59  1*USB_INTERFACE_DESC_SIZE + /* data interface */
60  2*USB_ENDPOINT_DESC_SIZE /* bulk endpoints */
61  ),
62  0x02, /* bNumInterfaces */
63  0x01, /* bConfigurationValue: 0x01 is used to select this configuration */
64  0x00, /* iConfiguration: no string to describe this configuration */
65  USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */
66 /*USB_CONFIG_REMOTE_WAKEUP*/,
67  USB_CONFIG_POWER_MA(100), /* bMaxPower, device power consumption is 100 mA */
68 /* Interface 0, Alternate Setting 0, Communication class interface descriptor */
69  USB_INTERFACE_DESC_SIZE, /* bLength */
70  USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
71  USB_CDC_CIF_NUM, /* bInterfaceNumber: Number of Interface */
72  0x00, /* bAlternateSetting: Alternate setting */
73  0x01, /* bNumEndpoints: One endpoint used */
74  CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass: Communication Interface Class */
75  CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass: Abstract Control Model */
76  0x00, /* bInterfaceProtocol: no protocol used */
77  0x5E, /* iInterface: */
78 /*Header Functional Descriptor*/
79  0x05, /* bLength: Endpoint Descriptor size */
80  CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
81  CDC_HEADER, /* bDescriptorSubtype: Header Func Desc */
82  WBVAL(CDC_V1_10), /* 1.10 */ /* bcdCDC */
83 /*Call Management Functional Descriptor*/
84  0x05, /* bFunctionLength */
85  CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
86  CDC_CALL_MANAGEMENT, /* bDescriptorSubtype: Call Management Func Desc */
87  0x01, /* bmCapabilities: device handles call management */
88  0x01, /* bDataInterface: CDC data IF ID */
89 /*Abstract Control Management Functional Descriptor*/
90  0x04, /* bFunctionLength */
91  CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
92  CDC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype: Abstract Control Management desc */
93  0x02, /* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */
94 /*Union Functional Descriptor*/
95  0x05, /* bFunctionLength */
96  CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
97  CDC_UNION, /* bDescriptorSubtype: Union func desc */
98  USB_CDC_CIF_NUM, /* bMasterInterface: Communication class interface is master */
99  USB_CDC_DIF_NUM, /* bSlaveInterface0: Data class interface is slave 0 */
100 /*Endpoint 1 Descriptor*/ /* event notification (optional) */
101  USB_ENDPOINT_DESC_SIZE, /* bLength */
102  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
103  USB_ENDPOINT_IN(1), /* bEndpointAddress */
104  USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
105  WBVAL(0x0010), /* wMaxPacketSize */
106  0x02, /* 2ms */ /* bInterval */
107 /* Interface 1, Alternate Setting 0, Data class interface descriptor*/
108  USB_INTERFACE_DESC_SIZE, /* bLength */
109  USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
110  USB_CDC_DIF_NUM, /* bInterfaceNumber: Number of Interface */
111  0x00, /* bAlternateSetting: no alternate setting */
112  0x02, /* bNumEndpoints: two endpoints used */
113  CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass: Data Interface Class */
114  0x00, /* bInterfaceSubClass: no subclass available */
115  0x00, /* bInterfaceProtocol: no protocol used */
116  0x5E, /* iInterface: */
117 /* Endpoint, EP3 Bulk Out */
118  USB_ENDPOINT_DESC_SIZE, /* bLength */
119  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
120  USB_ENDPOINT_OUT(3), /* bEndpointAddress */
121  USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
122  WBVAL(USB_CDC_BUFSIZE), /* wMaxPacketSize */
123  0x00, /* bInterval: ignore for Bulk transfer */
124 /* Endpoint, EP3 Bulk In */
125  USB_ENDPOINT_DESC_SIZE, /* bLength */
126  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
127  USB_ENDPOINT_IN(3), /* bEndpointAddress */
128  USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
129  WBVAL(USB_CDC_BUFSIZE), /* wMaxPacketSize */
130  0x00, /* bInterval: ignore for Bulk transfer */
131 /* Terminator */
132  0 /* bLength */
133 };
134 
135 
136 
137 
138 /* USB String Descriptor (optional) */
140 /* Index 0x00: LANGID Codes */
141  0x04, /* bLength */
142  USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
143  WBVAL(0x0409), /* US English */ /* wLANGID */
144 /* Index 0x01: Manufacturer */
145  (14*2 + 2), /* bLength (14 Char + Type + lenght) */
146  USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
147  'R',0,
148  'T',0,
149  ' ',0,
150  'C',0,
151  'O',0,
152  'R',0,
153  'P',0,
154  'O',0,
155  'R',0,
156  'A',0,
157  'T',0,
158  'I',0,
159  'O',0,
160  'N',0,
161 /* Index 0x02: Product */
162  (15*2 + 2), /* bLength ( 15 Char + Type + lenght) */
163  USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
164  'R',0,
165  'T',0,
166  '-',0,
167  'U',0,
168  'S',0,
169  'B',0,
170  '-',0,
171  '9',0,
172  'A',0,
173  'X',0,
174  'I',0,
175  'S',0,
176  '-',0,
177  '0',0,
178  '1',0,
179 /* Index 0x03: Serial Number */
180  (8*2 + 2), /* bLength (8 Char + Type + lenght) */
181  USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
182  '9',0,
183  'A',0,
184  'X',0,
185  'I',0,
186  'S',0,
187  '-',0,
188  '0',0,
189  '1',0,
190 /* Index 0x04: Interface 0, Alternate Setting 0 */
191  ( 4*2 + 2), /* bLength (4 Char + Type + lenght) */
192  USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
193  'V',0,
194  'C',0,
195  'O',0,
196  'M',0,
197 };
#define USB_ENDPOINT_DESC_SIZE
Definition: usbdesc.h:28
#define CDC_UNION
Definition: cdc.h:78
#define USB_INTERFACE_DESC_SIZE
Definition: usbdesc.h:27
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb.h:93
#define USB_ENDPOINT_TYPE_BULK
Definition: usb.h:135
#define USB_ENDPOINT_DESCRIPTOR_TYPE
Definition: usb.h:95
#define USB_PROD_ID
Definition: config.h:32
const uint8_t USB_ConfigDescriptor[]
Definition: usbdesc.c:50
#define CDC_CS_INTERFACE
Definition: cdc.h:67
#define CDC_ABSTRACT_CONTROL_MODEL
Definition: cdc.h:35
#define USB_CDC_BUFSIZE
Definition: usbcfg.h:147
#define USB_CDC_CIF_NUM
Definition: usbcfg.h:145
const uint8_t USB_DeviceDescriptor[]
Definition: usbdesc.c:31
#define CDC_CALL_MANAGEMENT
Definition: cdc.h:73
#define USB_CONFIG_POWER_MA(mA)
Definition: usb.h:124
#define USB_ENDPOINT_OUT(addr)
Definition: usb.h:128
unsigned char uint8_t
Definition: type.h:27
#define USB_DEVICE
Definition: config.h:33
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb.h:94
#define CDC_DATA_INTERFACE_CLASS
Definition: cdc.h:48
#define USB_MAX_PACKET0
Definition: usbcfg.h:60
#define WBVAL(x)
Definition: usbdesc.h:23
#define USB_DEVICE_CLASS_COMMUNICATIONS
Definition: usb.h:106
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb.h:91
#define CDC_ABSTRACT_CONTROL_MANAGEMENT
Definition: cdc.h:74
#define CDC_HEADER
Definition: cdc.h:72
#define USB_ENDPOINT_TYPE_INTERRUPT
Definition: usb.h:136
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb.h:92
const uint8_t USB_StringDescriptor[]
Definition: usbdesc.c:139
#define USB_CONFIGUARTION_DESC_SIZE
Definition: usbdesc.h:26
#define CDC_COMMUNICATION_INTERFACE_CLASS
Definition: cdc.h:30
#define CDC_V1_10
Definition: cdc.h:26
#define USB_VENDOR_ID
Definition: config.h:31
#define USB_CONFIG_BUS_POWERED
Definition: usb.h:119
#define USB_CDC_DIF_NUM
Definition: usbcfg.h:146
#define USB_DEVICE_DESC_SIZE
Definition: usbdesc.h:25
#define USB_ENDPOINT_IN(addr)
Definition: usb.h:129