Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Descriptors.c 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Copyright 2010 Peter Lawrence (majbthrd [at] gmail [dot] com)
  10. Permission to use, copy, modify, distribute, and sell this
  11. software and its documentation for any purpose is hereby granted
  12. without fee, provided that the above copyright notice appear in
  13. all copies and that both that the copyright notice and this
  14. permission notice and warranty disclaimer appear in supporting
  15. documentation, and that the name of the author not be used in
  16. advertising or publicity pertaining to distribution of the
  17. software without specific, written prior permission.
  18. The author disclaims all warranties with regard to this
  19. software, including all implied warranties of merchantability
  20. and fitness. In no event shall the author be liable for any
  21. special, indirect or consequential damages or any damages
  22. whatsoever resulting from loss of use, data or profits, whether
  23. in an action of contract, negligence or other tortious action,
  24. arising out of or in connection with the use or performance of
  25. this software.
  26. */
  27. /** \file
  28. *
  29. * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
  30. * computer-readable structures which the host requests upon device enumeration, to determine
  31. * the device's capabilities and functions.
  32. */
  33. #include "Descriptors.h"
  34. /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
  35. * device characteristics, including the supported USB version, control endpoint size and the
  36. * number of device configurations. The descriptor is read out by the USB host when the enumeration
  37. * process begins.
  38. */
  39. const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
  40. {
  41. .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
  42. .USBSpecification = VERSION_BCD(1,1,0),
  43. .Class = 0x00,
  44. .SubClass = 0x00,
  45. .Protocol = 0x00,
  46. .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
  47. .VendorID = 0x03EB,
  48. .ProductID = 0x2065,
  49. .ReleaseNumber = VERSION_BCD(0,0,1),
  50. .ManufacturerStrIndex = STRING_ID_Manufacturer,
  51. .ProductStrIndex = STRING_ID_Product,
  52. .SerialNumStrIndex = USE_INTERNAL_SERIAL,
  53. .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
  54. };
  55. /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
  56. * of the device in one of its supported configurations, including information about any device interfaces
  57. * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
  58. * a configuration so that the host may correctly communicate with the USB device.
  59. */
  60. const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
  61. {
  62. .Config =
  63. {
  64. .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
  65. .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
  66. .TotalInterfaces = 1,
  67. .ConfigurationNumber = 1,
  68. .ConfigurationStrIndex = NO_DESCRIPTOR,
  69. .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
  70. .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
  71. },
  72. .TM_Interface =
  73. {
  74. .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
  75. .InterfaceNumber = INTERFACE_ID_TestAndMeasurement,
  76. .AlternateSetting = 0x00,
  77. .TotalEndpoints = 3,
  78. .Class = 0xFE,
  79. .SubClass = 0x03,
  80. .Protocol = 0x01,
  81. .InterfaceStrIndex = NO_DESCRIPTOR
  82. },
  83. .TM_DataOutEndpoint =
  84. {
  85. .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
  86. .EndpointAddress = TMC_OUT_EPADDR,
  87. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  88. .EndpointSize = TMC_IO_EPSIZE,
  89. .PollingIntervalMS = 0x05
  90. },
  91. .TM_DataInEndpoint =
  92. {
  93. .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
  94. .EndpointAddress = TMC_IN_EPADDR,
  95. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  96. .EndpointSize = TMC_IO_EPSIZE,
  97. .PollingIntervalMS = 0x05
  98. },
  99. .TM_NotificationEndpoint =
  100. {
  101. .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
  102. .EndpointAddress = TMC_NOTIFICATION_EPADDR,
  103. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  104. .EndpointSize = TMC_NOTIFICATION_EPSIZE,
  105. .PollingIntervalMS = 0xFF
  106. }
  107. };
  108. /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
  109. * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
  110. * via the language ID table available at USB.org what languages the device supports for its string descriptors.
  111. */
  112. const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
  113. /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
  114. * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  115. * Descriptor.
  116. */
  117. const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera");
  118. /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
  119. * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  120. * Descriptor.
  121. */
  122. const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA TMC Demo");
  123. /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
  124. * documentation) by the application code so that the address and size of a requested descriptor can be given
  125. * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
  126. * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
  127. * USB host.
  128. */
  129. uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
  130. const uint8_t wIndex,
  131. const void** const DescriptorAddress)
  132. {
  133. const uint8_t DescriptorType = (wValue >> 8);
  134. const uint8_t DescriptorNumber = (wValue & 0xFF);
  135. const void* Address = NULL;
  136. uint16_t Size = NO_DESCRIPTOR;
  137. switch (DescriptorType)
  138. {
  139. case DTYPE_Device:
  140. Address = &DeviceDescriptor;
  141. Size = sizeof(USB_Descriptor_Device_t);
  142. break;
  143. case DTYPE_Configuration:
  144. Address = &ConfigurationDescriptor;
  145. Size = sizeof(USB_Descriptor_Configuration_t);
  146. break;
  147. case DTYPE_String:
  148. switch (DescriptorNumber)
  149. {
  150. case STRING_ID_Language:
  151. Address = &LanguageString;
  152. Size = pgm_read_byte(&LanguageString.Header.Size);
  153. break;
  154. case STRING_ID_Manufacturer:
  155. Address = &ManufacturerString;
  156. Size = pgm_read_byte(&ManufacturerString.Header.Size);
  157. break;
  158. case STRING_ID_Product:
  159. Address = &ProductString;
  160. Size = pgm_read_byte(&ProductString.Header.Size);
  161. break;
  162. }
  163. break;
  164. }
  165. *DescriptorAddress = Address;
  166. return Size;
  167. }