3 Copyright (C) Dean Camera, 2021.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11 Copyright 2021 Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com)
13 Permission to use, copy, modify, distribute, and sell this
14 software and its documentation for any purpose is hereby granted
15 without fee, provided that the above copyright notice appear in
16 all copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
22 The author disclaims all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
34 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
35 * computer-readable structures which the host requests upon device enumeration, to determine
36 * the device's capabilities and functions.
39 #include "Descriptors.h"
41 /** Device descriptor structure. This descriptor, located in FLASH 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
46 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
48 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
50 .USBSpecification
= VERSION_BCD(1,1,0),
51 .Class
= USB_CSCP_NoDeviceClass
,
52 .SubClass
= USB_CSCP_NoDeviceSubclass
,
53 .Protocol
= USB_CSCP_NoDeviceProtocol
,
55 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
59 .ReleaseNumber
= VERSION_BCD(0,0,1),
61 .ManufacturerStrIndex
= STRING_ID_Manufacturer
,
62 .ProductStrIndex
= STRING_ID_Product
,
63 .SerialNumStrIndex
= NO_DESCRIPTOR
,
65 .NumberOfConfigurations
= FIXED_NUM_CONFIGURATIONS
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.
73 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
77 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
79 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
82 .ConfigurationNumber
= 1,
83 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
85 .ConfigAttributes
= (USB_CONFIG_ATTR_RESERVED
| USB_CONFIG_ATTR_SELFPOWERED
),
87 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
92 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
94 .InterfaceNumber
= INTERFACE_ID_CCID
,
95 .AlternateSetting
= 0x00,
99 .Class
= CCID_CSCP_CCIDClass
,
100 .SubClass
= CCID_CSCP_NoSpecificSubclass
,
101 .Protocol
= CCID_CSCP_NoSpecificProtocol
,
103 .InterfaceStrIndex
= NO_DESCRIPTOR
108 .Header
= {.Size
= sizeof(USB_CCID_Descriptor_t
), .Type
= CCID_DTYPE_Functional
},
109 .CCID
= CCID_CURRENT_SPEC_RELEASE_NUMBER
,
110 .MaxSlotIndex
= 0x00,
111 .VoltageSupport
= CCID_VOLTAGESUPPORT_5V
,
112 .Protocols
= CCID_PROTOCOLS_T1
,
113 .DefaultClock
= CCID_DESCRIPTOR_CLOCK_MHZ(16),
114 .MaximumClock
= CCID_DESCRIPTOR_CLOCK_MHZ(16),
115 .NumClockSupported
= 0,
117 .MaxDataRate
= 307200,
118 .NumDataRatesSupported
= 0,
122 .Features
= CCID_Features_ExchangeLevel_ShortAPDU
| CCID_Features_Auto_ParameterConfiguration
| CCID_Features_Auto_ICCActivation
| CCID_Features_Auto_VoltageSelection
,
123 .MaxCCIDMessageLength
= CCID_EPSIZE
,
124 .ClassGetResponse
= 0xff,
125 .ClassEnvelope
= 0xff,
128 .MaxCCIDBusySlots
= 1
132 .CCID_BulkInEndpoint
=
134 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
136 .EndpointAddress
= CCID_IN_EPADDR
,
137 .Attributes
= EP_TYPE_BULK
,
138 .EndpointSize
= CCID_EPSIZE
,
139 .PollingIntervalMS
= 0x05
142 .CCID_BulkOutEndpoint
=
144 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
146 .EndpointAddress
= CCID_OUT_EPADDR
,
147 .Attributes
= EP_TYPE_BULK
,
148 .EndpointSize
= CCID_EPSIZE
,
149 .PollingIntervalMS
= 0x05
153 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
154 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
155 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
157 const USB_Descriptor_String_t PROGMEM LanguageString
= USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG
);
159 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
160 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
163 const USB_Descriptor_String_t PROGMEM ManufacturerString
= USB_STRING_DESCRIPTOR(L
"LUFA Library");
165 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
166 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
169 const USB_Descriptor_String_t PROGMEM ProductString
= USB_STRING_DESCRIPTOR(L
"LUFA CCID Demo");
171 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
172 * documentation) by the application code so that the address and size of a requested descriptor can be given
173 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
174 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
177 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
178 const uint16_t wIndex
,
179 const void** const DescriptorAddress
)
181 const uint8_t DescriptorType
= (wValue
>> 8);
182 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
184 const void* Address
= NULL
;
185 uint16_t Size
= NO_DESCRIPTOR
;
187 switch (DescriptorType
)
190 Address
= &DeviceDescriptor
;
191 Size
= sizeof(USB_Descriptor_Device_t
);
193 case DTYPE_Configuration
:
194 Address
= &ConfigurationDescriptor
;
195 Size
= sizeof(USB_Descriptor_Configuration_t
);
198 switch (DescriptorNumber
)
200 case STRING_ID_Language
:
201 Address
= &LanguageString
;
202 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
204 case STRING_ID_Manufacturer
:
205 Address
= &ManufacturerString
;
206 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
208 case STRING_ID_Product
:
209 Address
= &ProductString
;
210 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
217 *DescriptorAddress
= Address
;