From d91d9d40a471141bd46362f1e57be2d4ea46ccf7 Mon Sep 17 00:00:00 2001 From: lokher Date: Wed, 17 Sep 2025 16:55:14 +0800 Subject: [PATCH] Add "src" parameter for raw HID --- quantum/raw_hid.c | 2 +- quantum/raw_hid.h | 4 +++- quantum/via.c | 12 ++++++++---- tmk_core/protocol/chibios/usb_main.c | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/quantum/raw_hid.c b/quantum/raw_hid.c index 2c7a75f325..085c3b4675 100644 --- a/quantum/raw_hid.c +++ b/quantum/raw_hid.c @@ -8,7 +8,7 @@ void raw_hid_send(uint8_t *data, uint8_t length) { host_raw_hid_send(data, length); } -__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) { +__attribute__((weak)) void raw_hid_receive(uint8_t src, uint8_t *data, uint8_t length) { // Users should #include "raw_hid.h" in their own code // and implement this function there. Leave this as weak linkage // so users can opt to not handle data coming in. diff --git a/quantum/raw_hid.h b/quantum/raw_hid.h index 16830833cc..2dbb297125 100644 --- a/quantum/raw_hid.h +++ b/quantum/raw_hid.h @@ -5,6 +5,8 @@ #include +#define RAW_HID_SRC_USB 0 + /** * \file * @@ -18,7 +20,7 @@ * \param data A pointer to the received data. Always 32 bytes in length. * \param length The length of the buffer. Always 32. */ -void raw_hid_receive(uint8_t *data, uint8_t length); +void raw_hid_receive(uint8_t src, uint8_t *data, uint8_t length); /** * \brief Send an HID report. diff --git a/quantum/via.c b/quantum/via.c index 9446811af6..345b784fc6 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -279,17 +279,21 @@ __attribute__((weak)) void via_custom_value_command(uint8_t *data, uint8_t lengt // Keyboard level code can override this, but shouldn't need to. // Controlling custom features should be done by overriding // via_custom_value_command_kb() instead. -__attribute__((weak)) bool via_command_kb(uint8_t *data, uint8_t length) { +__attribute__((weak)) bool via_command_kb(uint8_t src, uint8_t *data, uint8_t length) { return false; } -void raw_hid_receive(uint8_t *data, uint8_t length) { +__attribute__((weak)) void via_raw_hid_send(uint8_t src, uint8_t *data, uint8_t length) { + raw_hid_send(data, length); +} + +void raw_hid_receive(uint8_t src, uint8_t *data, uint8_t length) { uint8_t *command_id = &(data[0]); uint8_t *command_data = &(data[1]); // If via_command_kb() returns true, the command was fully // handled, including calling raw_hid_send() - if (via_command_kb(data, length)) { + if (via_command_kb(src, data, length)) { return; } @@ -469,7 +473,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { // Return the same buffer, optionally with values changed // (i.e. returning state to the host, or the unhandled state). - raw_hid_send(data, length); + via_raw_hid_send(src, data, length); } #if defined(BACKLIGHT_ENABLE) diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index f45af845e1..c23a64d3af 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -520,7 +520,7 @@ void send_raw_hid(uint8_t *data, uint8_t length) { void raw_hid_task(void) { uint8_t buffer[RAW_EPSIZE]; while (receive_report(USB_ENDPOINT_OUT_RAW, buffer, sizeof(buffer))) { - raw_hid_receive(buffer, sizeof(buffer)); + raw_hid_receive(RAW_HID_SRC_USB, buffer, sizeof(buffer)); } }