Keyboard firmwares for Atmel AVR and Cortex-M
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.

USBHostHub.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* mbed USBHost Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef USBHOSTHUB_H
  17. #define USBHOSTHUB_H
  18. #include "USBHostConf.h"
  19. #if MAX_HUB_NB
  20. #include "USBHostTypes.h"
  21. #include "IUSBEnumerator.h"
  22. class USBHost;
  23. class USBDeviceConnected;
  24. class USBEndpoint;
  25. /**
  26. * A class to use a USB Hub
  27. */
  28. class USBHostHub : public IUSBEnumerator {
  29. public:
  30. /**
  31. * Constructor
  32. */
  33. USBHostHub();
  34. /**
  35. * Check if a USB Hub is connected
  36. *
  37. * @return true if a serial device is connected
  38. */
  39. bool connected();
  40. /**
  41. * Try to connect device
  42. *
  43. * @param dev device to connect
  44. * @return true if connection was successful
  45. */
  46. bool connect(USBDeviceConnected * dev);
  47. /**
  48. * Automatically called by USBHost when a device
  49. * has been enumerated by usb_thread
  50. *
  51. * @param dev device connected
  52. */
  53. void deviceConnected(USBDeviceConnected * dev);
  54. /**
  55. * Automatically called by USBHost when a device
  56. * has been disconnected from this hub
  57. *
  58. * @param dev device disconnected
  59. */
  60. void deviceDisconnected(USBDeviceConnected * dev);
  61. /**
  62. * Rest a specific port
  63. *
  64. * @param port port number
  65. */
  66. void portReset(uint8_t port);
  67. /*
  68. * Called by USBHost to set the instance of USBHost
  69. *
  70. * @param host host instance
  71. */
  72. void setHost(USBHost * host);
  73. /**
  74. * Called by USBhost when a hub has been disconnected
  75. */
  76. void hubDisconnected();
  77. protected:
  78. //From IUSBEnumerator
  79. virtual void setVidPid(uint16_t vid, uint16_t pid);
  80. virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
  81. virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
  82. private:
  83. USBHost * host;
  84. USBDeviceConnected * dev;
  85. bool dev_connected;
  86. USBEndpoint * int_in;
  87. uint8_t nb_port;
  88. uint8_t hub_characteristics;
  89. void rxHandler();
  90. uint8_t buf[sizeof(HubDescriptor)];
  91. int hub_intf;
  92. bool hub_device_found;
  93. void setPortFeature(uint32_t feature, uint8_t port);
  94. void clearPortFeature(uint32_t feature, uint8_t port);
  95. uint32_t getPortStatus(uint8_t port);
  96. USBDeviceConnected * device_children[MAX_HUB_PORT];
  97. void init();
  98. void disconnect();
  99. };
  100. #endif
  101. #endif