My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

udi_cdc_desc.c 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. * \file
  3. *
  4. * \brief Default descriptors for a USB Device with a single interface CDC
  5. *
  6. * Copyright (c) 2009-2016 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifdef ARDUINO_ARCH_SAM
  47. #include "conf_usb.h"
  48. #include "udd.h"
  49. #include "udc_desc.h"
  50. #include "udi_cdc.h"
  51. #if DISABLED(SDSUPPORT)
  52. /**
  53. * \defgroup udi_cdc_group_single_desc USB device descriptors for a single interface
  54. *
  55. * The following structures provide the USB device descriptors required for
  56. * USB Device with a single interface CDC.
  57. *
  58. * It is ready to use and do not require more definition.
  59. *
  60. * @{
  61. */
  62. //! Two interfaces for a CDC device
  63. #define USB_DEVICE_NB_INTERFACE (2*UDI_CDC_PORT_NB)
  64. #ifdef USB_DEVICE_LPM_SUPPORT
  65. # define USB_VERSION USB_V2_1
  66. #else
  67. # define USB_VERSION USB_V2_0
  68. #endif
  69. //! USB Device Descriptor
  70. COMPILER_WORD_ALIGNED
  71. UDC_DESC_STORAGE usb_dev_desc_t udc_device_desc = {
  72. .bLength = sizeof(usb_dev_desc_t),
  73. .bDescriptorType = USB_DT_DEVICE,
  74. .bcdUSB = LE16(USB_VERSION),
  75. #if UDI_CDC_PORT_NB > 1
  76. .bDeviceClass = 0,
  77. #else
  78. .bDeviceClass = CDC_CLASS_DEVICE,
  79. #endif
  80. .bDeviceSubClass = 0,
  81. .bDeviceProtocol = 0,
  82. .bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
  83. .idVendor = LE16(USB_DEVICE_VENDOR_ID),
  84. .idProduct = LE16(USB_DEVICE_PRODUCT_ID),
  85. .bcdDevice = LE16((USB_DEVICE_MAJOR_VERSION << 8)
  86. | USB_DEVICE_MINOR_VERSION),
  87. #ifdef USB_DEVICE_MANUFACTURE_NAME
  88. .iManufacturer = 1,
  89. #else
  90. .iManufacturer = 0, // No manufacture string
  91. #endif
  92. #ifdef USB_DEVICE_PRODUCT_NAME
  93. .iProduct = 2,
  94. #else
  95. .iProduct = 0, // No product string
  96. #endif
  97. #if (defined USB_DEVICE_SERIAL_NAME || defined USB_DEVICE_GET_SERIAL_NAME_POINTER)
  98. .iSerialNumber = 3,
  99. #else
  100. .iSerialNumber = 0, // No serial string
  101. #endif
  102. .bNumConfigurations = 1
  103. };
  104. #ifdef USB_DEVICE_HS_SUPPORT
  105. //! USB Device Qualifier Descriptor for HS
  106. COMPILER_WORD_ALIGNED
  107. UDC_DESC_STORAGE usb_dev_qual_desc_t udc_device_qual = {
  108. .bLength = sizeof(usb_dev_qual_desc_t),
  109. .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  110. .bcdUSB = LE16(USB_VERSION),
  111. #if UDI_CDC_PORT_NB > 1
  112. .bDeviceClass = 0,
  113. #else
  114. .bDeviceClass = CDC_CLASS_DEVICE,
  115. #endif
  116. .bDeviceSubClass = 0,
  117. .bDeviceProtocol = 0,
  118. .bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
  119. .bNumConfigurations = 1
  120. };
  121. #endif
  122. #ifdef USB_DEVICE_LPM_SUPPORT
  123. //! USB Device Qualifier Descriptor
  124. COMPILER_WORD_ALIGNED
  125. UDC_DESC_STORAGE usb_dev_lpm_desc_t udc_device_lpm = {
  126. .bos.bLength = sizeof(usb_dev_bos_desc_t),
  127. .bos.bDescriptorType = USB_DT_BOS,
  128. .bos.wTotalLength = LE16(sizeof(usb_dev_bos_desc_t) + sizeof(usb_dev_capa_ext_desc_t)),
  129. .bos.bNumDeviceCaps = 1,
  130. .capa_ext.bLength = sizeof(usb_dev_capa_ext_desc_t),
  131. .capa_ext.bDescriptorType = USB_DT_DEVICE_CAPABILITY,
  132. .capa_ext.bDevCapabilityType = USB_DC_USB20_EXTENSION,
  133. .capa_ext.bmAttributes = USB_DC_EXT_LPM,
  134. };
  135. #endif
  136. //! Structure for USB Device Configuration Descriptor
  137. COMPILER_PACK_SET(1)
  138. typedef struct {
  139. usb_conf_desc_t conf;
  140. #if UDI_CDC_PORT_NB == 1
  141. udi_cdc_comm_desc_t udi_cdc_comm_0;
  142. udi_cdc_data_desc_t udi_cdc_data_0;
  143. #else
  144. # define UDI_CDC_DESC_STRUCTURE(index, unused) \
  145. usb_iad_desc_t udi_cdc_iad_##index; \
  146. udi_cdc_comm_desc_t udi_cdc_comm_##index; \
  147. udi_cdc_data_desc_t udi_cdc_data_##index;
  148. MREPEAT(UDI_CDC_PORT_NB, UDI_CDC_DESC_STRUCTURE, ~)
  149. # undef UDI_CDC_DESC_STRUCTURE
  150. #endif
  151. } udc_desc_t;
  152. COMPILER_PACK_RESET()
  153. //! USB Device Configuration Descriptor filled for full and high speed
  154. COMPILER_WORD_ALIGNED
  155. UDC_DESC_STORAGE udc_desc_t udc_desc_fs = {
  156. .conf.bLength = sizeof(usb_conf_desc_t),
  157. .conf.bDescriptorType = USB_DT_CONFIGURATION,
  158. .conf.wTotalLength = LE16(sizeof(udc_desc_t)),
  159. .conf.bNumInterfaces = USB_DEVICE_NB_INTERFACE,
  160. .conf.bConfigurationValue = 1,
  161. .conf.iConfiguration = 0,
  162. .conf.bmAttributes = USB_CONFIG_ATTR_MUST_SET | USB_DEVICE_ATTR,
  163. .conf.bMaxPower = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
  164. #if UDI_CDC_PORT_NB == 1
  165. .udi_cdc_comm_0 = UDI_CDC_COMM_DESC_0,
  166. .udi_cdc_data_0 = UDI_CDC_DATA_DESC_0_FS,
  167. #else
  168. # define UDI_CDC_DESC_FS(index, unused) \
  169. .udi_cdc_iad_##index = UDI_CDC_IAD_DESC_##index,\
  170. .udi_cdc_comm_##index = UDI_CDC_COMM_DESC_##index,\
  171. .udi_cdc_data_##index = UDI_CDC_DATA_DESC_##index##_FS,
  172. MREPEAT(UDI_CDC_PORT_NB, UDI_CDC_DESC_FS, ~)
  173. # undef UDI_CDC_DESC_FS
  174. #endif
  175. };
  176. #ifdef USB_DEVICE_HS_SUPPORT
  177. COMPILER_WORD_ALIGNED
  178. UDC_DESC_STORAGE udc_desc_t udc_desc_hs = {
  179. .conf.bLength = sizeof(usb_conf_desc_t),
  180. .conf.bDescriptorType = USB_DT_CONFIGURATION,
  181. .conf.wTotalLength = LE16(sizeof(udc_desc_t)),
  182. .conf.bNumInterfaces = USB_DEVICE_NB_INTERFACE,
  183. .conf.bConfigurationValue = 1,
  184. .conf.iConfiguration = 0,
  185. .conf.bmAttributes = USB_CONFIG_ATTR_MUST_SET | USB_DEVICE_ATTR,
  186. .conf.bMaxPower = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
  187. #if UDI_CDC_PORT_NB == 1
  188. .udi_cdc_comm_0 = UDI_CDC_COMM_DESC_0,
  189. .udi_cdc_data_0 = UDI_CDC_DATA_DESC_0_HS,
  190. #else
  191. # define UDI_CDC_DESC_HS(index, unused) \
  192. .udi_cdc_iad_##index = UDI_CDC_IAD_DESC_##index, \
  193. .udi_cdc_comm_##index = UDI_CDC_COMM_DESC_##index, \
  194. .udi_cdc_data_##index = UDI_CDC_DATA_DESC_##index##_HS,
  195. MREPEAT(UDI_CDC_PORT_NB, UDI_CDC_DESC_HS, ~)
  196. # undef UDI_CDC_DESC_HS
  197. #endif
  198. };
  199. #endif
  200. /**
  201. * \name UDC structures which content all USB Device definitions
  202. */
  203. //@{
  204. //! Associate an UDI for each USB interface
  205. UDC_DESC_STORAGE udi_api_t *udi_apis[USB_DEVICE_NB_INTERFACE] = {
  206. # define UDI_CDC_API(index, unused) \
  207. &udi_api_cdc_comm, \
  208. &udi_api_cdc_data,
  209. MREPEAT(UDI_CDC_PORT_NB, UDI_CDC_API, ~)
  210. # undef UDI_CDC_API
  211. };
  212. //! Add UDI with USB Descriptors FS & HS
  213. UDC_DESC_STORAGE udc_config_speed_t udc_config_fs[1] = { {
  214. .desc = (usb_conf_desc_t UDC_DESC_STORAGE*)&udc_desc_fs,
  215. .udi_apis = udi_apis,
  216. }};
  217. #ifdef USB_DEVICE_HS_SUPPORT
  218. UDC_DESC_STORAGE udc_config_speed_t udc_config_hs[1] = { {
  219. .desc = (usb_conf_desc_t UDC_DESC_STORAGE*)&udc_desc_hs,
  220. .udi_apis = udi_apis,
  221. }};
  222. #endif
  223. //! Add all information about USB Device in global structure for UDC
  224. UDC_DESC_STORAGE udc_config_t udc_config = {
  225. .confdev_lsfs = &udc_device_desc,
  226. .conf_lsfs = udc_config_fs,
  227. #ifdef USB_DEVICE_HS_SUPPORT
  228. .confdev_hs = &udc_device_desc,
  229. .qualifier = &udc_device_qual,
  230. .conf_hs = udc_config_hs,
  231. #endif
  232. #ifdef USB_DEVICE_LPM_SUPPORT
  233. .conf_bos = &udc_device_lpm.bos,
  234. #else
  235. .conf_bos = NULL,
  236. #endif
  237. };
  238. //@}
  239. //@}
  240. #endif // SDSUPPORT
  241. #endif // ARDUINO_ARCH_SAM