Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB-USB: Poker X startup issue #770

Closed
tmk opened this issue Dec 26, 2023 · 2 comments
Closed

USB-USB: Poker X startup issue #770

tmk opened this issue Dec 26, 2023 · 2 comments

Comments

@tmk
Copy link
Owner

tmk commented Dec 26, 2023

Poker X is not enumerated when plugged in with converter simultaneously.

Protocol of switching USB to PS/2 causes probably. It seems to turn into PS/2 mode when USB interface is not configured for some period after plugin. After the keyboard enters into PS/2 mode, both D+ and D- are pull-up'd and it cannot be bus-reset anymore.

Holtek MCU: HT82K94E
https://www.holtek.com/webapi/116711/HT82K94xv240.pdf

Converter startup code

This takes long and prevents host functions of MAX3421 from configuring the keyboard.

#ifndef NO_USB_STARTUP_WAIT_LOOP
/* wait for USB startup */
while (USB_DeviceState != DEVICE_STATE_Configured
#ifdef CONSOLE_ENABLE
|| !console_is_ready()
#endif
) {
#if defined(INTERRUPT_CONTROL_ENDPOINT)
;
#else
USB_USBTask();
#endif
hook_usb_startup_wait_loop();
}
print("\nUSB configured.\n");
#endif

500ms delay in USB enumeration

This may causes also.

tmk/USB_Host_Shield_2.0@e37ed6c

@tmk
Copy link
Owner Author

tmk commented Dec 26, 2023

FIX for startup

call usb_host.Task() in statup delay loop.

diff --git a/converter/usb_usb/usb_usb.cpp b/converter/usb_usb/usb_usb.cpp
index e649a9a2..bb6c89ef 100644
--- a/converter/usb_usb/usb_usb.cpp
+++ b/converter/usb_usb/usb_usb.cpp
@@ -243,3 +243,17 @@ void hook_usb_suspend_loop(void)
         matrix_scan();
     }
 }
+
+void hook_usb_startup_wait_loop(void)
+{
+    usb_host.Task();
+
+    static uint8_t usb_state = 0;
+    if (usb_state != usb_host.getUsbTaskState()) {
+        usb_state = usb_host.getUsbTaskState();
+        xprintf("u:%02X\n", usb_state);
+        if (usb_state == USB_STATE_RUNNING) {
+            xprintf("s:%s\n", usb_host.getVbusState()==FSHOST ? "f" : "l");
+        }
+    }
+}

d825356

FIX for 500ms delay

diff --git a/Usb.cpp b/Usb.cpp
index f87b517..2038018 100644
--- a/Usb.cpp
+++ b/Usb.cpp
@@ -526,7 +526,7 @@ void USB::Task(void) //USB state machine
                                         usb_task_state = USB_STATE_CONFIGURING;
                                  */
                                 usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
-                                delay = (uint32_t)millis() + 500;
+                                delay = (uint32_t)millis() + 20;
                         }
                         break;
                 case USB_ATTACHED_SUBSTATE_WAIT_RESET:

Matrix Vita keyboard still needs this 500ms delay, perhaps.

https://geekhack.org/index.php?topic=69169.msg3073431

tmk/USB_Host_Shield_2.0@e37ed6c

This is left untouched for now.

tmk added a commit that referenced this issue Dec 30, 2023
- Poker X requires this to be enumerated
- MAX3421 task need to start at earlier stage
tmk added a commit that referenced this issue Dec 30, 2023
MAX3421 suspend/resume at startup can:
- prevent LUFA startup
- prevent Poker X from being enumerated
@tmk tmk closed this as completed Dec 30, 2023
@tmk
Copy link
Owner Author

tmk commented Jan 9, 2024

Prohibit MAX3421 suspension at startup

This and d825356 fixed the Poker X startup problem.

86157dc

commit 86157dc41d73914c5db1c4fc4b5f78f1bb0e6514
Author: tmk <hasu@tmk-kbd.com>
Date:   Sat Dec 30 00:03:02 2023 +0900

    usb_usb: Prohibit MAX3421 suspend at startup #770
    
    MAX3421 suspend/resume at startup can:
    - prevent LUFA startup
    - prevent Poker X from being enumerated

diff --git a/converter/usb_usb/usb_usb.cpp b/converter/usb_usb/usb_usb.cpp
index 95a3c103..aed3ff6e 100644
--- a/converter/usb_usb/usb_usb.cpp
+++ b/converter/usb_usb/usb_usb.cpp
@@ -226,8 +226,16 @@ void led_set(uint8_t usb_led)
     if (kbd4.isReady()) kbd4.SetLed(&usb_led);
 }
 
+static bool init_done = false;
+void hook_late_init()
+{
+    dprintf("[i]");
+    init_done = true;
+}
+
 void hook_usb_suspend_loop(void)
 {
+    dprintf("[s]");
 #ifndef TMK_LUFA_DEBUG_UART
     // This corrupts debug print when suspend
     suspend_power_down();
@@ -243,6 +251,8 @@ static uint8_t _led_stats = 0;
 void hook_usb_suspend_entry(void)
 {
     dprintf("[S]");
+    if (!init_done) return;
+
     matrix_clear();
     clear_keyboard();
 
@@ -260,6 +270,8 @@ void hook_usb_suspend_entry(void)
 void hook_usb_wakeup(void)
 {
     dprintf("[W]");
+    if (!init_done) return;
+
     suspend_wakeup_init();
 
 #ifdef UHS2_POWER_SAVING

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant