]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/USBHost/USBHostHub/USBHostHub.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / USBHost / USBHostHub / USBHostHub.h
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
17 #ifndef USBHOSTHUB_H
18 #define USBHOSTHUB_H
19
20 #include "USBHostConf.h"
21
22 #if MAX_HUB_NB
23
24 #include "USBHostTypes.h"
25 #include "IUSBEnumerator.h"
26
27 class USBHost;
28 class USBDeviceConnected;
29 class USBEndpoint;
30
31 /**
32  * A class to use a USB Hub
33  */
34 class USBHostHub : public IUSBEnumerator {
35 public:
36     /**
37     * Constructor
38     */
39     USBHostHub();
40
41     /**
42     * Check if a USB Hub is connected
43     *
44     * @return true if a serial device is connected
45     */
46     bool connected();
47
48     /**
49      * Try to connect device
50      *
51      * @param dev device to connect
52      * @return true if connection was successful
53      */
54     bool connect(USBDeviceConnected * dev);
55
56     /**
57     * Automatically called by USBHost when a device
58     * has been enumerated by usb_thread
59     *
60     * @param dev device connected
61     */
62     void deviceConnected(USBDeviceConnected * dev);
63
64     /**
65     * Automatically called by USBHost when a device
66     * has been disconnected from this hub
67     *
68     * @param dev device disconnected
69     */
70     void deviceDisconnected(USBDeviceConnected * dev);
71
72     /**
73     * Rest a specific port
74     *
75     * @param port port number
76     */
77     void portReset(uint8_t port);
78
79     /*
80     * Called by USBHost to set the instance of USBHost
81     *
82     * @param host host instance
83     */
84     void setHost(USBHost * host);
85
86     /**
87     * Called by USBhost when a hub has been disconnected
88     */
89     void hubDisconnected();
90
91 protected:
92     //From IUSBEnumerator
93     virtual void setVidPid(uint16_t vid, uint16_t pid);
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
95     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
96
97 private:
98     USBHost * host;
99     USBDeviceConnected * dev;
100     bool dev_connected;
101     USBEndpoint * int_in;
102     uint8_t nb_port;
103     uint8_t hub_characteristics;
104
105     void rxHandler();
106
107     uint8_t buf[sizeof(HubDescriptor)];
108
109     int hub_intf;
110     bool hub_device_found;
111
112     void setPortFeature(uint32_t feature, uint8_t port);
113     void clearPortFeature(uint32_t feature, uint8_t port);
114     uint32_t getPortStatus(uint8_t port);
115
116     USBDeviceConnected * device_children[MAX_HUB_PORT];
117
118     void init();
119     void disconnect();
120
121 };
122
123 #endif
124
125 #endif