V-USB: Implement GET_PROTOCOL and SET_PROTOCOL handling (#22324)

This commit is contained in:
Ryan 2023-10-25 09:54:43 +10:00 committed by GitHub
parent 7e0147f8e6
commit b7e62af755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -325,30 +325,44 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
usbRequest_t *rq = (void *)data; usbRequest_t *rq = (void *)data;
if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
if (rq->bRequest == USBRQ_HID_GET_REPORT) { switch (rq->bRequest) {
dprint("GET_REPORT:"); case USBRQ_HID_GET_REPORT:
if (rq->wIndex.word == KEYBOARD_INTERFACE) { dprint("GET_REPORT:");
usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent; if (rq->wIndex.word == KEYBOARD_INTERFACE) {
return sizeof(keyboard_report_sent); usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
} return sizeof(keyboard_report_sent);
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) { }
dprint("GET_IDLE:"); break;
usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate; case USBRQ_HID_GET_IDLE:
return 1; dprint("GET_IDLE:");
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) { usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate;
vusb_idle_rate = rq->wValue.bytes[1]; return 1;
dprintf("SET_IDLE: %02X", vusb_idle_rate); case USBRQ_HID_GET_PROTOCOL:
} else if (rq->bRequest == USBRQ_HID_SET_REPORT) { dprint("GET_PROTOCOL:");
dprint("SET_REPORT:"); usbMsgPtr = (usbMsgPtr_t)&keyboard_protocol;
// Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) return 1;
if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) { case USBRQ_HID_SET_REPORT:
dprint("SET_LED:"); dprint("SET_REPORT:");
last_req.kind = SET_LED; // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
last_req.len = rq->wLength.word; if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
} dprint("SET_LED:");
return USB_NO_MSG; // to get data in usbFunctionWrite last_req.kind = SET_LED;
} else { last_req.len = rq->wLength.word;
dprint("UNKNOWN:"); }
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 { } else {
dprint("VENDOR:"); dprint("VENDOR:");