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

V-USB: Fix GET_IDLE/SET_IDLE #22332

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "os_detection.h"
#endif

#define NEXT_INTERFACE __COUNTER__

/*
* Interface indexes
*/
enum usb_interfaces {
#ifndef KEYBOARD_SHARED_EP
KEYBOARD_INTERFACE = NEXT_INTERFACE,
KEYBOARD_INTERFACE,
#else
SHARED_INTERFACE = NEXT_INTERFACE,
SHARED_INTERFACE,
# define KEYBOARD_INTERFACE SHARED_INTERFACE
#endif

// It is important that the Raw HID interface is at a constant
// interface number, to support Linux/OSX platforms and chrome.hid
// If Raw HID is enabled, let it be always 1.
#ifdef RAW_ENABLE
RAW_INTERFACE = NEXT_INTERFACE,
RAW_INTERFACE,
#endif

#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
SHARED_INTERFACE = NEXT_INTERFACE,
SHARED_INTERFACE,
#endif

#ifdef CONSOLE_ENABLE
CONSOLE_INTERFACE = NEXT_INTERFACE,
CONSOLE_INTERFACE,
#endif

TOTAL_INTERFACES = NEXT_INTERFACE
TOTAL_INTERFACES
};

#define MAX_INTERFACES 3

#if (NEXT_INTERFACE - 1) > MAX_INTERFACES
#if TOTAL_INTERFACES > MAX_INTERFACES
# error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console
#endif
fauxpark marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -90,7 +88,7 @@ enum usb_interfaces {
#endif

static uint8_t keyboard_led_state = 0;
static uint8_t vusb_idle_rate = 0;
uint8_t keyboard_idle = 0;
uint8_t keyboard_protocol = 1;

/* Keyboard report send buffer */
Expand Down Expand Up @@ -335,7 +333,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
break;
case USBRQ_HID_GET_IDLE:
dprint("GET_IDLE:");
usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate;
usbMsgPtr = (usbMsgPtr_t)&keyboard_idle;
return 1;
case USBRQ_HID_GET_PROTOCOL:
dprint("GET_PROTOCOL:");
Expand All @@ -351,8 +349,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
}
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);
keyboard_idle = (rq->wValue.word & 0xFF00) >> 8;
dprintf("SET_IDLE: %02X", keyboard_idle);
break;
case USBRQ_HID_SET_PROTOCOL:
if (rq->wIndex.word == KEYBOARD_INTERFACE) {
Expand Down Expand Up @@ -1044,7 +1042,7 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
#endif
break;
case USBDESCR_HID:
switch (rq->wValue.bytes[0]) {
switch (rq->wIndex.word) {
#ifndef KEYBOARD_SHARED_EP
case KEYBOARD_INTERFACE:
usbMsgPtr = (usbMsgPtr_t)&usbConfigurationDescriptor.keyboardHID;
Expand Down