Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* USB EHCI Host for Teensy 3.6
  2. * Copyright 2017 Paul Stoffregen (paul@pjrc.com)
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <Arduino.h>
  24. #include "USBHost_t36.h" // Read this header first for key info
  25. void RawHIDController::init()
  26. {
  27. USBHost::contribute_Transfers(mytransfers, sizeof(mytransfers)/sizeof(Transfer_t));
  28. USBHIDParser::driver_ready_for_hid_collection(this);
  29. }
  30. hidclaim_t RawHIDController::claim_collection(USBHIDParser *driver, Device_t *dev, uint32_t topusage)
  31. {
  32. // only claim RAWHID devices currently: 16c0:0486
  33. #ifdef USBHOST_PRINT_DEBUG
  34. Serial.printf("Rawhid Claim: %x:%x usage: %x\n", dev->idVendor, dev->idProduct, topusage);
  35. #endif
  36. if ((dev->idVendor != 0x16c0 || (dev->idProduct) != 0x486)) return CLAIM_NO;
  37. if (mydevice != NULL && dev != mydevice) return CLAIM_NO;
  38. if (usage_) return CLAIM_NO; // Only claim one
  39. if (fixed_usage_ && (fixed_usage_ != topusage)) return CLAIM_NO; // See if we want specific one and if so is it this one
  40. mydevice = dev;
  41. collections_claimed++;
  42. usage_ = topusage;
  43. driver_ = driver; // remember the driver.
  44. return CLAIM_INTERFACE; // We wa
  45. }
  46. void RawHIDController::disconnect_collection(Device_t *dev)
  47. {
  48. if (--collections_claimed == 0) {
  49. mydevice = NULL;
  50. usage_ = 0;
  51. }
  52. }
  53. bool RawHIDController::hid_process_in_data(const Transfer_t *transfer)
  54. {
  55. #ifdef USBHOST_PRINT_DEBUG
  56. Serial.printf("RawHIDController::hid_process_in_data: %x\n", usage_);
  57. #endif
  58. if (receiveCB) {
  59. return (*receiveCB)(usage_, (const uint8_t *)transfer->buffer, transfer->length);
  60. }
  61. return true;
  62. }
  63. bool RawHIDController::hid_process_out_data(const Transfer_t *transfer)
  64. {
  65. #ifdef USBHOST_PRINT_DEBUG
  66. Serial.printf("RawHIDController::hid_process_out_data: %x\n", usage_);
  67. #endif
  68. return true;
  69. }
  70. bool RawHIDController::sendPacket(const uint8_t *buffer)
  71. {
  72. if (!driver_) return false;
  73. return driver_->sendPacket(buffer);
  74. }
  75. void RawHIDController::hid_input_begin(uint32_t topusage, uint32_t type, int lgmin, int lgmax)
  76. {
  77. // These should not be called as we are claiming the whole interface and not
  78. // allowing the parse to happen
  79. #ifdef USBHOST_PRINT_DEBUG
  80. Serial.printf("RawHID::hid_input_begin %x %x %x %x\n", topusage, type, lgmin, lgmax);
  81. #endif
  82. //hid_input_begin_ = true;
  83. }
  84. void RawHIDController::hid_input_data(uint32_t usage, int32_t value)
  85. {
  86. // These should not be called as we are claiming the whole interface and not
  87. // allowing the parse to happen
  88. #ifdef USBHOST_PRINT_DEBUG
  89. Serial.printf("RawHID: usage=%X, value=%d", usage, value);
  90. if ((value >= ' ') && (value <='~')) Serial.printf("(%c)", value);
  91. Serial.println();
  92. #endif
  93. }
  94. void RawHIDController::hid_input_end()
  95. {
  96. // These should not be called as we are claiming the whole interface and not
  97. // allowing the parse to happen
  98. #ifdef USBHOST_PRINT_DEBUG
  99. Serial.println("RawHID::hid_input_end");
  100. #endif
  101. // if (hid_input_begin_) {
  102. // hid_input_begin_ = false;
  103. // }
  104. }