summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2023-10-25 09:54:43 +1000
committerGitHub <noreply@github.com>2023-10-25 00:54:43 +0100
commitb7e62af755da6d35a1d44855b16651d9eed6f525 (patch)
tree9c544c6603f9065298b8d4a97cc505d2c8f7b984 /tmk_core
parent7e0147f8e6cebbf88a6f25c448cbd0246d3ab260 (diff)
V-USB: Implement `GET_PROTOCOL` and `SET_PROTOCOL` handling (#22324)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/vusb/vusb.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index d2c7749937..d7d2227687 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -325,30 +325,44 @@ 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:
+ if (rq->wIndex.word == KEYBOARD_INTERFACE) {
+ keyboard_protocol = rq->wValue.word & 0xFF;
+ dprintf("SET_PROTOCOL: %02X", keyboard_protocol);
+ }
+ break;
+ default:
+ dprint("UNKNOWN:");
+ break;
}
} else {
dprint("VENDOR:");