Rev Author Line No. Line
4932 kaklik 1 /************************************************************************
2 usb_descriptors.c
3  
4 WFF USB Generic HID Demonstration 3
5 usbGenericHidCommunication reference firmware 3_0_0_0
6 Copyright (C) 2011 Simon Inns
7  
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12  
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17  
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20  
21 Email: simon.inns@gmail.com
22  
23 ************************************************************************/
24  
25 #ifndef USB_DESCRIPTORS_C
26 #define USB_DESCRIPTORS_C
27  
28 // Local includes
29 #include "HardwareProfile.h"
30  
31 // Microchip Application Library includes
32 #include "./USB/usb.h"
33 #include "./USB/usb_function_hid.h"
34  
35 // Device Descriptor
36 ROM USB_DEVICE_DESCRIPTOR device_dsc=
37 {
38 0x12, // Size of this descriptor in bytes
39 USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
40 0x0200, // USB Spec Release Number in BCD format
41 0x00, // Class Code
42 0x00, // Subclass code
43 0x00, // Protocol code
44 USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h
45 USB_VID, // Vendor ID
46 USB_PID, // Product ID
47 0x0002, // Device release number in BCD format
48 0x01, // Manufacturer string index
49 0x02, // Product string index
50 0x03, // Device serial number string index
51 0x01 // Number of possible configurations
52 };
53  
54 // Configuration 1 Descriptor
55 ROM BYTE configDescriptor1[]=
56 {
57 // Configuration Descriptor
58 0x09, // Size of this descriptor in bytes (sizeof(USB_CFG_DSC))
59 USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type
60 0x29,0x00, // Total length of data for this cfg
61 1, // Number of interfaces in this cfg
62 1, // Index value of this configuration
63 0, // Configuration string index
64 _DEFAULT | _SELF, // Attributes, see usb_device.h
65 50, // Max power consumption (2X mA)
66  
67 // Interface Descriptor
68 0x09, // Size of this descriptor in bytes (sizeof(USB_INTF_DSC))
69 USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
70 0, // Interface Number
71 0, // Alternate Setting Number
72 2, // Number of endpoints in this intf
73 HID_INTF, // Class code
74 0, // Subclass code
75 0, // Protocol code
76 0, // Interface string index
77  
78 // HID Class-Specific Descriptor
79 0x09, // Size of this descriptor in bytes (sizeof(USB_HID_DSC)+3)
80 DSC_HID, // HID descriptor type
81 0x11,0x01, // HID Spec Release Number in BCD format (1.11)
82 0x00, // Country Code (0x00 for Not supported)
83 HID_NUM_OF_DSC, // Number of class descriptors, see usbcfg.h
84 DSC_RPT, // Report descriptor type
85 HID_RPT01_SIZE,0x00, // Size of the report descriptor (sizeof(hid_rpt01))
86  
87 // Endpoint Descriptor
88 0x07, // sizeof(USB_EP_DSC)
89 USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
90 HID_EP | _EP_IN, // Endpoint Address
91 _INTERRUPT, // Attributes
92 0x40,0x00, // size
93 0x01, // Interval
94  
95 // Endpoint Descriptor
96 0x07, // sizeof(USB_EP_DSC)
97 USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
98 HID_EP | _EP_OUT, // EndpointAddress
99 _INTERRUPT, // Attributes
100 0x40,0x00, // size
101 0x01 // Interval
102 };
103  
104 // Language code string descriptor
105 ROM struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={
106 sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409
107 }};
108  
109 // Manufacturer string descriptor (set in HardwareProfile.h)
110 ROM struct{BYTE bLength;BYTE bDscType;WORD string[MSDLENGTH];}sd001={
111 sizeof(sd001),USB_DESCRIPTOR_STRING,
112 {MSD}};
113  
114 // Product string descriptor (set in HardwareProfile.h)
115 ROM struct{BYTE bLength;BYTE bDscType;WORD string[PSDLENGTH];}sd002={
116 sizeof(sd002),USB_DESCRIPTOR_STRING,
117 {PSD}};
118  
119 // Device serial number string descriptor
120 ROM struct{BYTE bLength;BYTE bDscType;WORD string[DSNLENGTH];}sd003={
121 sizeof(sd003),USB_DESCRIPTOR_STRING,
122 {DSN}};
123  
124 // Class specific descriptor - HID
125 ROM struct{BYTE report[HID_RPT01_SIZE];}hid_rpt01={
126 {
127 0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1)
128 0x09, 0x01, // Usage (Vendor Usage 1)
129 0xA1, 0x01, // Collection (Application)
130 0x19, 0x01, // Usage Minimum
131 0x29, 0x40, // Usage Maximum //64 input usages total (0x01 to 0x40)
132 0x15, 0x01, // Logical Minimum (data bytes in the report may have minimum value = 0x00)
133 0x25, 0x40, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
134 0x75, 0x08, // Report Size: 8-bit field size
135 0x95, 0x40, // Report Count: Make sixty-four 8-bit fields (the next time the parser hits an "Input", "Output", or "Feature" item)
136 0x81, 0x00, // Input (Data, Array, Abs): Instantiates input packet fields based on the above report size, count, logical min/max, and usage.
137 0x19, 0x01, // Usage Minimum
138 0x29, 0x40, // Usage Maximum //64 output usages total (0x01 to 0x40)
139 0x91, 0x00, // Output (Data, Array, Abs): Instantiates output packet fields. Uses same report size and count as "Input" fields, since nothing new/different was specified to the parser since the "Input" item.
140 0xC0} // End Collection
141 };
142  
143  
144 // Array of configuration descriptors
145 ROM BYTE *ROM USB_CD_Ptr[]=
146 {
147 (ROM BYTE *ROM)&configDescriptor1
148 };
149  
150 // Array of string descriptors
151 ROM BYTE *ROM USB_SD_Ptr[]=
152 {
153 (ROM BYTE *ROM)&sd000,
154 (ROM BYTE *ROM)&sd001,
155 (ROM BYTE *ROM)&sd002,
156 (ROM BYTE *ROM)&sd003
157 };
158  
159 #endif