1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 
33 #ifndef _DESCRIPTORS_H_
34 #define _DESCRIPTORS_H_
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 /*-----------------------------------------------------------------------------+
42 | Include files                                                                |
43 |-----------------------------------------------------------------------------*/
44 #include <USB_API/USB_Common/types.h>
45 
46 //***********************************************************************************************
47 // CDC or HID - Define both for composite support
48 //***********************************************************************************************
49 #define _CDC_          // Needed for CDC inteface
50 //***********************************************************************************************
51 // CONFIGURATION CONSTANTS
52 //***********************************************************************************************
53 // These constants configure the API stack and help define the USB descriptors.
54 // Refer to Sec. 6 of the MSP430 USB CDC API Programmer's Guide for descriptions of these constants.
55 
56 // Configuration Constants that can change
57 // #define that relates to Device Descriptor
58 #define USB_VID               0x2047        // Vendor ID (VID)
59 
60 #ifdef eZ_FET
61   #define USB_PID               0x0013        // Product ID for eZ-FET
62 #endif
63 #ifdef MSP_FET
64   #define USB_PID               0x0014        // Product ID for MSP-FET
65 #endif
66 /*----------------------------------------------------------------------------+
67 | Firmware Version                                                            |
68 | How to detect version number of the FW running on MSP430?                   |
69 | on Windows Open ControlPanel->Systems->Hardware->DeviceManager->Ports->     |
70 |         Msp430->ApplicationUART->Details                                    |
71 +----------------------------------------------------------------------------*/
72 #define VER_FW_H              0x02          // Device release number, in binary-coded decimal
73 #define VER_FW_L              0x00          // Device release number, in binary-coded decimal
74 // If a serial number is to be reported, set this to the index within the string descriptor
75 //of the dummy serial number string.  It will then be automatically handled by the API.
76 // If no serial number is to be reported, set this to 0.
77 #define USB_STR_INDEX_SERNUM  3
78  #define PHDC_ENDPOINTS_NUMBER               2  // bulk in, bulk out
79 
80 
81 #define DESCRIPTOR_TOTAL_LENGTH             141    // wTotalLength, This is the sum of configuration descriptor length  + CDC descriptor length  + HID descriptor length
82 #define USB_NUM_INTERFACES                  4    // Number of implemented interfaces.
83 
84 #define CDC0_COMM_INTERFACE                0              // Comm interface number of CDC0
85 #define CDC0_DATA_INTERFACE                1              // Data interface number of CDC0
86 #define CDC0_INTEP_ADDR                    0x81           // Interrupt Endpoint Address of CDC0
87 #define CDC0_OUTEP_ADDR                    0x02           // Output Endpoint Address of CDC0
88 #define CDC0_INEP_ADDR                     0x82           // Input Endpoint Address of CDC0
89 
90 #define CDC1_COMM_INTERFACE                2              // Comm interface number of CDC1
91 #define CDC1_DATA_INTERFACE                3              // Data interface number of CDC1
92 #define CDC1_INTEP_ADDR                    0x83           // Interrupt Endpoint Address of CDC1
93 #define CDC1_OUTEP_ADDR                    0x04           // Output Endpoint Address of CDC1
94 #define CDC1_INEP_ADDR                     0x84           // Input Endpoint Address of CDC1
95 
96 #define CDC_NUM_INTERFACES                   2           //  Total Number of CDCs implemented. should set to 0 if there are no CDCs implemented.
97 #define HID_NUM_INTERFACES                   0           //  Total Number of HIDs implemented. should set to 0 if there are no HIDs implemented.
98 #define MSC_NUM_INTERFACES                   0           //  Total Number of MSCs implemented. should set to 0 if there are no MSCs implemented.
99 #define PHDC_NUM_INTERFACES                  0           //  Total Number of PHDCs implemented. should set to 0 if there are no PHDCs implemented.
100 // Interface numbers for the implemented CDSs and HIDs, This is to use in the Application(main.c) and in the interupt file(UsbIsr.c).
101 #define CDC0_INTFNUM                0
102 #define CDC1_INTFNUM                1
103 #define MSC_MAX_LUN_NUMBER                   1           // Maximum number of LUNs supported
104 
105 #define PUTWORD(x)      ((x)&0xFF),((x)>>8)
106 
107 #define USB_OUTEP_INT_EN BIT0 | BIT2 | BIT4
108 #define USB_INEP_INT_EN BIT0 | BIT1 | BIT2 | BIT3 | BIT4
109 // MCLK frequency of MCU, in Hz
110 // For running higher frequencies the Vcore voltage adjustment may required.
111 // Please refer to Data Sheet of the MSP430 device you use
112 #ifdef eZ_FET
113   #define USB_MCLK_FREQ 25000000                // MCLK frequency in Hz(eZ-FET, 5528)
114 #endif
115 #ifdef MSP_FET
116   #define USB_MCLK_FREQ 22000000                // MCLK frequency in Hz(MSP-FET, 6638)
117 #endif
118 
119 #define USB_PLL_XT        2                  // Defines which XT is used by the PLL (1=XT1, 2=XT2)
120 #define USB_XT_FREQ       USBPLL_SETCLK_4_0  // Indicates the freq of the crystal on the oscillator indicated by USB_PLL_XT
121 #define USB_DISABLE_XT_SUSPEND 0             // If non-zero, then USB_suspend() will disable the oscillator
122                                              // that is designated by USB_PLL_XT; if zero, USB_suspend won't
123                                              // affect the oscillator
124 #define USB_DMA_CHAN             0x00        // Set to 0xFF if no DMA channel will be used 0..7 for selected DMA channel
125 
126 
127 
128 // Controls whether the remote wakeup feature is supported by this device.
129 // A value of 0x20 indicates that is it supported (this value is the mask for
130 // the bmAttributes field in the configuration descriptor).
131 // A value of zero indicates remote wakeup is not supported.
132 // Other values are undefined, as they will interfere with bmAttributes.
133 #define USB_SUPPORT_REM_WAKE 0x00
134 
135 // Controls whether the application is self-powered to any degree.  Should be
136 // set to 0x40, unless the USB device is fully supplied by the bus.
137 #define USB_SUPPORT_SELF_POWERED 0x80
138 
139 // Controls what the device reports to the host regarding how much power it will
140 // consume from VBUS.  Expressed in 2mA units; that is, the number of mA
141 // communicated is twice the value of this field.
142 #define USB_MAX_POWER 0x32
143 //Configuration constants that can not change ( Fixed Values)
144 #define CDC_CLASS  2
145 #define HID_CLASS  3
146 #define MSC_CLASS  4
147 #define PHDC_CLASS 5
148 
149     #define MAX_PACKET_SIZE   0x40              // Max size of the USB packets.
150 
151 //***********************************************************************************************
152 // DESCRIPTOR CONSTANTS
153 //***********************************************************************************************
154 #define SIZEOF_DEVICE_DESCRIPTOR  0x12
155 //#define SIZEOF_REPORT_DESCRIPTOR  36
156 //#define USBHID_REPORT_LENGTH      64  // length of whole HID report (including Report ID)
157 #define CONFIG_STRING_INDEX       4
158 #define INTF_STRING_INDEX         5
159 #define USB_CONFIG_VALUE          0x01
160 //***********************************************************************************************
161 // OUTWARD DECLARATIONS
162 //***********************************************************************************************
163 
164 //Calculates the endpoint descriptor block number from given address
165 #define EDB(addr) ((addr&0x07)-1)
166 
167 /* Structure for generic part of configuration descriptor */
168 struct abromConfigurationDescriptorGenric
169 {
170     BYTE sizeof_config_descriptor;            // bLength
171     BYTE desc_type_config;                    // bDescriptorType: 2
172     BYTE sizeof_configuration_descriptor1;    // wTotalLength
173     BYTE sizeof_configuration_descriptor2;
174     BYTE usb_num_configurations;              // bNumInterfaces
175     BYTE bconfigurationvalue;                 // bConfigurationValue
176     BYTE  config_string_index;                // iConfiguration Description offset
177     BYTE mattributes;                         // bmAttributes, bus power, remote wakeup
178     BYTE usb_max_power;                       // Max. Power Consumption at 2mA unit
179 };
180 
181 /************************************************CDC Descriptor**************************/
182 struct abromConfigurationDescriptorCdc
183 {
184 //Interface Association Descriptor
185     BYTE bLength;                             // Size of this Descriptor in Bytes
186     BYTE bDescriptorType;                     // Descriptor Type (=11)
187     BYTE bFirstInterface;                     // Interface number of the first one associated with this function
188     BYTE bInterfaceCount;                     // Numver of contiguous interface associated with this function
189     BYTE bFunctionClass;                      // The class triad of this interface,
190     BYTE bFunctionSubClass;                   // usually same as the triad of the first interface
191     BYTE bFunctionProcotol;
192     BYTE iInterface;                          // Index of String Desc for this function
193 // interface descriptor (9 bytes)
194     BYTE blength_intf;                        // blength: interface descriptor size
195     BYTE desc_type_interface;                 // bdescriptortype: interface
196     BYTE interface_number_cdc;                // binterfacenumber
197     BYTE balternatesetting;                   // balternatesetting: alternate setting
198     BYTE bnumendpoints;                       // bnumendpoints: three endpoints used
199     BYTE binterfaceclass;                     // binterfaceclass: communication interface class
200     BYTE binterfacesubclass;                  // binterfacesubclass: abstract control model
201     BYTE binterfaceprotocol;                  // binterfaceprotocol: common at commands
202     BYTE intf_string_index;                   // interface:
203 //header functional descriptor
204     BYTE blength_header;                      // blength: endpoint descriptor size
205     BYTE bdescriptortype_header;              // bdescriptortype: cs_interface
206     BYTE bdescriptorsubtype_header;           // bdescriptorsubtype: header func desc
207     BYTE bcdcdc1;
208     BYTE bcdcdc2;                             // bcdcdc: spec release number
209 
210 //call managment functional descriptor
211     BYTE bfunctionlength;                     // bfunctionlength
212     BYTE bdescriptortype_c;                   // bdescriptortype: cs_interface
213     BYTE bdescriptorsubtype_c;                // bdescriptorsubtype: call management func desc
214     BYTE bmcapabilities;                      // bmcapabilities: d0+d1
215     BYTE intf_number_cdc;                     // bdatainterface: 0
216 
217 //acm functional descriptor
218     BYTE bfunctionlength_acm;                 // bfunctionlength
219     BYTE bdescriptortype_acm;                 // bdescriptortype: cs_interface
220     BYTE bdescriptorsubtype_acm;              // bdescriptorsubtype: abstract control management desc
221     BYTE bmcapabilities_acm;                  // bmcapabilities
222 
223 // Union Functional Descriptor
224     BYTE bLength_ufd;                         // Size, in bytes
225     BYTE bdescriptortype_ufd;                 // bDescriptorType: CS_INTERFACE
226     BYTE bdescriptorsubtype_ufd;              // bDescriptorSubtype: Union Functional Desc
227     BYTE bmasterinterface_ufd;                // bMasterInterface -- the controlling intf for the union
228     BYTE bslaveinterface_ufd;                 // bSlaveInterface -- the controlled intf for the union
229 
230 //Interrupt end point related fields
231     BYTE sizeof_epintep_descriptor;           // blength: endpoint descriptor size
232     BYTE desc_type_epintep;                   // bdescriptortype: endpoint
233     BYTE cdc_intep_addr;                      // bendpointaddress: (in2)
234     BYTE epintep_desc_attr_type_int;          // bmattributes: interrupt
235     BYTE epintep_wmaxpacketsize1;
236     BYTE epintep_wmaxpacketsize;              // wmaxpacketsize, 64 bytes
237     BYTE epintep_binterval;                   // binterval
238 
239 // Data interface descriptor (9 bytes)
240     BYTE blength_slaveintf;                   // blength: interface descriptor size
241     BYTE desc_type_slaveinterface;            // bdescriptortype: interface
242     BYTE interface_number_slavecdc;           // binterfacenumber
243     BYTE balternatesetting_slave;             // balternatesetting: alternate setting
244     BYTE bnumendpoints_slave;                 // bnumendpoints: three endpoints used
245     BYTE binterfaceclass_slave;               // binterfaceclass: data interface class
246     BYTE binterfacesubclass_slave;            // binterfacesubclass: abstract control model
247     BYTE binterfaceprotocol_slave;            // binterfaceprotocol: common at commands
248     BYTE intf_string_index_slave;             // interface:
249 
250 // Bulk out end point related fields
251     BYTE sizeof_outep_descriptor;             // blength: endpoint descriptor size
252     BYTE desc_type_outep;                     // bdescriptortype: endpoint
253     BYTE cdc_outep_addr;                      // bendpointaddress: (out3)
254     BYTE outep_desc_attr_type_bulk;           // bmattributes: bulk
255     BYTE outep_wmaxpacketsize1;
256     BYTE outep_wmaxpacketsize2;               // wmaxpacketsize, 64 bytes
257     BYTE outep_binterval;                     // binterval: ignored for bulk transfer
258 
259 // Bulk in related fields
260     BYTE sizeof_inep_descriptor;              // blength: endpoint descriptor size
261     BYTE desc_type_inep;                      // bdescriptortype: endpoint
262     BYTE cdc_inep_addr;                       // bendpointaddress: (in3)
263     BYTE inep_desc_attr_type_bulk;            // bmattributes: bulk
264     BYTE inep_wmaxpacketsize1;
265     BYTE inep_wmaxpacketsize2;                // wmaxpacketsize, 64 bytes
266     BYTE inep_binterval;                      // binterval: ignored for bulk transfer
267 };
268 
269 /**************************************HID descriptor structure *************************/
270 struct abromConfigurationDescriptorHid
271 {
272 //INTERFACE DESCRIPTOR (9 bytes)
273     BYTE sizeof_interface_descriptor;        // Desc Length
274     BYTE desc_type_interface;                // DescriptorType
275     BYTE interface_number_hid;               // Interface number
276     BYTE balternatesetting;                  // Any alternate settings if supported
277     BYTE bnumendpoints;                      // Number of end points required
278     BYTE binterfaceclass;                    // Class ID
279     BYTE binterfacesubclass;                 // Sub class ID
280     BYTE binterfaceprotocol;                 // Protocol
281     BYTE intf_string_index;                  // String Index
282 
283 //hid descriptor (9 bytes)
284     BYTE blength_hid_descriptor;             // HID Desc length
285     BYTE hid_descriptor_type;                // HID Desc Type
286     BYTE hidrevno1;                          // Rev no
287     BYTE hidrevno2;                          // Rev no - 2nd part
288     BYTE tcountry;                           // Country code
289     BYTE numhidclasses;                      // Number of HID classes to follow
290     BYTE report_descriptor_type;             // Report desc type
291     BYTE tlength;                            // Total length of report descriptor
292     BYTE size_rep_desc;
293 
294 //input end point descriptor (7 bytes)
295     BYTE size_inp_endpoint_descriptor;       // End point desc size
296     BYTE desc_type_inp_endpoint;             // Desc type
297     BYTE hid_inep_addr;                      // Input end point address
298     BYTE ep_desc_attr_type_inp_int;          // Type of end point
299     BYTE  inp_wmaxpacketsize1;               // Max packet size
300     BYTE  inp_wmaxpacketsize2;
301     BYTE inp_binterval;                      // bInterval in ms
302 
303  // Output end point descriptor; (7 bytes)
304     BYTE size_out_endpoint_descriptor;       // Output endpoint desc size
305     BYTE desc_type_out_endpoint;             // Desc type
306     BYTE hid_outep_addr;                     // Output end point address
307     BYTE ep_desc_attr_type_out_int;          // End point type
308     BYTE out_wmaxpacketsize1;                // Max packet size
309     BYTE out_wmaxpacketsize2;
310     BYTE out_binterval;                      // bInterval in ms
311 };
312 
313 /**************************************MSC descriptor structure *************************/
314 struct abromConfigurationDescriptorMsc
315 {
316 // INTERFACE DESCRIPTOR (9 bytes)
317     BYTE sizeof_interface_descriptor;         // Desc Length
318     BYTE desc_type_interface;                 // DescriptorType
319     BYTE interface_number_hid;                // Interface number
320     BYTE balternatesetting;                   // Any alternate settings if supported
321     BYTE bnumendpoints;                       // Number of end points required
322     BYTE binterfaceclass;                     // Class ID
323     BYTE binterfacesubclass;                  // Sub class ID
324     BYTE binterfaceprotocol;                  // Protocol
325     BYTE intf_string_index;                   // String Index
326 
327 // input end point descriptor (7 bytes)
328     BYTE size_inp_endpoint_descriptor;        // End point desc size
329     BYTE desc_type_inp_endpoint;              // Desc type
330     BYTE hid_inep_addr;                       // Input end point address
331     BYTE ep_desc_attr_type_inp_int;           // Type of end point
332     BYTE  inp_wmaxpacketsize1;                // Max packet size
333     BYTE  inp_wmaxpacketsize2;
334     BYTE inp_binterval;                       // bInterval in ms
335 
336 // Output end point descriptor; (7 bytes)
337     BYTE size_out_endpoint_descriptor;        // Output endpoint desc size
338     BYTE desc_type_out_endpoint;              // Desc type
339     BYTE hid_outep_addr;                      // Output end point address
340     BYTE ep_desc_attr_type_out_int;           // End point type
341     BYTE out_wmaxpacketsize1;                 // Max packet size
342     BYTE out_wmaxpacketsize2;
343     BYTE out_binterval;                       // bInterval in ms
344 };
345 
346 /* Global structure having Generic,CDC,HID, MSC structures */
347 struct  abromConfigurationDescriptorGroup
348 {
349     /* Generic part of config descriptor */
350     const struct abromConfigurationDescriptorGenric abromConfigurationDescriptorGenric;
351 #ifdef _MSC_
352     /* MSC descriptor structure */
353     const struct abromConfigurationDescriptorMsc stMsc[MSC_NUM_INTERFACES];
354 #endif
355 #ifdef _CDC_
356     /* CDC descriptor structure */
357     const struct abromConfigurationDescriptorCdc stCdc[CDC_NUM_INTERFACES];
358 #endif
359 #ifdef _HID_
360     /* HID descriptor structure */
361     const struct abromConfigurationDescriptorHid stHid[HID_NUM_INTERFACES];
362 #endif
363 #ifdef _PHDC_
364 /* PDC descriptor structure */
365     const struct abromConfigurationDescriptorPhdc stPhdc[PHDC_NUM_INTERFACES];
366 #endif
367 };
368 
369 extern const struct  abromConfigurationDescriptorGroup abromConfigurationDescriptorGroup;
370 extern BYTE const abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR];
371 extern BYTE const abromStringDescriptor[];
372 //extern BYTE const abromReportDescriptor[SIZEOF_REPORT_DESCRIPTOR];
373 
374 /* Handle Structure - Will be populated in descriptors.c based on number of CDC,HID interfaces */
375 struct tUsbHandle
376 {
377     BYTE ep_In_Addr;               // Input EP Addr
378     BYTE ep_Out_Addr;              // Output EP Addr
379     BYTE edb_Index;                // The EDB index
380     BYTE dev_Class;                // Device Class- 2 for CDC, 3 for HID
381     WORD intepEP_X_Buffer;         // Interupt X Buffer Addr
382     WORD intepEP_Y_Buffer;         // Interupt Y Buffer Addr
383     WORD oep_X_Buffer;             // Output X buffer Addr
384     WORD oep_Y_Buffer;             // Output Y buffer Addr
385     WORD iep_X_Buffer;             // Input X Buffer Addr
386     WORD iep_Y_Buffer;             // Input  Y Buffer Addr
387 };
388 
389 extern const struct tUsbHandle stUsbHandle[CDC_NUM_INTERFACES + HID_NUM_INTERFACES + MSC_NUM_INTERFACES + PHDC_NUM_INTERFACES];
390 extern const tDEVICE_REQUEST_COMPARE tUsbRequestList[];
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif
397 
398 /*------------------------ Nothing Below This Line --------------------------*/
399