slime@2
|
1 |
/*********************************************************************
|
slime@2
|
2 |
*
|
slime@2
|
3 |
* Microchip USB C18 Firmware Version 1.0
|
slime@2
|
4 |
*
|
slime@2
|
5 |
*********************************************************************
|
slime@2
|
6 |
* FileName: usbdsc.c
|
slime@2
|
7 |
* Dependencies: See INCLUDES section below
|
slime@2
|
8 |
* Processor: PIC18
|
slime@2
|
9 |
* Compiler: C18 2.30.01+
|
slime@2
|
10 |
* Company: Microchip Technology, Inc.
|
slime@2
|
11 |
*
|
slime@2
|
12 |
* Software License Agreement
|
slime@2
|
13 |
*
|
slime@2
|
14 |
* The software supplied herewith by Microchip Technology Incorporated
|
slime@2
|
15 |
* (the “Company”) for its PICmicro® Microcontroller is intended and
|
slime@2
|
16 |
* supplied to you, the Company’s customer, for use solely and
|
slime@2
|
17 |
* exclusively on Microchip PICmicro Microcontroller products. The
|
slime@2
|
18 |
* software is owned by the Company and/or its supplier, and is
|
slime@2
|
19 |
* protected under applicable copyright laws. All rights are reserved.
|
slime@2
|
20 |
* Any use in violation of the foregoing restrictions may subject the
|
slime@2
|
21 |
* user to criminal sanctions under applicable laws, as well as to
|
slime@2
|
22 |
* civil liability for the breach of the terms and conditions of this
|
slime@2
|
23 |
* license.
|
slime@2
|
24 |
*
|
slime@2
|
25 |
* THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
|
slime@2
|
26 |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
|
slime@2
|
27 |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
slime@2
|
28 |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
|
slime@2
|
29 |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
|
slime@2
|
30 |
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
slime@2
|
31 |
*
|
slime@2
|
32 |
********************************************************************/
|
slime@2
|
33 |
|
slime@2
|
34 |
/*********************************************************************
|
slime@2
|
35 |
* -usbdsc.c-
|
slime@2
|
36 |
* This file contains the USB descriptor information. It is used
|
slime@2
|
37 |
* in conjunction with the usbdsc.h file. When a descriptor is added
|
slime@2
|
38 |
* or removed from the main configuration descriptor, i.e. CFG01,
|
slime@2
|
39 |
* the user must also change the descriptor structure defined in
|
slime@2
|
40 |
* the usbdsc.h file. The structure is used to calculate the
|
slime@2
|
41 |
* descriptor size, i.e. sizeof(CFG01).
|
slime@2
|
42 |
*
|
slime@2
|
43 |
* A typical configuration descriptor consists of:
|
slime@2
|
44 |
* At least one configuration descriptor (USB_CFG_DSC)
|
slime@2
|
45 |
* One or more interface descriptors (USB_INTF_DSC)
|
slime@2
|
46 |
* One or more endpoint descriptors (USB_EP_DSC)
|
slime@2
|
47 |
*
|
slime@2
|
48 |
* Naming Convention:
|
slime@2
|
49 |
* To resolve ambiguity, the naming convention are as followed:
|
slime@2
|
50 |
* - USB_CFG_DSC type should be named cdxx, where xx is the
|
slime@2
|
51 |
* configuration number. This number should match the actual
|
slime@2
|
52 |
* index value of this configuration.
|
slime@2
|
53 |
* - USB_INTF_DSC type should be named i<yy>a<zz>, where yy is the
|
slime@2
|
54 |
* interface number and zz is the alternate interface number.
|
slime@2
|
55 |
* - USB_EP_DSC type should be named ep<##><d>_i<yy>a<zz>, where
|
slime@2
|
56 |
* ## is the endpoint number and d is the direction of transfer.
|
slime@2
|
57 |
* The interface name should also be listed as a suffix to identify
|
slime@2
|
58 |
* which interface does the endpoint belong to.
|
slime@2
|
59 |
*
|
slime@2
|
60 |
* Example:
|
slime@2
|
61 |
* If a device has one configuration, two interfaces; interface 0
|
slime@2
|
62 |
* has two endpoints (in and out), and interface 1 has one endpoint(in).
|
slime@2
|
63 |
* Then the CFG01 structure in the usbdsc.h should be:
|
slime@2
|
64 |
*
|
slime@2
|
65 |
* #define CFG01 rom struct \
|
slime@2
|
66 |
* { USB_CFG_DSC cd01; \
|
slime@2
|
67 |
* USB_INTF_DSC i00a00; \
|
slime@2
|
68 |
* USB_EP_DSC ep01o_i00a00; \
|
slime@2
|
69 |
* USB_EP_DSC ep01i_i00a00; \
|
slime@2
|
70 |
* USB_INTF_DSC i01a00; \
|
slime@2
|
71 |
* USB_EP_DSC ep02i_i01a00; \
|
slime@2
|
72 |
* } cfg01
|
slime@2
|
73 |
*
|
slime@2
|
74 |
* Note the hierarchy of the descriptors above, it follows the USB
|
slime@2
|
75 |
* specification requirement. All endpoints belonging to an interface
|
slime@2
|
76 |
* should be listed immediately after that interface.
|
slime@2
|
77 |
*
|
slime@2
|
78 |
* -------------------------------------------------------------------
|
slime@2
|
79 |
* Filling in the descriptor values in the usbdsc.c file:
|
slime@2
|
80 |
* -------------------------------------------------------------------
|
slime@2
|
81 |
* Most items should be self-explanatory, however, a few will be
|
slime@2
|
82 |
* explained for clarification.
|
slime@2
|
83 |
*
|
slime@2
|
84 |
* [Configuration Descriptor(USB_CFG_DSC)]
|
slime@2
|
85 |
* The configuration attribute must always have the _DEFAULT
|
slime@2
|
86 |
* definition at the minimum. Additional options can be ORed
|
slime@2
|
87 |
* to the _DEFAULT attribute. Available options are _SELF and _RWU.
|
slime@2
|
88 |
* These definitions are defined in the usbdefs_std_dsc.h file. The
|
slime@2
|
89 |
* _SELF tells the USB host that this device is self-powered. The
|
slime@2
|
90 |
* _RWU tells the USB host that this device supports Remote Wakeup.
|
slime@2
|
91 |
*
|
slime@2
|
92 |
* [Endpoint Descriptor(USB_EP_DSC)]
|
slime@2
|
93 |
* Assume the following example:
|
slime@2
|
94 |
* sizeof(USB_EP_DSC),DSC_EP,_EP01_OUT,_BULK,64,0x00
|
slime@2
|
95 |
*
|
slime@2
|
96 |
* The first two parameters are self-explanatory. They specify the
|
slime@2
|
97 |
* length of this endpoint descriptor (7) and the descriptor type.
|
slime@2
|
98 |
* The next parameter identifies the endpoint, the definitions are
|
slime@2
|
99 |
* defined in usbdefs_std_dsc.h and has the following naming
|
slime@2
|
100 |
* convention:
|
slime@2
|
101 |
* _EP<##>_<dir>
|
slime@2
|
102 |
* where ## is the endpoint number and dir is the direction of
|
slime@2
|
103 |
* transfer. The dir has the value of either 'OUT' or 'IN'.
|
slime@2
|
104 |
* The next parameter identifies the type of the endpoint. Available
|
slime@2
|
105 |
* options are _BULK, _INT, _ISO, and _CTRL. The _CTRL is not
|
slime@2
|
106 |
* typically used because the default control transfer endpoint is
|
slime@2
|
107 |
* not defined in the USB descriptors. When _ISO option is used,
|
slime@2
|
108 |
* addition options can be ORed to _ISO. Example:
|
slime@2
|
109 |
* _ISO|_AD|_FE
|
slime@2
|
110 |
* This describes the endpoint as an isochronous pipe with adaptive
|
slime@2
|
111 |
* and feedback attributes. See usbdefs_std_dsc.h and the USB
|
slime@2
|
112 |
* specification for details. The next parameter defines the size of
|
slime@2
|
113 |
* the endpoint. The last parameter in the polling interval.
|
slime@2
|
114 |
*
|
slime@2
|
115 |
* -------------------------------------------------------------------
|
slime@2
|
116 |
* Adding a USB String
|
slime@2
|
117 |
* -------------------------------------------------------------------
|
slime@2
|
118 |
* A string descriptor array should have the following format:
|
slime@2
|
119 |
*
|
slime@2
|
120 |
* rom struct{byte bLength;byte bDscType;word string[size];}sdxxx={
|
slime@2
|
121 |
* sizeof(sdxxx),DSC_STR,<text>};
|
slime@2
|
122 |
*
|
slime@2
|
123 |
* The above structure provides a means for the C compiler to
|
slime@2
|
124 |
* calculate the length of string descriptor sdxxx, where xxx is the
|
slime@2
|
125 |
* index number. The first two bytes of the descriptor are descriptor
|
slime@2
|
126 |
* length and type. The rest <text> are string texts which must be
|
slime@2
|
127 |
* in the unicode format. The unicode format is achieved by declaring
|
slime@2
|
128 |
* each character as a word type. The whole text string is declared
|
slime@2
|
129 |
* as a word array with the number of characters equals to <size>.
|
slime@2
|
130 |
* <size> has to be manually counted and entered into the array
|
slime@2
|
131 |
* declaration. Let's study this through an example:
|
slime@2
|
132 |
* if the string is "USB" , then the string descriptor should be:
|
slime@2
|
133 |
* (Using index 02)
|
slime@2
|
134 |
* rom struct{byte bLength;byte bDscType;word string[3];}sd002={
|
slime@2
|
135 |
* sizeof(sd002),DSC_STR,'U','S','B'};
|
slime@2
|
136 |
*
|
slime@2
|
137 |
* A USB project may have multiple strings and the firmware supports
|
slime@2
|
138 |
* the management of multiple strings through a look-up table.
|
slime@2
|
139 |
* The look-up table is defined as:
|
slime@2
|
140 |
* rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002};
|
slime@2
|
141 |
*
|
slime@2
|
142 |
* The above declaration has 3 strings, sd000, sd001, and sd002.
|
slime@2
|
143 |
* Strings can be removed or added. sd000 is a specialized string
|
slime@2
|
144 |
* descriptor. It defines the language code, usually this is
|
slime@2
|
145 |
* US English (0x0409). The index of the string must match the index
|
slime@2
|
146 |
* position of the USB_SD_Ptr array, &sd000 must be in position
|
slime@2
|
147 |
* USB_SD_Ptr[0], &sd001 must be in position USB_SD_Ptr[1] and so on.
|
slime@2
|
148 |
* The look-up table USB_SD_Ptr is used by the get string handler
|
slime@2
|
149 |
* function in usb9.c.
|
slime@2
|
150 |
*
|
slime@2
|
151 |
* -------------------------------------------------------------------
|
slime@2
|
152 |
*
|
slime@2
|
153 |
* The look-up table scheme also applies to the configuration
|
slime@2
|
154 |
* descriptor. A USB device may have multiple configuration
|
slime@2
|
155 |
* descriptors, i.e. CFG01, CFG02, etc. To add a configuration
|
slime@2
|
156 |
* descriptor, user must implement a structure similar to CFG01.
|
slime@2
|
157 |
* The next step is to add the configuration descriptor name, i.e.
|
slime@2
|
158 |
* cfg01, cfg02,.., to the look-up table USB_CD_Ptr. USB_CD_Ptr[0]
|
slime@2
|
159 |
* is a dummy place holder since configuration 0 is the un-configured
|
slime@2
|
160 |
* state according to the definition in the USB specification.
|
slime@2
|
161 |
*
|
slime@2
|
162 |
********************************************************************/
|
slime@2
|
163 |
|
slime@2
|
164 |
/*********************************************************************
|
slime@2
|
165 |
* Descriptor specific type definitions are defined in:
|
slime@2
|
166 |
* system\usb\usbdefs\usbdefs_std_dsc.h
|
slime@2
|
167 |
*
|
slime@2
|
168 |
* Configuration information is defined in:
|
slime@2
|
169 |
* autofiles\usbcfg.h
|
slime@2
|
170 |
********************************************************************/
|
slime@2
|
171 |
|
slime@2
|
172 |
/** I N C L U D E S *************************************************/
|
slime@2
|
173 |
#include "typedefs.h"
|
slime@2
|
174 |
#include "usb.h"
|
slime@2
|
175 |
|
slime@2
|
176 |
/** C O N S T A N T S ************************************************/
|
slime@2
|
177 |
#pragma romdata
|
slime@2
|
178 |
|
slime@2
|
179 |
/* Device Descriptor */
|
slime@2
|
180 |
rom USB_DEV_DSC device_dsc=
|
slime@2
|
181 |
{
|
slime@2
|
182 |
sizeof(USB_DEV_DSC), // Size of this descriptor in bytes
|
slime@2
|
183 |
DSC_DEV, // DEVICE descriptor type
|
slime@2
|
184 |
0x0200, // USB Spec Release Number in BCD format
|
slime@2
|
185 |
CDC_DEVICE, // Class Code
|
slime@2
|
186 |
0x00, // Subclass code
|
slime@2
|
187 |
0x00, // Protocol code
|
slime@2
|
188 |
EP0_BUFF_SIZE, // Max packet size for EP0, see usbcfg.h
|
slime@2
|
189 |
0x04D8, // Vendor ID
|
slime@2
|
190 |
0x000A, // Product ID: CDC RS-232 Emulation Demo
|
slime@2
|
191 |
0x0000, // Device release number in BCD format
|
slime@2
|
192 |
0x01, // Manufacturer string index
|
slime@2
|
193 |
0x02, // Product string index
|
slime@2
|
194 |
0x00, // Device serial number string index
|
slime@2
|
195 |
0x01 // Number of possible configurations
|
slime@2
|
196 |
};
|
slime@2
|
197 |
|
slime@2
|
198 |
/* Configuration 1 Descriptor */
|
slime@2
|
199 |
CFG01=
|
slime@2
|
200 |
{
|
slime@2
|
201 |
/* Configuration Descriptor */
|
slime@2
|
202 |
sizeof(USB_CFG_DSC), // Size of this descriptor in bytes
|
slime@2
|
203 |
DSC_CFG, // CONFIGURATION descriptor type
|
slime@2
|
204 |
sizeof(cfg01), // Total length of data for this cfg
|
slime@2
|
205 |
2, // Number of interfaces in this cfg
|
slime@2
|
206 |
1, // Index value of this configuration
|
slime@2
|
207 |
0, // Configuration string index
|
slime@2
|
208 |
_DEFAULT, // Attributes, see usbdefs_std_dsc.h
|
slime@2
|
209 |
50, // Max power consumption (2X mA)
|
slime@2
|
210 |
|
slime@2
|
211 |
/* Interface Descriptor */
|
slime@2
|
212 |
sizeof(USB_INTF_DSC), // Size of this descriptor in bytes
|
slime@2
|
213 |
DSC_INTF, // INTERFACE descriptor type
|
slime@2
|
214 |
0, // Interface Number
|
slime@2
|
215 |
0, // Alternate Setting Number
|
slime@2
|
216 |
1, // Number of endpoints in this intf
|
slime@2
|
217 |
COMM_INTF, // Class code
|
slime@2
|
218 |
ABSTRACT_CONTROL_MODEL, // Subclass code
|
slime@2
|
219 |
V25TER, // Protocol code
|
slime@2
|
220 |
0, // Interface string index
|
slime@2
|
221 |
|
slime@2
|
222 |
/* CDC Class-Specific Descriptors */
|
slime@2
|
223 |
sizeof(USB_CDC_HEADER_FN_DSC),CS_INTERFACE,DSC_FN_HEADER,0x0110,
|
slime@2
|
224 |
sizeof(USB_CDC_ACM_FN_DSC),CS_INTERFACE,DSC_FN_ACM,0x02,
|
slime@2
|
225 |
sizeof(USB_CDC_UNION_FN_DSC),CS_INTERFACE,DSC_FN_UNION,CDC_COMM_INTF_ID,CDC_DATA_INTF_ID,
|
slime@2
|
226 |
sizeof(USB_CDC_CALL_MGT_FN_DSC),CS_INTERFACE,DSC_FN_CALL_MGT,0x00,CDC_DATA_INTF_ID,
|
slime@2
|
227 |
|
slime@2
|
228 |
/* Endpoint Descriptor */
|
slime@2
|
229 |
sizeof(USB_EP_DSC),DSC_EP,_EP02_IN,_INT,CDC_INT_EP_SIZE,0x02,
|
slime@2
|
230 |
|
slime@2
|
231 |
/* Interface Descriptor */
|
slime@2
|
232 |
sizeof(USB_INTF_DSC), // Size of this descriptor in bytes
|
slime@2
|
233 |
DSC_INTF, // INTERFACE descriptor type
|
slime@2
|
234 |
1, // Interface Number
|
slime@2
|
235 |
0, // Alternate Setting Number
|
slime@2
|
236 |
2, // Number of endpoints in this intf
|
slime@2
|
237 |
DATA_INTF, // Class code
|
slime@2
|
238 |
0, // Subclass code
|
slime@2
|
239 |
NO_PROTOCOL, // Protocol code
|
slime@2
|
240 |
0, // Interface string index
|
slime@2
|
241 |
|
slime@2
|
242 |
/* Endpoint Descriptors */
|
slime@2
|
243 |
sizeof(USB_EP_DSC),DSC_EP,_EP03_OUT,_BULK,CDC_BULK_OUT_EP_SIZE,0x00,
|
slime@2
|
244 |
sizeof(USB_EP_DSC),DSC_EP,_EP03_IN,_BULK,CDC_BULK_IN_EP_SIZE,0x00
|
slime@2
|
245 |
};
|
slime@2
|
246 |
|
slime@2
|
247 |
rom struct{byte bLength;byte bDscType;word string[1];}sd000={
|
slime@2
|
248 |
sizeof(sd000),DSC_STR,0x0409};
|
slime@2
|
249 |
|
slime@2
|
250 |
rom struct{byte bLength;byte bDscType;word string[25];}sd001={
|
slime@2
|
251 |
sizeof(sd001),DSC_STR,
|
slime@2
|
252 |
'C','a','r','s','t','e','n',' ','P','r','e','s','s','e','r'};
|
slime@2
|
253 |
|
slime@2
|
254 |
rom struct{byte bLength;byte bDscType;word string[25];}sd002={
|
slime@2
|
255 |
sizeof(sd002),DSC_STR,
|
slime@2
|
256 |
'V','i','d','e','o',' ','v','2',' ','F','r','o','n','t','p','l','a','t','t','t','e'};
|
slime@2
|
257 |
|
slime@2
|
258 |
rom const unsigned char *rom USB_CD_Ptr[]={&cfg01,&cfg01};
|
slime@2
|
259 |
rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002};
|
slime@2
|
260 |
|
slime@2
|
261 |
rom pFunc ClassReqHandler[1]=
|
slime@2
|
262 |
{
|
slime@2
|
263 |
&USBCheckCDCRequest
|
slime@2
|
264 |
};
|
slime@2
|
265 |
|
slime@2
|
266 |
#pragma code
|
slime@2
|
267 |
|
slime@2
|
268 |
/** EOF usbdsc.c ****************************************************/
|