source: avrstuff/grip2hid/Descriptors.c@ d604513

main
Last change on this file since d604513 was d604513, checked in by Adrien Destugues <pulkomandy@…>, 3 years ago

Adjust software to the production PCB

  • Use the right MCU, port, etc.
  • Change USB IDs to V-USB shared one for USB Joysticks
  • Set vendor and product descriptions
  • Add makefile rule to program the AVR fuses
  • Property mode set to 100644
File size: 15.6 KB
Line 
1/*
2 LUFA Library
3 Copyright (C) Dean Camera, 2021.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7*/
8
9/*
10 Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29*/
30
31/** \file
32 *
33 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
34 * computer-readable structures which the host requests upon device enumeration, to determine
35 * the device's capabilities and functions.
36 */
37
38#include "Descriptors.h"
39
40/** HID class report descriptor. This is a special descriptor constructed with values from the
41 * USBIF HID class specification to describe the reports and capabilities of the HID device. This
42 * descriptor is parsed by the host and its contents used to determine what data (and in what encoding)
43 * the device will send, and what it may be sent back from the host. Refer to the HID specification for
44 * more details on HID report descriptors.
45 */
46const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =
47{
48 HID_RI_USAGE_PAGE(8, 0x01),
49 HID_RI_USAGE(8, 0x04),
50 HID_RI_COLLECTION(8, 0x01),
51
52 0x85, 0x01, // Report ID 1
53
54 // 15 constant bytes
55 HID_RI_REPORT_SIZE(8, 15),
56 HID_RI_REPORT_COUNT(8, 0x01),
57 HID_RI_INPUT(8, HID_IOF_CONSTANT),
58
59 HID_RI_USAGE_PAGE(8, 0x09),
60 HID_RI_LOGICAL_MINIMUM(8, 0x00),
61 HID_RI_LOGICAL_MAXIMUM(8, 0x01),
62
63 HID_RI_USAGE_MINIMUM(8, 7),
64 HID_RI_USAGE_MAXIMUM(8, 9),
65 HID_RI_USAGE(8, 4),
66 HID_RI_REPORT_SIZE(8, 0x01),
67 HID_RI_REPORT_COUNT(8, 4),
68 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
69
70 HID_RI_REPORT_SIZE(8, 1),
71 HID_RI_REPORT_COUNT(8, 0x01),
72 HID_RI_INPUT(8, HID_IOF_CONSTANT),
73
74 HID_RI_USAGE(8, 10),
75 HID_RI_USAGE_MINIMUM(8, 1),
76 HID_RI_USAGE_MAXIMUM(8, 3),
77 HID_RI_REPORT_SIZE(8, 0x01),
78 HID_RI_REPORT_COUNT(8, 4),
79 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
80
81 HID_RI_REPORT_SIZE(8, 1),
82 HID_RI_REPORT_COUNT(8, 0x01),
83 HID_RI_INPUT(8, HID_IOF_CONSTANT),
84
85 HID_RI_USAGE_MINIMUM(8, 5),
86 HID_RI_USAGE_MAXIMUM(8, 6),
87 HID_RI_REPORT_SIZE(8, 0x01),
88 HID_RI_REPORT_COUNT(8, 2),
89 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
90
91 HID_RI_USAGE_PAGE(8, 0x01),
92 HID_RI_USAGE(8, 0x01),
93 HID_RI_COLLECTION(8, 0x00),
94 HID_RI_USAGE(8, 0x31),
95 HID_RI_LOGICAL_MINIMUM(8, -2),
96 HID_RI_LOGICAL_MAXIMUM(8, 1),
97 HID_RI_REPORT_COUNT(8, 1),
98 HID_RI_REPORT_SIZE(8, 2),
99 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
100
101 HID_RI_REPORT_SIZE(8, 1),
102 HID_RI_REPORT_COUNT(8, 0x01),
103 HID_RI_INPUT(8, HID_IOF_CONSTANT),
104
105 HID_RI_USAGE(8, 0x30),
106 HID_RI_LOGICAL_MINIMUM(8, -2),
107 HID_RI_LOGICAL_MAXIMUM(8, 1),
108 HID_RI_REPORT_COUNT(8, 1),
109 HID_RI_REPORT_SIZE(8, 2),
110 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
111 HID_RI_END_COLLECTION(0),
112
113 HID_RI_END_COLLECTION(0),
114
115 HID_RI_USAGE_PAGE(8, 0x01),
116 HID_RI_USAGE(8, 0x04),
117 HID_RI_COLLECTION(8, 0x01),
118
119 0x85, 0x02, // Report ID 2
120
121 // 15 constant bytes
122 HID_RI_REPORT_SIZE(8, 15),
123 HID_RI_REPORT_COUNT(8, 0x01),
124 HID_RI_INPUT(8, HID_IOF_CONSTANT),
125
126 HID_RI_USAGE_PAGE(8, 0x09),
127 HID_RI_LOGICAL_MINIMUM(8, 0x00),
128 HID_RI_LOGICAL_MAXIMUM(8, 0x01),
129
130 HID_RI_USAGE_MINIMUM(8, 7),
131 HID_RI_USAGE_MAXIMUM(8, 9),
132 HID_RI_USAGE(8, 4),
133 HID_RI_REPORT_SIZE(8, 0x01),
134 HID_RI_REPORT_COUNT(8, 4),
135 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
136
137 HID_RI_REPORT_SIZE(8, 1),
138 HID_RI_REPORT_COUNT(8, 0x01),
139 HID_RI_INPUT(8, HID_IOF_CONSTANT),
140
141 HID_RI_USAGE(8, 10),
142 HID_RI_USAGE_MINIMUM(8, 1),
143 HID_RI_USAGE_MAXIMUM(8, 3),
144 HID_RI_REPORT_SIZE(8, 0x01),
145 HID_RI_REPORT_COUNT(8, 4),
146 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
147
148 HID_RI_REPORT_SIZE(8, 1),
149 HID_RI_REPORT_COUNT(8, 0x01),
150 HID_RI_INPUT(8, HID_IOF_CONSTANT),
151
152 HID_RI_USAGE_MINIMUM(8, 5),
153 HID_RI_USAGE_MAXIMUM(8, 6),
154 HID_RI_REPORT_SIZE(8, 0x01),
155 HID_RI_REPORT_COUNT(8, 2),
156 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
157
158 HID_RI_USAGE_PAGE(8, 0x01),
159 HID_RI_USAGE(8, 0x01),
160 HID_RI_COLLECTION(8, 0x00),
161 HID_RI_USAGE(8, 0x31),
162 HID_RI_LOGICAL_MINIMUM(8, -2),
163 HID_RI_LOGICAL_MAXIMUM(8, 1),
164 HID_RI_REPORT_COUNT(8, 1),
165 HID_RI_REPORT_SIZE(8, 2),
166 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
167
168 HID_RI_REPORT_SIZE(8, 1),
169 HID_RI_REPORT_COUNT(8, 0x01),
170 HID_RI_INPUT(8, HID_IOF_CONSTANT),
171
172 HID_RI_USAGE(8, 0x30),
173 HID_RI_LOGICAL_MINIMUM(8, -2),
174 HID_RI_LOGICAL_MAXIMUM(8, 1),
175 HID_RI_REPORT_COUNT(8, 1),
176 HID_RI_REPORT_SIZE(8, 2),
177 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
178 HID_RI_END_COLLECTION(0),
179
180 HID_RI_END_COLLECTION(0),
181
182 HID_RI_USAGE_PAGE(8, 0x01),
183 HID_RI_USAGE(8, 0x04),
184 HID_RI_COLLECTION(8, 0x01),
185
186 0x85, 0x03, // Report ID 3
187
188 // 15 constant bytes
189 HID_RI_REPORT_SIZE(8, 15),
190 HID_RI_REPORT_COUNT(8, 0x01),
191 HID_RI_INPUT(8, HID_IOF_CONSTANT),
192
193 HID_RI_USAGE_PAGE(8, 0x09),
194 HID_RI_LOGICAL_MINIMUM(8, 0x00),
195 HID_RI_LOGICAL_MAXIMUM(8, 0x01),
196
197 HID_RI_USAGE_MINIMUM(8, 7),
198 HID_RI_USAGE_MAXIMUM(8, 9),
199 HID_RI_USAGE(8, 4),
200 HID_RI_REPORT_SIZE(8, 0x01),
201 HID_RI_REPORT_COUNT(8, 4),
202 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
203
204 HID_RI_REPORT_SIZE(8, 1),
205 HID_RI_REPORT_COUNT(8, 0x01),
206 HID_RI_INPUT(8, HID_IOF_CONSTANT),
207
208 HID_RI_USAGE(8, 10),
209 HID_RI_USAGE_MINIMUM(8, 1),
210 HID_RI_USAGE_MAXIMUM(8, 3),
211 HID_RI_REPORT_SIZE(8, 0x01),
212 HID_RI_REPORT_COUNT(8, 4),
213 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
214
215 HID_RI_REPORT_SIZE(8, 1),
216 HID_RI_REPORT_COUNT(8, 0x01),
217 HID_RI_INPUT(8, HID_IOF_CONSTANT),
218
219 HID_RI_USAGE_MINIMUM(8, 5),
220 HID_RI_USAGE_MAXIMUM(8, 6),
221 HID_RI_REPORT_SIZE(8, 0x01),
222 HID_RI_REPORT_COUNT(8, 2),
223 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
224
225 HID_RI_USAGE_PAGE(8, 0x01),
226 HID_RI_USAGE(8, 0x01),
227 HID_RI_COLLECTION(8, 0x00),
228 HID_RI_USAGE(8, 0x31),
229 HID_RI_LOGICAL_MINIMUM(8, -2),
230 HID_RI_LOGICAL_MAXIMUM(8, 1),
231 HID_RI_REPORT_COUNT(8, 1),
232 HID_RI_REPORT_SIZE(8, 2),
233 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
234
235 HID_RI_REPORT_SIZE(8, 1),
236 HID_RI_REPORT_COUNT(8, 0x01),
237 HID_RI_INPUT(8, HID_IOF_CONSTANT),
238
239 HID_RI_USAGE(8, 0x30),
240 HID_RI_LOGICAL_MINIMUM(8, -2),
241 HID_RI_LOGICAL_MAXIMUM(8, 1),
242 HID_RI_REPORT_COUNT(8, 1),
243 HID_RI_REPORT_SIZE(8, 2),
244 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
245 HID_RI_END_COLLECTION(0),
246
247 HID_RI_END_COLLECTION(0),
248
249 HID_RI_USAGE_PAGE(8, 0x01),
250 HID_RI_USAGE(8, 0x04),
251 HID_RI_COLLECTION(8, 0x01),
252
253 0x85, 0x04, // Report ID 4
254
255 // 15 constant bytes
256 HID_RI_REPORT_SIZE(8, 15),
257 HID_RI_REPORT_COUNT(8, 0x01),
258 HID_RI_INPUT(8, HID_IOF_CONSTANT),
259
260 HID_RI_USAGE_PAGE(8, 0x09),
261 HID_RI_LOGICAL_MINIMUM(8, 0x00),
262 HID_RI_LOGICAL_MAXIMUM(8, 0x01),
263
264 HID_RI_USAGE_MINIMUM(8, 7),
265 HID_RI_USAGE_MAXIMUM(8, 9),
266 HID_RI_USAGE(8, 4),
267 HID_RI_REPORT_SIZE(8, 0x01),
268 HID_RI_REPORT_COUNT(8, 4),
269 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
270
271 HID_RI_REPORT_SIZE(8, 1),
272 HID_RI_REPORT_COUNT(8, 0x01),
273 HID_RI_INPUT(8, HID_IOF_CONSTANT),
274
275 HID_RI_USAGE(8, 10),
276 HID_RI_USAGE_MINIMUM(8, 1),
277 HID_RI_USAGE_MAXIMUM(8, 3),
278 HID_RI_REPORT_SIZE(8, 0x01),
279 HID_RI_REPORT_COUNT(8, 4),
280 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
281
282 HID_RI_REPORT_SIZE(8, 1),
283 HID_RI_REPORT_COUNT(8, 0x01),
284 HID_RI_INPUT(8, HID_IOF_CONSTANT),
285
286 HID_RI_USAGE_MINIMUM(8, 5),
287 HID_RI_USAGE_MAXIMUM(8, 6),
288 HID_RI_REPORT_SIZE(8, 0x01),
289 HID_RI_REPORT_COUNT(8, 2),
290 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
291
292 HID_RI_USAGE_PAGE(8, 0x01),
293 HID_RI_USAGE(8, 0x01),
294 HID_RI_COLLECTION(8, 0x00),
295 HID_RI_USAGE(8, 0x31),
296 HID_RI_LOGICAL_MINIMUM(8, -2),
297 HID_RI_LOGICAL_MAXIMUM(8, 1),
298 HID_RI_REPORT_COUNT(8, 1),
299 HID_RI_REPORT_SIZE(8, 2),
300 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
301
302 HID_RI_REPORT_SIZE(8, 1),
303 HID_RI_REPORT_COUNT(8, 0x01),
304 HID_RI_INPUT(8, HID_IOF_CONSTANT),
305
306 HID_RI_USAGE(8, 0x30),
307 HID_RI_LOGICAL_MINIMUM(8, -2),
308 HID_RI_LOGICAL_MAXIMUM(8, 1),
309 HID_RI_REPORT_COUNT(8, 1),
310 HID_RI_REPORT_SIZE(8, 2),
311 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
312 HID_RI_END_COLLECTION(0),
313
314 HID_RI_END_COLLECTION(0)
315};
316
317/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
318 * device characteristics, including the supported USB version, control endpoint size and the
319 * number of device configurations. The descriptor is read out by the USB host when the enumeration
320 * process begins.
321 */
322const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
323{
324 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
325
326 .USBSpecification = VERSION_BCD(1,1,0),
327 .Class = USB_CSCP_NoDeviceClass,
328 .SubClass = USB_CSCP_NoDeviceSubclass,
329 .Protocol = USB_CSCP_NoDeviceProtocol,
330
331 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
332
333 .VendorID = 0x16c0,
334 .ProductID = 0x27dc,
335 .ReleaseNumber = VERSION_BCD(0,0,1),
336
337 .ManufacturerStrIndex = STRING_ID_Manufacturer,
338 .ProductStrIndex = STRING_ID_Product,
339 .SerialNumStrIndex = NO_DESCRIPTOR,
340
341 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
342};
343
344/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
345 * of the device in one of its supported configurations, including information about any device interfaces
346 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
347 * a configuration so that the host may correctly communicate with the USB device.
348 */
349const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
350{
351 .Config =
352 {
353 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
354
355 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
356 .TotalInterfaces = 1,
357
358 .ConfigurationNumber = 1,
359 .ConfigurationStrIndex = NO_DESCRIPTOR,
360
361 .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
362
363 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
364 },
365
366 .HID_Interface =
367 {
368 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
369
370 .InterfaceNumber = INTERFACE_ID_Joystick,
371 .AlternateSetting = 0x00,
372
373 .TotalEndpoints = 1,
374
375 .Class = HID_CSCP_HIDClass,
376 .SubClass = HID_CSCP_NonBootSubclass,
377 .Protocol = HID_CSCP_NonBootProtocol,
378
379 .InterfaceStrIndex = NO_DESCRIPTOR
380 },
381
382 .HID_JoystickHID =
383 {
384 .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
385
386 .HIDSpec = VERSION_BCD(1,1,1),
387 .CountryCode = 0x00,
388 .TotalReportDescriptors = 1,
389 .HIDReportType = HID_DTYPE_Report,
390 .HIDReportLength = sizeof(JoystickReport)
391 },
392
393 .HID_ReportINEndpoint =
394 {
395 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
396
397 .EndpointAddress = JOYSTICK_EPADDR,
398 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
399 .EndpointSize = JOYSTICK_EPSIZE,
400 .PollingIntervalMS = 0x05
401 }
402};
403
404/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
405 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
406 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
407 */
408const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
409
410/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
411 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
412 * Descriptor.
413 */
414const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"PulkoTronics");
415
416/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
417 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
418 * Descriptor.
419 */
420const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"Gravis GrIP gamepads");
421
422/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
423 * documentation) by the application code so that the address and size of a requested descriptor can be given
424 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
425 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
426 * USB host.
427 */
428uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
429 const uint16_t wIndex,
430 const void** const DescriptorAddress)
431{
432 const uint8_t DescriptorType = (wValue >> 8);
433 const uint8_t DescriptorNumber = (wValue & 0xFF);
434
435 const void* Address = NULL;
436 uint16_t Size = NO_DESCRIPTOR;
437
438 switch (DescriptorType)
439 {
440 case DTYPE_Device:
441 Address = &DeviceDescriptor;
442 Size = sizeof(USB_Descriptor_Device_t);
443 break;
444 case DTYPE_Configuration:
445 Address = &ConfigurationDescriptor;
446 Size = sizeof(USB_Descriptor_Configuration_t);
447 break;
448 case DTYPE_String:
449 switch (DescriptorNumber)
450 {
451 case STRING_ID_Language:
452 Address = &LanguageString;
453 Size = pgm_read_byte(&LanguageString.Header.Size);
454 break;
455 case STRING_ID_Manufacturer:
456 Address = &ManufacturerString;
457 Size = pgm_read_byte(&ManufacturerString.Header.Size);
458 break;
459 case STRING_ID_Product:
460 Address = &ProductString;
461 Size = pgm_read_byte(&ProductString.Header.Size);
462 break;
463 }
464
465 break;
466 case HID_DTYPE_HID:
467 Address = &ConfigurationDescriptor.HID_JoystickHID;
468 Size = sizeof(USB_HID_Descriptor_HID_t);
469 break;
470 case HID_DTYPE_Report:
471 Address = &JoystickReport;
472 Size = sizeof(JoystickReport);
473 break;
474 }
475
476 *DescriptorAddress = Address;
477 return Size;
478}
479
Note: See TracBrowser for help on using the repository browser.