From 41cbc2c19d385cfc8762f9636f5892eba94502b6 Mon Sep 17 00:00:00 2001 From: Luke Arntson Date: Mon, 10 Jun 2024 20:15:58 -0400 Subject: [PATCH 1/3] Potential fix for USB host causing reboot to lag out --- src/usbhostmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usbhostmanager.cpp b/src/usbhostmanager.cpp index 9fec56760..459a139f9 100644 --- a/src/usbhostmanager.cpp +++ b/src/usbhostmanager.cpp @@ -12,7 +12,7 @@ void USBHostManager::start() { // This will happen after Gamepad has initialized - if (PeripheralManager::getInstance().isUSBEnabled(0)) { + if (PeripheralManager::getInstance().isUSBEnabled(0) && listeners.size() > 0) { pio_usb_configuration_t* pio_cfg = PeripheralManager::getInstance().getUSB(0)->getController(); tuh_configure(1, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, pio_cfg); tuh_init(BOARD_TUH_RHPORT); @@ -23,8 +23,8 @@ void USBHostManager::start() { // Shut down the USB bus if we are running USB right now void USBHostManager::shutdown() { - if (PeripheralManager::getInstance().isUSBEnabled(0)) { - tuh_rhport_reset_bus(BOARD_TUH_RHPORT, false); + if ( tuh_ready ) { + tuh_deinit(BOARD_TUH_RHPORT); } } From 476245141cdddf2f3c9c52c32c988324349e975b Mon Sep 17 00:00:00 2001 From: Luke Arntson Date: Tue, 11 Jun 2024 12:18:25 -0400 Subject: [PATCH 2/3] Adding 10 second aux time-out (will change to 1 second when verified working) --- src/usbhostmanager.cpp | 76 ++---------------------------------------- 1 file changed, 3 insertions(+), 73 deletions(-) diff --git a/src/usbhostmanager.cpp b/src/usbhostmanager.cpp index 459a139f9..500baf622 100644 --- a/src/usbhostmanager.cpp +++ b/src/usbhostmanager.cpp @@ -13,11 +13,14 @@ void USBHostManager::start() { // This will happen after Gamepad has initialized if (PeripheralManager::getInstance().isUSBEnabled(0) && listeners.size() > 0) { + sleep_ms(10000); // TinyUSB HOST Start-Up Temporary Fix 06.11.2024 pio_usb_configuration_t* pio_cfg = PeripheralManager::getInstance().getUSB(0)->getController(); tuh_configure(1, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, pio_cfg); tuh_init(BOARD_TUH_RHPORT); sleep_us(10); // ensure we are ready tuh_ready = true; + } else { + tuh_ready = false; } } @@ -102,81 +105,8 @@ void USBHostManager::xinput_report_sent_cb(uint8_t dev_addr, uint8_t instance, u } } -// HID: USB Host -static uint8_t _intf_num = 0; - -// Required helper class for HID_REQ_CONTROL_GET_REPORT addition -uint16_t count_interface_total_len(tusb_desc_interface_t const* desc_itf, uint8_t itf_count, uint16_t max_len) -{ - uint8_t const* p_desc = (uint8_t const*) desc_itf; - uint16_t len = 0; - - while (itf_count--) - { - // Next on interface desc - len += tu_desc_len(desc_itf); - p_desc = tu_desc_next(p_desc); - - while (len < max_len) - { - // return on IAD regardless of itf count - if ( tu_desc_type(p_desc) == TUSB_DESC_INTERFACE_ASSOCIATION ) return len; - - if ( (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE) && - ((tusb_desc_interface_t const*) p_desc)->bAlternateSetting == 0 ) - { - break; - } - - len += tu_desc_len(p_desc); - p_desc = tu_desc_next(p_desc); - } - } - - return len; -} - void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) { - // Get Interface Number for our HID class - uint16_t temp_buf[128]; - - if (XFER_RESULT_SUCCESS == tuh_descriptor_get_configuration_sync(dev_addr, 0, temp_buf, sizeof(temp_buf))) - { - tusb_desc_configuration_t const* desc_cfg = (tusb_desc_configuration_t*) temp_buf; - uint8_t const* desc_end = ((uint8_t const*) desc_cfg) + tu_le16toh(desc_cfg->wTotalLength); - uint8_t const* p_desc = tu_desc_next(desc_cfg); - - // parse each interfaces - while( p_desc < desc_end ) - { - uint8_t assoc_itf_count = 1; - // Class will always starts with Interface Association (if any) and then Interface descriptor - if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) ) - { - tusb_desc_interface_assoc_t const * desc_iad = (tusb_desc_interface_assoc_t const *) p_desc; - assoc_itf_count = desc_iad->bInterfaceCount; - - p_desc = tu_desc_next(p_desc); // next to Interface - } - - // must be interface from now - if( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) ) return; - tusb_desc_interface_t const* desc_itf = (tusb_desc_interface_t const*) p_desc; - - // only open and listen to HID endpoint IN (PS4) - if (desc_itf->bInterfaceClass == TUSB_CLASS_HID) - { - _intf_num = desc_itf->bInterfaceNumber; - break; // we got the interface number - } - - // next Interface or IAD descriptor - uint16_t const drv_len = count_interface_total_len(desc_itf, assoc_itf_count, (uint16_t) (desc_end-p_desc)); - p_desc += drv_len; - } - } // This block can be removed once TinyUSB library incorporates HID_REQ_CONTROL_GET_REPORT callback - USBHostManager::getInstance().hid_mount_cb(dev_addr, instance, desc_report, desc_len); if ( !tuh_hid_receive_report(dev_addr, instance) ) { // Error: cannot request report From e5d4a32c5a91b51a2f8e3128c971ddb9879d4723 Mon Sep 17 00:00:00 2001 From: Luke Arntson Date: Tue, 11 Jun 2024 12:34:25 -0400 Subject: [PATCH 3/3] Moved 10 seconds to 1 second for auxiliary ONLY when usb host is enabled --- src/usbhostmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usbhostmanager.cpp b/src/usbhostmanager.cpp index 500baf622..b757c2dd4 100644 --- a/src/usbhostmanager.cpp +++ b/src/usbhostmanager.cpp @@ -13,7 +13,7 @@ void USBHostManager::start() { // This will happen after Gamepad has initialized if (PeripheralManager::getInstance().isUSBEnabled(0) && listeners.size() > 0) { - sleep_ms(10000); // TinyUSB HOST Start-Up Temporary Fix 06.11.2024 + sleep_ms(1000); // TinyUSB HOST Start-Up Temporary Fix : TO-DO 06.11.2024 pio_usb_configuration_t* pio_cfg = PeripheralManager::getInstance().getUSB(0)->getController(); tuh_configure(1, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, pio_cfg); tuh_init(BOARD_TUH_RHPORT);