summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-12-05 00:13:37 -0500
committerGitHub <noreply@github.com>2016-12-05 00:13:37 -0500
commitc87d039839a67b0cae73a9bd85572a6cd08d117d (patch)
tree0a8b413164116ac34cbeb36dd589a55852ab81d3
parentd15d1d383322b10a9a88871dbf303d1067382e76 (diff)
parent1eec2b7277ed24a63c42ea6b53a4db530c35dbbd (diff)
Merge pull request #921 from Wilba6582/raw_hid
Initial version of Raw HID interface
-rw-r--r--keyboards/planck/planck.c2
-rw-r--r--keyboards/planck/rules.mk2
-rw-r--r--tmk_core/common.mk4
-rw-r--r--tmk_core/common/raw_hid.h8
-rw-r--r--tmk_core/protocol/lufa/descriptor.c87
-rw-r--r--tmk_core/protocol/lufa/descriptor.h35
-rw-r--r--tmk_core/protocol/lufa/lufa.c94
7 files changed, 222 insertions, 10 deletions
diff --git a/keyboards/planck/planck.c b/keyboards/planck/planck.c
index 645b450d1d..3980b02f50 100644
--- a/keyboards/planck/planck.c
+++ b/keyboards/planck/planck.c
@@ -16,4 +16,4 @@ void matrix_init_kb(void) {
PORTE |= (1<<6);
matrix_init_user();
-} \ No newline at end of file
+}
diff --git a/keyboards/planck/rules.mk b/keyboards/planck/rules.mk
index ccee972715..fb24e82354 100644
--- a/keyboards/planck/rules.mk
+++ b/keyboards/planck/rules.mk
@@ -65,4 +65,4 @@ RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this
API_SYSEX_ENABLE = yes
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
-SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend \ No newline at end of file
+SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index c32a12bb6f..3c1373c081 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -50,6 +50,10 @@ ifeq ($(strip $(EXTRAKEY_ENABLE)), yes)
TMK_COMMON_DEFS += -DEXTRAKEY_ENABLE
endif
+ifeq ($(strip $(RAW_ENABLE)), yes)
+ TMK_COMMON_DEFS += -DRAW_ENABLE
+endif
+
ifeq ($(strip $(CONSOLE_ENABLE)), yes)
TMK_COMMON_DEFS += -DCONSOLE_ENABLE
else
diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h
new file mode 100644
index 0000000000..86da02fd15
--- /dev/null
+++ b/tmk_core/common/raw_hid.h
@@ -0,0 +1,8 @@
+#ifndef _RAW_HID_H_
+#define _RAW_HID_H_
+
+void raw_hid_receive( uint8_t *data, uint8_t length );
+
+void raw_hid_send( uint8_t *data, uint8_t length );
+
+#endif
diff --git a/tmk_core/protocol/lufa/descriptor.c b/tmk_core/protocol/lufa/descriptor.c
index 6f2407f580..bf47787d29 100644
--- a/tmk_core/protocol/lufa/descriptor.c
+++ b/tmk_core/protocol/lufa/descriptor.c
@@ -164,6 +164,28 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtrakeyReport[] =
};
#endif
+#ifdef RAW_ENABLE
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM RawReport[] =
+{
+ HID_RI_USAGE_PAGE(16, 0xFF60), /* Vendor Page 0xFF60 */
+ HID_RI_USAGE(8, 0x61), /* Vendor Usage 0x61 */
+ HID_RI_COLLECTION(8, 0x01), /* Application */
+ HID_RI_USAGE(8, 0x62), /* Vendor Usage 0x62 */
+ HID_RI_LOGICAL_MINIMUM(8, 0x00),
+ HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+ HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+ HID_RI_USAGE(8, 0x63), /* Vendor Usage 0x63 */
+ HID_RI_LOGICAL_MINIMUM(8, 0x00),
+ HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
+ HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
+ HID_RI_END_COLLECTION(0),
+};
+#endif
+
#ifdef CONSOLE_ENABLE
const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] =
{
@@ -399,6 +421,58 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
},
#endif
+ /*
+ * Raw
+ */
+ #ifdef RAW_ENABLE
+ .Raw_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+
+ .InterfaceNumber = RAW_INTERFACE,
+ .AlternateSetting = 0x00,
+
+ .TotalEndpoints = 2,
+
+ .Class = HID_CSCP_HIDClass,
+ .SubClass = HID_CSCP_NonBootSubclass,
+ .Protocol = HID_CSCP_NonBootProtocol,
+
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+
+ .Raw_HID =
+ {
+ .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
+
+ .HIDSpec = VERSION_BCD(1,1,1),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = HID_DTYPE_Report,
+ .HIDReportLength = sizeof(RawReport)
+ },
+
+ .Raw_INEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = (ENDPOINT_DIR_IN | RAW_IN_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = RAW_EPSIZE,
+ .PollingIntervalMS = 0x01
+ },
+
+ .Raw_OUTEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = (ENDPOINT_DIR_OUT | RAW_OUT_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = RAW_EPSIZE,
+ .PollingIntervalMS = 0x01
+ },
+ #endif
+
/*
* Console
*/
@@ -754,7 +828,6 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.PollingIntervalMS = 0x05
},
#endif
-
};
@@ -846,6 +919,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
#endif
+#ifdef RAW_ENABLE
+ case RAW_INTERFACE:
+ Address = &ConfigurationDescriptor.Raw_HID;
+ Size = sizeof(USB_HID_Descriptor_HID_t);
+ break;
+#endif
#ifdef CONSOLE_ENABLE
case CONSOLE_INTERFACE:
Address = &ConfigurationDescriptor.Console_HID;
@@ -878,6 +957,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
Size = sizeof(ExtrakeyReport);
break;
#endif
+#ifdef RAW_ENABLE
+ case RAW_INTERFACE:
+ Address = &RawReport;
+ Size = sizeof(RawReport);
+ break;
+#endif
#ifdef CONSOLE_ENABLE
case CONSOLE_INTERFACE:
Address = &ConsoleReport;
diff --git a/tmk_core/protocol/lufa/descriptor.h b/tmk_core/protocol/lufa/descriptor.h
index c6c94e3618..24ce420e6a 100644
--- a/tmk_core/protocol/lufa/descriptor.h
+++ b/tmk_core/protocol/lufa/descriptor.h
@@ -71,6 +71,14 @@ typedef struct
USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
#endif
+#ifdef RAW_ENABLE
+ // Raw HID Interface
+ USB_Descriptor_Interface_t Raw_Interface;
+ USB_HID_Descriptor_HID_t Raw_HID;
+ USB_Descriptor_Endpoint_t Raw_INEndpoint;
+ USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
+#endif
+
#ifdef CONSOLE_ENABLE
// Console HID Interface
USB_Descriptor_Interface_t Console_Interface;
@@ -137,10 +145,16 @@ typedef struct
# define EXTRAKEY_INTERFACE MOUSE_INTERFACE
#endif
+#ifdef RAW_ENABLE
+# define RAW_INTERFACE (EXTRAKEY_INTERFACE + 1)
+#else
+# define RAW_INTERFACE EXTRAKEY_INTERFACE
+#endif
+
#ifdef CONSOLE_ENABLE
-# define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1)
+# define CONSOLE_INTERFACE (RAW_INTERFACE + 1)
#else
-# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
+# define CONSOLE_INTERFACE RAW_INTERFACE
#endif
#ifdef NKRO_ENABLE
@@ -182,12 +196,19 @@ typedef struct
# define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
#endif
+#ifdef RAW_ENABLE
+# define RAW_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
+# define RAW_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
+#else
+# define RAW_OUT_EPNUM EXTRAKEY_IN_EPNUM
+#endif
+
#ifdef CONSOLE_ENABLE
-# define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
-# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 1)
-//# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
+# define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
+//# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
+# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
#else
-# define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM
+# define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
#endif
#ifdef NKRO_ENABLE
@@ -217,7 +238,6 @@ typedef struct
# define CDC_OUT_EPNUM MIDI_STREAM_OUT_EPNUM
#endif
-
#if defined(__AVR_ATmega32U2__) && CDC_OUT_EPNUM > 4
# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL)"
#endif
@@ -225,6 +245,7 @@ typedef struct
#define KEYBOARD_EPSIZE 8
#define MOUSE_EPSIZE 8
#define EXTRAKEY_EPSIZE 8
+#define RAW_EPSIZE 32
#define CONSOLE_EPSIZE 32
#define NKRO_EPSIZE 32
#define MIDI_STREAM_EPSIZE 64
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index ee2552c190..dd78fe6213 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -84,6 +84,10 @@
#include "sysex_tools.h"
#endif
+#ifdef RAW_ENABLE
+ #include "raw_hid.h"
+#endif
+
uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1;
@@ -179,6 +183,80 @@ USB_ClassInfo_CDC_Device_t cdc_device =
};
#endif
+#ifdef RAW_ENABLE
+
+void raw_hid_send( uint8_t *data, uint8_t length )
+{
+ // TODO: implement variable size packet
+ if ( length != RAW_EPSIZE )
+ {
+ return;
+ }
+
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ {
+ return;
+ }
+
+ // TODO: decide if we allow calls to raw_hid_send() in the middle
+ // of other endpoint usage.
+ uint8_t ep = Endpoint_GetCurrentEndpoint();
+
+ Endpoint_SelectEndpoint(RAW_IN_EPNUM);
+
+ // Check to see if the host is ready to accept another packet
+ if (Endpoint_IsINReady())
+ {
+ // Write data
+ Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
+ // Finalize the stream transfer to send the last packet
+ Endpoint_ClearIN();
+ }
+
+ Endpoint_SelectEndpoint(ep);
+}
+
+__attribute__ ((weak))
+void raw_hid_receive( 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.
+}
+
+static void raw_hid_task(void)
+{
+ // Create a temporary buffer to hold the read in data from the host
+ uint8_t data[RAW_EPSIZE];
+ bool data_read = false;
+
+ // Device must be connected and configured for the task to run
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ return;
+
+ Endpoint_SelectEndpoint(RAW_OUT_EPNUM);
+
+ // Check to see if a packet has been sent from the host
+ if (Endpoint_IsOUTReceived())
+ {
+ // Check to see if the packet contains data
+ if (Endpoint_IsReadWriteAllowed())
+ {
+ /* Read data */
+ Endpoint_Read_Stream_LE(data, sizeof(data), NULL);
+ data_read = true;
+ }
+
+ // Finalize the stream transfer to receive the last packet
+ Endpoint_ClearOUT();
+
+ if ( data_read )
+ {
+ raw_hid_receive( data, sizeof(data) );
+ }
+ }
+}
+#endif
/*******************************************************************************
* Console
@@ -298,6 +376,8 @@ void EVENT_USB_Device_WakeUp()
#endif
}
+
+
#ifdef CONSOLE_ENABLE
static bool console_flush = false;
#define CONSOLE_FLUSH_SET(b) do { \
@@ -317,6 +397,7 @@ void EVENT_USB_Device_StartOfFrame(void)
Console_Task();
console_flush = false;
}
+
#endif
/** Event handler for the USB_ConfigurationChanged event.
@@ -345,6 +426,14 @@ void EVENT_USB_Device_ConfigurationChanged(void)
EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE);
#endif
+#ifdef RAW_ENABLE
+ /* Setup Raw HID Report Endpoints */
+ ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
+ RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
+ ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
+ RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
+#endif
+
#ifdef CONSOLE_ENABLE
/* Setup Console HID Report Endpoints */
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
@@ -1124,9 +1213,14 @@ int main(void)
CDC_Device_USBTask(&cdc_device);
#endif
+#ifdef RAW_ENABLE
+ raw_hid_task();
+#endif
+
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
+
}
}