Fix USB, DOS line endings, integrate and reorganize project
[rapper.git] / src / usb / desc.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 "lpc_types.h"
23 #include "usb.h"
24 #include "cdc.h"
25 #include "cfg.h"
26 #include "desc.h"
27
28
29 /* USB Standard Device Descriptor */
30 const uint8_t USB_DeviceDescriptor[] = {
31   USB_DEVICE_DESC_SIZE,              /* bLength */
32   USB_DEVICE_DESCRIPTOR_TYPE,        /* bDescriptorType */
33   WBVAL(0x0200), /* 2.0 */           /* bcdUSB */
34   USB_DEVICE_CLASS_COMMUNICATIONS,   /* bDeviceClass CDC*/
35   0x00,                              /* bDeviceSubClass */
36   0x00,                              /* bDeviceProtocol */
37   USB_MAX_PACKET0,                   /* bMaxPacketSize0 */
38   WBVAL(0x1FC9),                     /* idVendor */
39   WBVAL(0x2002),                     /* idProduct */
40   WBVAL(0x0100), /* 1.00 */          /* bcdDevice */
41   0x01,                              /* iManufacturer */
42   0x02,                              /* iProduct */
43   0x03,                              /* iSerialNumber */
44   0x01                               /* bNumConfigurations: one possible configuration*/
45 };
46
47 /* USB Configuration Descriptor */
48 /*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
49 const uint8_t USB_ConfigDescriptor[] = {
50 /* Configuration 1 */
51   USB_CONFIGUARTION_DESC_SIZE,          + /* bLength */
52   USB_CONFIGURATION_DESCRIPTOR_TYPE,    + /* bDescriptorType */
53   WBVAL(                                  /* wTotalLength */
54     (USB_CONFIGUARTION_DESC_SIZE)       +
55     (USB_INTERFACE_DESC_SIZE)           + /* communication interface */
56     0x0013                              + /* CDC functions */
57     (USB_ENDPOINT_DESC_SIZE)            + /* interrupt endpoint */
58     (USB_INTERFACE_DESC_SIZE)           + /* data interface */
59     (2*USB_ENDPOINT_DESC_SIZE)            /* bulk endpoints */
60       ),
61   0x02,                              /* bNumInterfaces */
62   0x01,                              /* bConfigurationValue: 0x01 is used to select this configuration */
63   0x00,                              /* iConfiguration: no string to describe this configuration */
64   USB_CONFIG_BUS_POWERED /*|*/       /* bmAttributes */
65 /*USB_CONFIG_REMOTE_WAKEUP*/,
66   USB_CONFIG_POWER_MA(100),          /* bMaxPower, device power consumption is 100 mA */
67 /* Interface 0, Alternate Setting 0, Communication class interface descriptor */
68   USB_INTERFACE_DESC_SIZE,           /* bLength */
69   USB_INTERFACE_DESCRIPTOR_TYPE,     /* bDescriptorType */
70   USB_CDC_CIF_NUM,                   /* bInterfaceNumber: Number of Interface */
71   0x00,                              /* bAlternateSetting: Alternate setting */
72   0x01,                              /* bNumEndpoints: One endpoint used */
73   CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass: Communication Interface Class */
74   CDC_ABSTRACT_CONTROL_MODEL,        /* bInterfaceSubClass: Abstract Control Model */
75   0x00,                              /* bInterfaceProtocol: no protocol used */
76   0x5E,                              /* iInterface: */
77 /*Header Functional Descriptor*/
78   0x05,                              /* bLength: Endpoint Descriptor size */
79   CDC_CS_INTERFACE,                  /* bDescriptorType: CS_INTERFACE */
80   CDC_HEADER,                        /* bDescriptorSubtype: Header Func Desc */
81   WBVAL(CDC_V1_10), /* 1.10 */       /* bcdCDC */
82 /*Call Management Functional Descriptor*/
83   0x05,                              /* bFunctionLength */
84   CDC_CS_INTERFACE,                  /* bDescriptorType: CS_INTERFACE */
85   CDC_CALL_MANAGEMENT,               /* bDescriptorSubtype: Call Management Func Desc */
86   0x01,                              /* bmCapabilities: device handles call management */
87   0x01,                              /* bDataInterface: CDC data IF ID */
88 /*Abstract Control Management Functional Descriptor*/
89   0x04,                              /* bFunctionLength */
90   CDC_CS_INTERFACE,                  /* bDescriptorType: CS_INTERFACE */
91   CDC_ABSTRACT_CONTROL_MANAGEMENT,   /* bDescriptorSubtype: Abstract Control Management desc */
92   0x02,                              /* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */
93 /*Union Functional Descriptor*/
94   0x05,                              /* bFunctionLength */
95   CDC_CS_INTERFACE,                  /* bDescriptorType: CS_INTERFACE */
96   CDC_UNION,                         /* bDescriptorSubtype: Union func desc */
97   USB_CDC_CIF_NUM,                   /* bMasterInterface: Communication class interface is master */
98   USB_CDC_DIF_NUM,                   /* bSlaveInterface0: Data class interface is slave 0 */
99 /*Endpoint 1 Descriptor*/            /* event notification (optional) */
100   USB_ENDPOINT_DESC_SIZE,            /* bLength */
101   USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
102   USB_ENDPOINT_IN(1),                /* bEndpointAddress */
103   USB_ENDPOINT_TYPE_INTERRUPT,       /* bmAttributes */
104   WBVAL(0x0010),                     /* wMaxPacketSize */
105   0x02,          /* 2ms */           /* bInterval */
106 /* Interface 1, Alternate Setting 0, Data class interface descriptor*/
107   USB_INTERFACE_DESC_SIZE,           /* bLength */
108   USB_INTERFACE_DESCRIPTOR_TYPE,     /* bDescriptorType */
109   USB_CDC_DIF_NUM,                   /* bInterfaceNumber: Number of Interface */
110   0x00,                              /* bAlternateSetting: no alternate setting */
111   0x02,                              /* bNumEndpoints: two endpoints used */
112   CDC_DATA_INTERFACE_CLASS,          /* bInterfaceClass: Data Interface Class */
113   0x00,                              /* bInterfaceSubClass: no subclass available */
114   0x00,                              /* bInterfaceProtocol: no protocol used */
115   0x5E,                              /* iInterface: */
116 /* Endpoint, EP2 Bulk Out */
117   USB_ENDPOINT_DESC_SIZE,            /* bLength */
118   USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
119   USB_ENDPOINT_OUT(2),               /* bEndpointAddress */
120   USB_ENDPOINT_TYPE_BULK,            /* bmAttributes */
121   WBVAL(USB_CDC_BUFSIZE),            /* wMaxPacketSize */
122   0x00,                              /* bInterval: ignore for Bulk transfer */
123 /* Endpoint, EP2 Bulk In */
124   USB_ENDPOINT_DESC_SIZE,            /* bLength */
125   USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
126   USB_ENDPOINT_IN(2),                /* bEndpointAddress */
127   USB_ENDPOINT_TYPE_BULK,            /* bmAttributes */
128   WBVAL(USB_CDC_BUFSIZE),            /* wMaxPacketSize */
129   0x00,                              /* bInterval: ignore for Bulk transfer */
130 /* Terminator */
131   0                                  /* bLength */
132 };
133
134
135
136
137 /* USB String Descriptor (optional) */
138 const uint8_t USB_StringDescriptor[] = {
139 /* Index 0x00: LANGID Codes */
140   0x04,                              /* bLength */
141   USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
142   WBVAL(0x0409), /* US English */    /* wLANGID */
143 /* Index 0x01: Manufacturer */
144   (7*2 + 2),                        /* bLength (13 Char + Type + lenght) */
145   USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
146   'L',0,
147   'a',0,
148   'b',0,
149   'i',0,
150   't',0,
151   'a',0,
152   't',0,
153 /* Index 0x02: Product */
154   (17*2 + 2),                        /* bLength ( 17 Char + Type + lenght) */
155   USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
156   'R',0,
157   'a',0,
158   'p',0,
159   'p',0,
160   'e',0,
161   'r',0,
162   ' ',0,
163   'U',0,
164   'S',0,
165   'B',0,
166   ' ',0,
167   'S',0,
168   'e',0,
169   'r',0,
170   'i',0,
171   'a',0,
172   'l',0,
173 /* Index 0x03: Serial Number */
174   (12*2 + 2),                        /* bLength (12 Char + Type + lenght) */
175   USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
176   'P',0,
177   'R',0,
178   'O',0,
179   'T',0,
180   'O',0,
181   'T',0,
182   'Y',0,
183   'P',0,
184   'E',0,
185   ' ',0,
186   '4',0,
187   '2',0,
188 /* Index 0x04: Interface 0, Alternate Setting 0 */
189   ( 4*2 + 2),                        /* bLength (4 Char + Type + lenght) */
190   USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
191   'V',0,
192   'C',0,
193   'O',0,
194   'M',0,
195 };