descriptor_test.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2019 Ha Thach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * This file is part of the TinyUSB stack.
  25. */
  26. #include "tusb_option.h"
  27. #include "descriptor_test.h"
  28. CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4)
  29. const uint8_t keyboard_report_descriptor[] = {
  30. HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
  31. HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
  32. HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
  33. HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
  34. HID_USAGE_MIN ( 224 ),
  35. HID_USAGE_MAX ( 231 ),
  36. HID_LOGICAL_MIN ( 0 ),
  37. HID_LOGICAL_MAX ( 1 ),
  38. HID_REPORT_COUNT ( 8 ), /* 8 bits */
  39. HID_REPORT_SIZE ( 1 ),
  40. HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* maskable modifier key */
  41. HID_REPORT_COUNT ( 1 ),
  42. HID_REPORT_SIZE ( 8 ),
  43. HID_INPUT ( HID_CONSTANT ), /* reserved */
  44. HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
  45. HID_USAGE_MIN ( 1 ),
  46. HID_USAGE_MAX ( 5 ),
  47. HID_REPORT_COUNT ( 5 ),
  48. HID_REPORT_SIZE ( 1 ),
  49. HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* 5-bit Led report */
  50. HID_REPORT_COUNT ( 1 ),
  51. HID_REPORT_SIZE ( 3 ), /* led padding */
  52. HID_OUTPUT ( HID_CONSTANT ),
  53. HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
  54. HID_USAGE_MIN ( 0 ),
  55. HID_USAGE_MAX ( 101 ),
  56. HID_LOGICAL_MIN ( 0 ),
  57. HID_LOGICAL_MAX ( 101 ),
  58. HID_REPORT_COUNT ( 6 ),
  59. HID_REPORT_SIZE ( 8 ),
  60. HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ), /* keycodes array 6 items */
  61. HID_COLLECTION_END
  62. };
  63. CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4)
  64. const uint8_t mouse_report_descriptor[] = {
  65. HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
  66. HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
  67. HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
  68. HID_USAGE (HID_USAGE_DESKTOP_POINTER),
  69. HID_COLLECTION ( HID_COLLECTION_PHYSICAL ),
  70. HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ),
  71. HID_USAGE_MIN ( 1 ),
  72. HID_USAGE_MAX ( 3 ),
  73. HID_LOGICAL_MIN ( 0 ),
  74. HID_LOGICAL_MAX ( 1 ),
  75. HID_REPORT_COUNT ( 3 ), /* Left, Right and Middle mouse*/
  76. HID_REPORT_SIZE ( 1 ),
  77. HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
  78. HID_REPORT_COUNT ( 1 ),
  79. HID_REPORT_SIZE ( 5 ),
  80. HID_INPUT ( HID_CONSTANT ), /* reserved */
  81. HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
  82. HID_USAGE ( HID_USAGE_DESKTOP_X ),
  83. HID_USAGE ( HID_USAGE_DESKTOP_Y ),
  84. HID_LOGICAL_MIN ( 0x81 ), /* -127 */
  85. HID_LOGICAL_MAX ( 0x7f ), /* 127 */
  86. HID_REPORT_COUNT ( 2 ), /* X, Y position */
  87. HID_REPORT_SIZE ( 8 ),
  88. HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
  89. HID_COLLECTION_END,
  90. HID_COLLECTION_END
  91. };
  92. CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4)
  93. tusb_desc_device_t const desc_device =
  94. {
  95. .bLength = sizeof(tusb_desc_device_t),
  96. .bDescriptorType = TUSB_DESC_TYPE_DEVICE,
  97. .bcdUSB = 0x0200,
  98. .bDeviceClass = 0x00,
  99. .bDeviceSubClass = 0x00,
  100. .bDeviceProtocol = 0x00,
  101. .bMaxPacketSize0 = 64,
  102. .idVendor = 0x1FC9,
  103. .idProduct = 0x4000,
  104. .bcdDevice = 0x0100,
  105. .iManufacturer = 0x01,
  106. .iProduct = 0x02,
  107. .iSerialNumber = 0x03,
  108. .bNumConfigurations = 0x02
  109. } ;
  110. CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4)
  111. const app_configuration_desc_t desc_configuration =
  112. {
  113. .configuration =
  114. {
  115. .bLength = sizeof(tusb_desc_configuration_t),
  116. .bDescriptorType = TUSB_DESC_TYPE_CONFIGURATION,
  117. .wTotalLength = sizeof(app_configuration_desc_t) - 1, // exclude termination
  118. .bNumInterfaces = 5,
  119. .bConfigurationValue = 1,
  120. .iConfiguration = 0x00,
  121. .bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
  122. .bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
  123. },
  124. //------------- HID Keyboard -------------//
  125. .keyboard_interface =
  126. {
  127. .bLength = sizeof(tusb_desc_interface_t),
  128. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  129. .bInterfaceNumber = 1,
  130. .bAlternateSetting = 0x00,
  131. .bNumEndpoints = 1,
  132. .bInterfaceClass = TUSB_CLASS_HID,
  133. .bInterfaceSubClass = HID_SUBCLASS_BOOT,
  134. .bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
  135. .iInterface = 0x00
  136. },
  137. .keyboard_hid =
  138. {
  139. .bLength = sizeof(tusb_hid_descriptor_hid_t),
  140. .bDescriptorType = HID_DESC_TYPE_HID,
  141. .bcdHID = 0x0111,
  142. .bCountryCode = HID_LOCAL_NotSupported,
  143. .bNumDescriptors = 1,
  144. .bReportType = HID_DESC_TYPE_REPORT,
  145. .wReportLength = sizeof(keyboard_report_descriptor)
  146. },
  147. .keyboard_endpoint =
  148. {
  149. .bLength = sizeof(tusb_desc_endpoint_t),
  150. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  151. .bEndpointAddress = 0x81,
  152. .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
  153. .wMaxPacketSize = 0x08,
  154. .bInterval = 0x0A
  155. },
  156. //------------- HID Mouse -------------//
  157. .mouse_interface =
  158. {
  159. .bLength = sizeof(tusb_desc_interface_t),
  160. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  161. .bInterfaceNumber = 2,
  162. .bAlternateSetting = 0x00,
  163. .bNumEndpoints = 1,
  164. .bInterfaceClass = TUSB_CLASS_HID,
  165. .bInterfaceSubClass = HID_SUBCLASS_BOOT,
  166. .bInterfaceProtocol = HID_PROTOCOL_MOUSE,
  167. .iInterface = 0x00
  168. },
  169. .mouse_hid =
  170. {
  171. .bLength = sizeof(tusb_hid_descriptor_hid_t),
  172. .bDescriptorType = HID_DESC_TYPE_HID,
  173. .bcdHID = 0x0111,
  174. .bCountryCode = HID_LOCAL_NotSupported,
  175. .bNumDescriptors = 1,
  176. .bReportType = HID_DESC_TYPE_REPORT,
  177. .wReportLength = sizeof(mouse_report_descriptor)
  178. },
  179. .mouse_endpoint =
  180. {
  181. .bLength = sizeof(tusb_desc_endpoint_t),
  182. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  183. .bEndpointAddress = 0x82,
  184. .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
  185. .wMaxPacketSize = 0x08,
  186. .bInterval = 0x0A
  187. },
  188. //------------- Mass Storage -------------//
  189. .msc_interface =
  190. {
  191. .bLength = sizeof(tusb_desc_interface_t),
  192. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  193. .bInterfaceNumber = 3,
  194. .bAlternateSetting = 0x00,
  195. .bNumEndpoints = 2,
  196. .bInterfaceClass = TUSB_CLASS_MSC,
  197. .bInterfaceSubClass = MSC_SUBCLASS_SCSI,
  198. .bInterfaceProtocol = MSC_PROTOCOL_BOT,
  199. .iInterface = 0x00
  200. },
  201. .msc_endpoint_in =
  202. {
  203. .bLength = sizeof(tusb_desc_endpoint_t),
  204. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  205. .bEndpointAddress = 0x83,
  206. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  207. .wMaxPacketSize = 512,
  208. .bInterval = 1
  209. },
  210. .msc_endpoint_out =
  211. {
  212. .bLength = sizeof(tusb_desc_endpoint_t),
  213. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  214. .bEndpointAddress = 0x03,
  215. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  216. .wMaxPacketSize = 512,
  217. .bInterval = 1
  218. },
  219. //------------- CDC Serial -------------//
  220. .cdc_comm_interface =
  221. {
  222. .bLength = sizeof(tusb_desc_interface_t),
  223. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  224. .bInterfaceNumber = 4,
  225. .bAlternateSetting = 0,
  226. .bNumEndpoints = 1,
  227. .bInterfaceClass = TUSB_CLASS_CDC,
  228. .bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
  229. .bInterfaceProtocol = CDC_COMM_PROTOCOL_ATCOMMAND,
  230. .iInterface = 0x00
  231. },
  232. .cdc_header =
  233. {
  234. .bLength = sizeof(cdc_desc_func_header_t),
  235. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
  236. .bDescriptorSubType = CDC_FUNC_DESC_HEADER,
  237. .bcdCDC = 0x0120
  238. },
  239. .cdc_acm =
  240. {
  241. .bLength = sizeof(cdc_desc_func_acm_t),
  242. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
  243. .bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT,
  244. .bmCapabilities = { // 0x06
  245. .support_line_request = 1,
  246. .support_send_break = 1
  247. }
  248. },
  249. .cdc_union =
  250. {
  251. .bLength = sizeof(cdc_desc_func_union_t), // plus number of
  252. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
  253. .bDescriptorSubType = CDC_FUNC_DESC_UNION,
  254. .bControlInterface = 1,
  255. .bSubordinateInterface = 2,
  256. },
  257. .cdc_endpoint_notification =
  258. {
  259. .bLength = sizeof(tusb_desc_endpoint_t),
  260. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  261. .bEndpointAddress = 0x84,
  262. .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
  263. .wMaxPacketSize = 8,
  264. .bInterval = 0x0a // lowest polling rate
  265. },
  266. //------------- CDC Data Interface -------------//
  267. .cdc_data_interface =
  268. {
  269. .bLength = sizeof(tusb_desc_interface_t),
  270. .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
  271. .bInterfaceNumber = 5,
  272. .bAlternateSetting = 0x00,
  273. .bNumEndpoints = 2,
  274. .bInterfaceClass = TUSB_CLASS_CDC_DATA,
  275. .bInterfaceSubClass = 0,
  276. .bInterfaceProtocol = 0,
  277. .iInterface = 0x00
  278. },
  279. .cdc_endpoint_out =
  280. {
  281. .bLength = sizeof(tusb_desc_endpoint_t),
  282. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  283. .bEndpointAddress = 5,
  284. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  285. .wMaxPacketSize = 64,
  286. .bInterval = 0
  287. },
  288. .cdc_endpoint_in =
  289. {
  290. .bLength = sizeof(tusb_desc_endpoint_t),
  291. .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
  292. .bEndpointAddress = 0x85,
  293. .bmAttributes = { .xfer = TUSB_XFER_BULK },
  294. .wMaxPacketSize = 64,
  295. .bInterval = 0
  296. },
  297. // TODO CDC & RNDIS
  298. .ConfigDescTermination = 0,
  299. };