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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. // Modifier Byte
  132. 0x85, 0x01, // Report ID (1),
  133. 0x75, 0x01, // Report Size (1),
  134. 0x95, 0x08, // Report Count (8),
  135. 0x15, 0x00, // Logical Minimum (0),
  136. 0x25, 0x01, // Logical Maximum (1),
  137. 0x05, 0x07, // Usage Page (Key Codes),
  138. 0x19, 0xE0, // Usage Minimum (224),
  139. 0x29, 0xE7, // Usage Maximum (231),
  140. 0x81, 0x02, // Input (Data, Variable, Absolute),
  141. // LED Report
  142. 0x85, 0x02, // Report ID (2),
  143. 0x75, 0x01, // Report Size (1),
  144. 0x95, 0x05, // Report Count (5),
  145. 0x05, 0x08, // Usage Page (LEDs),
  146. 0x19, 0x01, // Usage Minimum (1),
  147. 0x29, 0x05, // Usage Maximum (5),
  148. 0x91, 0x02, // Output (Data, Variable, Absolute),
  149. // LED Report Padding
  150. 0x75, 0x03, // Report Size (3),
  151. 0x95, 0x01, // Report Count (1),
  152. 0x91, 0x03, // Output (Constant),
  153. // Normal Keys - Using an NKRO Bitmap
  154. //
  155. // NOTES:
  156. // Supports all keys defined by the spec, except 1-3 which define error events
  157. // and 0 which is "no keys pressed"
  158. // See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf Chapter 10
  159. // Or Macros/PartialMap/usb_hid.h
  160. //
  161. // 50 (ISO \ due to \ bug) and 156 (Clear due to Delete bug) must be excluded
  162. // due to a Linux bug with bitmaps (not useful anyways)
  163. // 165-175 are reserved/unused as well as 222-223 and 232-65535
  164. // 224-231 are used for modifiers (see above)
  165. //
  166. // Compatibility Notes:
  167. // - Using a second endpoint for a boot mode device helps with compatibility
  168. // - DO NOT use Padding in the descriptor for bitfields
  169. // (Mac OSX silently fails... Windows/Linux work correctly)
  170. //
  171. // Packing of bitmaps are as follows:
  172. // 4-49 : 6 bytes + 1 Report ID byte (0x04-0x31) ( 46 bits + 2 padding bits for 6 bytes total)
  173. // 51-155 : 14 bytes + 1 Report ID byte (0x33-0x9B) (105 bits + 6 padding bits for 15 bytes total)
  174. // 157-164 : 1 byte + 1 Report ID byte (0x9D-0xA4) ( 8 bits)
  175. // 176-221 : 6 bytes + 1 Report ID byte (0xB0-0xDD) ( 46 bits + 2 padding bits for 6 bytes total)
  176. //
  177. // 4-49 (6 bytes/46 bits) - MainKeys
  178. 0x85, 0x03, // Report ID (3),
  179. 0x75, 0x01, // Report Size (1),
  180. 0x95, 0x2E, // Report Count (46),
  181. 0x15, 0x00, // Logical Minimum (0),
  182. 0x25, 0x01, // Logical Maximum (1),
  183. 0x05, 0x07, // Usage Page (Key Codes),
  184. 0x19, 0x04, // Usage Minimum (4),
  185. 0x29, 0x31, // Usage Maximum (49),
  186. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  187. // Should pad 2 bits according to the spec, but OSX doesn't like this -HaaTa
  188. // 51-155 (14 bytes/105 bits) - SecondaryKeys
  189. 0x85, 0x04, // Report ID (4),
  190. 0x75, 0x01, // Report Size (1),
  191. 0x95, 0x69, // Report Count (105),
  192. 0x15, 0x00, // Logical Minimum (0),
  193. 0x25, 0x01, // Logical Maximum (1),
  194. 0x05, 0x07, // Usage Page (Key Codes),
  195. 0x19, 0x33, // Usage Minimum (51),
  196. 0x29, 0x9B, // Usage Maximum (155),
  197. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  198. // Should pad 6 bits according to the spec, but OSX doesn't like this -HaaTa
  199. // 157-164 (1 byte/8 bits) - TertiaryKeys
  200. 0x85, 0x05, // Report ID (5),
  201. 0x75, 0x01, // Report Size (1),
  202. 0x95, 0x08, // Report Count (8),
  203. 0x15, 0x00, // Logical Minimum (0),
  204. 0x25, 0x01, // Logical Maximum (1),
  205. 0x05, 0x07, // Usage Page (Key Codes),
  206. 0x19, 0x9D, // Usage Minimum (157),
  207. 0x29, 0xA4, // Usage Maximum (164),
  208. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  209. // 176-221 (6 bytes/46 bits) - QuartiaryKeys
  210. 0x85, 0x06, // Report ID (6),
  211. 0x75, 0x01, // Report Size (1),
  212. 0x95, 0x2D, // Report Count (45),
  213. 0x15, 0x00, // Logical Minimum (0),
  214. 0x25, 0x01, // Logical Maximum (1),
  215. 0x05, 0x07, // Usage Page (Key Codes),
  216. 0x19, 0xB0, // Usage Minimum (176),
  217. 0x29, 0xDD, // Usage Maximum (221),
  218. 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
  219. // Should pad 2 bits according to the spec, but OSX doesn't like this -HaaTa
  220. 0xc0, // End Collection - Keyboard
  221. // System Control Collection
  222. //
  223. // NOTES:
  224. // Not bothering with NKRO for this table. If there's need, I can implement it. -HaaTa
  225. // Using a 1KRO scheme
  226. 0x05, 0x01, // Usage Page (Generic Desktop),
  227. 0x09, 0x80, // Usage (System Control),
  228. 0xA1, 0x01, // Collection (Application),
  229. 0x85, 0x07, // Report ID (7),
  230. 0x75, 0x08, // Report Size (8),
  231. 0x95, 0x01, // Report Count (1),
  232. 0x16, 0x81, 0x00, // Logical Minimum (129),
  233. 0x26, 0xB7, 0x00, // Logical Maximum (183),
  234. 0x19, 0x81, // Usage Minimum (129),
  235. 0x29, 0xB7, // Usage Maximum (183),
  236. 0x81, 0x00, // Input (Data, Array),
  237. 0xc0, // End Collection - System Control
  238. // Consumer Control Collection - Media Keys
  239. //
  240. // NOTES:
  241. // Not bothering with NKRO for this table. If there's a need, I can implement it. -HaaTa
  242. // Using a 1KRO scheme
  243. 0x05, 0x0c, // Usage Page (Consumer),
  244. 0x09, 0x01, // Usage (Consumer Control),
  245. 0xA1, 0x01, // Collection (Application),
  246. 0x85, 0x08, // Report ID (8),
  247. 0x75, 0x10, // Report Size (16),
  248. 0x95, 0x01, // Report Count (1),
  249. 0x16, 0x20, 0x00, // Logical Minimum (32),
  250. 0x26, 0x9C, 0x02, // Logical Maximum (668),
  251. 0x05, 0x0C, // Usage Page (Consumer),
  252. 0x19, 0x20, // Usage Minimum (32),
  253. 0x2A, 0x9C, 0x02, // Usage Maximum (668),
  254. 0x81, 0x00, // Input (Data, Array),
  255. 0xc0, // End Collection - Consumer Control
  256. };
  257. /* MOUSE
  258. // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
  259. static uint8_t mouse_report_desc[] = {
  260. 0x05, 0x01, // Usage Page (Generic Desktop)
  261. 0x09, 0x02, // Usage (Mouse)
  262. 0xA1, 0x01, // Collection (Application)
  263. 0x05, 0x09, // Usage Page (Button)
  264. 0x19, 0x01, // Usage Minimum (Button #1)
  265. 0x29, 0x03, // Usage Maximum (Button #3)
  266. 0x15, 0x00, // Logical Minimum (0)
  267. 0x25, 0x01, // Logical Maximum (1)
  268. 0x95, 0x03, // Report Count (3)
  269. 0x75, 0x01, // Report Size (1)
  270. 0x81, 0x02, // Input (Data, Variable, Absolute)
  271. 0x95, 0x01, // Report Count (1)
  272. 0x75, 0x05, // Report Size (5)
  273. 0x81, 0x03, // Input (Constant)
  274. 0x05, 0x01, // Usage Page (Generic Desktop)
  275. 0x09, 0x30, // Usage (X)
  276. 0x09, 0x31, // Usage (Y)
  277. 0x15, 0x00, // Logical Minimum (0)
  278. 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
  279. 0x75, 0x10, // Report Size (16),
  280. 0x95, 0x02, // Report Count (2),
  281. 0x81, 0x02, // Input (Data, Variable, Absolute)
  282. 0x09, 0x38, // Usage (Wheel)
  283. 0x15, 0x81, // Logical Minimum (-127)
  284. 0x25, 0x7F, // Logical Maximum (127)
  285. 0x75, 0x08, // Report Size (8),
  286. 0x95, 0x01, // Report Count (1),
  287. 0x81, 0x06, // Input (Data, Variable, Relative)
  288. 0xC0 // End Collection
  289. };
  290. */
  291. // ----- USB Configuration -----
  292. // USB Configuration Descriptor. This huge descriptor tells all
  293. // of the devices capbilities.
  294. static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
  295. // --- Configuration ---
  296. // - 9 bytes -
  297. // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
  298. 9, // bLength;
  299. 2, // bDescriptorType;
  300. LSB(CONFIG_DESC_SIZE), // wTotalLength
  301. MSB(CONFIG_DESC_SIZE),
  302. NUM_INTERFACE, // bNumInterfaces
  303. 1, // bConfigurationValue
  304. 0, // iConfiguration
  305. 0xA0, // bmAttributes
  306. 250, // bMaxPower
  307. // --- Keyboard HID --- Boot Mode Keyboard Interface
  308. // - 9 bytes -
  309. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  310. 9, // bLength
  311. 4, // bDescriptorType
  312. KEYBOARD_INTERFACE, // bInterfaceNumber
  313. 0, // bAlternateSetting
  314. 1, // bNumEndpoints
  315. 0x03, // bInterfaceClass (0x03 = HID)
  316. 0x01, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  317. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  318. 0, // iInterface
  319. // - 9 bytes -
  320. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  321. 9, // bLength
  322. 0x21, // bDescriptorType
  323. 0x11, 0x01, // bcdHID
  324. 0, // bCountryCode
  325. 1, // bNumDescriptors
  326. 0x22, // bDescriptorType
  327. LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
  328. MSB(sizeof(keyboard_report_desc)),
  329. // - 7 bytes -
  330. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  331. 7, // bLength
  332. 5, // bDescriptorType
  333. KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  334. 0x03, // bmAttributes (0x03=intr)
  335. KEYBOARD_SIZE, 0, // wMaxPacketSize
  336. KEYBOARD_INTERVAL, // bInterval
  337. // --- NKRO Keyboard HID --- OS Mode Keyboard Interface
  338. // - 9 bytes -
  339. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  340. 9, // bLength
  341. 4, // bDescriptorType
  342. NKRO_KEYBOARD_INTERFACE, // bInterfaceNumber
  343. 0, // bAlternateSetting
  344. 1, // bNumEndpoints
  345. 0x03, // bInterfaceClass (0x03 = HID)
  346. 0x00, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
  347. 0x01, // bInterfaceProtocol (0x01 = Keyboard)
  348. 0, // iInterface
  349. // - 9 bytes -
  350. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  351. 9, // bLength
  352. 0x21, // bDescriptorType
  353. 0x11, 0x01, // bcdHID
  354. 0, // bCountryCode
  355. 1, // bNumDescriptors
  356. 0x22, // bDescriptorType
  357. LSB(sizeof(nkro_keyboard_report_desc)), // wDescriptorLength
  358. MSB(sizeof(nkro_keyboard_report_desc)),
  359. // - 7 bytes -
  360. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  361. 7, // bLength
  362. 5, // bDescriptorType
  363. NKRO_KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
  364. 0x03, // bmAttributes (0x03=intr)
  365. NKRO_KEYBOARD_SIZE, 0, // wMaxPacketSize
  366. NKRO_KEYBOARD_INTERVAL, // bInterval
  367. // --- Serial CDC --- CDC IAD Descriptor
  368. // - 8 bytes -
  369. // interface association descriptor, USB ECN, Table 9-Z
  370. 8, // bLength
  371. 11, // bDescriptorType
  372. CDC_STATUS_INTERFACE, // bFirstInterface
  373. 2, // bInterfaceCount
  374. 0x02, // bFunctionClass
  375. 0x02, // bFunctionSubClass
  376. 0x01, // bFunctionProtocol
  377. 0, // iFunction
  378. // --- Serial CDC --- CDC Data Interface
  379. // - 9 bytes -
  380. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  381. 9, // bLength
  382. 4, // bDescriptorType
  383. CDC_STATUS_INTERFACE, // bInterfaceNumber
  384. 0, // bAlternateSetting
  385. 1, // bNumEndpoints
  386. 0x02, // bInterfaceClass
  387. 0x02, // bInterfaceSubClass
  388. 0x01, // bInterfaceProtocol
  389. 0, // iInterface
  390. // - 5 bytes -
  391. // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
  392. 5, // bFunctionLength
  393. 0x24, // bDescriptorType
  394. 0x00, // bDescriptorSubtype
  395. 0x10, 0x01, // bcdCDC
  396. // - 5 bytes -
  397. // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
  398. 5, // bFunctionLength
  399. 0x24, // bDescriptorType
  400. 0x01, // bDescriptorSubtype
  401. 0x01, // bmCapabilities
  402. CDC_DATA_INTERFACE, // bDataInterface
  403. // - 4 bytes -
  404. // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
  405. 4, // bFunctionLength
  406. 0x24, // bDescriptorType
  407. 0x02, // bDescriptorSubtype
  408. 0x06, // bmCapabilities
  409. // - 5 bytes -
  410. // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
  411. 5, // bFunctionLength
  412. 0x24, // bDescriptorType
  413. 0x06, // bDescriptorSubtype
  414. CDC_STATUS_INTERFACE, // bMasterInterface
  415. CDC_DATA_INTERFACE, // bSlaveInterface0
  416. // - 7 bytes -
  417. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  418. 7, // bLength
  419. 5, // bDescriptorType
  420. CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
  421. 0x03, // bmAttributes (0x03=intr)
  422. CDC_ACM_SIZE, 0, // wMaxPacketSize
  423. 64, // bInterval
  424. // - 9 bytes -
  425. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  426. 9, // bLength
  427. 4, // bDescriptorType
  428. CDC_DATA_INTERFACE, // bInterfaceNumber
  429. 0, // bAlternateSetting
  430. 2, // bNumEndpoints
  431. 0x0A, // bInterfaceClass
  432. 0x00, // bInterfaceSubClass
  433. 0x00, // bInterfaceProtocol
  434. 0, // iInterface
  435. // - 7 bytes -
  436. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  437. 7, // bLength
  438. 5, // bDescriptorType
  439. CDC_RX_ENDPOINT, // bEndpointAddress
  440. 0x02, // bmAttributes (0x02=bulk)
  441. CDC_RX_SIZE, 0, // wMaxPacketSize
  442. 0, // bInterval
  443. // - 7 bytes -
  444. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  445. 7, // bLength
  446. 5, // bDescriptorType
  447. CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
  448. 0x02, // bmAttributes (0x02=bulk)
  449. CDC_TX_SIZE, 0, // wMaxPacketSize
  450. 0, // bInterval
  451. /*
  452. // Mouse Interface
  453. // - 9 bytes -
  454. // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
  455. 9, // bLength
  456. 4, // bDescriptorType
  457. MOUSE_INTERFACE, // bInterfaceNumber
  458. 0, // bAlternateSetting
  459. 1, // bNumEndpoints
  460. 0x03, // bInterfaceClass (0x03 = HID)
  461. 0x00, // bInterfaceSubClass (0x01 = Boot)
  462. 0x00, // bInterfaceProtocol (0x02 = Mouse)
  463. 0, // iInterface
  464. // - 9 bytes -
  465. // HID interface descriptor, HID 1.11 spec, section 6.2.1
  466. 9, // bLength
  467. 0x21, // bDescriptorType
  468. 0x11, 0x01, // bcdHID
  469. 0, // bCountryCode
  470. 1, // bNumDescriptors
  471. 0x22, // bDescriptorType
  472. LSB(sizeof(mouse_report_desc)), // wDescriptorLength
  473. MSB(sizeof(mouse_report_desc)),
  474. // - 7 bytes -
  475. // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
  476. 7, // bLength
  477. 5, // bDescriptorType
  478. MOUSE_ENDPOINT | 0x80, // bEndpointAddress
  479. 0x03, // bmAttributes (0x03=intr)
  480. MOUSE_SIZE, 0, // wMaxPacketSize
  481. MOUSE_INTERVAL, // bInterval
  482. #endif // MOUSE_INTERFACE
  483. */
  484. };
  485. // ----- String Descriptors -----
  486. // The descriptors above can provide human readable strings,
  487. // referenced by index numbers. These descriptors are the
  488. // actual string data
  489. struct usb_string_descriptor_struct {
  490. uint8_t bLength;
  491. uint8_t bDescriptorType;
  492. uint16_t wString[];
  493. };
  494. extern struct usb_string_descriptor_struct usb_string_manufacturer_name
  495. __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
  496. extern struct usb_string_descriptor_struct usb_string_product_name
  497. __attribute__ ((weak, alias("usb_string_product_name_default")));
  498. extern struct usb_string_descriptor_struct usb_string_serial_number
  499. __attribute__ ((weak, alias("usb_string_serial_number_default")));
  500. struct usb_string_descriptor_struct string0 = {
  501. 4,
  502. 3,
  503. {0x0409}
  504. };
  505. struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
  506. sizeof(STR_MANUFACTURER),
  507. 3,
  508. STR_MANUFACTURER
  509. };
  510. struct usb_string_descriptor_struct usb_string_product_name_default = {
  511. sizeof(STR_PRODUCT),
  512. 3,
  513. STR_PRODUCT
  514. };
  515. struct usb_string_descriptor_struct usb_string_serial_number_default = {
  516. sizeof(STR_SERIAL),
  517. 3,
  518. STR_SERIAL
  519. };
  520. // ----- Descriptors List -----
  521. // This table provides access to all the descriptor data above.
  522. const usb_descriptor_list_t usb_descriptor_list[] = {
  523. //wValue, wIndex, address, length
  524. {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
  525. {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
  526. {0x0600, 0x0000, device_qualifier_descriptor, sizeof(device_qualifier_descriptor)},
  527. {0x0A00, 0x0000, usb_debug_descriptor, sizeof(usb_debug_descriptor)},
  528. {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
  529. {0x2100, KEYBOARD_INTERFACE, config_descriptor + KEYBOARD_DESC_OFFSET, 9},
  530. {0x2200, NKRO_KEYBOARD_INTERFACE, nkro_keyboard_report_desc, sizeof(nkro_keyboard_report_desc)},
  531. {0x2100, NKRO_KEYBOARD_INTERFACE, config_descriptor + NKRO_KEYBOARD_DESC_OFFSET, 9},
  532. /* MOUSE
  533. {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
  534. {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
  535. */
  536. {0x0300, 0x0000, (const uint8_t *)&string0, 0},
  537. {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
  538. {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
  539. {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
  540. {0, 0, NULL, 0}
  541. };
  542. // ----- Endpoint Configuration -----
  543. // See usb_desc.h for Endpoint configuration
  544. // 0x00 = not used
  545. // 0x19 = Recieve only
  546. // 0x15 = Transmit only
  547. // 0x1D = Transmit & Recieve
  548. //
  549. const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
  550. {
  551. #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
  552. ENDPOINT1_CONFIG,
  553. #elif (NUM_ENDPOINTS >= 1)
  554. ENDPOINT_UNUSED,
  555. #endif
  556. #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
  557. ENDPOINT2_CONFIG,
  558. #elif (NUM_ENDPOINTS >= 2)
  559. ENDPOINT_UNUSED,
  560. #endif
  561. #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
  562. ENDPOINT3_CONFIG,
  563. #elif (NUM_ENDPOINTS >= 3)
  564. ENDPOINT_UNUSED,
  565. #endif
  566. #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
  567. ENDPOINT4_CONFIG,
  568. #elif (NUM_ENDPOINTS >= 4)
  569. ENDPOINT_UNUSED,
  570. #endif
  571. #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
  572. ENDPOINT5_CONFIG,
  573. #elif (NUM_ENDPOINTS >= 5)
  574. ENDPOINT_UNUSED,
  575. #endif
  576. #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
  577. ENDPOINT6_CONFIG,
  578. #elif (NUM_ENDPOINTS >= 6)
  579. ENDPOINT_UNUSED,
  580. #endif
  581. #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
  582. ENDPOINT7_CONFIG,
  583. #elif (NUM_ENDPOINTS >= 7)
  584. ENDPOINT_UNUSED,
  585. #endif
  586. #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
  587. ENDPOINT8_CONFIG,
  588. #elif (NUM_ENDPOINTS >= 8)
  589. ENDPOINT_UNUSED,
  590. #endif
  591. #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
  592. ENDPOINT9_CONFIG,
  593. #elif (NUM_ENDPOINTS >= 9)
  594. ENDPOINT_UNUSED,
  595. #endif
  596. #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
  597. ENDPOINT10_CONFIG,
  598. #elif (NUM_ENDPOINTS >= 10)
  599. ENDPOINT_UNUSED,
  600. #endif
  601. #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
  602. ENDPOINT11_CONFIG,
  603. #elif (NUM_ENDPOINTS >= 11)
  604. ENDPOINT_UNUSED,
  605. #endif
  606. #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
  607. ENDPOINT12_CONFIG,
  608. #elif (NUM_ENDPOINTS >= 12)
  609. ENDPOINT_UNUSED,
  610. #endif
  611. #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
  612. ENDPOINT13_CONFIG,
  613. #elif (NUM_ENDPOINTS >= 13)
  614. ENDPOINT_UNUSED,
  615. #endif
  616. #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
  617. ENDPOINT14_CONFIG,
  618. #elif (NUM_ENDPOINTS >= 14)
  619. ENDPOINT_UNUSED,
  620. #endif
  621. #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
  622. ENDPOINT15_CONFIG,
  623. #elif (NUM_ENDPOINTS >= 15)
  624. ENDPOINT_UNUSED,
  625. #endif
  626. };