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 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 PJRC.COM, LLC.
  4. * Modified by Jacob Alexander (2013-2015)
  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. // Generated Includes
  35. #include <kll_defs.h>
  36. // ----- Macros -----
  37. #define LSB(n) ((n) & 255)
  38. #define MSB(n) (((n) >> 8) & 255)
  39. // ----- USB Device Descriptor -----
  40. // USB Device Descriptor. The USB host reads this first, to learn
  41. // what type of device is connected.
  42. static uint8_t device_descriptor[] = {
  43. 18, // bLength
  44. 1, // bDescriptorType
  45. 0x00, 0x02, // bcdUSB
  46. DEVICE_CLASS, // bDeviceClass
  47. DEVICE_SUBCLASS, // bDeviceSubClass
  48. DEVICE_PROTOCOL, // bDeviceProtocol
  49. EP0_SIZE, // bMaxPacketSize0
  50. LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
  51. LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
  52. 0x00, 0x01, // bcdDevice
  53. 1, // iManufacturer
  54. 2, // iProduct
  55. 3, // iSerialNumber
  56. 1 // bNumConfigurations
  57. };
  58. // USB Device Qualifier Descriptor
  59. static uint8_t device_qualifier_descriptor[] = {
  60. 0 // Indicate only single speed
  61. /* Device qualifier example (used for specifying multiple USB speeds)
  62. 10, // bLength
  63. 6, // bDescriptorType
  64. 0x00, 0x02, // bcdUSB
  65. DEVICE_CLASS, // bDeviceClass
  66. DEVICE_SUBCLASS, // bDeviceSubClass
  67. DEVICE_PROTOCOL, // bDeviceProtocol
  68. EP0_SIZE, // bMaxPacketSize0
  69. 0, // bNumOtherSpeedConfigurations
  70. 0 // bReserved
  71. */
  72. };
  73. // USB Debug Descriptor
  74. // XXX Not sure of exact use, lsusb requests it
  75. static uint8_t usb_debug_descriptor[] = {
  76. 0
  77. };
  78. // XXX
  79. // These descriptors must NOT be "const", because the USB DMA
  80. // has trouble accessing flash memory with enough bandwidth
  81. // while the processor is executing from flash.
  82. // XXX
  83. // ----- USB HID Report Descriptsors -----
  84. // Each HID interface needs a special report descriptor that tells
  85. // the meaning and format of the data.
  86. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  87. static uint8_t keyboard_report_desc[] = {
  88. // Keyboard Collection
  89. 0x05, 0x01, // Usage Page (Generic Desktop),
  90. 0x09, 0x06, // Usage (Keyboard),
  91. 0xA1, 0x01, // Collection (Application) - Keyboard,
  92. // Modifier Byte
  93. 0x75, 0x01, // Report Size (1),
  94. 0x95, 0x08, // Report Count (8),
  95. 0x05, 0x07, // Usage Page (Key Codes),
  96. 0x19, 0xE0, // Usage Minimum (224),
  97. 0x29, 0xE7, // Usage Maximum (231),
  98. 0x15, 0x00, // Logical Minimum (0),
  99. 0x25, 0x01, // Logical Maximum (1),
  100. 0x81, 0x02, // Input (Data, Variable, Absolute),
  101. // Reserved Byte
  102. 0x75, 0x08, // Report Size (8),
  103. 0x95, 0x01, // Report Count (1),
  104. 0x81, 0x03, // Output (Constant),
  105. // LED Report
  106. 0x75, 0x01, // Report Size (1),
  107. 0x95, 0x05, // Report Count (5),
  108. 0x05, 0x08, // Usage Page (LEDs),
  109. 0x19, 0x01, // Usage Minimum (1),
  110. 0x29, 0x05, // Usage Maximum (5),
  111. 0x91, 0x02, // Output (Data, Variable, Absolute),
  112. // LED Report Padding
  113. 0x75, 0x03, // Report Size (3),
  114. 0x95, 0x01, // Report Count (1),
  115. 0x91, 0x03, // Output (Constant),
  116. // Normal Keys
  117. 0x75, 0x08, // Report Size (8),
  118. 0x95, 0x06, // Report Count (6),
  119. 0x15, 0x00, // Logical Minimum (0),
  120. 0x25, 0x7F, // Logical Maximum(104),
  121. 0x05, 0x07, // Usage Page (Key Codes),
  122. 0x19, 0x00, // Usage Minimum (0),
  123. 0x29, 0x7F, // Usage Maximum (104),
  124. 0x81, 0x00, // Input (Data, Array),
  125. 0xc0, // End Collection - Keyboard
  126. };
  127. // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
  128. static uint8_t nkro_keyboard_report_desc[] = {
  129. // Keyboard Collection
  130. 0x05, 0x01, // Usage Page (Generic Desktop),
  131. 0x09, 0x06, // Usage (Keyboard),
  132. 0xA1, 0x01, // Collection (Application) - Keyboard,
  133. // LED Report
  134. 0x85, 0x01, // Report ID (1),
  135. 0x75, 0x01, // Report Size (1),
  136. 0x95, 0x05, // Report Count (5),
  137. 0x05, 0x08, // Usage Page (LEDs),
  138. 0x19, 0x01, // Usage Minimum (1),
  139. 0x29, 0x05, // Usage Maximum (5),
  140. 0x91, 0x02, // Output (Data, Variable, Absolute),
  141. // LED Report Padding
  142. 0x75, 0x03, // Report Size (3),
  143. 0x95, 0x01, // Report Count (1),
  144. 0x91, 0x03, // Output (Constant),
  145. // Normal Keys - Using an NKRO Bitmap
  146. //
  147. // NOTES:
  148. // Supports all keys defined by the spec, except 1-3 which define error events
  149. // and 0 which is "no keys pressed"
  150. // See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf Chapter 10
  151. // Or Macros/PartialMap/usb_hid.h
  152. //
  153. // 50 (ISO \ due to \ bug) and 156 (Clear due to Delete bug) must be excluded
  154. // due to a Linux bug with bitmaps (not useful anyways)
  155. // 165-175 are reserved/unused as well as 222-223 and 232-65535
  156. //
  157. // Compatibility Notes:
  158. // - Using a second endpoint for a boot mode device helps with compatibility
  159. // - DO NOT use Padding in the descriptor for bitfields
  160. // (Mac OSX silently fails... Windows/Linux work correctly)
  161. // - DO NOT use Report IDs, Windows 8.1 will not update keyboard correctly (modifiers disappear)
  162. // (all other OSs, including OSX work fine...)
  163. // (you can use them *iff* you only have 1 per collection)
  164. // - Mac OSX and Windows 8.1 are extremely picky about padding
  165. //
  166. // Packing of bitmaps are as follows:
  167. // 4-49 : 6 bytes (0x04-0x31) ( 46 bits + 2 padding bits for 6 bytes total)
  168. // 51-155 : 14 bytes (0x33-0x9B) (105 bits + 6 padding bits for 15 bytes total)
  169. // 157-164 : 1 byte (0x9D-0xA4) ( 8 bits)
  170. // 176-221 : 6 bytes (0xB0-0xDD) ( 46 bits + 2 padding bits for 6 bytes total)
  171. // 224-231 : 1 byte (0xE0-0xE7) ( 8 bits)
  172. // Modifier Byte
  173. 0x75, 0x01, // Report Size (1),
  174. 0x95, 0x08, // Report Count (8),
  175. 0x15, 0x00, // Logical Minimum (0),
  176. 0x25, 0x01, // Logical Maximum (1),
  177. 0x05, 0x07, // Usage Page (Key Codes),
  178. 0x19, 0xE0, // Usage Minimum (224),
  179. 0x29, 0xE7, // Usage Maximum (231),
  180. 0x81, 0x02, // Input (Data, Variable, Absolute),
  181. // 4-49 (6 bytes/46 bits) - MainKeys
  182. 0x75, 0x01, // Report Size (1),
  183. 0x95, 0x2E, // Report Count (46),
  184. 0x15, 0x00, // Logical Minimum (0),
  185. 0x25, 0x01, // Logical Maximum (1),
  186. 0x05, 0x07, // Usage Page (Key Codes),
  187. 0x19, 0x04, // Usage Minimum (4),
  188. 0x29, 0x31, // Usage Maximum (49),
  189. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  190. // Padding (2 bits)
  191. 0x75, 0x02, // Report Size (2),
  192. 0x95, 0x01, // Report Count (1),
  193. 0x81, 0x03, // Input (Constant),
  194. // 51-155 (14 bytes/105 bits) - SecondaryKeys
  195. 0x75, 0x01, // Report Size (1),
  196. 0x95, 0x69, // Report Count (105),
  197. 0x15, 0x00, // Logical Minimum (0),
  198. 0x25, 0x01, // Logical Maximum (1),
  199. 0x05, 0x07, // Usage Page (Key Codes),
  200. 0x19, 0x33, // Usage Minimum (51),
  201. 0x29, 0x9B, // Usage Maximum (155),
  202. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  203. // Padding (7 bits)
  204. 0x75, 0x07, // Report Size (7),
  205. 0x95, 0x01, // Report Count (1),
  206. 0x81, 0x03, // Input (Constant),
  207. // 157-164 (1 byte/8 bits) - TertiaryKeys
  208. 0x75, 0x01, // Report Size (1),
  209. 0x95, 0x08, // Report Count (8),
  210. 0x15, 0x00, // Logical Minimum (0),
  211. 0x25, 0x01, // Logical Maximum (1),
  212. 0x05, 0x07, // Usage Page (Key Codes),
  213. 0x19, 0x9D, // Usage Minimum (157),
  214. 0x29, 0xA4, // Usage Maximum (164),
  215. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  216. // 176-221 (6 bytes/46 bits) - QuartiaryKeys
  217. 0x75, 0x01, // Report Size (1),
  218. 0x95, 0x2E, // Report Count (46),
  219. 0x15, 0x00, // Logical Minimum (0),
  220. 0x25, 0x01, // Logical Maximum (1),
  221. 0x05, 0x07, // Usage Page (Key Codes),
  222. 0x19, 0xB0, // Usage Minimum (176),
  223. 0x29, 0xDD, // Usage Maximum (221),
  224. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  225. // Padding (2 bits)
  226. 0x75, 0x02, // Report Size (2),
  227. 0x95, 0x01, // Report Count (1),
  228. 0x81, 0x03, // Input (Constant),
  229. 0xc0, // End Collection - Keyboard
  230. };
  231. // System Control and Consumer Control
  232. static uint8_t sys_ctrl_report_desc[] = {
  233. // System Control Collection
  234. //
  235. // NOTES:
  236. // Not bothering with NKRO for this table. If there's need, I can implement it. -HaaTa
  237. // Using a 1KRO scheme
  238. 0x05, 0x01, // Usage Page (Generic Desktop),
  239. 0x09, 0x80, // Usage (System Control),
  240. 0xA1, 0x01, // Collection (Application),
  241. 0x85, 0x02, // Report ID (2),
  242. 0x75, 0x08, // Report Size (8),
  243. 0x95, 0x01, // Report Count (1),
  244. 0x16, 0x81, 0x00, // Logical Minimum (129),
  245. 0x26, 0xB7, 0x00, // Logical Maximum (183),
  246. 0x19, 0x81, // Usage Minimum (129),
  247. 0x29, 0xB7, // Usage Maximum (183),
  248. 0x81, 0x00, // Input (Data, Array),
  249. 0xc0, // End Collection - System Control
  250. // Consumer Control Collection - Media Keys
  251. //
  252. // NOTES:
  253. // Not bothering with NKRO for this table. If there's a need, I can implement it. -HaaTa
  254. // Using a 1KRO scheme
  255. 0x05, 0x0c, // Usage Page (Consumer),
  256. 0x09, 0x01, // Usage (Consumer Control),
  257. 0xA1, 0x01, // Collection (Application),
  258. 0x85, 0x03, // Report ID (3),
  259. 0x75, 0x10, // Report Size (16),
  260. 0x95, 0x01, // Report Count (1),
  261. 0x16, 0x01, 0x00, // Logical Minimum (1),
  262. 0x26, 0x9C, 0x02, // Logical Maximum (668),
  263. 0x05, 0x0C, // Usage Page (Consumer),
  264. 0x19, 0x01, // Usage Minimum (1),
  265. 0x2A, 0x9C, 0x02, // Usage Maximum (668),
  266. 0x81, 0x00, // Input (Data, Array),
  267. 0xc0, // End Collection - Consumer Control
  268. };
  269. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  270. static uint8_t mouse_report_desc[] = {
  271. 0x05, 0x01, // Usage Page (Generic Desktop)
  272. 0x09, 0x02, // Usage (Mouse)
  273. 0xA1, 0x01, // Collection (Application)
  274. 0x05, 0x09, // Usage Page (Button)
  275. 0x19, 0x01, // Usage Minimum (Button #1)
  276. 0x29, 0x03, // Usage Maximum (Button #3)
  277. 0x15, 0x00, // Logical Minimum (0)
  278. 0x25, 0x01, // Logical Maximum (1)
  279. 0x95, 0x03, // Report Count (3)
  280. 0x75, 0x01, // Report Size (1)
  281. 0x81, 0x02, // Input (Data, Variable, Absolute)
  282. 0x95, 0x01, // Report Count (1)
  283. 0x75, 0x05, // Report Size (5)
  284. 0x81, 0x03, // Input (Constant)
  285. 0x05, 0x01, // Usage Page (Generic Desktop)
  286. 0x09, 0x30, // Usage (X)
  287. 0x09, 0x31, // Usage (Y)
  288. 0x15, 0x00, // Logical Minimum (0)
  289. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  290. 0x75, 0x10, // Report Size (16),
  291. 0x95, 0x02, // Report Count (2),
  292. 0x81, 0x02, // Input (Data, Variable, Absolute)
  293. 0x09, 0x38, // Usage (Wheel)
  294. 0x15, 0x81, // Logical Minimum (-127)
  295. 0x25, 0x7F, // Logical Maximum (127)
  296. 0x75, 0x08, // Report Size (8),
  297. 0x95, 0x01, // Report Count (1),
  298. 0x81, 0x06, // Input (Data, Variable, Relative)
  299. 0xC0 // End Collection
  300. };
  301. // Joystick Protocol, HID 1.11 spec, Apendix D, page 64-65
  302. static uint8_t joystick_report_desc[] = {
  303. 0x05, 0x01, // Usage Page (Generic Desktop)
  304. 0x09, 0x04, // Usage (Joystick)
  305. 0xA1, 0x01, // Collection (Application)
  306. 0x15, 0x00, // Logical Minimum (0)
  307. 0x25, 0x01, // Logical Maximum (1)
  308. 0x75, 0x01, // Report Size (1)
  309. 0x95, 0x20, // Report Count (32)
  310. 0x05, 0x09, // Usage Page (Button)
  311. 0x19, 0x01, // Usage Minimum (Button #1)
  312. 0x29, 0x20, // Usage Maximum (Button #32)
  313. 0x81, 0x02, // Input (variable,absolute)
  314. 0x15, 0x00, // Logical Minimum (0)
  315. 0x25, 0x07, // Logical Maximum (7)
  316. 0x35, 0x00, // Physical Minimum (0)
  317. 0x46, 0x3B, 0x01, // Physical Maximum (315)
  318. 0x75, 0x04, // Report Size (4)
  319. 0x95, 0x01, // Report Count (1)
  320. 0x65, 0x14, // Unit (20)
  321. 0x05, 0x01, // Usage Page (Generic Desktop)
  322. 0x09, 0x39, // Usage (Hat switch)
  323. 0x81, 0x42, // Input (variable,absolute,null_state)
  324. 0x05, 0x01, // Usage Page (Generic Desktop)
  325. 0x09, 0x01, // Usage (Pointer)
  326. 0xA1, 0x00, // Collection ()
  327. 0x15, 0x00, // Logical Minimum (0)
  328. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  329. 0x75, 0x0A, // Report Size (10)
  330. 0x95, 0x04, // Report Count (4)
  331. 0x09, 0x30, // Usage (X)
  332. 0x09, 0x31, // Usage (Y)
  333. 0x09, 0x32, // Usage (Z)
  334. 0x09, 0x35, // Usage (Rz)
  335. 0x81, 0x02, // Input (variable,absolute)
  336. 0xC0, // End Collection
  337. 0x15, 0x00, // Logical Minimum (0)
  338. 0x26, 0xFF, 0x03, // Logical Maximum (1023)
  339. 0x75, 0x0A, // Report Size (10)
  340. 0x95, 0x02, // Report Count (2)
  341. 0x09, 0x36, // Usage (Slider)
  342. 0x09, 0x36, // Usage (Slider)
  343. 0x81, 0x02, // Input (variable,absolute)
  344. 0xC0 // End Collection
  345. };
  346. // ----- USB Configuration -----
  347. // USB Configuration Descriptor. This huge descriptor tells all
  348. // of the devices capbilities.
  349. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  350. // --- Configuration ---
  351. // - 9 bytes -
  352. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  353. 9, // bLength;
  354. 2, // bDescriptorType;
  355. LSB(CONFIG_DESC_SIZE), // wTotalLength
  356. MSB(CONFIG_DESC_SIZE),
  357. NUM_INTERFACE, // bNumInterfaces
  358. 1, // bConfigurationValue
  359. 0, // iConfiguration
  360. 0xA0, // bmAttributes
  361. 250, // bMaxPower
  362. // --- Keyboard HID --- Boot Mode Keyboard Interface
  363. // - 9 bytes -
  364. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  365. 9, // bLength
  366. 4, // bDescriptorType
  367. KEYBOARD_INTERFACE, // bInterfaceNumber
  368. 0, // bAlternateSetting
  369. 1, // bNumEndpoints
  370. 0x03, // bInterfaceClass (0x03 = HID)
  371. 0x01, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  372. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  373. KEYBOARD_INTERFACE + 4, // iInterface
  374. // - 9 bytes -
  375. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  376. 9, // bLength
  377. 0x21, // bDescriptorType
  378. 0x11, 0x01, // bcdHID
  379. KeyboardLocale_define, // bCountryCode
  380. 1, // bNumDescriptors
  381. 0x22, // bDescriptorType
  382. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  383. MSB(sizeof(keyboard_report_desc)),
  384. // - 7 bytes -
  385. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  386. 7, // bLength
  387. 5, // bDescriptorType
  388. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  389. 0x03, // bmAttributes (0x03=intr)
  390. KEYBOARD_SIZE, 0, // wMaxPacketSize
  391. KEYBOARD_INTERVAL, // bInterval
  392. // --- NKRO Keyboard HID --- OS Mode Keyboard Interface
  393. // - 9 bytes -
  394. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  395. 9, // bLength
  396. 4, // bDescriptorType
  397. NKRO_KEYBOARD_INTERFACE, // bInterfaceNumber
  398. 0, // bAlternateSetting
  399. 1, // bNumEndpoints
  400. 0x03, // bInterfaceClass (0x03 = HID)
  401. 0x00, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  402. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  403. NKRO_KEYBOARD_INTERFACE + 4, // iInterface
  404. // - 9 bytes -
  405. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  406. 9, // bLength
  407. 0x21, // bDescriptorType
  408. 0x11, 0x01, // bcdHID
  409. KeyboardLocale_define, // bCountryCode
  410. 1, // bNumDescriptors
  411. 0x22, // bDescriptorType
  412. LSB(sizeof(nkro_keyboard_report_desc)), // wDescriptorLength
  413. MSB(sizeof(nkro_keyboard_report_desc)),
  414. // - 7 bytes -
  415. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  416. 7, // bLength
  417. 5, // bDescriptorType
  418. NKRO_KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  419. 0x03, // bmAttributes (0x03=intr)
  420. NKRO_KEYBOARD_SIZE, 0, // wMaxPacketSize
  421. NKRO_KEYBOARD_INTERVAL, // bInterval
  422. // --- Serial CDC --- CDC IAD Descriptor
  423. // - 8 bytes -
  424. // interface association descriptor, USB ECN, Table 9-Z
  425. 8, // bLength
  426. 11, // bDescriptorType
  427. CDC_STATUS_INTERFACE, // bFirstInterface
  428. 2, // bInterfaceCount
  429. 0x02, // bFunctionClass
  430. 0x02, // bFunctionSubClass
  431. 0x01, // bFunctionProtocol
  432. CDC_STATUS_INTERFACE + 4, // iFunction
  433. // --- Serial CDC --- CDC Data Interface
  434. // - 9 bytes -
  435. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  436. 9, // bLength
  437. 4, // bDescriptorType
  438. CDC_STATUS_INTERFACE, // bInterfaceNumber
  439. 0, // bAlternateSetting
  440. 1, // bNumEndpoints
  441. 0x02, // bInterfaceClass
  442. 0x02, // bInterfaceSubClass
  443. 0x01, // bInterfaceProtocol
  444. CDC_STATUS_INTERFACE + 4, // iInterface
  445. // - 5 bytes -
  446. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  447. 5, // bFunctionLength
  448. 0x24, // bDescriptorType
  449. 0x00, // bDescriptorSubtype
  450. 0x10, 0x01, // bcdCDC
  451. // - 5 bytes -
  452. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  453. 5, // bFunctionLength
  454. 0x24, // bDescriptorType
  455. 0x01, // bDescriptorSubtype
  456. 0x01, // bmCapabilities
  457. CDC_DATA_INTERFACE, // bDataInterface
  458. // - 4 bytes -
  459. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  460. 4, // bFunctionLength
  461. 0x24, // bDescriptorType
  462. 0x02, // bDescriptorSubtype
  463. 0x06, // bmCapabilities
  464. // - 5 bytes -
  465. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  466. 5, // bFunctionLength
  467. 0x24, // bDescriptorType
  468. 0x06, // bDescriptorSubtype
  469. CDC_STATUS_INTERFACE, // bMasterInterface
  470. CDC_DATA_INTERFACE, // bSlaveInterface0
  471. // - 7 bytes -
  472. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  473. 7, // bLength
  474. 5, // bDescriptorType
  475. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  476. 0x03, // bmAttributes (0x03=intr)
  477. CDC_ACM_SIZE, 0, // wMaxPacketSize
  478. 64, // bInterval
  479. // - 9 bytes -
  480. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  481. 9, // bLength
  482. 4, // bDescriptorType
  483. CDC_DATA_INTERFACE, // bInterfaceNumber
  484. 0, // bAlternateSetting
  485. 2, // bNumEndpoints
  486. 0x0A, // bInterfaceClass
  487. 0x00, // bInterfaceSubClass
  488. 0x00, // bInterfaceProtocol
  489. CDC_DATA_INTERFACE + 4, // iInterface
  490. // - 7 bytes -
  491. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  492. 7, // bLength
  493. 5, // bDescriptorType
  494. CDC_RX_ENDPOINT, // bEndpointAddress
  495. 0x02, // bmAttributes (0x02=bulk)
  496. CDC_RX_SIZE, 0, // wMaxPacketSize
  497. 0, // bInterval
  498. // - 7 bytes -
  499. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  500. 7, // bLength
  501. 5, // bDescriptorType
  502. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  503. 0x02, // bmAttributes (0x02=bulk)
  504. CDC_TX_SIZE, 0, // wMaxPacketSize
  505. 0, // bInterval
  506. // --- Mouse Interface ---
  507. // - 9 bytes -
  508. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  509. 9, // bLength
  510. 4, // bDescriptorType
  511. MOUSE_INTERFACE, // bInterfaceNumber
  512. 0, // bAlternateSetting
  513. 1, // bNumEndpoints
  514. 0x03, // bInterfaceClass (0x03 = HID)
  515. 0x00, // bInterfaceSubClass (0x01 = Boot)
  516. 0x02, // bInterfaceProtocol (0x02 = Mouse)
  517. MOUSE_INTERFACE + 4, // iInterface
  518. // - 9 bytes -
  519. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  520. 9, // bLength
  521. 0x21, // bDescriptorType
  522. 0x11, 0x01, // bcdHID
  523. 0, // bCountryCode
  524. 1, // bNumDescriptors
  525. 0x22, // bDescriptorType
  526. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  527. MSB(sizeof(mouse_report_desc)),
  528. // - 7 bytes -
  529. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  530. 7, // bLength
  531. 5, // bDescriptorType
  532. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  533. 0x03, // bmAttributes (0x03=intr)
  534. MOUSE_SIZE, 0, // wMaxPacketSize
  535. MOUSE_INTERVAL, // bInterval
  536. // --- Joystick Interface ---
  537. // - 9 bytes -
  538. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  539. 9, // bLength
  540. 4, // bDescriptorType
  541. JOYSTICK_INTERFACE, // bInterfaceNumber
  542. 0, // bAlternateSetting
  543. 1, // bNumEndpoints
  544. 0x03, // bInterfaceClass (0x03 = HID)
  545. 0x00, // bInterfaceSubClass
  546. 0x00, // bInterfaceProtocol
  547. JOYSTICK_INTERFACE + 4, // iInterface
  548. // - 9 bytes -
  549. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  550. 9, // bLength
  551. 0x21, // bDescriptorType
  552. 0x11, 0x01, // bcdHID
  553. 0, // bCountryCode
  554. 1, // bNumDescriptors
  555. 0x22, // bDescriptorType
  556. LSB(sizeof(joystick_report_desc)), // wDescriptorLength
  557. MSB(sizeof(joystick_report_desc)),
  558. // - 7 bytes -
  559. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  560. 7, // bLength
  561. 5, // bDescriptorType
  562. JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
  563. 0x03, // bmAttributes (0x03=intr)
  564. JOYSTICK_SIZE, 0, // wMaxPacketSize
  565. JOYSTICK_INTERVAL, // bInterval
  566. // --- System/Consumer Control ---
  567. // - 9 bytes -
  568. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  569. 9, // bLength
  570. 4, // bDescriptorType
  571. SYS_CTRL_INTERFACE, // bInterfaceNumber
  572. 0, // bAlternateSetting
  573. 1, // bNumEndpoints
  574. 0x03, // bInterfaceClass (0x03 = HID)
  575. 0x01, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  576. 0x00, // bInterfaceProtocol (0x00 = None)
  577. SYS_CTRL_INTERFACE + 4, // iInterface
  578. // - 9 bytes -
  579. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  580. 9, // bLength
  581. 0x21, // bDescriptorType
  582. 0x11, 0x01, // bcdHID
  583. KeyboardLocale_define, // bCountryCode
  584. 1, // bNumDescriptors
  585. 0x22, // bDescriptorType
  586. LSB(sizeof(sys_ctrl_report_desc)), // wDescriptorLength
  587. MSB(sizeof(sys_ctrl_report_desc)),
  588. // - 7 bytes -
  589. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  590. 7, // bLength
  591. 5, // bDescriptorType
  592. SYS_CTRL_ENDPOINT | 0x80, // bEndpointAddress
  593. 0x03, // bmAttributes (0x03=intr)
  594. SYS_CTRL_SIZE, 0, // wMaxPacketSize
  595. SYS_CTRL_INTERVAL, // bInterval
  596. };
  597. // ----- String Descriptors -----
  598. // The descriptors above can provide human readable strings,
  599. // referenced by index numbers. These descriptors are the
  600. // actual string data
  601. struct usb_string_descriptor_struct {
  602. uint8_t bLength;
  603. uint8_t bDescriptorType;
  604. uint16_t wString[];
  605. };
  606. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  607. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  608. extern struct usb_string_descriptor_struct usb_string_product_name
  609. __attribute__ ((weak, alias("usb_string_product_name_default")));
  610. extern struct usb_string_descriptor_struct usb_string_serial_number
  611. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  612. struct usb_string_descriptor_struct string0 = {
  613. 4,
  614. 3,
  615. {0x0409}
  616. };
  617. #define usb_string_descriptor(name, str) \
  618. struct usb_string_descriptor_struct name = { \
  619. sizeof(str), \
  620. 3, \
  621. {str} \
  622. }
  623. usb_string_descriptor( usb_string_manufacturer_name_default, STR_MANUFACTURER );
  624. usb_string_descriptor( usb_string_product_name_default, STR_PRODUCT );
  625. usb_string_descriptor( usb_string_serial_number_default, STR_SERIAL );
  626. usb_string_descriptor( usb_string_keyboard_name, KEYBOARD_NAME );
  627. usb_string_descriptor( usb_string_nkro_keyboard_name, NKRO_KEYBOARD_NAME );
  628. usb_string_descriptor( usb_string_cdc_status_name, CDC_STATUS_NAME );
  629. usb_string_descriptor( usb_string_cdc_data_name, CDC_DATA_NAME );
  630. usb_string_descriptor( usb_string_mouse_name, MOUSE_NAME );
  631. usb_string_descriptor( usb_string_joystick_name, JOYSTICK_NAME );
  632. usb_string_descriptor( usb_string_sys_ctrl_name, SYS_CTRL_NAME );
  633. // ----- Descriptors List -----
  634. // This table provides access to all the descriptor data above.
  635. const usb_descriptor_list_t usb_descriptor_list[] = {
  636. //wValue, wIndex, address, length
  637. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  638. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  639. {0x0600, 0x0000, device_qualifier_descriptor, sizeof(device_qualifier_descriptor)},
  640. {0x0A00, 0x0000, usb_debug_descriptor, sizeof(usb_debug_descriptor)},
  641. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  642. {0x2100, KEYBOARD_INTERFACE, config_descriptor + KEYBOARD_DESC_OFFSET, 9},
  643. {0x2200, NKRO_KEYBOARD_INTERFACE, nkro_keyboard_report_desc, sizeof(nkro_keyboard_report_desc)},
  644. {0x2100, NKRO_KEYBOARD_INTERFACE, config_descriptor + NKRO_KEYBOARD_DESC_OFFSET, 9},
  645. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  646. {0x2100, MOUSE_INTERFACE, config_descriptor + MOUSE_DESC_OFFSET, 9},
  647. {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
  648. {0x2100, JOYSTICK_INTERFACE, config_descriptor + JOYSTICK_DESC_OFFSET, 9},
  649. {0x2200, SYS_CTRL_INTERFACE, sys_ctrl_report_desc, sizeof(sys_ctrl_report_desc)},
  650. {0x2100, SYS_CTRL_INTERFACE, config_descriptor + SYS_CTRL_DESC_OFFSET, 9},
  651. #define iInterfaceString(num, var) \
  652. {0x0300 + 4 + num, 0x409, (const uint8_t *)&var, 0 }
  653. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  654. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  655. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  656. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  657. iInterfaceString( KEYBOARD_INTERFACE, usb_string_keyboard_name ),
  658. iInterfaceString( NKRO_KEYBOARD_INTERFACE, usb_string_nkro_keyboard_name ),
  659. iInterfaceString( CDC_STATUS_INTERFACE, usb_string_cdc_status_name ),
  660. iInterfaceString( CDC_DATA_INTERFACE, usb_string_cdc_data_name ),
  661. iInterfaceString( MOUSE_INTERFACE, usb_string_mouse_name ),
  662. iInterfaceString( JOYSTICK_INTERFACE, usb_string_joystick_name ),
  663. iInterfaceString( SYS_CTRL_INTERFACE, usb_string_sys_ctrl_name ),
  664. {0, 0, NULL, 0}
  665. };
  666. // ----- Endpoint Configuration -----
  667. // See usb_desc.h for Endpoint configuration
  668. // 0x00 = not used
  669. // 0x19 = Recieve only
  670. // 0x15 = Transmit only
  671. // 0x1D = Transmit & Recieve
  672. //
  673. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  674. {
  675. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  676. ENDPOINT1_CONFIG,
  677. #elif (NUM_ENDPOINTS >= 1)
  678. ENDPOINT_UNUSED,
  679. #endif
  680. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  681. ENDPOINT2_CONFIG,
  682. #elif (NUM_ENDPOINTS >= 2)
  683. ENDPOINT_UNUSED,
  684. #endif
  685. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  686. ENDPOINT3_CONFIG,
  687. #elif (NUM_ENDPOINTS >= 3)
  688. ENDPOINT_UNUSED,
  689. #endif
  690. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  691. ENDPOINT4_CONFIG,
  692. #elif (NUM_ENDPOINTS >= 4)
  693. ENDPOINT_UNUSED,
  694. #endif
  695. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  696. ENDPOINT5_CONFIG,
  697. #elif (NUM_ENDPOINTS >= 5)
  698. ENDPOINT_UNUSED,
  699. #endif
  700. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  701. ENDPOINT6_CONFIG,
  702. #elif (NUM_ENDPOINTS >= 6)
  703. ENDPOINT_UNUSED,
  704. #endif
  705. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  706. ENDPOINT7_CONFIG,
  707. #elif (NUM_ENDPOINTS >= 7)
  708. ENDPOINT_UNUSED,
  709. #endif
  710. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  711. ENDPOINT8_CONFIG,
  712. #elif (NUM_ENDPOINTS >= 8)
  713. ENDPOINT_UNUSED,
  714. #endif
  715. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  716. ENDPOINT9_CONFIG,
  717. #elif (NUM_ENDPOINTS >= 9)
  718. ENDPOINT_UNUSED,
  719. #endif
  720. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  721. ENDPOINT10_CONFIG,
  722. #elif (NUM_ENDPOINTS >= 10)
  723. ENDPOINT_UNUSED,
  724. #endif
  725. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  726. ENDPOINT11_CONFIG,
  727. #elif (NUM_ENDPOINTS >= 11)
  728. ENDPOINT_UNUSED,
  729. #endif
  730. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  731. ENDPOINT12_CONFIG,
  732. #elif (NUM_ENDPOINTS >= 12)
  733. ENDPOINT_UNUSED,
  734. #endif
  735. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  736. ENDPOINT13_CONFIG,
  737. #elif (NUM_ENDPOINTS >= 13)
  738. ENDPOINT_UNUSED,
  739. #endif
  740. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  741. ENDPOINT14_CONFIG,
  742. #elif (NUM_ENDPOINTS >= 14)
  743. ENDPOINT_UNUSED,
  744. #endif
  745. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  746. ENDPOINT15_CONFIG,
  747. #elif (NUM_ENDPOINTS >= 15)
  748. ENDPOINT_UNUSED,
  749. #endif
  750. };