tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.96k stars 1.7k forks source link

usb_usb: SET_PROTCOL/SET_IDLE can fail on some keyboards #738

Closed tmk closed 2 years ago

tmk commented 2 years ago

Anne Pro2 replys to SET_PROTOCOL/SET_IDLE request with STALL for no reason. It is a boot keyboar interface and should support the requests.

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

Fix: The converter will continue to work even when the requests fails.

tmk commented 1 year ago

HHKB Hybrid doesn't work with this fix.

diff --git a/hidboot.h b/hidboot.h
index 4fe83ff..f00c1f2 100644
--- a/hidboot.h
+++ b/hidboot.h
@@ -462,7 +462,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
         for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
                 USBTRACE2("\r\nInterface:", i);
                 rcode = SetProtocol(i, bRptProtoEnable ? HID_RPT_PROTOCOL : USB_HID_BOOT_PROTOCOL);
-                if(rcode) goto FailSetProtocol;
+                //if(rcode) goto FailSetProtocol;
                 USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode);
                 rcode = SetIdle(i, 0, 0);
                 USBTRACE2("SET_IDLE rcode:", rcode);

https://github.com/tmk/USB_Host_Shield_2.0/commit/007760d863af62379190f4cba71a70ac8ce5e779

MAX3421e replies with hrJERR to SET_PROTCOL and SET_IDLE at first time for some reason.

usb_state: 20
usb_state: 40
usb_state: 50
usb_state: 51
Ci BM Init
Ci Addr:01
Ci NC:01
HID_PROTOCOL_KEYBOARD
Ci Ci bNumEP:02
Cnf:01
bIfaceNum:00
bNumIface:00

Interface:00
crSU:0D
PROTOCOL SET HID_BOOT rcode:0D
crSU:0D
SET_IDLE rcode:0D
crSU:0D
RPIPE rcode:0D
BM configured
host.Task: 2318
usb_state: 90
speed: full
crSU:0D

It seems hrJERR indicates no activity on the bus while device is there. The keyboard is not ready yet and hidboot configuring process should be retried, perhaps. It works at second try.

Fixed at https://github.com/tmk/USB_Host_Shield_2.0/commit/ad5ce999c33094511d870840eb9f526db700c302

usb_state: 20
usb_state: 40
usb_state: 50
usb_state: 51
BM Init
Addr:01
NC:01
HID_PROTOCOL_KEYBOARD
bNumEP:02
Cnf:01
bIfaceNum:00
bNumIface:00

Interface:00
SetProto:0D
BM Init
Addr:01
NC:01
HID_PROTOCOL_KEYBOARD
bNumEP:02
Cnf:01
bIfaceNum:00
bNumIface:00

Interface:00
PROTOCOL SET HID_BOOT rcode:00
SET_IDLE rcode:00
RPIPE rcode:00
BM configured
host.Task: 4735
usb_state: 90
speed: full