aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorWilba6582 <Jason.S.Wiliams@gmail.com>2016-11-28 18:31:16 +1100
committerWilba6582 <Jason.S.Wiliams@gmail.com>2016-12-01 00:44:54 +1100
commitfe001d46fd06924bb81fe8d506f5be8894db3df0 (patch)
tree8beec7a385a2cdc0e6d1444a6e55e479fa47083c /tmk_core
parent81ea909467c8a5bfbd803c58e685c5de74dbc249 (diff)
downloadqmk_firmware-fe001d46fd06924bb81fe8d506f5be8894db3df0.tar.gz
qmk_firmware-fe001d46fd06924bb81fe8d506f5be8894db3df0.zip
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 f826a7b54..d65f02f12 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 39d4824b6..aeb5f0781 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -80,6 +80,10 @@
80 #include "sysex_tools.h" 80 #include "sysex_tools.h"
81#endif 81#endif
82 82
83#ifdef RAW_ENABLE
84 #include "raw_hid.h"
85#endif
86
83uint8_t keyboard_idle = 0; 87uint8_t keyboard_idle = 0;
84/* 0: Boot Protocol, 1: Report Protocol(default) */ 88/* 0: Boot Protocol, 1: Report Protocol(default) */
85uint8_t keyboard_protocol = 1; 89uint8_t keyboard_protocol = 1;
@@ -175,6 +179,80 @@ USB_ClassInfo_CDC_Device_t cdc_device =
175}; 179};
176#endif 180#endif
177 181
182#ifdef RAW_ENABLE
183
184void raw_hid_send( uint8_t *data, uint8_t length )
185{
186 // TODO: implement variable size packet
187 if ( length != RAW_EPSIZE )
188 {
189 return;
190 }
191
192 if (USB_DeviceState != DEVICE_STATE_Configured)
193 {
194 return;
195 }
196
197 // TODO: decide if we allow calls to raw_hid_send() in the middle
198 // of other endpoint usage.
199 uint8_t ep = Endpoint_GetCurrentEndpoint();
200
201 Endpoint_SelectEndpoint(RAW_IN_EPNUM);
202
203 // Check to see if the host is ready to accept another packet
204 if (Endpoint_IsINReady())
205 {
206 // Write data
207 Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
208 // Finalize the stream transfer to send the last packet
209 Endpoint_ClearIN();
210 }
211
212 Endpoint_SelectEndpoint(ep);
213}
214
215__attribute__ ((weak))
216void raw_hid_receive( uint8_t *data, uint8_t length )
217{
218 // Users should #include "raw_hid.h" in their own code
219 // and implement this function there. Leave this as weak linkage
220 // so users can opt to not handle data coming in.
221}
222
223static void raw_hid_task(void)
224{
225 // Create a temporary buffer to hold the read in data from the host
226 uint8_t data[RAW_EPSIZE];
227 bool data_read = false;
228
229 // Device must be connected and configured for the task to run
230 if (USB_DeviceState != DEVICE_STATE_Configured)
231 return;
232
233 Endpoint_SelectEndpoint(RAW_OUT_EPNUM);
234
235 // Check to see if a packet has been sent from the host
236 if (Endpoint_IsOUTReceived())
237 {
238 // Check to see if the packet contains data
239 if (Endpoint_IsReadWriteAllowed())
240 {
241 /* Read data */
242 Endpoint_Read_Stream_LE(data, sizeof(data), NULL);
243 data_read = true;
244 }
245
246 // Finalize the stream transfer to receive the last packet
247 Endpoint_ClearOUT();
248
249 if ( data_read )
250 {
251 raw_hid_receive( data, sizeof(data) );
252 }
253 }
254}
255#endif
178 256
179/******************************************************************************* 257/*******************************************************************************
180 * Console 258 * Console
@@ -294,6 +372,8 @@ void EVENT_USB_Device_WakeUp()
294#endif 372#endif
295} 373}
296 374
375
376
297#ifdef CONSOLE_ENABLE 377#ifdef CONSOLE_ENABLE
298static bool console_flush = false; 378static bool console_flush = false;
299#define CONSOLE_FLUSH_SET(b) do { \ 379#define CONSOLE_FLUSH_SET(b) do { \
@@ -311,6 +391,7 @@ void EVENT_USB_Device_StartOfFrame(void)
311 Console_Task(); 391 Console_Task();
312 console_flush = false; 392 console_flush = false;
313} 393}
394
314#endif 395#endif
315 396
316/** Event handler for the USB_ConfigurationChanged event. 397/** Event handler for the USB_ConfigurationChanged event.
@@ -339,6 +420,14 @@ void EVENT_USB_Device_ConfigurationChanged(void)
339 EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE); 420 EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE);
340#endif 421#endif
341 422
423#ifdef RAW_ENABLE
424 /* Setup Raw HID Report Endpoints */
425 ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
426 RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
427 ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
428 RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
429#endif
430
342#ifdef CONSOLE_ENABLE 431#ifdef CONSOLE_ENABLE
343 /* Setup Console HID Report Endpoints */ 432 /* Setup Console HID Report Endpoints */
344 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, 433 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
@@ -1064,9 +1153,14 @@ int main(void)
1064 CDC_Device_USBTask(&cdc_device); 1153 CDC_Device_USBTask(&cdc_device);
1065#endif 1154#endif
1066 1155
1156#ifdef RAW_ENABLE
1157 raw_hid_task();
1158#endif
1159
1067#if !defined(INTERRUPT_CONTROL_ENDPOINT) 1160#if !defined(INTERRUPT_CONTROL_ENDPOINT)
1068 USB_USBTask(); 1161 USB_USBTask();
1069#endif 1162#endif
1163
1070 } 1164 }
1071} 1165}
1072 1166