aboutsummaryrefslogtreecommitdiff
path: root/protocol
diff options
context:
space:
mode:
authortmk <hasu@tmk-kbd.com>2014-11-29 20:47:15 +0900
committertmk <hasu@tmk-kbd.com>2015-01-15 17:08:48 +0900
commit20caf673d8ba7fb7675e2559bfebad6ddb9d6fd0 (patch)
treee1651c9a8734f33727e9da553cc712c6b51adbc6 /protocol
parent9179246a1d69024449829218aa7fb967d8ccc3f5 (diff)
downloadqmk_firmware-20caf673d8ba7fb7675e2559bfebad6ddb9d6fd0.tar.gz
qmk_firmware-20caf673d8ba7fb7675e2559bfebad6ddb9d6fd0.zip
Fix lufa sendchar() infinite wait loop
- FrameNumber is not updated when adapter powered - can be blocked in sendchar() when pluged into AC adapter
Diffstat (limited to 'protocol')
-rw-r--r--protocol/lufa/lufa.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index ee15b7f45..3d6b3ea00 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -148,6 +148,7 @@ static void Console_Task(void)
148*/ 148*/
149void EVENT_USB_Device_Connect(void) 149void EVENT_USB_Device_Connect(void)
150{ 150{
151 print("[C]");
151 /* For battery powered device */ 152 /* For battery powered device */
152 if (!USB_IsInitialized) { 153 if (!USB_IsInitialized) {
153 USB_Init(); 154 USB_Init();
@@ -157,6 +158,7 @@ void EVENT_USB_Device_Connect(void)
157 158
158void EVENT_USB_Device_Disconnect(void) 159void EVENT_USB_Device_Disconnect(void)
159{ 160{
161 print("[D]");
160 /* For battery powered device */ 162 /* For battery powered device */
161/* TODO: This doesn't work. After several plug in/outs can not be enumerated. 163/* TODO: This doesn't work. After several plug in/outs can not be enumerated.
162 if (USB_IsInitialized) { 164 if (USB_IsInitialized) {
@@ -169,10 +171,12 @@ void EVENT_USB_Device_Disconnect(void)
169 171
170void EVENT_USB_Device_Reset(void) 172void EVENT_USB_Device_Reset(void)
171{ 173{
174 print("[R]");
172} 175}
173 176
174void EVENT_USB_Device_Suspend() 177void EVENT_USB_Device_Suspend()
175{ 178{
179 print("[S]");
176#ifdef SLEEP_LED_ENABLE 180#ifdef SLEEP_LED_ENABLE
177 sleep_led_enable(); 181 sleep_led_enable();
178#endif 182#endif
@@ -180,6 +184,7 @@ void EVENT_USB_Device_Suspend()
180 184
181void EVENT_USB_Device_WakeUp() 185void EVENT_USB_Device_WakeUp()
182{ 186{
187 print("[W]");
183 suspend_wakeup_init(); 188 suspend_wakeup_init();
184 189
185#ifdef SLEEP_LED_ENABLE 190#ifdef SLEEP_LED_ENABLE
@@ -489,37 +494,28 @@ int8_t sendchar(uint8_t c)
489 uint8_t ep = Endpoint_GetCurrentEndpoint(); 494 uint8_t ep = Endpoint_GetCurrentEndpoint();
490 Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); 495 Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
491 if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) { 496 if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
492 Endpoint_SelectEndpoint(ep); 497 goto ERROR_EXIT;
493 return -1;
494 } 498 }
495 499
496 if (timeouted && !Endpoint_IsReadWriteAllowed()) { 500 if (timeouted && !Endpoint_IsReadWriteAllowed()) {
497 Endpoint_SelectEndpoint(ep); 501 goto ERROR_EXIT;
498 return - 1;
499 } 502 }
500 503
501 timeouted = false; 504 timeouted = false;
502 505
503 uint8_t timeout = SEND_TIMEOUT; 506 uint8_t timeout = SEND_TIMEOUT;
504 uint16_t prevFN = USB_Device_GetFrameNumber();
505 while (!Endpoint_IsReadWriteAllowed()) { 507 while (!Endpoint_IsReadWriteAllowed()) {
506 switch (USB_DeviceState) { 508 if (USB_DeviceState != DEVICE_STATE_Configured) {
507 case DEVICE_STATE_Unattached: 509 goto ERROR_EXIT;
508 case DEVICE_STATE_Suspended:
509 return -1;
510 } 510 }
511 if (Endpoint_IsStalled()) { 511 if (Endpoint_IsStalled()) {
512 Endpoint_SelectEndpoint(ep); 512 goto ERROR_EXIT;
513 return -1;
514 } 513 }
515 if (prevFN != USB_Device_GetFrameNumber()) { 514 if (!(timeout--)) {
516 if (!(timeout--)) { 515 timeouted = true;
517 timeouted = true; 516 goto ERROR_EXIT;
518 Endpoint_SelectEndpoint(ep);
519 return -1;
520 }
521 prevFN = USB_Device_GetFrameNumber();
522 } 517 }
518 _delay_ms(1);
523 } 519 }
524 520
525 Endpoint_Write_8(c); 521 Endpoint_Write_8(c);
@@ -530,6 +526,9 @@ int8_t sendchar(uint8_t c)
530 526
531 Endpoint_SelectEndpoint(ep); 527 Endpoint_SelectEndpoint(ep);
532 return 0; 528 return 0;
529ERROR_EXIT:
530 Endpoint_SelectEndpoint(ep);
531 return -1;
533} 532}
534#else 533#else
535int8_t sendchar(uint8_t c) 534int8_t sendchar(uint8_t c)
@@ -587,6 +586,7 @@ int main(void)
587 print("Keyboard start.\n"); 586 print("Keyboard start.\n");
588 while (1) { 587 while (1) {
589 while (USB_DeviceState == DEVICE_STATE_Suspended) { 588 while (USB_DeviceState == DEVICE_STATE_Suspended) {
589 print("[s]");
590 suspend_power_down(); 590 suspend_power_down();
591 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { 591 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
592 USB_Device_SendRemoteWakeup(); 592 USB_Device_SendRemoteWakeup();