aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
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 /tmk_core
parentd15d1d383322b10a9a88871dbf303d1067382e76 (diff)
parent1eec2b7277ed24a63c42ea6b53a4db530c35dbbd (diff)
downloadqmk_firmware-c87d039839a67b0cae73a9bd85572a6cd08d117d.tar.gz
qmk_firmware-c87d039839a67b0cae73a9bd85572a6cd08d117d.zip
Merge pull request #921 from Wilba6582/raw_hid
Initial version of Raw HID interface
Diffstat (limited to 'tmk_core')
-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
5 files changed, 220 insertions, 8 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index c32a12bb6..3c1373c08 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -50,6 +50,10 @@ ifeq ($(strip $(EXTRAKEY_ENABLE)), yes)
50 TMK_COMMON_DEFS += -DEXTRAKEY_ENABLE 50 TMK_COMMON_DEFS += -DEXTRAKEY_ENABLE
51endif 51endif
52 52
53ifeq ($(strip $(RAW_ENABLE)), yes)
54 TMK_COMMON_DEFS += -DRAW_ENABLE
55endif
56
53ifeq ($(strip $(CONSOLE_ENABLE)), yes) 57ifeq ($(strip $(CONSOLE_ENABLE)), yes)
54 TMK_COMMON_DEFS += -DCONSOLE_ENABLE 58 TMK_COMMON_DEFS += -DCONSOLE_ENABLE
55else 59else
diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h
new file mode 100644
index 000000000..86da02fd1
--- /dev/null
+++ b/tmk_core/common/raw_hid.h
@@ -0,0 +1,8 @@
1#ifndef _RAW_HID_H_
2#define _RAW_HID_H_
3
4void raw_hid_receive( uint8_t *data, uint8_t length );
5
6void raw_hid_send( uint8_t *data, uint8_t length );
7
8#endif
diff --git a/tmk_core/protocol/lufa/descriptor.c b/tmk_core/protocol/lufa/descriptor.c
index 6f2407f58..bf47787d2 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[] =
164}; 164};
165#endif 165#endif
166 166
167#ifdef RAW_ENABLE
168const USB_Descriptor_HIDReport_Datatype_t PROGMEM RawReport[] =
169{
170 HID_RI_USAGE_PAGE(16, 0xFF60), /* Vendor Page 0xFF60 */
171 HID_RI_USAGE(8, 0x61), /* Vendor Usage 0x61 */
172 HID_RI_COLLECTION(8, 0x01), /* Application */
173 HID_RI_USAGE(8, 0x62), /* Vendor Usage 0x62 */
174 HID_RI_LOGICAL_MINIMUM(8, 0x00),
175 HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
176 HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
177 HID_RI_REPORT_SIZE(8, 0x08),
178 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
179 HID_RI_USAGE(8, 0x63), /* Vendor Usage 0x63 */
180 HID_RI_LOGICAL_MINIMUM(8, 0x00),
181 HID_RI_LOGICAL_MAXIMUM(16, 0x00FF),
182 HID_RI_REPORT_COUNT(8, RAW_EPSIZE),
183 HID_RI_REPORT_SIZE(8, 0x08),
184 HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
185 HID_RI_END_COLLECTION(0),
186};
187#endif
188
167#ifdef CONSOLE_ENABLE 189#ifdef CONSOLE_ENABLE
168const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = 190const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] =
169{ 191{
@@ -399,6 +421,58 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
399 }, 421 },
400#endif 422#endif
401 423
424 /*
425 * Raw
426 */
427 #ifdef RAW_ENABLE
428 .Raw_Interface =
429 {
430 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
431
432 .InterfaceNumber = RAW_INTERFACE,
433 .AlternateSetting = 0x00,
434
435 .TotalEndpoints = 2,
436
437 .Class = HID_CSCP_HIDClass,
438 .SubClass = HID_CSCP_NonBootSubclass,
439 .Protocol = HID_CSCP_NonBootProtocol,
440
441 .InterfaceStrIndex = NO_DESCRIPTOR
442 },
443
444 .Raw_HID =
445 {
446 .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
447
448 .HIDSpec = VERSION_BCD(1,1,1),
449 .CountryCode = 0x00,
450 .TotalReportDescriptors = 1,
451 .HIDReportType = HID_DTYPE_Report,
452 .HIDReportLength = sizeof(RawReport)
453 },
454
455 .Raw_INEndpoint =
456 {
457 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
458
459 .EndpointAddress = (ENDPOINT_DIR_IN | RAW_IN_EPNUM),
460 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
461 .EndpointSize = RAW_EPSIZE,
462 .PollingIntervalMS = 0x01
463 },
464
465 .Raw_OUTEndpoint =
466 {
467 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
468
469 .EndpointAddress = (ENDPOINT_DIR_OUT | RAW_OUT_EPNUM),
470 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
471 .EndpointSize = RAW_EPSIZE,
472 .PollingIntervalMS = 0x01
473 },
474 #endif
475
402 /* 476 /*
403 * Console 477 * Console
404 */ 478 */
@@ -754,7 +828,6 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
754 .PollingIntervalMS = 0x05 828 .PollingIntervalMS = 0x05
755 }, 829 },
756#endif 830#endif
757
758}; 831};
759 832
760 833
@@ -846,6 +919,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
846 Size = sizeof(USB_HID_Descriptor_HID_t); 919 Size = sizeof(USB_HID_Descriptor_HID_t);
847 break; 920 break;
848#endif 921#endif
922#ifdef RAW_ENABLE
923 case RAW_INTERFACE:
924 Address = &ConfigurationDescriptor.Raw_HID;
925 Size = sizeof(USB_HID_Descriptor_HID_t);
926 break;
927#endif
849#ifdef CONSOLE_ENABLE 928#ifdef CONSOLE_ENABLE
850 case CONSOLE_INTERFACE: 929 case CONSOLE_INTERFACE:
851 Address = &ConfigurationDescriptor.Console_HID; 930 Address = &ConfigurationDescriptor.Console_HID;
@@ -878,6 +957,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
878 Size = sizeof(ExtrakeyReport); 957 Size = sizeof(ExtrakeyReport);
879 break; 958 break;
880#endif 959#endif
960#ifdef RAW_ENABLE
961 case RAW_INTERFACE:
962 Address = &RawReport;
963 Size = sizeof(RawReport);
964 break;
965#endif
881#ifdef CONSOLE_ENABLE 966#ifdef CONSOLE_ENABLE
882 case CONSOLE_INTERFACE: 967 case CONSOLE_INTERFACE:
883 Address = &ConsoleReport; 968 Address = &ConsoleReport;
diff --git a/tmk_core/protocol/lufa/descriptor.h b/tmk_core/protocol/lufa/descriptor.h
index c6c94e361..24ce420e6 100644
--- a/tmk_core/protocol/lufa/descriptor.h
+++ b/tmk_core/protocol/lufa/descriptor.h
@@ -71,6 +71,14 @@ typedef struct
71 USB_Descriptor_Endpoint_t Extrakey_INEndpoint; 71 USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
72#endif 72#endif
73 73
74#ifdef RAW_ENABLE
75 // Raw HID Interface
76 USB_Descriptor_Interface_t Raw_Interface;
77 USB_HID_Descriptor_HID_t Raw_HID;
78 USB_Descriptor_Endpoint_t Raw_INEndpoint;
79 USB_Descriptor_Endpoint_t Raw_OUTEndpoint;
80#endif
81
74#ifdef CONSOLE_ENABLE 82#ifdef CONSOLE_ENABLE
75 // Console HID Interface 83 // Console HID Interface
76 USB_Descriptor_Interface_t Console_Interface; 84 USB_Descriptor_Interface_t Console_Interface;
@@ -137,10 +145,16 @@ typedef struct
137# define EXTRAKEY_INTERFACE MOUSE_INTERFACE 145# define EXTRAKEY_INTERFACE MOUSE_INTERFACE
138#endif 146#endif
139 147
148#ifdef RAW_ENABLE
149# define RAW_INTERFACE (EXTRAKEY_INTERFACE + 1)
150#else
151# define RAW_INTERFACE EXTRAKEY_INTERFACE
152#endif
153
140#ifdef CONSOLE_ENABLE 154#ifdef CONSOLE_ENABLE
141# define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1) 155# define CONSOLE_INTERFACE (RAW_INTERFACE + 1)
142#else 156#else
143# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE 157# define CONSOLE_INTERFACE RAW_INTERFACE
144#endif 158#endif
145 159
146#ifdef NKRO_ENABLE 160#ifdef NKRO_ENABLE
@@ -182,12 +196,19 @@ typedef struct
182# define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM 196# define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
183#endif 197#endif
184 198
199#ifdef RAW_ENABLE
200# define RAW_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
201# define RAW_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
202#else
203# define RAW_OUT_EPNUM EXTRAKEY_IN_EPNUM
204#endif
205
185#ifdef CONSOLE_ENABLE 206#ifdef CONSOLE_ENABLE
186# define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1) 207# define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
187# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 1) 208//# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
188//# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2) 209# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
189#else 210#else
190# define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM 211# define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
191#endif 212#endif
192 213
193#ifdef NKRO_ENABLE 214#ifdef NKRO_ENABLE
@@ -217,7 +238,6 @@ typedef struct
217# define CDC_OUT_EPNUM MIDI_STREAM_OUT_EPNUM 238# define CDC_OUT_EPNUM MIDI_STREAM_OUT_EPNUM
218#endif 239#endif
219 240
220
221#if defined(__AVR_ATmega32U2__) && CDC_OUT_EPNUM > 4 241#if defined(__AVR_ATmega32U2__) && CDC_OUT_EPNUM > 4
222# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL)" 242# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL)"
223#endif 243#endif
@@ -225,6 +245,7 @@ typedef struct
225#define KEYBOARD_EPSIZE 8 245#define KEYBOARD_EPSIZE 8
226#define MOUSE_EPSIZE 8 246#define MOUSE_EPSIZE 8
227#define EXTRAKEY_EPSIZE 8 247#define EXTRAKEY_EPSIZE 8
248#define RAW_EPSIZE 32
228#define CONSOLE_EPSIZE 32 249#define CONSOLE_EPSIZE 32
229#define NKRO_EPSIZE 32 250#define NKRO_EPSIZE 32
230#define MIDI_STREAM_EPSIZE 64 251#define MIDI_STREAM_EPSIZE 64
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index ee2552c19..dd78fe621 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -84,6 +84,10 @@
84 #include "sysex_tools.h" 84 #include "sysex_tools.h"
85#endif 85#endif
86 86
87#ifdef RAW_ENABLE
88 #include "raw_hid.h"
89#endif
90
87uint8_t keyboard_idle = 0; 91uint8_t keyboard_idle = 0;
88/* 0: Boot Protocol, 1: Report Protocol(default) */ 92/* 0: Boot Protocol, 1: Report Protocol(default) */
89uint8_t keyboard_protocol = 1; 93uint8_t keyboard_protocol = 1;
@@ -179,6 +183,80 @@ USB_ClassInfo_CDC_Device_t cdc_device =
179}; 183};
180#endif 184#endif
181 185
186#ifdef RAW_ENABLE
187
188void raw_hid_send( uint8_t *data, uint8_t length )
189{
190 // TODO: implement variable size packet
191 if ( length != RAW_EPSIZE )
192 {
193 return;
194 }
195
196 if (USB_DeviceState != DEVICE_STATE_Configured)
197 {
198 return;
199 }
200
201 // TODO: decide if we allow calls to raw_hid_send() in the middle
202 // of other endpoint usage.
203 uint8_t ep = Endpoint_GetCurrentEndpoint();
204
205 Endpoint_SelectEndpoint(RAW_IN_EPNUM);
206
207 // Check to see if the host is ready to accept another packet
208 if (Endpoint_IsINReady())
209 {
210 // Write data
211 Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
212 // Finalize the stream transfer to send the last packet
213 Endpoint_ClearIN();
214 }
215
216 Endpoint_SelectEndpoint(ep);
217}
218
219__attribute__ ((weak))
220void raw_hid_receive( uint8_t *data, uint8_t length )
221{
222 // Users should #include "raw_hid.h" in their own code
223 // and implement this function there. Leave this as weak linkage
224 // so users can opt to not handle data coming in.
225}
226
227static void raw_hid_task(void)
228{
229 // Create a temporary buffer to hold the read in data from the host
230 uint8_t data[RAW_EPSIZE];
231 bool data_read = false;
232
233 // Device must be connected and configured for the task to run
234 if (USB_DeviceState != DEVICE_STATE_Configured)
235 return;
236
237 Endpoint_SelectEndpoint(RAW_OUT_EPNUM);
238
239 // Check to see if a packet has been sent from the host
240 if (Endpoint_IsOUTReceived())
241 {
242 // Check to see if the packet contains data
243 if (Endpoint_IsReadWriteAllowed())
244 {
245 /* Read data */
246 Endpoint_Read_Stream_LE(data, sizeof(data), NULL);
247 data_read = true;
248 }
249
250 // Finalize the stream transfer to receive the last packet
251 Endpoint_ClearOUT();
252
253 if ( data_read )
254 {
255 raw_hid_receive( data, sizeof(data) );
256 }
257 }
258}
259#endif
182 260
183/******************************************************************************* 261/*******************************************************************************
184 * Console 262 * Console
@@ -298,6 +376,8 @@ void EVENT_USB_Device_WakeUp()
298#endif 376#endif
299} 377}
300 378
379
380
301#ifdef CONSOLE_ENABLE 381#ifdef CONSOLE_ENABLE
302static bool console_flush = false; 382static bool console_flush = false;
303#define CONSOLE_FLUSH_SET(b) do { \ 383#define CONSOLE_FLUSH_SET(b) do { \
@@ -317,6 +397,7 @@ void EVENT_USB_Device_StartOfFrame(void)
317 Console_Task(); 397 Console_Task();
318 console_flush = false; 398 console_flush = false;
319} 399}
400
320#endif 401#endif
321 402
322/** Event handler for the USB_ConfigurationChanged event. 403/** Event handler for the USB_ConfigurationChanged event.
@@ -345,6 +426,14 @@ void EVENT_USB_Device_ConfigurationChanged(void)
345 EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE); 426 EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE);
346#endif 427#endif
347 428
429#ifdef RAW_ENABLE
430 /* Setup Raw HID Report Endpoints */
431 ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
432 RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
433 ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
434 RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
435#endif
436
348#ifdef CONSOLE_ENABLE 437#ifdef CONSOLE_ENABLE
349 /* Setup Console HID Report Endpoints */ 438 /* Setup Console HID Report Endpoints */
350 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, 439 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
@@ -1124,9 +1213,14 @@ int main(void)
1124 CDC_Device_USBTask(&cdc_device); 1213 CDC_Device_USBTask(&cdc_device);
1125#endif 1214#endif
1126 1215
1216#ifdef RAW_ENABLE
1217 raw_hid_task();
1218#endif
1219
1127#if !defined(INTERRUPT_CONTROL_ENDPOINT) 1220#if !defined(INTERRUPT_CONTROL_ENDPOINT)
1128 USB_USBTask(); 1221 USB_USBTask();
1129#endif 1222#endif
1223
1130 } 1224 }
1131} 1225}
1132 1226