Add script reading bootloader flags
[pub/lufa.git] / Bootloaders / HID / Descriptors.c
index 48ef78e..6a82c23 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2021.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2021  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -48,16 +48,16 @@ const USB_Descriptor_HIDReport_Datatype_t HIDReport[] =
        HID_RI_USAGE_PAGE(16, 0xFFDC), /* Vendor Page 0xDC */
        HID_RI_USAGE(8, 0xFB), /* Vendor Usage 0xFB */
        HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */
-           HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */
-           HID_RI_LOGICAL_MINIMUM(8, 0x00),
-           HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
-           HID_RI_REPORT_SIZE(8, 0x08),
-           HID_RI_REPORT_COUNT(16, (sizeof(uint16_t) + SPM_PAGESIZE)),
-           HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+               HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */
+               HID_RI_LOGICAL_MINIMUM(8, 0x00),
+               HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
+               HID_RI_REPORT_SIZE(8, 0x08),
+               HID_RI_REPORT_COUNT(16, (sizeof(uint16_t) + SPM_PAGESIZE)),
+               HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
        HID_RI_END_COLLECTION(0),
 };
 
-/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
+/** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
  *  device characteristics, including the supported USB version, control endpoint size and the
  *  number of device configurations. The descriptor is read out by the USB host when the enumeration
  *  process begins.
@@ -66,7 +66,7 @@ const USB_Descriptor_Device_t DeviceDescriptor =
 {
        .Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
 
-       .USBSpecification       = VERSION_BCD(01.10),
+       .USBSpecification       = VERSION_BCD(1,1,0),
        .Class                  = USB_CSCP_NoDeviceClass,
        .SubClass               = USB_CSCP_NoDeviceSubclass,
        .Protocol               = USB_CSCP_NoDeviceProtocol,
@@ -75,7 +75,7 @@ const USB_Descriptor_Device_t DeviceDescriptor =
 
        .VendorID               = 0x03EB,
        .ProductID              = 0x2067,
-       .ReleaseNumber          = VERSION_BCD(00.01),
+       .ReleaseNumber          = VERSION_BCD(0,0,1),
 
        .ManufacturerStrIndex   = NO_DESCRIPTOR,
        .ProductStrIndex        = NO_DESCRIPTOR,
@@ -84,7 +84,7 @@ const USB_Descriptor_Device_t DeviceDescriptor =
        .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
 };
 
-/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
+/** Configuration descriptor structure. This descriptor, located in SRAM memory, describes the usage
  *  of the device in one of its supported configurations, including information about any device interfaces
  *  and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
  *  a configuration so that the host may correctly communicate with the USB device.
@@ -101,7 +101,7 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
                        .ConfigurationNumber    = 1,
                        .ConfigurationStrIndex  = NO_DESCRIPTOR,
 
-                       .ConfigAttributes       = USB_CONFIG_ATTR_BUSPOWERED,
+                       .ConfigAttributes       = USB_CONFIG_ATTR_RESERVED,
 
                        .MaxPowerConsumption    = USB_CONFIG_POWER_MA(100)
                },
@@ -110,7 +110,7 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
                {
                        .Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
 
-                       .InterfaceNumber        = 0x00,
+                       .InterfaceNumber        = INTERFACE_ID_GenericHID,
                        .AlternateSetting       = 0x00,
 
                        .TotalEndpoints         = 1,
@@ -126,7 +126,7 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
                {
                        .Header                 = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
 
-                       .HIDSpec                = VERSION_BCD(01.11),
+                       .HIDSpec                = VERSION_BCD(1,1,1),
                        .CountryCode            = 0x00,
                        .TotalReportDescriptors = 1,
                        .HIDReportType          = HID_DTYPE_Report,
@@ -137,10 +137,10 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
                {
                        .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
 
-                       .EndpointAddress        = (ENDPOINT_DIR_IN | HID_IN_EPNUM),
+                       .EndpointAddress        = HID_IN_EPADDR,
                        .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
                        .EndpointSize           = HID_IN_EPSIZE,
-                       .PollingIntervalMS      = 0x01
+                       .PollingIntervalMS      = 0x05
                },
 };
 
@@ -151,7 +151,7 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
  *  USB host.
  */
 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
-                                    const uint8_t wIndex,
+                                    const uint16_t wIndex,
                                     const void** const DescriptorAddress)
 {
        const uint8_t DescriptorType   = (wValue >> 8);
@@ -175,7 +175,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
                Address = &ConfigurationDescriptor.HID_VendorHID;
                Size    = sizeof(USB_HID_Descriptor_HID_t);
        }
-       else
+       else if (DescriptorType == HID_DTYPE_Report)
        {
                Address = &HIDReport;
                Size    = sizeof(HIDReport);