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

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