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