descriptor_test.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /**************************************************************************/
  2. /*!
  3. @file descriptor_test.c
  4. @author hathach (tinyusb.org)
  5. @section LICENSE
  6. Software License Agreement (BSD License)
  7. Copyright (c) 2013, hathach (tinyusb.org)
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holders nor the
  17. names of its contributors may be used to endorse or promote products
  18. derived from this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
  20. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  23. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
  26. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. This file is part of the tinyusb stack.
  30. */
  31. /**************************************************************************/
  32. #include "tusb_option.h"
  33. #include "descriptor_test.h"
  34. TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
  35. const uint8_t keyboard_report_descriptor[] = {
  36. HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
  37. HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
  38. HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
  39. HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
  40. HID_USAGE_MIN ( 224 ),
  41. HID_USAGE_MAX ( 231 ),
  42. HID_LOGICAL_MIN ( 0 ),
  43. HID_LOGICAL_MAX ( 1 ),
  44. HID_REPORT_COUNT ( 8 ), /* 8 bits */
  45. HID_REPORT_SIZE ( 1 ),
  46. HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* maskable modifier key */
  47. HID_REPORT_COUNT ( 1 ),
  48. HID_REPORT_SIZE ( 8 ),
  49. HID_INPUT ( HID_CONSTANT ), /* reserved */
  50. HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
  51. HID_USAGE_MIN ( 1 ),
  52. HID_USAGE_MAX ( 5 ),
  53. HID_REPORT_COUNT ( 5 ),
  54. HID_REPORT_SIZE ( 1 ),
  55. HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* 5-bit Led report */
  56. HID_REPORT_COUNT ( 1 ),
  57. HID_REPORT_SIZE ( 3 ), /* led padding */
  58. HID_OUTPUT ( HID_CONSTANT ),
  59. HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
  60. HID_USAGE_MIN ( 0 ),
  61. HID_USAGE_MAX ( 101 ),
  62. HID_LOGICAL_MIN ( 0 ),
  63. HID_LOGICAL_MAX ( 101 ),
  64. HID_REPORT_COUNT ( 6 ),
  65. HID_REPORT_SIZE ( 8 ),
  66. HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ), /* keycodes array 6 items */
  67. HID_COLLECTION_END
  68. };
  69. TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
  70. const uint8_t mouse_report_descriptor[] = {
  71. HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
  72. HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
  73. HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
  74. HID_USAGE (HID_USAGE_DESKTOP_POINTER),
  75. HID_COLLECTION ( HID_COLLECTION_PHYSICAL ),
  76. HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ),
  77. HID_USAGE_MIN ( 1 ),
  78. HID_USAGE_MAX ( 3 ),
  79. HID_LOGICAL_MIN ( 0 ),
  80. HID_LOGICAL_MAX ( 1 ),
  81. HID_REPORT_COUNT ( 3 ), /* Left, Right and Middle mouse*/
  82. HID_REPORT_SIZE ( 1 ),
  83. HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
  84. HID_REPORT_COUNT ( 1 ),
  85. HID_REPORT_SIZE ( 5 ),
  86. HID_INPUT ( HID_CONSTANT ), /* reserved */
  87. HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
  88. HID_USAGE ( HID_USAGE_DESKTOP_X ),
  89. HID_USAGE ( HID_USAGE_DESKTOP_Y ),
  90. HID_LOGICAL_MIN ( 0x81 ), /* -127 */
  91. HID_LOGICAL_MAX ( 0x7f ), /* 127 */
  92. HID_REPORT_COUNT ( 2 ), /* X, Y position */
  93. HID_REPORT_SIZE ( 8 ),
  94. HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
  95. HID_COLLECTION_END,
  96. HID_COLLECTION_END
  97. };
  98. TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
  99. tusb_descriptor_device_t const desc_device =
  100. {
  101. .bLength = sizeof(tusb_descriptor_device_t),
  102. .bDescriptorType = TUSB_DESC_TYPE_DEVICE,
  103. .bcdUSB = 0x0200,
  104. .bDeviceClass = 0x00,
  105. .bDeviceSubClass = 0x00,
  106. .bDeviceProtocol = 0x00,
  107. .bMaxPacketSize0 = 64,
  108. .idVendor = 0x1FC9,
  109. .idProduct = 0x4000,
  110. .bcdDevice = 0x0100,
  111. .iManufacturer = 0x01,
  112. .iProduct = 0x02,
  113. .iSerialNumber = 0x03,
  114. .bNumConfigurations = 0x02
  115. } ;
  116. TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
  117. const app_configuration_desc_t desc_configuration =
  118. {
  119. .configuration =
  120. {
  121. .bLength = sizeof(tusb_descriptor_configuration_t),
  122. .bDescriptorType = TUSB_DESC_TYPE_CONFIGURATION,
  123. .wTotalLength = sizeof(app_configuration_desc_t) - 1, // exclude termination
  124. .bNumInterfaces = 5,
  125. .bConfigurationValue = 1,
  126. .iConfiguration = 0x00,
  127. .bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
  128. .bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
  129. },
  130. //------------- HID Keyboard -------------//
  131. .keyboard_interface =
  132. {
  133. .bLength = sizeof(tusb_descriptor_interface_t),
  134. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  135. .bInterfaceNumber = 1,
  136. .bAlternateSetting = 0x00,
  137. .bNumEndpoints = 1,
  138. .bInterfaceClass = TUSB_CLASS_HID,
  139. .bInterfaceSubClass = HID_SUBCLASS_BOOT,
  140. .bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
  141. .iInterface = 0x00
  142. },
  143. .keyboard_hid =
  144. {
  145. .bLength = sizeof(tusb_hid_descriptor_hid_t),
  146. .bDescriptorType = HID_DESC_TYPE_HID,
  147. .bcdHID = 0x0111,
  148. .bCountryCode = HID_Local_NotSupported,
  149. .bNumDescriptors = 1,
  150. .bReportType = HID_DESC_TYPE_REPORT,
  151. .wReportLength = sizeof(keyboard_report_descriptor)
  152. },
  153. .keyboard_endpoint =
  154. {
  155. .bLength = sizeof(tusb_descriptor_endpoint_t),
  156. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  157. .bEndpointAddress = 0x81,
  158. .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
  159. .wMaxPacketSize = 0x08,
  160. .bInterval = 0x0A
  161. },
  162. //------------- HID Mouse -------------//
  163. .mouse_interface =
  164. {
  165. .bLength = sizeof(tusb_descriptor_interface_t),
  166. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  167. .bInterfaceNumber = 2,
  168. .bAlternateSetting = 0x00,
  169. .bNumEndpoints = 1,
  170. .bInterfaceClass = TUSB_CLASS_HID,
  171. .bInterfaceSubClass = HID_SUBCLASS_BOOT,
  172. .bInterfaceProtocol = HID_PROTOCOL_MOUSE,
  173. .iInterface = 0x00
  174. },
  175. .mouse_hid =
  176. {
  177. .bLength = sizeof(tusb_hid_descriptor_hid_t),
  178. .bDescriptorType = HID_DESC_TYPE_HID,
  179. .bcdHID = 0x0111,
  180. .bCountryCode = HID_Local_NotSupported,
  181. .bNumDescriptors = 1,
  182. .bReportType = HID_DESC_TYPE_REPORT,
  183. .wReportLength = sizeof(mouse_report_descriptor)
  184. },
  185. .mouse_endpoint =
  186. {
  187. .bLength = sizeof(tusb_descriptor_endpoint_t),
  188. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  189. .bEndpointAddress = 0x82,
  190. .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
  191. .wMaxPacketSize = 0x08,
  192. .bInterval = 0x0A
  193. },
  194. //------------- Mass Storage -------------//
  195. .msc_interface =
  196. {
  197. .bLength = sizeof(tusb_descriptor_interface_t),
  198. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  199. .bInterfaceNumber = 3,
  200. .bAlternateSetting = 0x00,
  201. .bNumEndpoints = 2,
  202. .bInterfaceClass = TUSB_CLASS_MSC,
  203. .bInterfaceSubClass = MSC_SUBCLASS_SCSI,
  204. .bInterfaceProtocol = MSC_PROTOCOL_BOT,
  205. .iInterface = 0x00
  206. },
  207. .msc_endpoint_in =
  208. {
  209. .bLength = sizeof(tusb_descriptor_endpoint_t),
  210. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  211. .bEndpointAddress = 0x83,
  212. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  213. .wMaxPacketSize = 512,
  214. .bInterval = 1
  215. },
  216. .msc_endpoint_out =
  217. {
  218. .bLength = sizeof(tusb_descriptor_endpoint_t),
  219. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  220. .bEndpointAddress = 0x03,
  221. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  222. .wMaxPacketSize = 512,
  223. .bInterval = 1
  224. },
  225. //------------- CDC Serial -------------//
  226. .cdc_comm_interface =
  227. {
  228. .bLength = sizeof(tusb_descriptor_interface_t),
  229. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  230. .bInterfaceNumber = 4,
  231. .bAlternateSetting = 0,
  232. .bNumEndpoints = 1,
  233. .bInterfaceClass = TUSB_CLASS_CDC,
  234. .bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
  235. .bInterfaceProtocol = CDC_COMM_PROTOCOL_ATCOMMAND,
  236. .iInterface = 0x00
  237. },
  238. .cdc_header =
  239. {
  240. .bLength = sizeof(cdc_desc_func_header_t),
  241. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
  242. .bDescriptorSubType = CDC_FUNC_DESC_HEADER,
  243. .bcdCDC = 0x0120
  244. },
  245. .cdc_acm =
  246. {
  247. .bLength = sizeof(cdc_desc_func_abstract_control_management_t),
  248. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
  249. .bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT,
  250. .bmCapabilities = { // 0x06
  251. .support_line_request = 1,
  252. .support_send_break = 1
  253. }
  254. },
  255. .cdc_union =
  256. {
  257. .bLength = sizeof(cdc_desc_func_union_t), // plus number of
  258. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
  259. .bDescriptorSubType = CDC_FUNC_DESC_UNION,
  260. .bControlInterface = 1,
  261. .bSubordinateInterface = 2,
  262. },
  263. .cdc_endpoint_notification =
  264. {
  265. .bLength = sizeof(tusb_descriptor_endpoint_t),
  266. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  267. .bEndpointAddress = 0x84,
  268. .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
  269. .wMaxPacketSize = 8,
  270. .bInterval = 0x0a // lowest polling rate
  271. },
  272. //------------- CDC Data Interface -------------//
  273. .cdc_data_interface =
  274. {
  275. .bLength = sizeof(tusb_descriptor_interface_t),
  276. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  277. .bInterfaceNumber = 5,
  278. .bAlternateSetting = 0x00,
  279. .bNumEndpoints = 2,
  280. .bInterfaceClass = TUSB_CLASS_CDC_DATA,
  281. .bInterfaceSubClass = 0,
  282. .bInterfaceProtocol = 0,
  283. .iInterface = 0x00
  284. },
  285. .cdc_endpoint_out =
  286. {
  287. .bLength = sizeof(tusb_descriptor_endpoint_t),
  288. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  289. .bEndpointAddress = 5,
  290. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  291. .wMaxPacketSize = 64,
  292. .bInterval = 0
  293. },
  294. .cdc_endpoint_in =
  295. {
  296. .bLength = sizeof(tusb_descriptor_endpoint_t),
  297. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  298. .bEndpointAddress = 0x85,
  299. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  300. .wMaxPacketSize = 64,
  301. .bInterval = 0
  302. },
  303. // TODO CDC & RNDIS
  304. .ConfigDescTermination = 0,
  305. };