Added new EVENT_CDC_Device_BreakSent() event and CDC_Host_SendBreak() function to...
[pub/USBasp.git] / Bootloaders / TeensyHID / Descriptors.c
index 791269c..52d6c73 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
          \r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
  */\r
 USB_Descriptor_HIDReport_Datatype_t HIDReport[] =\r
 {\r
-       0x06, 0x9c, 0xff,     /* Usage Page (Vendor Defined)                     */\r
-       0x09, 0x1B,           /* Usage (Vendor Defined)                          */\r
-       0xa1, 0x01,           /* Collection (Vendor Defined)                     */\r
-       0x0a, 0x19, 0x00,     /*   Usage (Vendor Defined)                        */\r
-       0x75, 0x08,           /*   Report Size (8)                               */\r
-       0x95, 0x82,           /*   Report Count (130)                            */\r
-       0x15, 0x00,           /*   Logical Minimum (0)                           */\r
-       0x25, 0xff,           /*   Logical Maximum (255)                         */\r
-       0x91, 0x02,           /*   Output (Data, Variable, Absolute)             */\r
-       0xc0                  /* End Collection                                  */\r
+       0x06, 0x9c, 0xff,        /* Usage Page (Vendor Defined)                     */\r
+       0x09, TEENSY_USAGEPAGE,  /* Usage (Vendor Defined)                          */\r
+       0xa1, 0x01,              /* Collection (Vendor Defined)                     */\r
+       0x0a, 0x19, 0x00,        /*   Usage (Vendor Defined)                        */\r
+       0x75, 0x08,              /*   Report Size (8)                               */\r
+#if (SPM_PAGESIZE == 128)    /*   Report Count (SPM_PAGESIZE + 2)               */\r
+       0x95, (SPM_PAGESIZE + 2),\r
+#else\r
+       0x96, ((SPM_PAGESIZE + 2) & 0xFF), ((SPM_PAGESIZE + 2) >> 8),\r
+#endif\r
+       0x15, 0x00,              /*   Logical Minimum (0)                           */\r
+       0x25, 0xff,              /*   Logical Maximum (255)                         */\r
+       0x91, 0x02,              /*   Output (Data, Variable, Absolute)             */\r
+       0xc0                     /* End Collection                                  */\r
 };\r
 \r
 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall\r
@@ -106,7 +110,7 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor =
                        .MaxPowerConsumption    = USB_CONFIG_POWER_MA(100)\r
                },\r
                \r
-       .Interface = \r
+       .HID_Interface = \r
                {\r
                        .Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},\r
 \r
@@ -122,7 +126,7 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor =
                        .InterfaceStrIndex      = NO_DESCRIPTOR\r
                },\r
 \r
-       .HIDDescriptor = \r
+       .HID_VendorHID = \r
                {  \r
                        .Header                 = {.Size = sizeof(USB_Descriptor_HID_t), .Type = DTYPE_HID},\r
                        \r
@@ -133,7 +137,7 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor =
                        .HIDReportLength        = sizeof(HIDReport)\r
                },\r
                \r
-       .HIDEndpoint = \r
+       .HID_ReportINEndpoint = \r
                {\r
                        .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
 \r
@@ -152,31 +156,34 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor =
  */\r
 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)\r
 {\r
-       const uint8_t  DescriptorType   = (wValue >> 8);\r
+       const uint8_t DescriptorType = (wValue >> 8);\r
 \r
        void*    Address = NULL;\r
        uint16_t Size    = NO_DESCRIPTOR;\r
 \r
-       switch (DescriptorType)\r
+       /* If/Else If chain compiles slightly smaller than a switch case */\r
+\r
+       if (DescriptorType == DTYPE_Device)\r
+       {\r
+               Address = (void*)&DeviceDescriptor;\r
+               Size    = sizeof(USB_Descriptor_Device_t);      \r
+       }\r
+       else if (DescriptorType == DTYPE_Configuration)\r
+       {\r
+               Address = (void*)&ConfigurationDescriptor;\r
+               Size    = sizeof(USB_Descriptor_Configuration_t);       \r
+       }\r
+       else if (DescriptorType == DTYPE_HID)\r
+       {\r
+               Address = (void*)&ConfigurationDescriptor.HID_VendorHID;\r
+               Size    = sizeof(USB_Descriptor_HID_t);\r
+       }\r
+       else\r
        {\r
-               case DTYPE_Device:\r
-                       Address = (void*)&DeviceDescriptor;\r
-                       Size    = sizeof(USB_Descriptor_Device_t);\r
-                       break;\r
-               case DTYPE_Configuration:\r
-                       Address = (void*)&ConfigurationDescriptor;\r
-                       Size    = sizeof(USB_Descriptor_Configuration_t);\r
-                       break;\r
-               case DTYPE_HID:\r
-                       Address = (void*)&ConfigurationDescriptor.HIDDescriptor;\r
-                       Size    = sizeof(USB_Descriptor_HID_t);\r
-                       break;\r
-               case DTYPE_Report:\r
-                       Address = (void*)&HIDReport;\r
-                       Size    = sizeof(HIDReport);\r
-                       break;\r
+               Address = (void*)&HIDReport;\r
+               Size    = sizeof(HIDReport);\r
        }\r
-       \r
+\r
        *DescriptorAddress = Address;\r
        return Size;\r
 }\r