Kiibohd Controller
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

usb_desc.c 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 PJRC.COM, LLC.
  4. * Modified by Jacob Alexander (2013-2014)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * 1. The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * 2. If the Software is incorporated into a build system that allows
  18. * selection among a list of target devices, then similar target
  19. * devices manufactured by PJRC.COM must be included in the list of
  20. * target devices and selectable in the same manner.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  26. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  28. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. * SOFTWARE.
  30. */
  31. // ----- Includes -----
  32. // Local Includes
  33. #include "usb_desc.h"
  34. // ----- Macros -----
  35. #define LSB(n) ((n) & 255)
  36. #define MSB(n) (((n) >> 8) & 255)
  37. // ----- USB Device Descriptor -----
  38. // USB Device Descriptor. The USB host reads this first, to learn
  39. // what type of device is connected.
  40. static uint8_t device_descriptor[] = {
  41. 18, // bLength
  42. 1, // bDescriptorType
  43. 0x00, 0x02, // bcdUSB
  44. DEVICE_CLASS, // bDeviceClass
  45. DEVICE_SUBCLASS, // bDeviceSubClass
  46. DEVICE_PROTOCOL, // bDeviceProtocol
  47. EP0_SIZE, // bMaxPacketSize0
  48. LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
  49. LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
  50. 0x00, 0x01, // bcdDevice
  51. 1, // iManufacturer
  52. 2, // iProduct
  53. 3, // iSerialNumber
  54. 1 // bNumConfigurations
  55. };
  56. // USB Device Qualifier Descriptor
  57. static uint8_t device_qualifier_descriptor[] = {
  58. 0 // Indicate only single speed
  59. /* Device qualifier example (used for specifying multiple USB speeds)
  60. 10, // bLength
  61. 6, // bDescriptorType
  62. 0x00, 0x02, // bcdUSB
  63. DEVICE_CLASS, // bDeviceClass
  64. DEVICE_SUBCLASS, // bDeviceSubClass
  65. DEVICE_PROTOCOL, // bDeviceProtocol
  66. EP0_SIZE, // bMaxPacketSize0
  67. 0, // bNumOtherSpeedConfigurations
  68. 0 // bReserved
  69. */
  70. };
  71. // USB Debug Descriptor
  72. // XXX Not sure of exact use, lsusb requests it
  73. static uint8_t usb_debug_descriptor[] = {
  74. 0
  75. };
  76. // XXX
  77. // These descriptors must NOT be "const", because the USB DMA
  78. // has trouble accessing flash memory with enough bandwidth
  79. // while the processor is executing from flash.
  80. // XXX
  81. // ----- USB HID Report Descriptsors -----
  82. // Each HID interface needs a special report descriptor that tells
  83. // the meaning and format of the data.
  84. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  85. static uint8_t keyboard_report_desc[] = {
  86. // Keyboard Collection
  87. 0x05, 0x01, // Usage Page (Generic Desktop),
  88. 0x09, 0x06, // Usage (Keyboard),
  89. 0xA1, 0x01, // Collection (Application) - Keyboard,
  90. // Modifier Byte
  91. 0x75, 0x01, // Report Size (1),
  92. 0x95, 0x08, // Report Count (8),
  93. 0x05, 0x07, // Usage Page (Key Codes),
  94. 0x19, 0xE0, // Usage Minimum (224),
  95. 0x29, 0xE7, // Usage Maximum (231),
  96. 0x15, 0x00, // Logical Minimum (0),
  97. 0x25, 0x01, // Logical Maximum (1),
  98. 0x81, 0x02, // Input (Data, Variable, Absolute),
  99. // Reserved Byte
  100. 0x75, 0x08, // Report Size (8),
  101. 0x95, 0x01, // Report Count (1),
  102. 0x81, 0x03, // Output (Constant),
  103. // LED Report
  104. 0x75, 0x01, // Report Size (1),
  105. 0x95, 0x05, // Report Count (5),
  106. 0x05, 0x08, // Usage Page (LEDs),
  107. 0x19, 0x01, // Usage Minimum (1),
  108. 0x29, 0x05, // Usage Maximum (5),
  109. 0x91, 0x02, // Output (Data, Variable, Absolute),
  110. // LED Report Padding
  111. 0x75, 0x03, // Report Size (3),
  112. 0x95, 0x01, // Report Count (1),
  113. 0x91, 0x03, // Output (Constant),
  114. // Normal Keys
  115. 0x75, 0x08, // Report Size (8),
  116. 0x95, 0x06, // Report Count (6),
  117. 0x15, 0x00, // Logical Minimum (0),
  118. 0x25, 0x7F, // Logical Maximum(104),
  119. 0x05, 0x07, // Usage Page (Key Codes),
  120. 0x19, 0x00, // Usage Minimum (0),
  121. 0x29, 0x7F, // Usage Maximum (104),
  122. 0x81, 0x00, // Input (Data, Array),
  123. 0xc0, // End Collection - Keyboard
  124. };
  125. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  126. static uint8_t nkro_keyboard_report_desc[] = {
  127. // Keyboard Collection
  128. 0x05, 0x01, // Usage Page (Generic Desktop),
  129. 0x09, 0x06, // Usage (Keyboard),
  130. 0xA1, 0x01, // Collection (Application) - Keyboard,
  131. // LED Report
  132. 0x85, 0x01, // Report ID (1),
  133. 0x75, 0x01, // Report Size (1),
  134. 0x95, 0x05, // Report Count (5),
  135. 0x05, 0x08, // Usage Page (LEDs),
  136. 0x19, 0x01, // Usage Minimum (1),
  137. 0x29, 0x05, // Usage Maximum (5),
  138. 0x91, 0x02, // Output (Data, Variable, Absolute),
  139. // LED Report Padding
  140. 0x75, 0x03, // Report Size (3),
  141. 0x95, 0x01, // Report Count (1),
  142. 0x91, 0x03, // Output (Constant),
  143. // Normal Keys - Using an NKRO Bitmap
  144. //
  145. // NOTES:
  146. // Supports all keys defined by the spec, except 1-3 which define error events
  147. // and 0 which is "no keys pressed"
  148. // See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf Chapter 10
  149. // Or Macros/PartialMap/usb_hid.h
  150. //
  151. // 50 (ISO \ due to \ bug) and 156 (Clear due to Delete bug) must be excluded
  152. // due to a Linux bug with bitmaps (not useful anyways)
  153. // 165-175 are reserved/unused as well as 222-223 and 232-65535
  154. //
  155. // Compatibility Notes:
  156. // - Using a second endpoint for a boot mode device helps with compatibility
  157. // - DO NOT use Padding in the descriptor for bitfields
  158. // (Mac OSX silently fails... Windows/Linux work correctly)
  159. // - DO NOT use Report IDs, Windows 8.1 will not update keyboard correctly (modifiers disappear)
  160. // (all other OSs, including OSX work fine...)
  161. // (you can use them *iff* you only have 1 per collection)
  162. // - Mac OSX and Windows 8.1 are extremely picky about padding
  163. //
  164. // Packing of bitmaps are as follows:
  165. // 4-49 : 6 bytes (0x04-0x31) ( 46 bits + 2 padding bits for 6 bytes total)
  166. // 51-155 : 14 bytes (0x33-0x9B) (105 bits + 6 padding bits for 15 bytes total)
  167. // 157-164 : 1 byte (0x9D-0xA4) ( 8 bits)
  168. // 176-221 : 6 bytes (0xB0-0xDD) ( 46 bits + 2 padding bits for 6 bytes total)
  169. // 224-231 : 1 byte (0xE0-0xE7) ( 8 bits)
  170. // Modifier Byte
  171. 0x75, 0x01, // Report Size (1),
  172. 0x95, 0x08, // Report Count (8),
  173. 0x15, 0x00, // Logical Minimum (0),
  174. 0x25, 0x01, // Logical Maximum (1),
  175. 0x05, 0x07, // Usage Page (Key Codes),
  176. 0x19, 0xE0, // Usage Minimum (224),
  177. 0x29, 0xE7, // Usage Maximum (231),
  178. 0x81, 0x02, // Input (Data, Variable, Absolute),
  179. // 4-49 (6 bytes/46 bits) - MainKeys
  180. 0x75, 0x01, // Report Size (1),
  181. 0x95, 0x2E, // Report Count (46),
  182. 0x15, 0x00, // Logical Minimum (0),
  183. 0x25, 0x01, // Logical Maximum (1),
  184. 0x05, 0x07, // Usage Page (Key Codes),
  185. 0x19, 0x04, // Usage Minimum (4),
  186. 0x29, 0x31, // Usage Maximum (49),
  187. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  188. // Padding (2 bits)
  189. 0x75, 0x02, // Report Size (2),
  190. 0x95, 0x01, // Report Count (1),
  191. 0x81, 0x03, // Input (Constant),
  192. // 51-155 (14 bytes/105 bits) - SecondaryKeys
  193. 0x75, 0x01, // Report Size (1),
  194. 0x95, 0x69, // Report Count (105),
  195. 0x15, 0x00, // Logical Minimum (0),
  196. 0x25, 0x01, // Logical Maximum (1),
  197. 0x05, 0x07, // Usage Page (Key Codes),
  198. 0x19, 0x33, // Usage Minimum (51),
  199. 0x29, 0x9B, // Usage Maximum (155),
  200. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  201. // Padding (7 bits)
  202. 0x75, 0x07, // Report Size (7),
  203. 0x95, 0x01, // Report Count (1),
  204. 0x81, 0x03, // Input (Constant),
  205. // 157-164 (1 byte/8 bits) - TertiaryKeys
  206. 0x75, 0x01, // Report Size (1),
  207. 0x95, 0x08, // Report Count (8),
  208. 0x15, 0x00, // Logical Minimum (0),
  209. 0x25, 0x01, // Logical Maximum (1),
  210. 0x05, 0x07, // Usage Page (Key Codes),
  211. 0x19, 0x9D, // Usage Minimum (157),
  212. 0x29, 0xA4, // Usage Maximum (164),
  213. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  214. // 176-221 (6 bytes/46 bits) - QuartiaryKeys
  215. 0x75, 0x01, // Report Size (1),
  216. 0x95, 0x2E, // Report Count (46),
  217. 0x15, 0x00, // Logical Minimum (0),
  218. 0x25, 0x01, // Logical Maximum (1),
  219. 0x05, 0x07, // Usage Page (Key Codes),
  220. 0x19, 0xB0, // Usage Minimum (176),
  221. 0x29, 0xDD, // Usage Maximum (221),
  222. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  223. // Padding (2 bits)
  224. 0x75, 0x02, // Report Size (2),
  225. 0x95, 0x01, // Report Count (1),
  226. 0x81, 0x03, // Input (Constant),
  227. 0xc0, // End Collection - Keyboard
  228. // System Control Collection
  229. //
  230. // NOTES:
  231. // Not bothering with NKRO for this table. If there's need, I can implement it. -HaaTa
  232. // Using a 1KRO scheme
  233. 0x05, 0x01, // Usage Page (Generic Desktop),
  234. 0x09, 0x80, // Usage (System Control),
  235. 0xA1, 0x01, // Collection (Application),
  236. 0x85, 0x02, // Report ID (2),
  237. 0x75, 0x08, // Report Size (8),
  238. 0x95, 0x01, // Report Count (1),
  239. 0x16, 0x81, 0x00, // Logical Minimum (129),
  240. 0x26, 0xB7, 0x00, // Logical Maximum (183),
  241. 0x19, 0x81, // Usage Minimum (129),
  242. 0x29, 0xB7, // Usage Maximum (183),
  243. 0x81, 0x00, // Input (Data, Array),
  244. 0xc0, // End Collection - System Control
  245. // Consumer Control Collection - Media Keys
  246. //
  247. // NOTES:
  248. // Not bothering with NKRO for this table. If there's a need, I can implement it. -HaaTa
  249. // Using a 1KRO scheme
  250. 0x05, 0x0c, // Usage Page (Consumer),
  251. 0x09, 0x01, // Usage (Consumer Control),
  252. 0xA1, 0x01, // Collection (Application),
  253. 0x85, 0x03, // Report ID (3),
  254. 0x75, 0x10, // Report Size (16),
  255. 0x95, 0x01, // Report Count (1),
  256. 0x16, 0x20, 0x00, // Logical Minimum (32),
  257. 0x26, 0x9C, 0x02, // Logical Maximum (668),
  258. 0x05, 0x0C, // Usage Page (Consumer),
  259. 0x19, 0x20, // Usage Minimum (32),
  260. 0x2A, 0x9C, 0x02, // Usage Maximum (668),
  261. 0x81, 0x00, // Input (Data, Array),
  262. 0xc0, // End Collection - Consumer Control
  263. };
  264. /* MOUSE
  265. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  266. static uint8_t mouse_report_desc[] = {
  267. 0x05, 0x01, // Usage Page (Generic Desktop)
  268. 0x09, 0x02, // Usage (Mouse)
  269. 0xA1, 0x01, // Collection (Application)
  270. 0x05, 0x09, // Usage Page (Button)
  271. 0x19, 0x01, // Usage Minimum (Button #1)
  272. 0x29, 0x03, // Usage Maximum (Button #3)
  273. 0x15, 0x00, // Logical Minimum (0)
  274. 0x25, 0x01, // Logical Maximum (1)
  275. 0x95, 0x03, // Report Count (3)
  276. 0x75, 0x01, // Report Size (1)
  277. 0x81, 0x02, // Input (Data, Variable, Absolute)
  278. 0x95, 0x01, // Report Count (1)
  279. 0x75, 0x05, // Report Size (5)
  280. 0x81, 0x03, // Input (Constant)
  281. 0x05, 0x01, // Usage Page (Generic Desktop)
  282. 0x09, 0x30, // Usage (X)
  283. 0x09, 0x31, // Usage (Y)
  284. 0x15, 0x00, // Logical Minimum (0)
  285. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  286. 0x75, 0x10, // Report Size (16),
  287. 0x95, 0x02, // Report Count (2),
  288. 0x81, 0x02, // Input (Data, Variable, Absolute)
  289. 0x09, 0x38, // Usage (Wheel)
  290. 0x15, 0x81, // Logical Minimum (-127)
  291. 0x25, 0x7F, // Logical Maximum (127)
  292. 0x75, 0x08, // Report Size (8),
  293. 0x95, 0x01, // Report Count (1),
  294. 0x81, 0x06, // Input (Data, Variable, Relative)
  295. 0xC0 // End Collection
  296. };
  297. */
  298. // ----- USB Configuration -----
  299. // USB Configuration Descriptor. This huge descriptor tells all
  300. // of the devices capbilities.
  301. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  302. // --- Configuration ---
  303. // - 9 bytes -
  304. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  305. 9, // bLength;
  306. 2, // bDescriptorType;
  307. LSB(CONFIG_DESC_SIZE), // wTotalLength
  308. MSB(CONFIG_DESC_SIZE),
  309. NUM_INTERFACE, // bNumInterfaces
  310. 1, // bConfigurationValue
  311. 0, // iConfiguration
  312. 0xA0, // bmAttributes
  313. 250, // bMaxPower
  314. // --- Keyboard HID --- Boot Mode Keyboard Interface
  315. // - 9 bytes -
  316. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  317. 9, // bLength
  318. 4, // bDescriptorType
  319. KEYBOARD_INTERFACE, // bInterfaceNumber
  320. 0, // bAlternateSetting
  321. 1, // bNumEndpoints
  322. 0x03, // bInterfaceClass (0x03 = HID)
  323. 0x01, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  324. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  325. 0, // iInterface
  326. // - 9 bytes -
  327. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  328. 9, // bLength
  329. 0x21, // bDescriptorType
  330. 0x11, 0x01, // bcdHID
  331. 0, // bCountryCode
  332. 1, // bNumDescriptors
  333. 0x22, // bDescriptorType
  334. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  335. MSB(sizeof(keyboard_report_desc)),
  336. // - 7 bytes -
  337. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  338. 7, // bLength
  339. 5, // bDescriptorType
  340. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  341. 0x03, // bmAttributes (0x03=intr)
  342. KEYBOARD_SIZE, 0, // wMaxPacketSize
  343. KEYBOARD_INTERVAL, // bInterval
  344. // --- NKRO Keyboard HID --- OS Mode Keyboard Interface
  345. // - 9 bytes -
  346. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  347. 9, // bLength
  348. 4, // bDescriptorType
  349. NKRO_KEYBOARD_INTERFACE, // bInterfaceNumber
  350. 0, // bAlternateSetting
  351. 1, // bNumEndpoints
  352. 0x03, // bInterfaceClass (0x03 = HID)
  353. 0x00, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  354. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  355. 0, // iInterface
  356. // - 9 bytes -
  357. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  358. 9, // bLength
  359. 0x21, // bDescriptorType
  360. 0x11, 0x01, // bcdHID
  361. 0, // bCountryCode
  362. 1, // bNumDescriptors
  363. 0x22, // bDescriptorType
  364. LSB(sizeof(nkro_keyboard_report_desc)), // wDescriptorLength
  365. MSB(sizeof(nkro_keyboard_report_desc)),
  366. // - 7 bytes -
  367. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  368. 7, // bLength
  369. 5, // bDescriptorType
  370. NKRO_KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  371. 0x03, // bmAttributes (0x03=intr)
  372. NKRO_KEYBOARD_SIZE, 0, // wMaxPacketSize
  373. NKRO_KEYBOARD_INTERVAL, // bInterval
  374. // --- Serial CDC --- CDC IAD Descriptor
  375. // - 8 bytes -
  376. // interface association descriptor, USB ECN, Table 9-Z
  377. 8, // bLength
  378. 11, // bDescriptorType
  379. CDC_STATUS_INTERFACE, // bFirstInterface
  380. 2, // bInterfaceCount
  381. 0x02, // bFunctionClass
  382. 0x02, // bFunctionSubClass
  383. 0x01, // bFunctionProtocol
  384. 0, // iFunction
  385. // --- Serial CDC --- CDC Data Interface
  386. // - 9 bytes -
  387. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  388. 9, // bLength
  389. 4, // bDescriptorType
  390. CDC_STATUS_INTERFACE, // bInterfaceNumber
  391. 0, // bAlternateSetting
  392. 1, // bNumEndpoints
  393. 0x02, // bInterfaceClass
  394. 0x02, // bInterfaceSubClass
  395. 0x01, // bInterfaceProtocol
  396. 0, // iInterface
  397. // - 5 bytes -
  398. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  399. 5, // bFunctionLength
  400. 0x24, // bDescriptorType
  401. 0x00, // bDescriptorSubtype
  402. 0x10, 0x01, // bcdCDC
  403. // - 5 bytes -
  404. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  405. 5, // bFunctionLength
  406. 0x24, // bDescriptorType
  407. 0x01, // bDescriptorSubtype
  408. 0x01, // bmCapabilities
  409. CDC_DATA_INTERFACE, // bDataInterface
  410. // - 4 bytes -
  411. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  412. 4, // bFunctionLength
  413. 0x24, // bDescriptorType
  414. 0x02, // bDescriptorSubtype
  415. 0x06, // bmCapabilities
  416. // - 5 bytes -
  417. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  418. 5, // bFunctionLength
  419. 0x24, // bDescriptorType
  420. 0x06, // bDescriptorSubtype
  421. CDC_STATUS_INTERFACE, // bMasterInterface
  422. CDC_DATA_INTERFACE, // bSlaveInterface0
  423. // - 7 bytes -
  424. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  425. 7, // bLength
  426. 5, // bDescriptorType
  427. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  428. 0x03, // bmAttributes (0x03=intr)
  429. CDC_ACM_SIZE, 0, // wMaxPacketSize
  430. 64, // bInterval
  431. // - 9 bytes -
  432. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  433. 9, // bLength
  434. 4, // bDescriptorType
  435. CDC_DATA_INTERFACE, // bInterfaceNumber
  436. 0, // bAlternateSetting
  437. 2, // bNumEndpoints
  438. 0x0A, // bInterfaceClass
  439. 0x00, // bInterfaceSubClass
  440. 0x00, // bInterfaceProtocol
  441. 0, // iInterface
  442. // - 7 bytes -
  443. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  444. 7, // bLength
  445. 5, // bDescriptorType
  446. CDC_RX_ENDPOINT, // bEndpointAddress
  447. 0x02, // bmAttributes (0x02=bulk)
  448. CDC_RX_SIZE, 0, // wMaxPacketSize
  449. 0, // bInterval
  450. // - 7 bytes -
  451. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  452. 7, // bLength
  453. 5, // bDescriptorType
  454. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  455. 0x02, // bmAttributes (0x02=bulk)
  456. CDC_TX_SIZE, 0, // wMaxPacketSize
  457. 0, // bInterval
  458. /*
  459. // Mouse Interface
  460. // - 9 bytes -
  461. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  462. 9, // bLength
  463. 4, // bDescriptorType
  464. MOUSE_INTERFACE, // bInterfaceNumber
  465. 0, // bAlternateSetting
  466. 1, // bNumEndpoints
  467. 0x03, // bInterfaceClass (0x03 = HID)
  468. 0x00, // bInterfaceSubClass (0x01 = Boot)
  469. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  470. 0, // iInterface
  471. // - 9 bytes -
  472. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  473. 9, // bLength
  474. 0x21, // bDescriptorType
  475. 0x11, 0x01, // bcdHID
  476. 0, // bCountryCode
  477. 1, // bNumDescriptors
  478. 0x22, // bDescriptorType
  479. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  480. MSB(sizeof(mouse_report_desc)),
  481. // - 7 bytes -
  482. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  483. 7, // bLength
  484. 5, // bDescriptorType
  485. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  486. 0x03, // bmAttributes (0x03=intr)
  487. MOUSE_SIZE, 0, // wMaxPacketSize
  488. MOUSE_INTERVAL, // bInterval
  489. #endif // MOUSE_INTERFACE
  490. */
  491. };
  492. // ----- String Descriptors -----
  493. // The descriptors above can provide human readable strings,
  494. // referenced by index numbers. These descriptors are the
  495. // actual string data
  496. struct usb_string_descriptor_struct {
  497. uint8_t bLength;
  498. uint8_t bDescriptorType;
  499. uint16_t wString[];
  500. };
  501. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  502. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  503. extern struct usb_string_descriptor_struct usb_string_product_name
  504. __attribute__ ((weak, alias("usb_string_product_name_default")));
  505. extern struct usb_string_descriptor_struct usb_string_serial_number
  506. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  507. struct usb_string_descriptor_struct string0 = {
  508. 4,
  509. 3,
  510. {0x0409}
  511. };
  512. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  513. sizeof(STR_MANUFACTURER),
  514. 3,
  515. {STR_MANUFACTURER}
  516. };
  517. struct usb_string_descriptor_struct usb_string_product_name_default = {
  518. sizeof(STR_PRODUCT),
  519. 3,
  520. {STR_PRODUCT}
  521. };
  522. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  523. sizeof(STR_SERIAL),
  524. 3,
  525. {STR_SERIAL}
  526. };
  527. // ----- Descriptors List -----
  528. // This table provides access to all the descriptor data above.
  529. const usb_descriptor_list_t usb_descriptor_list[] = {
  530. //wValue, wIndex, address, length
  531. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  532. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  533. {0x0600, 0x0000, device_qualifier_descriptor, sizeof(device_qualifier_descriptor)},
  534. {0x0A00, 0x0000, usb_debug_descriptor, sizeof(usb_debug_descriptor)},
  535. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  536. {0x2100, KEYBOARD_INTERFACE, config_descriptor + KEYBOARD_DESC_OFFSET, 9},
  537. {0x2200, NKRO_KEYBOARD_INTERFACE, nkro_keyboard_report_desc, sizeof(nkro_keyboard_report_desc)},
  538. {0x2100, NKRO_KEYBOARD_INTERFACE, config_descriptor + NKRO_KEYBOARD_DESC_OFFSET, 9},
  539. /* MOUSE
  540. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  541. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
  542. */
  543. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  544. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  545. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  546. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  547. {0, 0, NULL, 0}
  548. };
  549. // ----- Endpoint Configuration -----
  550. // See usb_desc.h for Endpoint configuration
  551. // 0x00 = not used
  552. // 0x19 = Recieve only
  553. // 0x15 = Transmit only
  554. // 0x1D = Transmit & Recieve
  555. //
  556. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  557. {
  558. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  559. ENDPOINT1_CONFIG,
  560. #elif (NUM_ENDPOINTS >= 1)
  561. ENDPOINT_UNUSED,
  562. #endif
  563. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  564. ENDPOINT2_CONFIG,
  565. #elif (NUM_ENDPOINTS >= 2)
  566. ENDPOINT_UNUSED,
  567. #endif
  568. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  569. ENDPOINT3_CONFIG,
  570. #elif (NUM_ENDPOINTS >= 3)
  571. ENDPOINT_UNUSED,
  572. #endif
  573. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  574. ENDPOINT4_CONFIG,
  575. #elif (NUM_ENDPOINTS >= 4)
  576. ENDPOINT_UNUSED,
  577. #endif
  578. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  579. ENDPOINT5_CONFIG,
  580. #elif (NUM_ENDPOINTS >= 5)
  581. ENDPOINT_UNUSED,
  582. #endif
  583. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  584. ENDPOINT6_CONFIG,
  585. #elif (NUM_ENDPOINTS >= 6)
  586. ENDPOINT_UNUSED,
  587. #endif
  588. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  589. ENDPOINT7_CONFIG,
  590. #elif (NUM_ENDPOINTS >= 7)
  591. ENDPOINT_UNUSED,
  592. #endif
  593. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  594. ENDPOINT8_CONFIG,
  595. #elif (NUM_ENDPOINTS >= 8)
  596. ENDPOINT_UNUSED,
  597. #endif
  598. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  599. ENDPOINT9_CONFIG,
  600. #elif (NUM_ENDPOINTS >= 9)
  601. ENDPOINT_UNUSED,
  602. #endif
  603. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  604. ENDPOINT10_CONFIG,
  605. #elif (NUM_ENDPOINTS >= 10)
  606. ENDPOINT_UNUSED,
  607. #endif
  608. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  609. ENDPOINT11_CONFIG,
  610. #elif (NUM_ENDPOINTS >= 11)
  611. ENDPOINT_UNUSED,
  612. #endif
  613. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  614. ENDPOINT12_CONFIG,
  615. #elif (NUM_ENDPOINTS >= 12)
  616. ENDPOINT_UNUSED,
  617. #endif
  618. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  619. ENDPOINT13_CONFIG,
  620. #elif (NUM_ENDPOINTS >= 13)
  621. ENDPOINT_UNUSED,
  622. #endif
  623. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  624. ENDPOINT14_CONFIG,
  625. #elif (NUM_ENDPOINTS >= 14)
  626. ENDPOINT_UNUSED,
  627. #endif
  628. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  629. ENDPOINT15_CONFIG,
  630. #elif (NUM_ENDPOINTS >= 15)
  631. ENDPOINT_UNUSED,
  632. #endif
  633. };