]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/Bootloaders/MassStorage/Descriptors.c
Squashed 'tmk_core/' changes from d5c5ac6..8da1898
[tmk_keyboard.git] / protocol / lufa / LUFA-git / Bootloaders / MassStorage / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 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
41 /** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
42 * device characteristics, including the supported USB version, control endpoint size and the
43 * number of device configurations. The descriptor is read out by the USB host when the enumeration
44 * process begins.
45 */
46 const USB_Descriptor_Device_t DeviceDescriptor =
47 {
48 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
49
50 .USBSpecification = VERSION_BCD(1,1,0),
51 .Class = USB_CSCP_NoDeviceClass,
52 .SubClass = USB_CSCP_NoDeviceSubclass,
53 .Protocol = USB_CSCP_NoDeviceProtocol,
54
55 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
56
57 .VendorID = 0x03EB,
58 .ProductID = 0x2045,
59 .ReleaseNumber = VERSION_BCD(0,0,1),
60
61 .ManufacturerStrIndex = NO_DESCRIPTOR,
62 .ProductStrIndex = NO_DESCRIPTOR,
63 .SerialNumStrIndex = NO_DESCRIPTOR,
64
65 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
66 };
67
68 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
69 * of the device in one of its supported configurations, including information about any device interfaces
70 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
71 * a configuration so that the host may correctly communicate with the USB device.
72 */
73 const USB_Descriptor_Configuration_t ConfigurationDescriptor =
74 {
75 .Config =
76 {
77 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
78
79 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
80 .TotalInterfaces = 1,
81
82 .ConfigurationNumber = 1,
83 .ConfigurationStrIndex = NO_DESCRIPTOR,
84
85 .ConfigAttributes = USB_CONFIG_ATTR_RESERVED,
86
87 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
88 },
89
90 .MS_Interface =
91 {
92 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
93
94 .InterfaceNumber = INTERFACE_ID_MassStorage,
95 .AlternateSetting = 0,
96
97 .TotalEndpoints = 2,
98
99 .Class = MS_CSCP_MassStorageClass,
100 .SubClass = MS_CSCP_SCSITransparentSubclass,
101 .Protocol = MS_CSCP_BulkOnlyTransportProtocol,
102
103 .InterfaceStrIndex = NO_DESCRIPTOR
104 },
105
106 .MS_DataInEndpoint =
107 {
108 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
109
110 .EndpointAddress = MASS_STORAGE_IN_EPADDR,
111 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
112 .EndpointSize = MASS_STORAGE_IO_EPSIZE,
113 .PollingIntervalMS = 0x05
114 },
115
116 .MS_DataOutEndpoint =
117 {
118 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
119
120 .EndpointAddress = MASS_STORAGE_OUT_EPADDR,
121 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
122 .EndpointSize = MASS_STORAGE_IO_EPSIZE,
123 .PollingIntervalMS = 0x05
124 }
125 };
126
127 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
128 * documentation) by the application code so that the address and size of a requested descriptor can be given
129 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
130 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
131 * USB host.
132 */
133 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
134 const uint8_t wIndex,
135 const void** const DescriptorAddress)
136 {
137 const uint8_t DescriptorType = (wValue >> 8);
138
139 const void* Address = NULL;
140 uint16_t Size = NO_DESCRIPTOR;
141
142 /* If/Else If chain compiles slightly smaller than a switch case */
143 if (DescriptorType == DTYPE_Device)
144 {
145 Address = &DeviceDescriptor;
146 Size = sizeof(USB_Descriptor_Device_t);
147 }
148 else if (DescriptorType == DTYPE_Configuration)
149 {
150 Address = &ConfigurationDescriptor;
151 Size = sizeof(USB_Descriptor_Configuration_t);
152 }
153
154 *DescriptorAddress = Address;
155 return Size;
156 }
157
Imprint / Impressum