-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDescriptors.c
More file actions
executable file
·329 lines (267 loc) · 11.8 KB
/
Descriptors.c
File metadata and controls
executable file
·329 lines (267 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/***********************************************************/
/* ____ ___ _ _ ___ ___ ____ _ */
/* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */
/* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */
/* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */
/* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */
/* */
/* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */
/***********************************************************/
/* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */
/* serial from ATMEGA328 interfaced on ARDUINO UNO */
/***********************************************************/
/* This is the USB Configuration part */
/***********************************************************/
/* Please look at LICENSE for details */
/* Please consult https://github.com/racerxdl/piuio_clone */
/***********************************************************/
/** \file
*
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
* computer-readable structures which the host requests upon device enumeration, to determine
* the device's capabilities and functions.
*/
#include "Descriptors.h"
int piuio_which_device = 0; // Default is PIUIO
/** Device descriptor for the regular PIUIO
*/
const USB_Descriptor_Device_t PROGMEM DeviceDescriptorPIUIO =
{
// All "Device Description" is here
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(1,0,0),
.Class = 0xFF,
.SubClass = 0x00,
.Protocol = 0x00,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x0547, // PIUIO Vendor ID. Cypress 0x547
.ProductID = 0x1002, // PIUIO Product ID. FX-USB 0x1002
.ReleaseNumber = VERSION_BCD(1,0,0),
.ManufacturerStrIndex = STRING_ID_Manufacturer,
.ProductStrIndex = STRING_ID_Product,
.SerialNumStrIndex = NO_DESCRIPTOR,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
/** Device descriptor for the LXIOv1 */
const USB_Descriptor_Device_t PROGMEM DeviceDescriptorLXIO1 =
{
// All "Device Description" is here
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(1,1,0),
.Class = 0x00,
.SubClass = 0x00,
.Protocol = 0x00,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x0d2f, // LXIO v1 Vendor ID.
.ProductID = 0x1020, // LXIO v1 Product ID.
.ReleaseNumber = VERSION_BCD(0,0,1),
.ManufacturerStrIndex = STRING_ID_Manufacturer,
.ProductStrIndex = STRING_ID_Product,
.SerialNumStrIndex = NO_DESCRIPTOR,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
/** Device descriptor for the LXIOv2 */
const USB_Descriptor_Device_t PROGMEM DeviceDescriptorLXIO2 =
{
// All "Device Description" is here
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(1,1,0),
.Class = 0x00,
.SubClass = 0x00,
.Protocol = 0x00,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x0d2f, // LXIO v1 Vendor ID.
.ProductID = 0x1040, // LXIO v2 Product ID.
.ReleaseNumber = VERSION_BCD(0,0,1),
.ManufacturerStrIndex = STRING_ID_Manufacturer,
.ProductStrIndex = STRING_ID_Product,
.SerialNumStrIndex = NO_DESCRIPTOR,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
const USB_Descriptor_Device_t* DeviceDescriptors[] = {
&DeviceDescriptorPIUIO,
&DeviceDescriptorLXIO1,
&DeviceDescriptorLXIO2,
};
/** Configuration descriptor structure for PIUIO*/
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptorPIUIO =
{
.Config =
{
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces = 1,
.ConfigurationNumber = 1,
.ConfigurationStrIndex = NO_DESCRIPTOR,
// PIUIO does have own power supply. But I dont like that lol, so mine is just USB powered.
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
// This is the value in mA, it will be divided by two (100 mean 50mA). Its just an info for PC
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
},
.USB_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = INTERFACE_ID_PIUIO,
.AlternateSetting = 0x00,
// We dont need any additional entry points, so this will be 0
.TotalEndpoints = 0,
// The interface didn't have nothing
.Class = 0x00,
.SubClass = 0x00,
.Protocol = 0x00,
.InterfaceStrIndex = NO_DESCRIPTOR
},
};
const USB_Descriptor_HIDReport_Datatype_t PROGMEM LXIOReport[] =
{
#if 1
HID_DESCRIPTOR_VENDOR(0, 1, 2, 3, 16)
#else
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
0x09, 0x01, // Usage (0x01)
0xA1, 0x01, // Collection (Application)
0x09, 0x02, // Usage (0x02)
0x15, 0x00, // Logical Minimum (0)
0x25, 0xFF, // Logical Maximum (-1)
0x75, 0x08, // Report Size (8)
0x95, 0x10, // Report Count (16)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0x03, // Usage (0x03)
0x15, 0x00, // Logical Minimum (0)
0x25, 0xFF, // Logical Maximum (-1)
0x75, 0x08, // Report Size (8)
0x95, 0x10, // Report Count (16)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
#endif
};
const USB_DescriptorLXIO_Configuration_t PROGMEM ConfigurationDescriptorLXIO =
{
.Config =
{
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_DescriptorLXIO_Configuration_t),
.TotalInterfaces = 1,
.ConfigurationNumber = 1,
.ConfigurationStrIndex = NO_DESCRIPTOR,
// PIUIO does have own power supply. But I dont like that lol, so mine is just USB powered.
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
// This is the value in mA, it will be divided by two (100 mean 50mA). Its just an info for PC
.MaxPowerConsumption = 50
},
.USB_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = INTERFACE_ID_PIUIO,
.AlternateSetting = 0x00,
// Two interrupt endpoints please
.TotalEndpoints = 2,
// The interface didn't have nothing
.Class = 0x03,
.SubClass = 0x00,
.Protocol = 0x00,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.HID_Desc =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = HID_DTYPE_HID},
.HIDSpec = VERSION_BCD(1,1,1),
.CountryCode = 0x00,
.TotalReportDescriptors = 1,
.HIDReportType = HID_DTYPE_Report,
.HIDReportLength = sizeof(LXIOReport)
},
.EP0_Desc =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = LXIO_EP0ADDR,
.Attributes = (EP_TYPE_INTERRUPT),
.EndpointSize = LXIO_EPSIZE,
.PollingIntervalMS = 1
},
.EP1_Desc =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = LXIO_EP1ADDR,
.Attributes = (EP_TYPE_INTERRUPT),
.EndpointSize = LXIO_EPSIZE,
.PollingIntervalMS = 1
}
};
const void* ConfigurationDescriptors[] = {
&ConfigurationDescriptorPIUIO,
&ConfigurationDescriptorLXIO,
&ConfigurationDescriptorLXIO,
};
const int ConfigurationDescriptorSizes[] = {
sizeof(USB_Descriptor_Configuration_t),
sizeof(USB_DescriptorLXIO_Configuration_t),
sizeof(USB_DescriptorLXIO_Configuration_t),
};
/** Language descriptor structure.*/
const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
/** Manufacturer descriptor string.*/
const USB_Descriptor_String_t PROGMEM ManufacturerStringPIUIO = USB_STRING_DESCRIPTOR(L"NTDEC");
const USB_Descriptor_String_t PROGMEM ManufacturerStringLXIO = USB_STRING_DESCRIPTOR(L"ANDAMIRO");
const USB_Descriptor_String_t* ManufacturerStrings[] = {
&ManufacturerStringPIUIO,
&ManufacturerStringLXIO,
&ManufacturerStringLXIO,
};
/** Product descriptor string.*/
const USB_Descriptor_String_t PROGMEM ProductStringPIUIO = USB_STRING_DESCRIPTOR(L"PIUIO");
const USB_Descriptor_String_t PROGMEM ProductStringLXIO = USB_STRING_DESCRIPTOR(L"PIU HID V1.00");
const USB_Descriptor_String_t* ProductStrings[] = {
&ProductStringPIUIO,
&ProductStringLXIO,
&ProductStringLXIO,
};
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint16_t wIndex,
const void** const DescriptorAddress)
{
const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType)
{
case DTYPE_Device:
Address = DeviceDescriptors[piuio_which_device];
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = ConfigurationDescriptors[piuio_which_device];
Size = ConfigurationDescriptorSizes[piuio_which_device];
break;
case DTYPE_String:
switch (DescriptorNumber)
{
case STRING_ID_Language:
Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size);
break;
case STRING_ID_Manufacturer:
Address = ManufacturerStrings[piuio_which_device];
Size = pgm_read_byte(&ManufacturerStrings[piuio_which_device]->Header.Size);
break;
case STRING_ID_Product:
Address = ProductStrings[piuio_which_device];
Size = pgm_read_byte(&ProductStrings[piuio_which_device]->Header.Size);
break;
}
break;
// LXIO only dumps these descriptor
// If by accident come from a PIUIO, well, fat chance
case HID_DTYPE_HID:
Address = &ConfigurationDescriptorLXIO.HID_Desc;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
case HID_DTYPE_Report:
Address = &LXIOReport;
Size = sizeof(LXIOReport);
break;
}
*DescriptorAddress = Address;
return Size;
}