From 5215c51e266796b957a9b67dd1f5996c7e02d37b Mon Sep 17 00:00:00 2001 From: fauxpark Date: Mon, 23 Oct 2023 15:53:33 +1100 Subject: [PATCH 1/3] V-USB: Implement `GET_PROTOCOL` and `SET_PROTOCOL` handling --- tmk_core/protocol/vusb/vusb.c | 63 ++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index d2c774993783..9a3e3a3a68b6 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -325,30 +325,45 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (void *)data; if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ - if (rq->bRequest == USBRQ_HID_GET_REPORT) { - dprint("GET_REPORT:"); - if (rq->wIndex.word == KEYBOARD_INTERFACE) { - usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent; - return sizeof(keyboard_report_sent); - } - } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { - dprint("GET_IDLE:"); - usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate; - return 1; - } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { - vusb_idle_rate = rq->wValue.bytes[1]; - dprintf("SET_IDLE: %02X", vusb_idle_rate); - } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { - dprint("SET_REPORT:"); - // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) - if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { - dprint("SET_LED:"); - last_req.kind = SET_LED; - last_req.len = rq->wLength.word; - } - return USB_NO_MSG; // to get data in usbFunctionWrite - } else { - dprint("UNKNOWN:"); + switch (rq->bRequest) { + case USBRQ_HID_GET_REPORT: + dprint("GET_REPORT:"); + if (rq->wIndex.word == KEYBOARD_INTERFACE) { + usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent; + return sizeof(keyboard_report_sent); + } + break; + case USBRQ_HID_GET_IDLE: + dprint("GET_IDLE:"); + usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate; + return 1; + case USBRQ_HID_GET_PROTOCOL: + dprint("GET_PROTOCOL:"); + usbMsgPtr = (usbMsgPtr_t)&keyboard_protocol; + return 1; + case USBRQ_HID_SET_REPORT: + dprint("SET_REPORT:"); + // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) + if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { + dprint("SET_LED:"); + last_req.kind = SET_LED; + last_req.len = rq->wLength.word; + } + return USB_NO_MSG; // to get data in usbFunctionWrite + case USBRQ_HID_SET_IDLE: + vusb_idle_rate = rq->wValue.bytes[1]; + dprintf("SET_IDLE: %02X", vusb_idle_rate); + break; + case USBRQ_HID_SET_PROTOCOL: + // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) + if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { + keyboard_protocol = rq->wValue.bytes[1]; + dprintf("SET_PROTOCOL: %02X", keyboard_protocol); + } + return USB_NO_MSG; // to get data in usbFunctionWrite + default: + dprint("UNKNOWN:"); + break; } } else { dprint("VENDOR:"); From dd4d502a3c9be4324e183fa961065733a3f2d4f4 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Tue, 24 Oct 2023 19:34:44 +1100 Subject: [PATCH 2/3] Report Type and ID is not applicable for `SET_PROTOCOL` --- tmk_core/protocol/vusb/vusb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 9a3e3a3a68b6..6f6be9d3635a 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -355,8 +355,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) { dprintf("SET_IDLE: %02X", vusb_idle_rate); break; case USBRQ_HID_SET_PROTOCOL: - // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) - if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { + if (rq->wIndex.word == KEYBOARD_INTERFACE) { keyboard_protocol = rq->wValue.bytes[1]; dprintf("SET_PROTOCOL: %02X", keyboard_protocol); } From 1097020569b8d096f15481202cec4e0d64497900 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Tue, 24 Oct 2023 19:43:29 +1100 Subject: [PATCH 3/3] No data to read --- tmk_core/protocol/vusb/vusb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 6f6be9d3635a..d7d222768727 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -356,10 +356,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) { break; case USBRQ_HID_SET_PROTOCOL: if (rq->wIndex.word == KEYBOARD_INTERFACE) { - keyboard_protocol = rq->wValue.bytes[1]; + keyboard_protocol = rq->wValue.word & 0xFF; dprintf("SET_PROTOCOL: %02X", keyboard_protocol); } - return USB_NO_MSG; // to get data in usbFunctionWrite + break; default: dprint("UNKNOWN:"); break;