mikroSDK Reference Manual
hub.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
36#ifndef _TUSB_HUB_H_
37#define _TUSB_HUB_H_
38
39#include "common/tusb_common.h"
40
41#ifdef __cplusplus
42 extern "C" {
43#endif
44
45//D1...D0: Logical Power Switching Mode
46//00: Ganged power switching (all ports’power at
47//once)
48//01: Individual port power switching
49//1X: Reserved. Used only on 1.0 compliant hubs
50//that implement no power switching
51//D2: Identifies a Compound Device
52//0: Hub is not part of a compound device.
53//1: Hub is part of a compound device.
54//D4...D3: Over-current Protection Mode
55//00: Global Over-current Protection. The hub
56//reports over-current as a summation of all
57//ports’current draw, without a breakdown of
58//individual port over-current status.
59//01: Individual Port Over-current Protection. The
60//hub reports over-current on a per-port basis.
61//Each port has an over-current status.
62//1X: No Over-current Protection. This option is
63//allowed only for bus-powered hubs that do not
64//implement over-current protection.
65//
66//D6...D5: TT Think TIme
67//00: TT requires at most 8 FS bit times of inter
68//transaction gap on a full-/low-speed
69//downstream bus.
70//01: TT requires at most 16 FS bit times.
71//10: TT requires at most 24 FS bit times.
72//11: TT requires at most 32 FS bit times.
73//D7: Port Indicators Supported
74//0: Port Indicators are not supported on its
75//downstream facing ports and the
76//PORT_INDICATOR request has no effect.
77//1: Port Indicators are supported on its
78//downstream facing ports and the
79//PORT_INDICATOR request controls the
80//indicators. See Section 11.5.3.
81//D15...D8: Reserved
82
83typedef struct TU_ATTR_PACKED{
84 uint8_t bLength ;
85 uint8_t bDescriptorType ;
86 uint8_t bNbrPorts;
87 uint16_t wHubCharacteristics;
88 uint8_t bPwrOn2PwrGood;
89 uint8_t bHubContrCurrent;
90 uint8_t DeviceRemovable; // bitmap each bit for a port (from bit1)
91 uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff
93
94TU_VERIFY_STATIC( sizeof(descriptor_hub_desc_t) == 9, "size is not correct");
95
96enum {
97 HUB_REQUEST_GET_STATUS = 0 ,
98 HUB_REQUEST_CLEAR_FEATURE = 1 ,
99
100 HUB_REQUEST_SET_FEATURE = 3 ,
101
102 HUB_REQUEST_GET_DESCRIPTOR = 6 ,
103 HUB_REQUEST_SET_DESCRIPTOR = 7 ,
104 HUB_REQUEST_CLEAR_TT_BUFFER = 8 ,
105 HUB_REQUEST_RESET_TT = 9 ,
106 HUB_REQUEST_GET_TT_STATE = 10 ,
107 HUB_REQUEST_STOP_TT = 11
108};
109
110enum {
111 HUB_FEATURE_HUB_LOCAL_POWER_CHANGE = 0,
112 HUB_FEATURE_HUB_OVER_CURRENT_CHANGE
113};
114
115enum{
116 HUB_FEATURE_PORT_CONNECTION = 0,
117 HUB_FEATURE_PORT_ENABLE = 1,
118 HUB_FEATURE_PORT_SUSPEND = 2,
119 HUB_FEATURE_PORT_OVER_CURRENT = 3,
120 HUB_FEATURE_PORT_RESET = 4,
121
122 HUB_FEATURE_PORT_POWER = 8,
123 HUB_FEATURE_PORT_LOW_SPEED = 9,
124
125 HUB_FEATURE_PORT_CONNECTION_CHANGE = 16,
126 HUB_FEATURE_PORT_ENABLE_CHANGE = 17,
127 HUB_FEATURE_PORT_SUSPEND_CHANGE = 18,
128 HUB_FEATURE_PORT_OVER_CURRENT_CHANGE = 19,
129 HUB_FEATURE_PORT_RESET_CHANGE = 20,
130 HUB_FEATURE_PORT_TEST = 21,
131 HUB_FEATURE_PORT_INDICATOR = 22
132};
133
134// data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub)
135typedef struct {
136 union{
137 struct TU_ATTR_PACKED {
138 uint16_t local_power_source : 1;
139 uint16_t over_current : 1;
140 uint16_t : 14;
141 };
142
143 uint16_t value;
144 } status, change;
146
147TU_VERIFY_STATIC( sizeof(hub_status_response_t) == 4, "size is not correct");
148
149// data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num
150typedef struct {
151 union {
152 struct TU_ATTR_PACKED {
153 uint16_t connection : 1;
154 uint16_t port_enable : 1;
155 uint16_t suspend : 1;
156 uint16_t over_current : 1;
157 uint16_t reset : 1;
158
159 uint16_t : 3;
160 uint16_t port_power : 1;
161 uint16_t low_speed : 1;
162 uint16_t high_speed : 1;
163 uint16_t port_test_mode : 1;
164 uint16_t port_indicator_control : 1;
165 uint16_t TU_RESERVED : 3;
166 };
167
168 uint16_t value;
169 } status, change;
171
172TU_VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct");
173
174// Clear feature
175bool hub_port_clear_feature (uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
176 tuh_xfer_cb_t complete_cb, uintptr_t user_data);
177
178// Set feature
179bool hub_port_set_feature (uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
180 tuh_xfer_cb_t complete_cb, uintptr_t user_data);
181
182// Get port status
183bool hub_port_get_status (uint8_t hub_addr, uint8_t hub_port, void* resp,
184 tuh_xfer_cb_t complete_cb, uintptr_t user_data);
185
186// Get status from Interrupt endpoint
187bool hub_edpt_status_xfer(uint8_t dev_addr);
188
189// Reset a port
190static inline bool hub_port_reset(uint8_t hub_addr, uint8_t hub_port,
191 tuh_xfer_cb_t complete_cb, uintptr_t user_data)
192{
193 return hub_port_set_feature(hub_addr, hub_port, HUB_FEATURE_PORT_RESET, complete_cb, user_data);
194}
195
196// Clear Reset Change
197static inline bool hub_port_clear_reset_change(uint8_t hub_addr, uint8_t hub_port,
198 tuh_xfer_cb_t complete_cb, uintptr_t user_data)
199{
200 return hub_port_clear_feature(hub_addr, hub_port, HUB_FEATURE_PORT_RESET_CHANGE, complete_cb, user_data);
201}
202
203
204//--------------------------------------------------------------------+
205// Internal Class Driver API
206//--------------------------------------------------------------------+
207void hub_init (void);
208bool hub_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
209bool hub_set_config (uint8_t dev_addr, uint8_t itf_num);
210bool hub_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
211void hub_close (uint8_t dev_addr);
212
213#ifdef __cplusplus
214 }
215#endif
216
217#endif /* _TUSB_HUB_H_ */
218
uint8_t bDescriptorType
Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
Definition audio.h:657
uint8_t bLength
Size of this descriptor in bytes: 9.
Definition audio.h:656
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
Definition hub.h:150
Definition hub.h:135