Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

419 lines
20KB

  1. /* USB EHCI Host for Teensy 3.6
  2. Copyright 2017 Paul Stoffregen (paul@pjrc.com)
  3. Permission is hereby granted, free of charge, to any person obtaining a
  4. copy of this software and associated documentation files (the
  5. "Software"), to deal in the Software without restriction, including
  6. without limitation the rights to use, copy, modify, merge, publish,
  7. distribute, shiublicense, and/or sell copies of the Software, and to
  8. permit persons to whom the Software is furnished to do so, subject to
  9. the following conditions:
  10. The above copyright notice and this permission notice shall be included
  11. in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  16. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  17. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  18. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. #include "HidDumper.h"
  21. bool HIDDumpController::show_raw_data = true;
  22. bool HIDDumpController::show_formated_data = true;
  23. bool HIDDumpController::changed_data_only = false;
  24. void HIDDumpController::init()
  25. {
  26. USBHost::contribute_Transfers(mytransfers, sizeof(mytransfers) / sizeof(Transfer_t));
  27. USBHIDParser::driver_ready_for_hid_collection(this);
  28. }
  29. hidclaim_t HIDDumpController::claim_collection(USBHIDParser *driver, Device_t *dev, uint32_t topusage)
  30. {
  31. // only claim RAWHID devices currently: 16c0:0486
  32. Serial.printf("HIDDumpController Claim: %x:%x usage: %x", dev->idVendor, dev->idProduct, topusage);
  33. if (mydevice != NULL && dev != mydevice) {
  34. Serial.println("- NO (Device)");
  35. return CLAIM_NO;
  36. }
  37. if (usage_ && (usage_ != topusage)) {
  38. Serial.printf(" - NO (Usage: %x)\n");
  39. return CLAIM_NO; // Only claim one
  40. }
  41. mydevice = dev;
  42. collections_claimed++;
  43. usage_ = topusage;
  44. driver_ = driver; // remember the driver.
  45. Serial.println(" - Yes");
  46. return CLAIM_INTERFACE; // We want
  47. }
  48. void HIDDumpController::disconnect_collection(Device_t *dev)
  49. {
  50. if (--collections_claimed == 0) {
  51. mydevice = NULL;
  52. usage_ = 0;
  53. }
  54. }
  55. void dump_hexbytes(const void *ptr, uint32_t len)
  56. {
  57. if (ptr == NULL || len == 0) return;
  58. uint32_t count = 0;
  59. // if (len > 64) len = 64; // don't go off deep end...
  60. const uint8_t *p = (const uint8_t *)ptr;
  61. while (len--) {
  62. if (*p < 16) Serial.print('0');
  63. Serial.print(*p++, HEX);
  64. count++;
  65. if (((count & 0x1f) == 0) && len) Serial.print("\n");
  66. else Serial.print(' ');
  67. }
  68. Serial.println();
  69. }
  70. bool HIDDumpController::hid_process_in_data(const Transfer_t *transfer)
  71. {
  72. // return true if we are not showing formated data...
  73. hid_input_begin_level_ = 0; // always make sure we reset to 0
  74. count_usages_ = index_usages_; // remember how many we output for this one
  75. index_usages_ = 0; // reset the index back to zero
  76. Serial.printf("HID(%x)", usage_);
  77. if (show_raw_data) {
  78. Serial.print(": ");
  79. dump_hexbytes(transfer->buffer, transfer->length);
  80. }
  81. else Serial.println();
  82. return !show_formated_data;
  83. }
  84. bool HIDDumpController::hid_process_out_data(const Transfer_t *transfer)
  85. {
  86. Serial.printf("HIDDumpController::hid_process_out_data: %x\n", usage_);
  87. return true;
  88. }
  89. void indent_level(int level) {
  90. if ((level > 5) || (level < 0)) return; // bail if something is off...
  91. while (level--) Serial.print(" ");
  92. }
  93. void HIDDumpController::hid_input_begin(uint32_t topusage, uint32_t type, int lgmin, int lgmax)
  94. {
  95. // Lets do simplified data for changed only
  96. if (changed_data_only) return;
  97. indent_level(hid_input_begin_level_);
  98. Serial.printf("Begin topusage:%x type:%x min:%d max:%d\n", topusage, type, lgmin, lgmax);
  99. if (hid_input_begin_level_ < 2)
  100. hid_input_begin_level_++;
  101. }
  102. void HIDDumpController::hid_input_data(uint32_t usage, int32_t value)
  103. {
  104. bool output_data = !changed_data_only;
  105. // See if something changed.
  106. if (index_usages_ < count_usages_) {
  107. if ((usage != usages_[index_usages_]) || (value != values_[index_usages_])) {
  108. output_data = true;
  109. }
  110. } else {
  111. output_data = true;
  112. }
  113. if (index_usages_ < MAX_CHANGE_TRACKED) {
  114. usages_[index_usages_] = usage;
  115. values_[index_usages_] = value;
  116. index_usages_++;
  117. }
  118. if (output_data) {
  119. indent_level(hid_input_begin_level_);
  120. Serial.printf("usage=%X, value=%d", usage, value);
  121. if ((value >= ' ') && (value <= '~')) Serial.printf(":%c", value);
  122. // maybe print out some information about some of the Usage numbers that we know about
  123. // The information comes from the USB document, HID Usage Tables
  124. // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
  125. uint16_t usage_page = usage >> 16;
  126. usage = usage & 0xffff; // keep the lower part
  127. switch (usage_page) {
  128. case 1: // Generic Desktop control:
  129. switch (usage) {
  130. case 0x30: Serial.print("(X)"); break;
  131. case 0x31: Serial.print("(Y)"); break;
  132. case 0x32: Serial.print("(Z)"); break;
  133. case 0x33: Serial.print("(Rx)"); break;
  134. case 0x34: Serial.print("(Ry)"); break;
  135. case 0x35: Serial.print("(Rz)"); break;
  136. case 0x36: Serial.print("(Slider)"); break;
  137. case 0x37: Serial.print("(Dial)"); break;
  138. case 0x38: Serial.print("(Wheel)"); break;
  139. case 0x39: Serial.print("(Hat)"); break;
  140. case 0x3D: Serial.print("(Start)"); break;
  141. case 0x3E: Serial.print("(Select)"); break;
  142. case 0x40: Serial.print("(Vx)"); break;
  143. case 0x41: Serial.print("(Vy)"); break;
  144. case 0x42: Serial.print("(Vz)"); break;
  145. case 0x43: Serial.print("(Vbrx)"); break;
  146. case 0x44: Serial.print("(Vbry)"); break;
  147. case 0x45: Serial.print("(Vbrz)"); break;
  148. case 0x46: Serial.print("(Vno)"); break;
  149. case 0x90: Serial.print("(D-Up)"); break;
  150. case 0x91: Serial.print("(D-Dn)"); break;
  151. case 0x92: Serial.print("(D-Right)"); break;
  152. case 0x93: Serial.print("(D-Left)"); break;
  153. default:
  154. break;
  155. }
  156. break;
  157. case 9: // Button
  158. Serial.printf(" (BUTTON %d)", usage);
  159. break;
  160. case 0xC: // Consummer page
  161. switch (usage) {
  162. case 0x20 : Serial.print("(+10)"); break;
  163. case 0x21 : Serial.print("(+100)"); break;
  164. case 0x22 : Serial.print("(AM/PM)"); break;
  165. case 0x30 : Serial.print("(Power)"); break;
  166. case 0x31 : Serial.print("(Reset)"); break;
  167. case 0x32 : Serial.print("(Sleep)"); break;
  168. case 0x33 : Serial.print("(Sleep After)"); break;
  169. case 0x34 : Serial.print("(Sleep Mode)"); break;
  170. case 0x35 : Serial.print("(Illumination)"); break;
  171. case 0x36 : Serial.print("(Function Buttons)"); break;
  172. case 0x40 : Serial.print("(Menu)"); break;
  173. case 0x41 : Serial.print("(Menu Pick)"); break;
  174. case 0x42 : Serial.print("(Menu Up)"); break;
  175. case 0x43 : Serial.print("(Menu Down)"); break;
  176. case 0x44 : Serial.print("(Menu Left)"); break;
  177. case 0x45 : Serial.print("(Menu Right)"); break;
  178. case 0x46 : Serial.print("(Menu Escape)"); break;
  179. case 0x47 : Serial.print("(Menu Value Increase)"); break;
  180. case 0x48 : Serial.print("(Menu Value Decrease)"); break;
  181. case 0x60 : Serial.print("(Data On Screen)"); break;
  182. case 0x61 : Serial.print("(Closed Caption)"); break;
  183. case 0x62 : Serial.print("(Closed Caption Select)"); break;
  184. case 0x63 : Serial.print("(VCR/TV)"); break;
  185. case 0x64 : Serial.print("(Broadcast Mode)"); break;
  186. case 0x65 : Serial.print("(Snapshot)"); break;
  187. case 0x66 : Serial.print("(Still)"); break;
  188. case 0x80 : Serial.print("(Selection)"); break;
  189. case 0x81 : Serial.print("(Assign Selection)"); break;
  190. case 0x82 : Serial.print("(Mode Step)"); break;
  191. case 0x83 : Serial.print("(Recall Last)"); break;
  192. case 0x84 : Serial.print("(Enter Channel)"); break;
  193. case 0x85 : Serial.print("(Order Movie)"); break;
  194. case 0x86 : Serial.print("(Channel)"); break;
  195. case 0x87 : Serial.print("(Media Selection)"); break;
  196. case 0x88 : Serial.print("(Media Select Computer)"); break;
  197. case 0x89 : Serial.print("(Media Select TV)"); break;
  198. case 0x8A : Serial.print("(Media Select WWW)"); break;
  199. case 0x8B : Serial.print("(Media Select DVD)"); break;
  200. case 0x8C : Serial.print("(Media Select Telephone)"); break;
  201. case 0x8D : Serial.print("(Media Select Program Guide)"); break;
  202. case 0x8E : Serial.print("(Media Select Video Phone)"); break;
  203. case 0x8F : Serial.print("(Media Select Games)"); break;
  204. case 0x90 : Serial.print("(Media Select Messages)"); break;
  205. case 0x91 : Serial.print("(Media Select CD)"); break;
  206. case 0x92 : Serial.print("(Media Select VCR)"); break;
  207. case 0x93 : Serial.print("(Media Select Tuner)"); break;
  208. case 0x94 : Serial.print("(Quit)"); break;
  209. case 0x95 : Serial.print("(Help)"); break;
  210. case 0x96 : Serial.print("(Media Select Tape)"); break;
  211. case 0x97 : Serial.print("(Media Select Cable)"); break;
  212. case 0x98 : Serial.print("(Media Select Satellite)"); break;
  213. case 0x99 : Serial.print("(Media Select Security)"); break;
  214. case 0x9A : Serial.print("(Media Select Home)"); break;
  215. case 0x9B : Serial.print("(Media Select Call)"); break;
  216. case 0x9C : Serial.print("(Channel Increment)"); break;
  217. case 0x9D : Serial.print("(Channel Decrement)"); break;
  218. case 0x9E : Serial.print("(Media Select SAP)"); break;
  219. case 0xA0 : Serial.print("(VCR Plus)"); break;
  220. case 0xA1 : Serial.print("(Once)"); break;
  221. case 0xA2 : Serial.print("(Daily)"); break;
  222. case 0xA3 : Serial.print("(Weekly)"); break;
  223. case 0xA4 : Serial.print("(Monthly)"); break;
  224. case 0xB0 : Serial.print("(Play)"); break;
  225. case 0xB1 : Serial.print("(Pause)"); break;
  226. case 0xB2 : Serial.print("(Record)"); break;
  227. case 0xB3 : Serial.print("(Fast Forward)"); break;
  228. case 0xB4 : Serial.print("(Rewind)"); break;
  229. case 0xB5 : Serial.print("(Scan Next Track)"); break;
  230. case 0xB6 : Serial.print("(Scan Previous Track)"); break;
  231. case 0xB7 : Serial.print("(Stop)"); break;
  232. case 0xB8 : Serial.print("(Eject)"); break;
  233. case 0xB9 : Serial.print("(Random Play)"); break;
  234. case 0xBA : Serial.print("(Select DisC)"); break;
  235. case 0xBB : Serial.print("(Enter Disc)"); break;
  236. case 0xBC : Serial.print("(Repeat)"); break;
  237. case 0xBD : Serial.print("(Tracking)"); break;
  238. case 0xBE : Serial.print("(Track Normal)"); break;
  239. case 0xBF : Serial.print("(Slow Tracking)"); break;
  240. case 0xC0 : Serial.print("(Frame Forward)"); break;
  241. case 0xC1 : Serial.print("(Frame Back)"); break;
  242. case 0xC2 : Serial.print("(Mark)"); break;
  243. case 0xC3 : Serial.print("(Clear Mark)"); break;
  244. case 0xC4 : Serial.print("(Repeat From Mark)"); break;
  245. case 0xC5 : Serial.print("(Return To Mark)"); break;
  246. case 0xC6 : Serial.print("(Search Mark Forward)"); break;
  247. case 0xC7 : Serial.print("(Search Mark Backwards)"); break;
  248. case 0xC8 : Serial.print("(Counter Reset)"); break;
  249. case 0xC9 : Serial.print("(Show Counter)"); break;
  250. case 0xCA : Serial.print("(Tracking Increment)"); break;
  251. case 0xCB : Serial.print("(Tracking Decrement)"); break;
  252. case 0xCD : Serial.print("(Pause/Continue)"); break;
  253. case 0xE0 : Serial.print("(Volume)"); break;
  254. case 0xE1 : Serial.print("(Balance)"); break;
  255. case 0xE2 : Serial.print("(Mute)"); break;
  256. case 0xE3 : Serial.print("(Bass)"); break;
  257. case 0xE4 : Serial.print("(Treble)"); break;
  258. case 0xE5 : Serial.print("(Bass Boost)"); break;
  259. case 0xE6 : Serial.print("(Surround Mode)"); break;
  260. case 0xE7 : Serial.print("(Loudness)"); break;
  261. case 0xE8 : Serial.print("(MPX)"); break;
  262. case 0xE9 : Serial.print("(Volume Up)"); break;
  263. case 0xEA : Serial.print("(Volume Down)"); break;
  264. case 0xF0 : Serial.print("(Speed Select)"); break;
  265. case 0xF1 : Serial.print("(Playback Speed)"); break;
  266. case 0xF2 : Serial.print("(Standard Play)"); break;
  267. case 0xF3 : Serial.print("(Long Play)"); break;
  268. case 0xF4 : Serial.print("(Extended Play)"); break;
  269. case 0xF5 : Serial.print("(Slow)"); break;
  270. case 0x100: Serial.print("(Fan Enable)"); break;
  271. case 0x101: Serial.print("(Fan Speed)"); break;
  272. case 0x102: Serial.print("(Light)"); break;
  273. case 0x103: Serial.print("(Light Illumination Level)"); break;
  274. case 0x104: Serial.print("(Climate Control Enable)"); break;
  275. case 0x105: Serial.print("(Room Temperature)"); break;
  276. case 0x106: Serial.print("(Security Enable)"); break;
  277. case 0x107: Serial.print("(Fire Alarm)"); break;
  278. case 0x108: Serial.print("(Police Alarm)"); break;
  279. case 0x150: Serial.print("(Balance Right)"); break;
  280. case 0x151: Serial.print("(Balance Left)"); break;
  281. case 0x152: Serial.print("(Bass Increment)"); break;
  282. case 0x153: Serial.print("(Bass Decrement)"); break;
  283. case 0x154: Serial.print("(Treble Increment)"); break;
  284. case 0x155: Serial.print("(Treble Decrement)"); break;
  285. case 0x160: Serial.print("(Speaker System)"); break;
  286. case 0x161: Serial.print("(Channel Left)"); break;
  287. case 0x162: Serial.print("(Channel Right)"); break;
  288. case 0x163: Serial.print("(Channel Center)"); break;
  289. case 0x164: Serial.print("(Channel Front)"); break;
  290. case 0x165: Serial.print("(Channel Center Front)"); break;
  291. case 0x166: Serial.print("(Channel Side)"); break;
  292. case 0x167: Serial.print("(Channel Surround)"); break;
  293. case 0x168: Serial.print("(Channel Low Frequency Enhancement)"); break;
  294. case 0x169: Serial.print("(Channel Top)"); break;
  295. case 0x16A: Serial.print("(Channel Unknown)"); break;
  296. case 0x170: Serial.print("(Sub-channel)"); break;
  297. case 0x171: Serial.print("(Sub-channel Increment)"); break;
  298. case 0x172: Serial.print("(Sub-channel Decrement)"); break;
  299. case 0x173: Serial.print("(Alternate Audio Increment)"); break;
  300. case 0x174: Serial.print("(Alternate Audio Decrement)"); break;
  301. case 0x180: Serial.print("(Application Launch Buttons)"); break;
  302. case 0x181: Serial.print("(AL Launch Button Configuration Tool)"); break;
  303. case 0x182: Serial.print("(AL Programmable Button Configuration)"); break;
  304. case 0x183: Serial.print("(AL Consumer Control Configuration)"); break;
  305. case 0x184: Serial.print("(AL Word Processor)"); break;
  306. case 0x185: Serial.print("(AL Text Editor)"); break;
  307. case 0x186: Serial.print("(AL Spreadsheet)"); break;
  308. case 0x187: Serial.print("(AL Graphics Editor)"); break;
  309. case 0x188: Serial.print("(AL Presentation App)"); break;
  310. case 0x189: Serial.print("(AL Database App)"); break;
  311. case 0x18A: Serial.print("(AL Email Reader)"); break;
  312. case 0x18B: Serial.print("(AL Newsreader)"); break;
  313. case 0x18C: Serial.print("(AL Voicemail)"); break;
  314. case 0x18D: Serial.print("(AL Contacts/Address Book)"); break;
  315. case 0x18E: Serial.print("(AL Calendar/Schedule)"); break;
  316. case 0x18F: Serial.print("(AL Task/Project Manager)"); break;
  317. case 0x190: Serial.print("(AL Log/Journal/Timecard)"); break;
  318. case 0x191: Serial.print("(AL Checkbook/Finance)"); break;
  319. case 0x192: Serial.print("(AL Calculator)"); break;
  320. case 0x193: Serial.print("(AL A/V Capture/Playback)"); break;
  321. case 0x194: Serial.print("(AL Local Machine Browser)"); break;
  322. case 0x195: Serial.print("(AL LAN/WAN Browser)"); break;
  323. case 0x196: Serial.print("(AL Internet Browser)"); break;
  324. case 0x197: Serial.print("(AL Remote Networking/ISP Connect)"); break;
  325. case 0x198: Serial.print("(AL Network Conference)"); break;
  326. case 0x199: Serial.print("(AL Network Chat)"); break;
  327. case 0x19A: Serial.print("(AL Telephony/Dialer)"); break;
  328. case 0x19B: Serial.print("(AL Logon)"); break;
  329. case 0x19C: Serial.print("(AL Logoff)"); break;
  330. case 0x19D: Serial.print("(AL Logon/Logoff)"); break;
  331. case 0x19E: Serial.print("(AL Terminal Lock/Screensaver)"); break;
  332. case 0x19F: Serial.print("(AL Control Panel)"); break;
  333. case 0x1A0: Serial.print("(AL Command Line Processor/Run)"); break;
  334. case 0x1A1: Serial.print("(AL Process/Task Manager)"); break;
  335. case 0x1A2: Serial.print("(AL Select Tast/Application)"); break;
  336. case 0x1A3: Serial.print("(AL Next Task/Application)"); break;
  337. case 0x1A4: Serial.print("(AL Previous Task/Application)"); break;
  338. case 0x1A5: Serial.print("(AL Preemptive Halt Task/Application)"); break;
  339. case 0x200: Serial.print("(Generic GUI Application Controls)"); break;
  340. case 0x201: Serial.print("(AC New)"); break;
  341. case 0x202: Serial.print("(AC Open)"); break;
  342. case 0x203: Serial.print("(AC Close)"); break;
  343. case 0x204: Serial.print("(AC Exit)"); break;
  344. case 0x205: Serial.print("(AC Maximize)"); break;
  345. case 0x206: Serial.print("(AC Minimize)"); break;
  346. case 0x207: Serial.print("(AC Save)"); break;
  347. case 0x208: Serial.print("(AC Print)"); break;
  348. case 0x209: Serial.print("(AC Properties)"); break;
  349. case 0x21A: Serial.print("(AC Undo)"); break;
  350. case 0x21B: Serial.print("(AC Copy)"); break;
  351. case 0x21C: Serial.print("(AC Cut)"); break;
  352. case 0x21D: Serial.print("(AC Paste)"); break;
  353. case 0x21E: Serial.print("(AC Select All)"); break;
  354. case 0x21F: Serial.print("(AC Find)"); break;
  355. case 0x220: Serial.print("(AC Find and Replace)"); break;
  356. case 0x221: Serial.print("(AC Search)"); break;
  357. case 0x222: Serial.print("(AC Go To)"); break;
  358. case 0x223: Serial.print("(AC Home)"); break;
  359. case 0x224: Serial.print("(AC Back)"); break;
  360. case 0x225: Serial.print("(AC Forward)"); break;
  361. case 0x226: Serial.print("(AC Stop)"); break;
  362. case 0x227: Serial.print("(AC Refresh)"); break;
  363. case 0x228: Serial.print("(AC Previous Link)"); break;
  364. case 0x229: Serial.print("(AC Next Link)"); break;
  365. case 0x22A: Serial.print("(AC Bookmarks)"); break;
  366. case 0x22B: Serial.print("(AC History)"); break;
  367. case 0x22C: Serial.print("(AC Subscriptions)"); break;
  368. case 0x22D: Serial.print("(AC Zoom In)"); break;
  369. case 0x22E: Serial.print("(AC Zoom Out)"); break;
  370. case 0x22F: Serial.print("(AC Zoom)"); break;
  371. case 0x230: Serial.print("(AC Full Screen View)"); break;
  372. case 0x231: Serial.print("(AC Normal View)"); break;
  373. case 0x232: Serial.print("(AC View Toggle)"); break;
  374. case 0x233: Serial.print("(AC Scroll Up)"); break;
  375. case 0x234: Serial.print("(AC Scroll Down)"); break;
  376. case 0x235: Serial.print("(AC Scroll)"); break;
  377. case 0x236: Serial.print("(AC Pan Left)"); break;
  378. case 0x237: Serial.print("(AC Pan Right)"); break;
  379. case 0x238: Serial.print("(AC Pan)"); break;
  380. case 0x239: Serial.print("(AC New Window)"); break;
  381. case 0x23A: Serial.print("(AC Tile Horizontally)"); break;
  382. case 0x23B: Serial.print("(AC Tile Vertically)"); break;
  383. case 0x23C: Serial.print("(AC Format)"); break;
  384. }
  385. break;
  386. }
  387. Serial.println();
  388. }
  389. }
  390. void HIDDumpController::hid_input_end()
  391. {
  392. // Lets do simplified data for changed only
  393. if (changed_data_only) return;
  394. hid_input_begin_level_--;
  395. indent_level(hid_input_begin_level_);
  396. Serial.println("END:");
  397. }