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.

109 satır
3.7KB

  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. * Note: special thanks to the Linux kernel for the CH341's method of operation, particularly how the baud rate is encoded.
  24. */
  25. #include <Arduino.h>
  26. #include "USBHost_t36.h" // Read this header first for key info
  27. #define print USBHost::print_
  28. #define println USBHost::println_
  29. /************************************************************/
  30. // Define mapping VID/PID - to Serial Device type.
  31. /************************************************************/
  32. /************************************************************/
  33. // Initialization and claiming of devices & interfaces
  34. /************************************************************/
  35. void BluetoothController::init()
  36. {
  37. contribute_Pipes(mypipes, sizeof(mypipes)/sizeof(Pipe_t));
  38. contribute_Transfers(mytransfers, sizeof(mytransfers)/sizeof(Transfer_t));
  39. contribute_String_Buffers(mystring_bufs, sizeof(mystring_bufs)/sizeof(strbuf_t));
  40. driver_ready_for_device(this);
  41. }
  42. bool BluetoothController::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t len)
  43. {
  44. // only claim at device level
  45. println("BluetoothController claim this=", (uint32_t)this, HEX);
  46. print("vid=", dev->idVendor, HEX);
  47. print(", pid=", dev->idProduct, HEX);
  48. print(", bDeviceClass = ", dev->bDeviceClass, HEX);
  49. print(", bDeviceSubClass = ", dev->bDeviceSubClass, HEX);
  50. println(", bDeviceProtocol = ", dev->bDeviceProtocol, HEX);
  51. print_hexbytes(descriptors, len);
  52. // Lets try to support the main USB Bluetooth class...
  53. // http://www.usb.org/developers/defined_class/#BaseClassE0h
  54. if (dev->bDeviceClass != 0xe0) return false; // not base class wireless controller
  55. if ((dev->bDeviceSubClass != 1) || (dev->bDeviceProtocol != 1)) return false; // Bluetooth Programming Interface
  56. if (type == 0) {
  57. }
  58. return false;
  59. }
  60. void BluetoothController::disconnect()
  61. {
  62. }
  63. void BluetoothController::control(const Transfer_t *transfer)
  64. {
  65. //println("control callback (bluetooth) ", pending_control, HEX);
  66. }
  67. /************************************************************/
  68. // Interrupt-based Data Movement
  69. /************************************************************/
  70. void BluetoothController::rx_callback(const Transfer_t *transfer)
  71. {
  72. if (!transfer->driver) return;
  73. ((BluetoothController *)(transfer->driver))->rx_data(transfer);
  74. }
  75. void BluetoothController::tx_callback(const Transfer_t *transfer)
  76. {
  77. if (!transfer->driver) return;
  78. ((BluetoothController *)(transfer->driver))->tx_data(transfer);
  79. }
  80. void BluetoothController::rx_data(const Transfer_t *transfer)
  81. {
  82. //uint32_t len = transfer->length - ((transfer->qtd.token >> 16) & 0x7FFF);
  83. }
  84. void BluetoothController::tx_data(const Transfer_t *transfer)
  85. {
  86. }