From ee079a41f1450ef567e15699275596ebe058236a Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Fri, 2 Oct 2020 11:10:08 +0100 Subject: async handing of colour --- tmk_core/common/raw_hid.h | 1 + tmk_core/protocol/vusb/vusb.c | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'tmk_core') diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h index c579157f1..1e4be6a92 100644 --- a/tmk_core/common/raw_hid.h +++ b/tmk_core/common/raw_hid.h @@ -2,6 +2,7 @@ #define _RAW_HID_H_ void raw_hid_receive(uint8_t *data, uint8_t length); +void raw_hid_dispatch(void); void raw_hid_send(uint8_t *data, uint8_t length); diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 7d1a0a7a2..c32b595bc 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -107,10 +107,8 @@ void vusb_transfer_keyboard(void) { * RAW HID *------------------------------------------------------------------*/ #ifdef RAW_ENABLE -# define RAW_BUFFER_SIZE 8 # define RAW_EPSIZE 8 -static uint8_t raw_output_buffer[RAW_BUFFER_SIZE]; static uint8_t raw_output_received_bytes = 0; #if 0 @@ -140,11 +138,15 @@ __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) { // so users can opt to not handle data coming in. } +__attribute__((weak)) void raw_hid_dispatch(void) { + // 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. +} + + void raw_hid_task(void) { - if (raw_output_received_bytes == RAW_BUFFER_SIZE) { - raw_hid_receive(raw_output_buffer, RAW_BUFFER_SIZE); - raw_output_received_bytes = 0; - } + raw_hid_dispatch(); } #endif @@ -340,16 +342,9 @@ uchar usbFunctionWrite(uchar *data, uchar len) { void usbFunctionWriteOut(uchar *data, uchar len) { #ifdef RAW_ENABLE // Data from host must be divided every 8bytes - if (len != 8) { - dprint("RAW: invalid length\n"); - raw_output_received_bytes = 0; - return; - } + raw_hid_receive(data, len); - for (uint8_t i = 0; i < 8; i++) { - raw_output_buffer[i] = data[i]; - } - raw_output_received_bytes = len; + raw_output_received_bytes = 1; #endif } @@ -491,14 +486,14 @@ const PROGMEM uchar raw_hid_report[] = { 0x09, 0x62, // Usage (Vendor Defined) 0x15, 0x00, // Logical Minimum (0) 0x26, 0xFF, 0x00, // Logical Maximum (255) - 0x95, RAW_BUFFER_SIZE, // Report Count + 0x95, RAW_EPSIZE, // Report Count 0x75, 0x08, // Report Size (8) 0x81, 0x02, // Input (Data, Variable, Absolute) // Data from host 0x09, 0x63, // Usage (Vendor Defined) 0x15, 0x00, // Logical Minimum (0) 0x26, 0xFF, 0x00, // Logical Maximum (255) - 0x95, RAW_BUFFER_SIZE, // Report Count + 0x95, RAW_EPSIZE, // Report Count 0x75, 0x08, // Report Size (8) 0x91, 0x02, // Output (Data, Variable, Absolute) 0xC0 // End Collection -- cgit v1.2.3