Open FFBoard
Open source force feedback firmware
hub.h
Go to the documentation of this file.
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
92} descriptor_hub_desc_t;
93
94TU_VERIFY_STATIC( sizeof(descriptor_hub_desc_t) == 9, "size is not correct");
95
96enum {
99
101
109
110enum {
114
115enum{
121
124
133
134// data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub)
135typedef struct {
136 union{
137 struct TU_ATTR_PACKED {
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 {
158
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,
177
178// Set feature
179bool hub_port_set_feature (uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
181
182// Get port status
183bool hub_port_get_status (uint8_t hub_addr, uint8_t hub_port, void* resp,
185
186// Get status from Interrupt endpoint
187bool hub_edpt_status_xfer(uint8_t dev_addr);
188
189// Reset a port
190TU_ATTR_ALWAYS_INLINE static inline
191bool hub_port_reset(uint8_t hub_addr, uint8_t hub_port, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
193}
194
195// Clear Reset Change
196TU_ATTR_ALWAYS_INLINE static inline
197bool hub_port_clear_reset_change(uint8_t hub_addr, uint8_t hub_port, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
199}
200
201
202//--------------------------------------------------------------------+
203// Internal Class Driver API
204//--------------------------------------------------------------------+
205bool hub_init (void);
206bool hub_deinit (void);
207bool hub_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
208bool hub_set_config (uint8_t dev_addr, uint8_t itf_num);
209bool hub_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
210void hub_close (uint8_t dev_addr);
211
212#ifdef __cplusplus
213 }
214#endif
215
216#endif /* _TUSB_HUB_H_ */
217
uint8_t dev_addr
Definition: dcd_pic32mz.c:81
bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void *resp, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
Definition: hub.c:150
void hub_close(uint8_t dev_addr)
Definition: hub.c:224
bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
Definition: hub.c:194
bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
Definition: hub.c:86
bool hub_deinit(void)
Definition: hub.c:190
bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
Definition: hub.c:334
bool hub_edpt_status_xfer(uint8_t dev_addr)
Definition: hub.c:235
TU_VERIFY_STATIC(sizeof(descriptor_hub_desc_t)==9, "size is not correct")
bool hub_init(void)
Definition: hub.c:185
static TU_ATTR_ALWAYS_INLINE bool hub_port_clear_reset_change(uint8_t hub_addr, uint8_t hub_port, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
Definition: hub.h:197
bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
Definition: hub.c:118
bool hub_set_config(uint8_t dev_addr, uint8_t itf_num)
Definition: hub.c:249
static TU_ATTR_ALWAYS_INLINE bool hub_port_reset(uint8_t hub_addr, uint8_t hub_port, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
Definition: hub.h:191
@ HUB_FEATURE_HUB_LOCAL_POWER_CHANGE
Definition: hub.h:111
@ HUB_FEATURE_HUB_OVER_CURRENT_CHANGE
Definition: hub.h:112
@ HUB_REQUEST_STOP_TT
Definition: hub.h:107
@ HUB_REQUEST_SET_DESCRIPTOR
Definition: hub.h:103
@ HUB_REQUEST_RESET_TT
Definition: hub.h:105
@ HUB_REQUEST_CLEAR_TT_BUFFER
Definition: hub.h:104
@ HUB_REQUEST_CLEAR_FEATURE
Definition: hub.h:98
@ HUB_REQUEST_SET_FEATURE
Definition: hub.h:100
@ HUB_REQUEST_GET_STATUS
Definition: hub.h:97
@ HUB_REQUEST_GET_DESCRIPTOR
Definition: hub.h:102
@ HUB_REQUEST_GET_TT_STATE
Definition: hub.h:106
@ HUB_FEATURE_PORT_OVER_CURRENT
Definition: hub.h:119
@ HUB_FEATURE_PORT_RESET_CHANGE
Definition: hub.h:129
@ HUB_FEATURE_PORT_SUSPEND_CHANGE
Definition: hub.h:127
@ HUB_FEATURE_PORT_LOW_SPEED
Definition: hub.h:123
@ HUB_FEATURE_PORT_CONNECTION
Definition: hub.h:116
@ HUB_FEATURE_PORT_ENABLE
Definition: hub.h:117
@ HUB_FEATURE_PORT_ENABLE_CHANGE
Definition: hub.h:126
@ HUB_FEATURE_PORT_TEST
Definition: hub.h:130
@ HUB_FEATURE_PORT_CONNECTION_CHANGE
Definition: hub.h:125
@ HUB_FEATURE_PORT_RESET
Definition: hub.h:120
@ HUB_FEATURE_PORT_POWER
Definition: hub.h:122
@ HUB_FEATURE_PORT_SUSPEND
Definition: hub.h:118
@ HUB_FEATURE_PORT_OVER_CURRENT_CHANGE
Definition: hub.h:128
@ HUB_FEATURE_PORT_INDICATOR
Definition: hub.h:131
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
volatile uint16_t
Definition: hcd_rusb2.c:58
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
uint16_t port_indicator_control
Definition: hub.h:164
uint16_t over_current
Definition: hub.h:156
uint16_t port_enable
Definition: hub.h:154
uint16_t TU_RESERVED
Definition: hub.h:165
uint16_t port_test_mode
Definition: hub.h:163
uint16_t local_power_source
Definition: hub.h:138
uint16_t over_current
Definition: hub.h:139
uint16_t value
Definition: hub.h:143
xfer_result_t
Definition: tusb_types.h:236
uintptr_t user_data
Definition: usbh.c:262
tuh_xfer_cb_t complete_cb
Definition: usbh.c:261
void(* tuh_xfer_cb_t)(tuh_xfer_t *xfer)
Definition: usbh.h:44