diff options
Diffstat (limited to 'protocol/lufa/lufa.c')
| -rw-r--r-- | protocol/lufa/lufa.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 10511ba67..99d241ded 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -111,6 +111,7 @@ void SetupHardware(void) | |||
| 111 | USB_Device_EnableSOFEvents(); | 111 | USB_Device_EnableSOFEvents(); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | #ifdef CONSOLE_ENABLE | ||
| 114 | static void Console_Task(void) | 115 | static void Console_Task(void) |
| 115 | { | 116 | { |
| 116 | /* Device must be connected and configured for the task to run */ | 117 | /* Device must be connected and configured for the task to run */ |
| @@ -146,6 +147,11 @@ static void Console_Task(void) | |||
| 146 | 147 | ||
| 147 | /* IN packet */ | 148 | /* IN packet */ |
| 148 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); | 149 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); |
| 150 | |||
| 151 | // fill empty bank | ||
| 152 | while (Endpoint_IsReadWriteAllowed()) | ||
| 153 | Endpoint_Write_8(0); | ||
| 154 | |||
| 149 | // flash senchar packet | 155 | // flash senchar packet |
| 150 | if (Endpoint_IsINReady()) { | 156 | if (Endpoint_IsINReady()) { |
| 151 | Endpoint_ClearIN(); | 157 | Endpoint_ClearIN(); |
| @@ -153,6 +159,11 @@ static void Console_Task(void) | |||
| 153 | 159 | ||
| 154 | Endpoint_SelectEndpoint(ep); | 160 | Endpoint_SelectEndpoint(ep); |
| 155 | } | 161 | } |
| 162 | #else | ||
| 163 | static void Console_Task(void) | ||
| 164 | { | ||
| 165 | } | ||
| 166 | #endif | ||
| 156 | 167 | ||
| 157 | 168 | ||
| 158 | /******************************************************************************* | 169 | /******************************************************************************* |
| @@ -168,14 +179,9 @@ void EVENT_USB_Device_Disconnect(void) | |||
| 168 | { | 179 | { |
| 169 | } | 180 | } |
| 170 | 181 | ||
| 171 | #define CONSOLE_TASK_INTERVAL 50 | ||
| 172 | void EVENT_USB_Device_StartOfFrame(void) | 182 | void EVENT_USB_Device_StartOfFrame(void) |
| 173 | { | 183 | { |
| 174 | static uint8_t interval; | 184 | Console_Task(); |
| 175 | if (++interval == CONSOLE_TASK_INTERVAL) { | ||
| 176 | Console_Task(); | ||
| 177 | interval = 0; | ||
| 178 | } | ||
| 179 | } | 185 | } |
| 180 | 186 | ||
| 181 | /** Event handler for the USB_ConfigurationChanged event. | 187 | /** Event handler for the USB_ConfigurationChanged event. |
| @@ -197,15 +203,17 @@ void EVENT_USB_Device_ConfigurationChanged(void) | |||
| 197 | 203 | ||
| 198 | #ifdef EXTRAKEY_ENABLE | 204 | #ifdef EXTRAKEY_ENABLE |
| 199 | /* Setup Extra HID Report Endpoint */ | 205 | /* Setup Extra HID Report Endpoint */ |
| 200 | ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRA_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 206 | ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRAKEY_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 201 | EXTRA_EPSIZE, ENDPOINT_BANK_SINGLE); | 207 | EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 202 | #endif | 208 | #endif |
| 203 | 209 | ||
| 210 | #ifdef CONSOLE_ENABLE | ||
| 204 | /* Setup Console HID Report Endpoints */ | 211 | /* Setup Console HID Report Endpoints */ |
| 205 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 212 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 206 | CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); | 213 | CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); |
| 207 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | 214 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, |
| 208 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | 215 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 216 | #endif | ||
| 209 | } | 217 | } |
| 210 | 218 | ||
| 211 | /* | 219 | /* |
| @@ -371,7 +379,7 @@ static void send_system(uint16_t data) | |||
| 371 | .report_id = REPORT_ID_SYSTEM, | 379 | .report_id = REPORT_ID_SYSTEM, |
| 372 | .usage = data | 380 | .usage = data |
| 373 | }; | 381 | }; |
| 374 | Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); | 382 | Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); |
| 375 | if (Endpoint_IsReadWriteAllowed()) { | 383 | if (Endpoint_IsReadWriteAllowed()) { |
| 376 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); | 384 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); |
| 377 | Endpoint_ClearIN(); | 385 | Endpoint_ClearIN(); |
| @@ -384,7 +392,7 @@ static void send_consumer(uint16_t data) | |||
| 384 | .report_id = REPORT_ID_CONSUMER, | 392 | .report_id = REPORT_ID_CONSUMER, |
| 385 | .usage = data | 393 | .usage = data |
| 386 | }; | 394 | }; |
| 387 | Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); | 395 | Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); |
| 388 | if (Endpoint_IsReadWriteAllowed()) { | 396 | if (Endpoint_IsReadWriteAllowed()) { |
| 389 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); | 397 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); |
| 390 | Endpoint_ClearIN(); | 398 | Endpoint_ClearIN(); |
| @@ -395,12 +403,14 @@ static void send_consumer(uint16_t data) | |||
| 395 | /******************************************************************************* | 403 | /******************************************************************************* |
| 396 | * sendchar | 404 | * sendchar |
| 397 | ******************************************************************************/ | 405 | ******************************************************************************/ |
| 398 | #define SEND_TIMEOUT 10 | 406 | #ifdef CONSOLE_ENABLE |
| 407 | #define SEND_TIMEOUT 5 | ||
| 399 | int8_t sendchar(uint8_t c) | 408 | int8_t sendchar(uint8_t c) |
| 400 | { | 409 | { |
| 401 | if (USB_DeviceState != DEVICE_STATE_Configured) | 410 | if (USB_DeviceState != DEVICE_STATE_Configured) |
| 402 | return -1; | 411 | return -1; |
| 403 | 412 | ||
| 413 | uint8_t ep = Endpoint_GetCurrentEndpoint(); | ||
| 404 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); | 414 | Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); |
| 405 | 415 | ||
| 406 | uint8_t timeout = SEND_TIMEOUT; | 416 | uint8_t timeout = SEND_TIMEOUT; |
| @@ -411,11 +421,15 @@ int8_t sendchar(uint8_t c) | |||
| 411 | case DEVICE_STATE_Suspended: | 421 | case DEVICE_STATE_Suspended: |
| 412 | return -1; | 422 | return -1; |
| 413 | } | 423 | } |
| 414 | if (Endpoint_IsStalled()) | 424 | if (Endpoint_IsStalled()) { |
| 425 | Endpoint_SelectEndpoint(ep); | ||
| 415 | return -1; | 426 | return -1; |
| 427 | } | ||
| 416 | if (prevFN != USB_Device_GetFrameNumber()) { | 428 | if (prevFN != USB_Device_GetFrameNumber()) { |
| 417 | if (!(timeout--)) | 429 | if (!(timeout--)) { |
| 430 | Endpoint_SelectEndpoint(ep); | ||
| 418 | return -1; | 431 | return -1; |
| 432 | } | ||
| 419 | prevFN = USB_Device_GetFrameNumber(); | 433 | prevFN = USB_Device_GetFrameNumber(); |
| 420 | } | 434 | } |
| 421 | } | 435 | } |
| @@ -426,5 +440,12 @@ int8_t sendchar(uint8_t c) | |||
| 426 | if (!Endpoint_IsReadWriteAllowed()) | 440 | if (!Endpoint_IsReadWriteAllowed()) |
| 427 | Endpoint_ClearIN(); | 441 | Endpoint_ClearIN(); |
| 428 | 442 | ||
| 443 | Endpoint_SelectEndpoint(ep); | ||
| 444 | return 0; | ||
| 445 | } | ||
| 446 | #else | ||
| 447 | int8_t sendchar(uint8_t c) | ||
| 448 | { | ||
| 429 | return 0; | 449 | return 0; |
| 430 | } | 450 | } |
| 451 | #endif | ||
