USARTDescriptors.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2018.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2018 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. *
  28. * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
  29. * computer-readable structures which the host requests upon device enumeration, to determine
  30. * the device's capabilities and functions.
  31. */
  32. #include "USARTDescriptors.h"
  33. /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
  34. * device characteristics, including the supported USB version, control endpoint size and the
  35. * number of device configurations. The descriptor is read out by the USB host when the enumeration
  36. * process begins.
  37. */
  38. const USB_Descriptor_Device_t PROGMEM USART_DeviceDescriptor =
  39. {
  40. .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
  41. .USBSpecification = VERSION_BCD(1,1,0),
  42. .Class = CDC_CSCP_CDCClass,
  43. .SubClass = CDC_CSCP_NoSpecificSubclass,
  44. .Protocol = CDC_CSCP_NoSpecificProtocol,
  45. .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
  46. .VendorID = 0x03EB,
  47. .ProductID = 0x204B,
  48. .ReleaseNumber = VERSION_BCD(0,0,1),
  49. .ManufacturerStrIndex = USART_STRING_ID_Manufacturer,
  50. .ProductStrIndex = USART_STRING_ID_Product,
  51. .SerialNumStrIndex = USE_INTERNAL_SERIAL,
  52. .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
  53. };
  54. /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
  55. * of the device in one of its supported configurations, including information about any device interfaces
  56. * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
  57. * a configuration so that the host may correctly communicate with the USB device.
  58. */
  59. const USART_USB_Descriptor_Configuration_t PROGMEM USART_ConfigurationDescriptor =
  60. {
  61. .Config =
  62. {
  63. .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
  64. .TotalConfigurationSize = sizeof(USART_USB_Descriptor_Configuration_t),
  65. .TotalInterfaces = 2,
  66. .ConfigurationNumber = 1,
  67. .ConfigurationStrIndex = NO_DESCRIPTOR,
  68. .ConfigAttributes = USB_CONFIG_ATTR_RESERVED,
  69. .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
  70. },
  71. .CDC_CCI_Interface =
  72. {
  73. .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
  74. .InterfaceNumber = INTERFACE_ID_CDC_CCI,
  75. .AlternateSetting = 0,
  76. .TotalEndpoints = 1,
  77. .Class = CDC_CSCP_CDCClass,
  78. .SubClass = CDC_CSCP_ACMSubclass,
  79. .Protocol = CDC_CSCP_ATCommandProtocol,
  80. .InterfaceStrIndex = NO_DESCRIPTOR
  81. },
  82. .CDC_Functional_Header =
  83. {
  84. .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
  85. .Subtype = CDC_DSUBTYPE_CSInterface_Header,
  86. .CDCSpecification = VERSION_BCD(1,1,0),
  87. },
  88. .CDC_Functional_ACM =
  89. {
  90. .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
  91. .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
  92. .Capabilities = 0x06,
  93. },
  94. .CDC_Functional_Union =
  95. {
  96. .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
  97. .Subtype = CDC_DSUBTYPE_CSInterface_Union,
  98. .MasterInterfaceNumber = INTERFACE_ID_CDC_CCI,
  99. .SlaveInterfaceNumber = INTERFACE_ID_CDC_DCI,
  100. },
  101. .CDC_NotificationEndpoint =
  102. {
  103. .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
  104. .EndpointAddress = CDC_NOTIFICATION_EPADDR,
  105. .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  106. .EndpointSize = CDC_NOTIFICATION_EPSIZE,
  107. .PollingIntervalMS = 0xFF
  108. },
  109. .CDC_DCI_Interface =
  110. {
  111. .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
  112. .InterfaceNumber = INTERFACE_ID_CDC_DCI,
  113. .AlternateSetting = 0,
  114. .TotalEndpoints = 2,
  115. .Class = CDC_CSCP_CDCDataClass,
  116. .SubClass = CDC_CSCP_NoDataSubclass,
  117. .Protocol = CDC_CSCP_NoDataProtocol,
  118. .InterfaceStrIndex = NO_DESCRIPTOR
  119. },
  120. .CDC_DataOutEndpoint =
  121. {
  122. .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
  123. .EndpointAddress = CDC_RX_EPADDR,
  124. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  125. .EndpointSize = CDC_TXRX_EPSIZE,
  126. .PollingIntervalMS = 0x05
  127. },
  128. .CDC_DataInEndpoint =
  129. {
  130. .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
  131. .EndpointAddress = CDC_TX_EPADDR,
  132. .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  133. .EndpointSize = CDC_TXRX_EPSIZE,
  134. .PollingIntervalMS = 0x05
  135. }
  136. };
  137. /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
  138. * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
  139. * via the language ID table available at USB.org what languages the device supports for its string descriptors.
  140. */
  141. const USB_Descriptor_String_t PROGMEM USART_LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
  142. /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
  143. * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  144. * Descriptor.
  145. */
  146. const USB_Descriptor_String_t PROGMEM USART_ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera");
  147. /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
  148. * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  149. * Descriptor.
  150. */
  151. const USB_Descriptor_String_t PROGMEM USART_ProductString = USB_STRING_DESCRIPTOR(L"LUFA XPLAIN Bridge");
  152. /** Descriptor retrieval function for the USART Bridge descriptors. This function is in turn called by the GetDescriptor
  153. * callback function in the main source file, to retrieve the device's descriptors when in USART bridge mode.
  154. */
  155. uint16_t USART_GetDescriptor(const uint16_t wValue,
  156. const uint16_t wIndex,
  157. const void** const DescriptorAddress)
  158. {
  159. const uint8_t DescriptorType = (wValue >> 8);
  160. const uint8_t DescriptorNumber = (wValue & 0xFF);
  161. const void* Address = NULL;
  162. uint16_t Size = NO_DESCRIPTOR;
  163. switch (DescriptorType)
  164. {
  165. case DTYPE_Device:
  166. Address = &USART_DeviceDescriptor;
  167. Size = sizeof(USB_Descriptor_Device_t);
  168. break;
  169. case DTYPE_Configuration:
  170. Address = &USART_ConfigurationDescriptor;
  171. Size = sizeof(USART_USB_Descriptor_Configuration_t);
  172. break;
  173. case DTYPE_String:
  174. switch (DescriptorNumber)
  175. {
  176. case USART_STRING_ID_Language:
  177. Address = &USART_LanguageString;
  178. Size = pgm_read_byte(&USART_LanguageString.Header.Size);
  179. break;
  180. case USART_STRING_ID_Manufacturer:
  181. Address = &USART_ManufacturerString;
  182. Size = pgm_read_byte(&USART_ManufacturerString.Header.Size);
  183. break;
  184. case USART_STRING_ID_Product:
  185. Address = &USART_ProductString;
  186. Size = pgm_read_byte(&USART_ProductString.Header.Size);
  187. break;
  188. }
  189. break;
  190. }
  191. *DescriptorAddress = Address;
  192. return Size;
  193. }