diff options
| author | Joel Challis <git@zvecr.com> | 2025-05-11 23:38:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-12 08:38:48 +1000 |
| commit | 88c094908bb94324e28876f2beb8028a9fad086d (patch) | |
| tree | 4e47c513470873b59ac20735bdec99afb903fd5a /tmk_core/protocol | |
| parent | c045c3e00c41597fbc82239376611d3ac8a7a52e (diff) | |
Add raw_hid support to host driver (#25255)
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/chibios/chibios.c | 12 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 12 | ||||
| -rw-r--r-- | tmk_core/protocol/host.c | 12 | ||||
| -rw-r--r-- | tmk_core/protocol/host.h | 1 | ||||
| -rw-r--r-- | tmk_core/protocol/host_driver.h | 3 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 35 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 22 |
7 files changed, 65 insertions, 32 deletions
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c index d752f3746b..19d8121e34 100644 --- a/tmk_core/protocol/chibios/chibios.c +++ b/tmk_core/protocol/chibios/chibios.c | |||
| @@ -66,9 +66,19 @@ void send_keyboard(report_keyboard_t *report); | |||
| 66 | void send_nkro(report_nkro_t *report); | 66 | void send_nkro(report_nkro_t *report); |
| 67 | void send_mouse(report_mouse_t *report); | 67 | void send_mouse(report_mouse_t *report); |
| 68 | void send_extra(report_extra_t *report); | 68 | void send_extra(report_extra_t *report); |
| 69 | void send_raw_hid(uint8_t *data, uint8_t length); | ||
| 69 | 70 | ||
| 70 | /* host struct */ | 71 | /* host struct */ |
| 71 | host_driver_t chibios_driver = {.keyboard_leds = usb_device_state_get_leds, .send_keyboard = send_keyboard, .send_nkro = send_nkro, .send_mouse = send_mouse, .send_extra = send_extra}; | 72 | host_driver_t chibios_driver = { |
| 73 | .keyboard_leds = usb_device_state_get_leds, | ||
| 74 | .send_keyboard = send_keyboard, | ||
| 75 | .send_nkro = send_nkro, | ||
| 76 | .send_mouse = send_mouse, | ||
| 77 | .send_extra = send_extra, | ||
| 78 | #ifdef RAW_ENABLE | ||
| 79 | .send_raw_hid = send_raw_hid, | ||
| 80 | #endif | ||
| 81 | }; | ||
| 72 | 82 | ||
| 73 | #ifdef VIRTSER_ENABLE | 83 | #ifdef VIRTSER_ENABLE |
| 74 | void virtser_task(void); | 84 | void virtser_task(void); |
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 5a5354416f..f9d7f5c4d6 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c | |||
| @@ -32,6 +32,10 @@ | |||
| 32 | #include "usb_driver.h" | 32 | #include "usb_driver.h" |
| 33 | #include "usb_types.h" | 33 | #include "usb_types.h" |
| 34 | 34 | ||
| 35 | #ifdef RAW_ENABLE | ||
| 36 | # include "raw_hid.h" | ||
| 37 | #endif | ||
| 38 | |||
| 35 | #ifdef NKRO_ENABLE | 39 | #ifdef NKRO_ENABLE |
| 36 | # include "keycode_config.h" | 40 | # include "keycode_config.h" |
| 37 | 41 | ||
| @@ -515,19 +519,13 @@ void console_task(void) { | |||
| 515 | #endif /* CONSOLE_ENABLE */ | 519 | #endif /* CONSOLE_ENABLE */ |
| 516 | 520 | ||
| 517 | #ifdef RAW_ENABLE | 521 | #ifdef RAW_ENABLE |
| 518 | void raw_hid_send(uint8_t *data, uint8_t length) { | 522 | void send_raw_hid(uint8_t *data, uint8_t length) { |
| 519 | if (length != RAW_EPSIZE) { | 523 | if (length != RAW_EPSIZE) { |
| 520 | return; | 524 | return; |
| 521 | } | 525 | } |
| 522 | send_report(USB_ENDPOINT_IN_RAW, data, length); | 526 | send_report(USB_ENDPOINT_IN_RAW, data, length); |
| 523 | } | 527 | } |
| 524 | 528 | ||
| 525 | __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) { | ||
| 526 | // Users should #include "raw_hid.h" in their own code | ||
| 527 | // and implement this function there. Leave this as weak linkage | ||
| 528 | // so users can opt to not handle data coming in. | ||
| 529 | } | ||
| 530 | |||
| 531 | void raw_hid_task(void) { | 529 | void raw_hid_task(void) { |
| 532 | uint8_t buffer[RAW_EPSIZE]; | 530 | uint8_t buffer[RAW_EPSIZE]; |
| 533 | while (receive_report(USB_ENDPOINT_OUT_RAW, buffer, sizeof(buffer))) { | 531 | while (receive_report(USB_ENDPOINT_OUT_RAW, buffer, sizeof(buffer))) { |
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index e785cb24cc..4874d7c1d3 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c | |||
| @@ -55,6 +55,9 @@ host_driver_t bt_driver = { | |||
| 55 | .send_nkro = bluetooth_send_nkro, | 55 | .send_nkro = bluetooth_send_nkro, |
| 56 | .send_mouse = bluetooth_send_mouse, | 56 | .send_mouse = bluetooth_send_mouse, |
| 57 | .send_extra = bluetooth_send_extra, | 57 | .send_extra = bluetooth_send_extra, |
| 58 | # ifdef RAW_ENABLE | ||
| 59 | .send_raw_hid = bluetooth_send_raw_hid, | ||
| 60 | # endif | ||
| 58 | }; | 61 | }; |
| 59 | #endif | 62 | #endif |
| 60 | 63 | ||
| @@ -299,6 +302,15 @@ void host_programmable_button_send(uint32_t data) { | |||
| 299 | 302 | ||
| 300 | __attribute__((weak)) void send_programmable_button(report_programmable_button_t *report) {} | 303 | __attribute__((weak)) void send_programmable_button(report_programmable_button_t *report) {} |
| 301 | 304 | ||
| 305 | #ifdef RAW_ENABLE | ||
| 306 | void host_raw_hid_send(uint8_t *data, uint8_t length) { | ||
| 307 | host_driver_t *driver = host_get_active_driver(); | ||
| 308 | if (!driver || !driver->send_raw_hid) return; | ||
| 309 | |||
| 310 | (*driver->send_raw_hid)(data, length); | ||
| 311 | } | ||
| 312 | #endif | ||
| 313 | |||
| 302 | uint16_t host_last_system_usage(void) { | 314 | uint16_t host_last_system_usage(void) { |
| 303 | return last_system_usage; | 315 | return last_system_usage; |
| 304 | } | 316 | } |
diff --git a/tmk_core/protocol/host.h b/tmk_core/protocol/host.h index 8e8a18e2ed..a0b1e73dcc 100644 --- a/tmk_core/protocol/host.h +++ b/tmk_core/protocol/host.h | |||
| @@ -41,6 +41,7 @@ void host_mouse_send(report_mouse_t *report); | |||
| 41 | void host_system_send(uint16_t usage); | 41 | void host_system_send(uint16_t usage); |
| 42 | void host_consumer_send(uint16_t usage); | 42 | void host_consumer_send(uint16_t usage); |
| 43 | void host_programmable_button_send(uint32_t data); | 43 | void host_programmable_button_send(uint32_t data); |
| 44 | void host_raw_hid_send(uint8_t *data, uint8_t length); | ||
| 44 | 45 | ||
| 45 | uint16_t host_last_system_usage(void); | 46 | uint16_t host_last_system_usage(void); |
| 46 | uint16_t host_last_consumer_usage(void); | 47 | uint16_t host_last_consumer_usage(void); |
diff --git a/tmk_core/protocol/host_driver.h b/tmk_core/protocol/host_driver.h index 8aa38b6dee..c2835aaa99 100644 --- a/tmk_core/protocol/host_driver.h +++ b/tmk_core/protocol/host_driver.h | |||
| @@ -29,6 +29,9 @@ typedef struct { | |||
| 29 | void (*send_nkro)(report_nkro_t *); | 29 | void (*send_nkro)(report_nkro_t *); |
| 30 | void (*send_mouse)(report_mouse_t *); | 30 | void (*send_mouse)(report_mouse_t *); |
| 31 | void (*send_extra)(report_extra_t *); | 31 | void (*send_extra)(report_extra_t *); |
| 32 | #ifdef RAW_ENABLE | ||
| 33 | void (*send_raw_hid)(uint8_t *, uint8_t); | ||
| 34 | #endif | ||
| 32 | } host_driver_t; | 35 | } host_driver_t; |
| 33 | 36 | ||
| 34 | void send_joystick(report_joystick_t *report); | 37 | void send_joystick(report_joystick_t *report); |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 81da035f0c..d59468133c 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -75,11 +75,24 @@ | |||
| 75 | static report_keyboard_t keyboard_report_sent; | 75 | static report_keyboard_t keyboard_report_sent; |
| 76 | 76 | ||
| 77 | /* Host driver */ | 77 | /* Host driver */ |
| 78 | static void send_keyboard(report_keyboard_t *report); | 78 | static void send_keyboard(report_keyboard_t *report); |
| 79 | static void send_nkro(report_nkro_t *report); | 79 | static void send_nkro(report_nkro_t *report); |
| 80 | static void send_mouse(report_mouse_t *report); | 80 | static void send_mouse(report_mouse_t *report); |
| 81 | static void send_extra(report_extra_t *report); | 81 | static void send_extra(report_extra_t *report); |
| 82 | host_driver_t lufa_driver = {.keyboard_leds = usb_device_state_get_leds, .send_keyboard = send_keyboard, .send_nkro = send_nkro, .send_mouse = send_mouse, .send_extra = send_extra}; | 82 | #ifdef RAW_ENABLE |
| 83 | static void send_raw_hid(uint8_t *data, uint8_t length); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | host_driver_t lufa_driver = { | ||
| 87 | .keyboard_leds = usb_device_state_get_leds, | ||
| 88 | .send_keyboard = send_keyboard, | ||
| 89 | .send_nkro = send_nkro, | ||
| 90 | .send_mouse = send_mouse, | ||
| 91 | .send_extra = send_extra, | ||
| 92 | #ifdef RAW_ENABLE | ||
| 93 | .send_raw_hid = send_raw_hid, | ||
| 94 | #endif | ||
| 95 | }; | ||
| 83 | 96 | ||
| 84 | void send_report(uint8_t endpoint, void *report, size_t size) { | 97 | void send_report(uint8_t endpoint, void *report, size_t size) { |
| 85 | uint8_t timeout = 255; | 98 | uint8_t timeout = 255; |
| @@ -131,21 +144,11 @@ USB_ClassInfo_CDC_Device_t cdc_device = { | |||
| 131 | * | 144 | * |
| 132 | * FIXME: Needs doc | 145 | * FIXME: Needs doc |
| 133 | */ | 146 | */ |
| 134 | void raw_hid_send(uint8_t *data, uint8_t length) { | 147 | static void send_raw_hid(uint8_t *data, uint8_t length) { |
| 135 | if (length != RAW_EPSIZE) return; | 148 | if (length != RAW_EPSIZE) return; |
| 136 | send_report(RAW_IN_EPNUM, data, RAW_EPSIZE); | 149 | send_report(RAW_IN_EPNUM, data, RAW_EPSIZE); |
| 137 | } | 150 | } |
| 138 | 151 | ||
| 139 | /** \brief Raw HID Receive | ||
| 140 | * | ||
| 141 | * FIXME: Needs doc | ||
| 142 | */ | ||
| 143 | __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) { | ||
| 144 | // Users should #include "raw_hid.h" in their own code | ||
| 145 | // and implement this function there. Leave this as weak linkage | ||
| 146 | // so users can opt to not handle data coming in. | ||
| 147 | } | ||
| 148 | |||
| 149 | /** \brief Raw HID Task | 152 | /** \brief Raw HID Task |
| 150 | * | 153 | * |
| 151 | * FIXME: Needs doc | 154 | * FIXME: Needs doc |
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 56cf82e5a6..43cce6eb2f 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
| @@ -144,7 +144,7 @@ static void send_report(uint8_t endpoint, void *report, size_t size) { | |||
| 144 | static uint8_t raw_output_buffer[RAW_BUFFER_SIZE]; | 144 | static uint8_t raw_output_buffer[RAW_BUFFER_SIZE]; |
| 145 | static uint8_t raw_output_received_bytes = 0; | 145 | static uint8_t raw_output_received_bytes = 0; |
| 146 | 146 | ||
| 147 | void raw_hid_send(uint8_t *data, uint8_t length) { | 147 | static void send_raw_hid(uint8_t *data, uint8_t length) { |
| 148 | if (length != RAW_BUFFER_SIZE) { | 148 | if (length != RAW_BUFFER_SIZE) { |
| 149 | return; | 149 | return; |
| 150 | } | 150 | } |
| @@ -152,12 +152,6 @@ void raw_hid_send(uint8_t *data, uint8_t length) { | |||
| 152 | send_report(4, data, 32); | 152 | send_report(4, data, 32); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) { | ||
| 156 | // Users should #include "raw_hid.h" in their own code | ||
| 157 | // and implement this function there. Leave this as weak linkage | ||
| 158 | // so users can opt to not handle data coming in. | ||
| 159 | } | ||
| 160 | |||
| 161 | void raw_hid_task(void) { | 155 | void raw_hid_task(void) { |
| 162 | usbPoll(); | 156 | usbPoll(); |
| 163 | 157 | ||
| @@ -213,8 +207,20 @@ static void send_keyboard(report_keyboard_t *report); | |||
| 213 | static void send_nkro(report_nkro_t *report); | 207 | static void send_nkro(report_nkro_t *report); |
| 214 | static void send_mouse(report_mouse_t *report); | 208 | static void send_mouse(report_mouse_t *report); |
| 215 | static void send_extra(report_extra_t *report); | 209 | static void send_extra(report_extra_t *report); |
| 210 | #ifdef RAW_ENABLE | ||
| 211 | static void send_raw_hid(uint8_t *data, uint8_t length); | ||
| 212 | #endif | ||
| 216 | 213 | ||
| 217 | 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}; | 214 | static host_driver_t driver = { |
| 215 | .keyboard_leds = usb_device_state_get_leds, | ||
| 216 | .send_keyboard = send_keyboard, | ||
| 217 | .send_nkro = send_nkro, | ||
| 218 | .send_mouse = send_mouse, | ||
| 219 | .send_extra = send_extra, | ||
| 220 | #ifdef RAW_ENABLE | ||
| 221 | .send_raw_hid = send_raw_hid, | ||
| 222 | #endif | ||
| 223 | }; | ||
| 218 | 224 | ||
| 219 | host_driver_t *vusb_driver(void) { | 225 | host_driver_t *vusb_driver(void) { |
| 220 | return &driver; | 226 | return &driver; |
