aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/vusb/vusb.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2024-11-27 21:29:12 +1100
committerNick Brassel <nick@tzarc.org>2024-11-27 21:29:12 +1100
commit9f76541b29056150cf57d69569a14a59e13995c7 (patch)
tree66c7398d873fcda88aebe3090603aefe045ff52e /tmk_core/protocol/vusb/vusb.c
parent57be4871616ee9a8fe042f6186010d436ec7d4b1 (diff)
parenteb04b94eecbb9b3e64ca9c74f937b5f762440b17 (diff)
Merge branch 'develop'
Diffstat (limited to 'tmk_core/protocol/vusb/vusb.c')
-rw-r--r--tmk_core/protocol/vusb/vusb.c91
1 files changed, 59 insertions, 32 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index fa14820e72..fdbfcc17dc 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h"
#include "wait.h"
#include "usb_descriptor_common.h"
+#include "usb_device_state.h"
#ifdef RAW_ENABLE
# include "raw_hid.h"
@@ -85,10 +86,6 @@ _Static_assert(TOTAL_INTERFACES <= MAX_INTERFACES, "There are not enough availab
# error Mouse/Extra Keys share an endpoint with Console. Please disable one of the two.
#endif
-static uint8_t keyboard_led_state = 0;
-uint8_t keyboard_idle = 0;
-uint8_t keyboard_protocol = 1;
-
static report_keyboard_t keyboard_report_sent;
static void send_report_fragment(uint8_t endpoint, void *data, size_t size) {
@@ -212,24 +209,19 @@ void console_task(void) {
/*------------------------------------------------------------------*
* Host driver
*------------------------------------------------------------------*/
-static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_nkro(report_nkro_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_extra(report_extra_t *report);
+static void send_keyboard(report_keyboard_t *report);
+static void send_nkro(report_nkro_t *report);
+static void send_mouse(report_mouse_t *report);
+static void send_extra(report_extra_t *report);
-static host_driver_t driver = {keyboard_leds, send_keyboard, send_nkro, send_mouse, send_extra};
+static host_driver_t driver = {.keyboard_leds = usb_device_state_get_leds, .send_keyboard = send_keyboard, .send_nkro = send_nkro, .send_mouse = send_mouse, .send_extra = send_extra};
host_driver_t *vusb_driver(void) {
return &driver;
}
-static uint8_t keyboard_leds(void) {
- return keyboard_led_state;
-}
-
static void send_keyboard(report_keyboard_t *report) {
- if (!keyboard_protocol) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_BOOT) {
send_report(1, &report->mods, 8);
} else {
send_report(1, report, sizeof(report_keyboard_t));
@@ -304,11 +296,15 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
break;
case USBRQ_HID_GET_IDLE:
dprint("GET_IDLE:");
- usbMsgPtr = (usbMsgPtr_t)&keyboard_idle;
+ static uint8_t keyboard_idle;
+ keyboard_idle = usb_device_state_get_idle_rate();
+ usbMsgPtr = (usbMsgPtr_t)&keyboard_idle;
return 1;
case USBRQ_HID_GET_PROTOCOL:
dprint("GET_PROTOCOL:");
- usbMsgPtr = (usbMsgPtr_t)&keyboard_protocol;
+ static uint8_t keyboard_protocol;
+ keyboard_protocol = usb_device_state_get_protocol();
+ usbMsgPtr = (usbMsgPtr_t)&keyboard_protocol;
return 1;
case USBRQ_HID_SET_REPORT:
dprint("SET_REPORT:");
@@ -320,13 +316,13 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
}
return USB_NO_MSG; // to get data in usbFunctionWrite
case USBRQ_HID_SET_IDLE:
- keyboard_idle = (rq->wValue.word & 0xFF00) >> 8;
- dprintf("SET_IDLE: %02X", keyboard_idle);
+ usb_device_state_set_idle_rate(rq->wValue.word >> 8);
+ dprintf("SET_IDLE: %02X", usb_device_state_get_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);
+ usb_device_state_set_protocol(rq->wValue.word & 0xFF);
+ dprintf("SET_PROTOCOL: %02X", usb_device_state_get_protocol());
}
break;
default:
@@ -347,9 +343,9 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
}
switch (last_req.kind) {
case SET_LED:
- dprintf("SET_LED: %02X\n", data[0]);
- keyboard_led_state = data[0];
- last_req.len = 0;
+ usb_device_state_set_leds(data[0]);
+ dprintf("SET_LED: %02X\n", usb_device_state_get_leds());
+ last_req.len = 0;
return 1;
break;
case NONE:
@@ -524,23 +520,37 @@ const PROGMEM uchar shared_hid_report[] = {
# endif
0x81, 0x06, // Input (Data, Variable, Relative)
- // Vertical wheel (1 byte)
+ // Vertical wheel (1 or 2 bytes)
0x09, 0x38, // Usage (Wheel)
+# ifndef WHEEL_EXTENDED_REPORT
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
+# else
+ 0x16, 0x01, 0x80, // Logical Minimum (-32767)
+ 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
+ 0x95, 0x01, // Report Count (1)
+ 0x75, 0x10, // Report Size (16)
+# endif
0x81, 0x06, // Input (Data, Variable, Relative)
- // Horizontal wheel (1 byte)
+ // Horizontal wheel (1 or 2 bytes)
0x05, 0x0C, // Usage Page (Consumer)
0x0A, 0x38, 0x02, // Usage (AC Pan)
- 0x15, 0x81, // Logical Minimum (-127)
- 0x25, 0x7F, // Logical Maximum (127)
+# ifndef WHEEL_EXTENDED_REPORT
+ 0x15, 0x81, // Logical Minimum (-127)
+ 0x25, 0x7F, // Logical Maximum (127)
+ 0x95, 0x01, // Report Count (1)
+ 0x75, 0x08, // Report Size (8)
+# else
+ 0x16, 0x01, 0x80, // Logical Minimum (-32767)
+ 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
0x95, 0x01, // Report Count (1)
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x06, // Input (Data, Variable, Relative)
- 0xC0, // End Collection
- 0xC0, // End Collection
+ 0x75, 0x10, // Report Size (16)
+# endif
+ 0x81, 0x06, // Input (Data, Variable, Relative)
+ 0xC0, // End Collection
+ 0xC0, // End Collection
#endif
#ifdef EXTRAKEY_ENABLE
@@ -611,6 +621,23 @@ const PROGMEM uchar shared_hid_report[] = {
0x81, 0x02, // Input (Data, Variable, Absolute)
# endif
+# ifdef JOYSTICK_HAS_HAT
+ // Hat Switch (4 bits)
+ 0x09, 0x39, // Usage (Hat Switch)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x25, 0x07, // Logical Maximum (7)
+ 0x35, 0x00, // Physical Minimum (0)
+ 0x46, 0x3B, 0x01, // Physical Maximum (315)
+ 0x65, 0x14, // Unit (Degree, English Rotation)
+ 0x95, 0x01, // Report Count (1)
+ 0x75, 0x04, // Report Size (4)
+ 0x81, 0x42, // Input (Data, Variable, Absolute, Null State)
+ // Padding (4 bits)
+ 0x95, 0x04, // Report Count (4)
+ 0x75, 0x01, // Report Size (1)
+ 0x81, 0x01, // Input (Constant)
+# endif
+
# if JOYSTICK_BUTTON_COUNT > 0
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button 1)