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: iMate compatibility #710

Open
tmk opened this issue Oct 25, 2021 · 1 comment
Open

USB-USB: iMate compatibility #710

tmk opened this issue Oct 25, 2021 · 1 comment

Comments

@tmk
Copy link
Owner

tmk commented Oct 25, 2021

commit 9ba9c09d7cd608abae95ac7b74992f8ec42c7b41
Author: tmk <[email protected]>
Date:   Sun Sep 26 23:31:26 2021 +0900

    usb_usb: Poll mouse interface for iMate
    
    Griffin iMate doesn't any keyboard report without polling mouse interface

diff --git a/converter/usb_usb/usb_usb.cpp b/converter/usb_usb/usb_usb.cpp
index 625a3b82..5a46c9f4 100644
--- a/converter/usb_usb/usb_usb.cpp
+++ b/converter/usb_usb/usb_usb.cpp
@@ -75,10 +75,10 @@ static bool matrix_is_mod =false;
  * This supports two cascaded hubs and four keyboards
  */
 USB usb_host;
-HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd1(&usb_host);
-HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd2(&usb_host);
-HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd3(&usb_host);
-HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd4(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE>    kbd1(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE>    kbd2(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE>    kbd3(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE>    kbd4(&usb_host);
 KBDReportParser kbd_parser1;
 KBDReportParser kbd_parser2;
 KBDReportParser kbd_parser3;
diff --git a/tmk_core/protocol/usb_hid/parser.cpp b/tmk_core/protocol/usb_hid/parser.cpp
index bc2744d0..fed8144d 100644
--- a/tmk_core/protocol/usb_hid/parser.cpp
+++ b/tmk_core/protocol/usb_hid/parser.cpp
@@ -12,6 +12,8 @@ void KBDReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *b
     }
     xprintf("\r\n");
 
+    if (len != 8) return;   // not keyboard data
+
     // Rollover error
     // Cherry: 0101010101010101
     // https://geekhack.org/index.php?topic=69169.msg2638223#msg2638223
@tmk
Copy link
Owner Author

tmk commented Mar 8, 2022

USB Descriptor of Griffin Technology iMate, ADB Adapter - 077d:0405:
https://gist.github.com/tmk/472e52c9502302be173790c5e5fa0829

Griffin iMate doesn't send any keyboard report without polling mouse interface.

This patch may be needed for this.

Author: Jun Wako <[email protected]>
Date:   Sun Sep 26 23:35:13 2021 +0900

    hidboot: Use actual number of interface and endpoint
    
    When supporting both keyboard and mouse protocol we should
    handle cases that number of interface and endpoint is 1 or 2
    
    This change is required to support Griffin iMate, which
    doesn't any keyboard report without polling mouse interface

diff --git a/hidboot.h b/hidboot.h
index 1effc6c..c51a3dc 100644
--- a/hidboot.h
+++ b/hidboot.h
@@ -437,7 +437,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
         }
         USBTRACE2("bNumEP:", bNumEP);
 
-        if(bNumEP != (uint8_t)(totalEndpoints(BOOT_PROTOCOL))) {
+        if(bNumEP == 1) { // Not found any Interrupt-IN Endpoint
                 rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
                 goto Fail;
         }
@@ -461,7 +461,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
         USBTRACE2("bNumIface:", bNumIface);
 
         // Yes, mouse wants SetProtocol and SetIdle too!
-        for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
+        for(uint8_t i = 0; i <= bIfaceNum; i++) {   // Assuming bIfaceNum indicates the last interface
                 USBTRACE2("\r\nInterface:", i);
                 rcode = SetProtocol(i, bRptProtoEnable ? HID_RPT_PROTOCOL : USB_HID_BOOT_PROTOCOL);
                 if(rcode) goto FailSetProtocol;
@@ -587,7 +587,8 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
         if(bPollEnable && ((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L)) {
 
                 // To-do: optimize manually, using the for loop only if needed.
-                for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
+                for(int i = 0; i < (bNumEP - 1); i++) { // bNumEP is number of interrupt-IN EP + EP0
+                        if (epInfo[epInterruptInIndex + i].epAddr == 0) continue;   // EP is not registered
                         const uint16_t const_buff_len = 64;
 
                         USBTRACE3("(hidboot.h) i=", i, 0x81);

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