Add "src" parameter for raw HID

This commit is contained in:
lokher
2025-09-17 16:55:14 +08:00
parent bcf899cc8a
commit d91d9d40a4
4 changed files with 13 additions and 7 deletions

View File

@@ -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.

View File

@@ -5,6 +5,8 @@
#include <stdint.h>
#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.

View File

@@ -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)

View File

@@ -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));
}
}