|
12 | 12 |
|
13 | 13 | void USBHostManager::start() { |
14 | 14 | // This will happen after Gamepad has initialized |
15 | | - if (PeripheralManager::getInstance().isUSBEnabled(0)) { |
| 15 | + if (PeripheralManager::getInstance().isUSBEnabled(0) && listeners.size() > 0) { |
| 16 | + sleep_ms(1000); // TinyUSB HOST Start-Up Temporary Fix : TO-DO 06.11.2024 |
16 | 17 | pio_usb_configuration_t* pio_cfg = PeripheralManager::getInstance().getUSB(0)->getController(); |
17 | 18 | tuh_configure(1, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, pio_cfg); |
18 | 19 | tuh_init(BOARD_TUH_RHPORT); |
19 | 20 | sleep_us(10); // ensure we are ready |
20 | 21 | tuh_ready = true; |
| 22 | + } else { |
| 23 | + tuh_ready = false; |
21 | 24 | } |
22 | 25 | } |
23 | 26 |
|
24 | 27 | // Shut down the USB bus if we are running USB right now |
25 | 28 | void USBHostManager::shutdown() { |
26 | | - if (PeripheralManager::getInstance().isUSBEnabled(0)) { |
27 | | - tuh_rhport_reset_bus(BOARD_TUH_RHPORT, false); |
| 29 | + if ( tuh_ready ) { |
| 30 | + tuh_deinit(BOARD_TUH_RHPORT); |
28 | 31 | } |
29 | 32 | } |
30 | 33 |
|
@@ -102,81 +105,8 @@ void USBHostManager::xinput_report_sent_cb(uint8_t dev_addr, uint8_t instance, u |
102 | 105 | } |
103 | 106 | } |
104 | 107 |
|
105 | | -// HID: USB Host |
106 | | -static uint8_t _intf_num = 0; |
107 | | - |
108 | | -// Required helper class for HID_REQ_CONTROL_GET_REPORT addition |
109 | | -uint16_t count_interface_total_len(tusb_desc_interface_t const* desc_itf, uint8_t itf_count, uint16_t max_len) |
110 | | -{ |
111 | | - uint8_t const* p_desc = (uint8_t const*) desc_itf; |
112 | | - uint16_t len = 0; |
113 | | - |
114 | | - while (itf_count--) |
115 | | - { |
116 | | - // Next on interface desc |
117 | | - len += tu_desc_len(desc_itf); |
118 | | - p_desc = tu_desc_next(p_desc); |
119 | | - |
120 | | - while (len < max_len) |
121 | | - { |
122 | | - // return on IAD regardless of itf count |
123 | | - if ( tu_desc_type(p_desc) == TUSB_DESC_INTERFACE_ASSOCIATION ) return len; |
124 | | - |
125 | | - if ( (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE) && |
126 | | - ((tusb_desc_interface_t const*) p_desc)->bAlternateSetting == 0 ) |
127 | | - { |
128 | | - break; |
129 | | - } |
130 | | - |
131 | | - len += tu_desc_len(p_desc); |
132 | | - p_desc = tu_desc_next(p_desc); |
133 | | - } |
134 | | - } |
135 | | - |
136 | | - return len; |
137 | | -} |
138 | | - |
139 | 108 | void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) |
140 | 109 | { |
141 | | - // Get Interface Number for our HID class |
142 | | - uint16_t temp_buf[128]; |
143 | | - |
144 | | - if (XFER_RESULT_SUCCESS == tuh_descriptor_get_configuration_sync(dev_addr, 0, temp_buf, sizeof(temp_buf))) |
145 | | - { |
146 | | - tusb_desc_configuration_t const* desc_cfg = (tusb_desc_configuration_t*) temp_buf; |
147 | | - uint8_t const* desc_end = ((uint8_t const*) desc_cfg) + tu_le16toh(desc_cfg->wTotalLength); |
148 | | - uint8_t const* p_desc = tu_desc_next(desc_cfg); |
149 | | - |
150 | | - // parse each interfaces |
151 | | - while( p_desc < desc_end ) |
152 | | - { |
153 | | - uint8_t assoc_itf_count = 1; |
154 | | - // Class will always starts with Interface Association (if any) and then Interface descriptor |
155 | | - if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) ) |
156 | | - { |
157 | | - tusb_desc_interface_assoc_t const * desc_iad = (tusb_desc_interface_assoc_t const *) p_desc; |
158 | | - assoc_itf_count = desc_iad->bInterfaceCount; |
159 | | - |
160 | | - p_desc = tu_desc_next(p_desc); // next to Interface |
161 | | - } |
162 | | - |
163 | | - // must be interface from now |
164 | | - if( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) ) return; |
165 | | - tusb_desc_interface_t const* desc_itf = (tusb_desc_interface_t const*) p_desc; |
166 | | - |
167 | | - // only open and listen to HID endpoint IN (PS4) |
168 | | - if (desc_itf->bInterfaceClass == TUSB_CLASS_HID) |
169 | | - { |
170 | | - _intf_num = desc_itf->bInterfaceNumber; |
171 | | - break; // we got the interface number |
172 | | - } |
173 | | - |
174 | | - // next Interface or IAD descriptor |
175 | | - uint16_t const drv_len = count_interface_total_len(desc_itf, assoc_itf_count, (uint16_t) (desc_end-p_desc)); |
176 | | - p_desc += drv_len; |
177 | | - } |
178 | | - } // This block can be removed once TinyUSB library incorporates HID_REQ_CONTROL_GET_REPORT callback |
179 | | - |
180 | 110 | USBHostManager::getInstance().hid_mount_cb(dev_addr, instance, desc_report, desc_len); |
181 | 111 | if ( !tuh_hid_receive_report(dev_addr, instance) ) { |
182 | 112 | // Error: cannot request report |
|
0 commit comments