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