diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-12-05 00:13:37 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-12-05 00:13:37 -0500 |
| commit | c87d039839a67b0cae73a9bd85572a6cd08d117d (patch) | |
| tree | 0a8b413164116ac34cbeb36dd589a55852ab81d3 /tmk_core/protocol/lufa/lufa.c | |
| parent | d15d1d383322b10a9a88871dbf303d1067382e76 (diff) | |
| parent | 1eec2b7277ed24a63c42ea6b53a4db530c35dbbd (diff) | |
| download | qmk_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/protocol/lufa/lufa.c')
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 94 |
1 files changed, 94 insertions, 0 deletions
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 | |||
| 87 | uint8_t keyboard_idle = 0; | 91 | uint8_t keyboard_idle = 0; |
| 88 | /* 0: Boot Protocol, 1: Report Protocol(default) */ | 92 | /* 0: Boot Protocol, 1: Report Protocol(default) */ |
| 89 | uint8_t keyboard_protocol = 1; | 93 | uint8_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 | |||
| 188 | void 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)) | ||
| 220 | void 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 | |||
| 227 | static 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 |
| 302 | static bool console_flush = false; | 382 | static 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 | ||
