]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Initial version of Raw HID interface
authorWilba6582 <Jason.S.Wiliams@gmail.com>
Mon, 28 Nov 2016 07:31:16 +0000 (18:31 +1100)
committerWilba6582 <Jason.S.Wiliams@gmail.com>
Wed, 30 Nov 2016 13:44:54 +0000 (00:44 +1100)
keyboards/planck/planck.c
keyboards/planck/rules.mk
tmk_core/common.mk
tmk_core/common/raw_hid.h [new file with mode: 0644]
tmk_core/protocol/lufa/descriptor.c
tmk_core/protocol/lufa/descriptor.h
tmk_core/protocol/lufa/lufa.c

index 645b450d1db5ca409d3e35bc922ca1f47682ed81..0d37b6622366103991b75e21e78e910f9f400c52 100644 (file)
@@ -1,5 +1,8 @@
 #include "planck.h"
 
+#include "raw_hid.h"
+#include "keymap.h"
+
 #ifdef ONEHAND_ENABLE
 __attribute__ ((weak))
 const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
@@ -16,4 +19,15 @@ void matrix_init_kb(void) {
        PORTE |= (1<<6);
 
        matrix_init_user();
-}
\ No newline at end of file
+}
+
+#ifdef RAW_ENABLE
+
+void raw_hid_receive( uint8_t *data, uint8_t length )
+{
+       // Basic test of Raw HID
+       // Echo back data received
+       raw_hid_send( data, length );
+}
+
+#endif
index ccee972715a37324662addf229580bb74863ca68..4874d92b9fd063f238cdd61edd992c8441bc83e5 100644 (file)
@@ -62,7 +62,8 @@ AUDIO_ENABLE ?= no           # Audio output on port C6
 UNICODE_ENABLE ?= no         # Unicode
 BLUETOOTH_ENABLE ?= no       # Enable Bluetooth with the Adafruit EZ-Key HID
 RGBLIGHT_ENABLE ?= no        # Enable WS2812 RGB underlight.  Do not enable this with audio at the same time.
-API_SYSEX_ENABLE = yes
+API_SYSEX_ENABLE = no
+RAW_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
index f826a7b540b87da494a7d18fa74629523b813ecb..d65f02f12bbc0523d74624ed8b5bea53f6e4fcc4 100644 (file)
@@ -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 (file)
index 0000000..86da02f
--- /dev/null
@@ -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
index 6f2407f5805ee04a04536385b0a33669e0a4e49e..bf47787d296b3bc6817dbcb3aa1da911068e36d5 100644 (file)
@@ -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;
index c6c94e3618404db4e4ec887ede39a1b44972f319..24ce420e6ac477634dc931de7c09659f63220bf0 100644 (file)
@@ -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
index 39d4824b6b9cb6a5b5c56394d720a021bb1cb70f..aeb5f07815378f1da7f37c0f38080cabad30621d 100644 (file)
   #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;
@@ -175,6 +179,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
@@ -294,6 +372,8 @@ void EVENT_USB_Device_WakeUp()
 #endif
 }
 
+
+
 #ifdef CONSOLE_ENABLE
 static bool console_flush = false;
 #define CONSOLE_FLUSH_SET(b)   do { \
@@ -311,6 +391,7 @@ void EVENT_USB_Device_StartOfFrame(void)
     Console_Task();
     console_flush = false;
 }
+
 #endif
 
 /** Event handler for the USB_ConfigurationChanged event.
@@ -339,6 +420,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,
@@ -1064,9 +1153,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
+
     }
 }