Kiibohd Controller
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

usb_desc.c 30KB

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