Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

rawhid.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. USBHDBGSerial.printf("Rawhid Claim: %x:%x usage: %x\n", dev->idVendor, dev->idProduct, topusage);
  35. #endif
  36. if (dev->idVendor != 0x16c0) return CLAIM_NO; // NOT PJRC
  37. if (mydevice != NULL && dev != mydevice) return CLAIM_NO;
  38. if (usage_) return CLAIM_NO; // Only claim one
  39. if (fixed_usage_ ) {
  40. if (fixed_usage_ != topusage) return CLAIM_NO; // See if we want specific one and if so is it this one
  41. } else if (dev->idProduct != 0x486) return CLAIM_NO; // otherwise mainly used for RAWHID Serial type.
  42. mydevice = dev;
  43. collections_claimed++;
  44. usage_ = topusage;
  45. driver_ = driver; // remember the driver.
  46. return CLAIM_INTERFACE; // We wa
  47. }
  48. void RawHIDController::disconnect_collection(Device_t *dev)
  49. {
  50. if (--collections_claimed == 0) {
  51. mydevice = NULL;
  52. usage_ = 0;
  53. }
  54. }
  55. bool RawHIDController::hid_process_in_data(const Transfer_t *transfer)
  56. {
  57. #ifdef USBHOST_PRINT_DEBUG
  58. USBHDBGSerial.printf("RawHIDController::hid_process_in_data: %x\n", usage_);
  59. #endif
  60. if (receiveCB) {
  61. return (*receiveCB)(usage_, (const uint8_t *)transfer->buffer, transfer->length);
  62. }
  63. return true;
  64. }
  65. bool RawHIDController::hid_process_out_data(const Transfer_t *transfer)
  66. {
  67. #ifdef USBHOST_PRINT_DEBUG
  68. USBHDBGSerial.printf("RawHIDController::hid_process_out_data: %x\n", usage_);
  69. #endif
  70. return true;
  71. }
  72. bool RawHIDController::sendPacket(const uint8_t *buffer)
  73. {
  74. if (!driver_) return false;
  75. return driver_->sendPacket(buffer);
  76. }
  77. void RawHIDController::hid_input_begin(uint32_t topusage, uint32_t type, int lgmin, int lgmax)
  78. {
  79. // These should not be called as we are claiming the whole interface and not
  80. // allowing the parse to happen
  81. #ifdef USBHOST_PRINT_DEBUG
  82. USBHDBGSerial.printf("RawHID::hid_input_begin %x %x %x %x\n", topusage, type, lgmin, lgmax);
  83. #endif
  84. //hid_input_begin_ = true;
  85. }
  86. void RawHIDController::hid_input_data(uint32_t usage, int32_t value)
  87. {
  88. // These should not be called as we are claiming the whole interface and not
  89. // allowing the parse to happen
  90. #ifdef USBHOST_PRINT_DEBUG
  91. USBHDBGSerial.printf("RawHID: usage=%X, value=%d", usage, value);
  92. if ((value >= ' ') && (value <='~')) USBHDBGSerial.printf("(%c)", value);
  93. USBHDBGSerial.println();
  94. #endif
  95. }
  96. void RawHIDController::hid_input_end()
  97. {
  98. // These should not be called as we are claiming the whole interface and not
  99. // allowing the parse to happen
  100. #ifdef USBHOST_PRINT_DEBUG
  101. USBHDBGSerial.println("RawHID::hid_input_end");
  102. #endif
  103. // if (hid_input_begin_) {
  104. // hid_input_begin_ = false;
  105. // }
  106. }