tinyusb
hub.h
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
48 #ifndef _TUSB_HUB_H_
49 #define _TUSB_HUB_H_
50 
51 #include "common/common.h"
52 #include "usbh.h"
53 
54 #ifdef __cplusplus
55  extern "C" {
56 #endif
57 
58 //D1...D0: Logical Power Switching Mode
59 //00: Ganged power switching (all ports’power at
60 //once)
61 //01: Individual port power switching
62 //1X: Reserved. Used only on 1.0 compliant hubs
63 //that implement no power switching
64 //D2: Identifies a Compound Device
65 //0: Hub is not part of a compound device.
66 //1: Hub is part of a compound device.
67 //D4...D3: Over-current Protection Mode
68 //00: Global Over-current Protection. The hub
69 //reports over-current as a summation of all
70 //ports’current draw, without a breakdown of
71 //individual port over-current status.
72 //01: Individual Port Over-current Protection. The
73 //hub reports over-current on a per-port basis.
74 //Each port has an over-current status.
75 //1X: No Over-current Protection. This option is
76 //allowed only for bus-powered hubs that do not
77 //implement over-current protection.
78 //
79 //D6...D5: TT Think TIme
80 //00: TT requires at most 8 FS bit times of inter
81 //transaction gap on a full-/low-speed
82 //downstream bus.
83 //01: TT requires at most 16 FS bit times.
84 //10: TT requires at most 24 FS bit times.
85 //11: TT requires at most 32 FS bit times.
86 //D7: Port Indicators Supported
87 //0: Port Indicators are not supported on its
88 //downstream facing ports and the
89 //PORT_INDICATOR request has no effect.
90 //1: Port Indicators are supported on its
91 //downstream facing ports and the
92 //PORT_INDICATOR request controls the
93 //indicators. See Section 11.5.3.
94 //D15...D8: Reserved
95 
96 typedef ATTR_PACKED_STRUCT(struct){
97  uint8_t bLength ;
98  uint8_t bDescriptorType ;
99  uint8_t bNbrPorts;
100  uint16_t wHubCharacteristics;
101  uint8_t bPwrOn2PwrGood;
102  uint8_t bHubContrCurrent;
103  uint8_t DeviceRemovable; // bitmap each bit for a port (from bit1)
104  uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff
106 
107 STATIC_ASSERT( sizeof(descriptor_hub_desc_t) == 9, "size is not correct");
108 
109 enum {
110  HUB_REQUEST_GET_STATUS = 0 ,
111  HUB_REQUEST_CLEAR_FEATURE = 1 ,
112 
113  HUB_REQUEST_SET_FEATURE = 3 ,
114 
115  HUB_REQUEST_GET_DESCRIPTOR = 6 ,
116  HUB_REQUEST_SET_DESCRIPTOR = 7 ,
117  HUB_REQUEST_CLEAR_TT_BUFFER = 8 ,
118  HUB_REQUEST_RESET_TT = 9 ,
119  HUB_REQUEST_GET_TT_STATE = 10 ,
120  HUB_REQUEST_STOP_TT = 11
121 };
122 
123 enum {
124  HUB_FEATURE_HUB_LOCAL_POWER_CHANGE = 0,
125  HUB_FEATURE_HUB_OVER_CURRENT_CHANGE
126 };
127 
128 enum{
129  HUB_FEATURE_PORT_CONNECTION = 0,
130  HUB_FEATURE_PORT_ENABLE = 1,
131  HUB_FEATURE_PORT_SUSPEND = 2,
132  HUB_FEATURE_PORT_OVER_CURRENT = 3,
133  HUB_FEATURE_PORT_RESET = 4,
134 
135  HUB_FEATURE_PORT_POWER = 8,
136  HUB_FEATURE_PORT_LOW_SPEED = 9,
137 
138  HUB_FEATURE_PORT_CONNECTION_CHANGE = 16,
139  HUB_FEATURE_PORT_ENABLE_CHANGE = 17,
140  HUB_FEATURE_PORT_SUSPEND_CHANGE = 18,
141  HUB_FEATURE_PORT_OVER_CURRENT_CHANGE = 19,
142  HUB_FEATURE_PORT_RESET_CHANGE = 20,
143  HUB_FEATURE_PORT_TEST = 21,
144  HUB_FEATURE_PORT_INDICATOR = 22
145 };
146 
147 // data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub)
148 typedef struct {
149  union{
150  ATTR_PACKED_STRUCT(struct) {
151  uint16_t local_power_source : 1;
152  uint16_t over_current : 1;
153  uint16_t : 14;
154  };
155 
156  uint16_t value;
157  } status, status_change;
159 
160 STATIC_ASSERT( sizeof(hub_status_response_t) == 4, "size is not correct");
161 
162 // data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num
163 typedef struct {
164  union {
165  ATTR_PACKED_STRUCT(struct) {
166  uint16_t connect_status : 1;
167  uint16_t port_enable : 1;
168  uint16_t suspend : 1;
169  uint16_t over_current : 1;
170  uint16_t reset : 1;
171 
172  uint16_t : 3;
173  uint16_t port_power : 1;
174  uint16_t low_speed_device_attached : 1;
175  uint16_t high_speed_device_attached : 1;
176  uint16_t port_test_mode : 1;
177  uint16_t port_indicator_control : 1;
178  uint16_t : 0;
179  };
180 
181  uint16_t value;
182  } status_current, status_change;
184 
185 STATIC_ASSERT( sizeof(hub_port_status_response_t) == 4, "size is not correct");
186 
187 tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port);
188 tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature);
189 tusb_speed_t hub_port_get_speed(void);
190 tusb_error_t hub_status_pipe_queue(uint8_t dev_addr);
191 
192 //--------------------------------------------------------------------+
193 // USBH-CLASS DRIVER API
194 //--------------------------------------------------------------------+
195 #ifdef _TINY_USB_SOURCE_FILE_
196 
197 void hub_init(void);
198 tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
199 void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
200 void hub_close(uint8_t dev_addr);
201 
202 #endif
203 
204 #ifdef __cplusplus
205  }
206 #endif
207 
208 #endif /* _TUSB_HUB_H_ */
209 
USB Standard Interface Descriptor (section 9.6.1 table 9-12)
Definition: std_descriptors.h:90
tusb_speed_t
defined base on EHCI specs value for Endpoint Speed
Definition: tusb_types.h:51
#define ATTR_WARN_UNUSED_RESULT
The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this...
Definition: compiler_gcc.h:118
uint8_t bLength
Size of descriptor.
Definition: hub.h:97
Definition: hcd.h:55
uint8_t bDescriptorType
Other_speed_Configuration Type.
Definition: hub.h:98
Definition: hub.h:96
Definition: hub.h:148
tusb_error_t
Error Code returned.
Definition: tusb_errors.h:100
Definition: hub.h:163