aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/lufa
diff options
context:
space:
mode:
authortmk <hasu@tmk-kbd.com>2015-05-22 18:10:28 +0900
committertmk <hasu@tmk-kbd.com>2015-05-22 18:11:42 +0900
commitfdce0c9cc0b7f8e9f1497cae3ea63a6672ceaf71 (patch)
tree06d0a22a0bd2a1c63b97a0c34e1909748dc61b9e /tmk_core/protocol/lufa
parent5b46031658a69104526ef43284acd943ba21b772 (diff)
downloadqmk_firmware-fdce0c9cc0b7f8e9f1497cae3ea63a6672ceaf71.tar.gz
qmk_firmware-fdce0c9cc0b7f8e9f1497cae3ea63a6672ceaf71.zip
lufa: Fix console flush #223
Old console sent unneeded empty data every one milli sencond. After this fix console flushes endpoint data bank every 50ms only when needed.
Diffstat (limited to 'tmk_core/protocol/lufa')
-rw-r--r--tmk_core/protocol/lufa/lufa.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 391064c9b..85fdeabdd 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -197,10 +197,24 @@ void EVENT_USB_Device_WakeUp()
197#endif 197#endif
198} 198}
199 199
200#ifdef CONSOLE_ENABLE
201static bool console_flush = false;
202#define CONSOLE_FLUSH_SET(b) do { \
203 uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \
204} while (0)
205
206// called every 1ms
200void EVENT_USB_Device_StartOfFrame(void) 207void EVENT_USB_Device_StartOfFrame(void)
201{ 208{
209 static uint8_t count;
210 if (++count % 50) return;
211 count = 0;
212
213 if (!console_flush) return;
202 Console_Task(); 214 Console_Task();
215 console_flush = false;
203} 216}
217#endif
204 218
205/** Event handler for the USB_ConfigurationChanged event. 219/** Event handler for the USB_ConfigurationChanged event.
206 * This is fired when the host sets the current configuration of the USB device after enumeration. 220 * This is fired when the host sets the current configuration of the USB device after enumeration.
@@ -491,6 +505,10 @@ int8_t sendchar(uint8_t c)
491 // Because sendchar() is called so many times, waiting each call causes big lag. 505 // Because sendchar() is called so many times, waiting each call causes big lag.
492 static bool timeouted = false; 506 static bool timeouted = false;
493 507
508 // prevents Console_Task() from running during sendchar() runs.
509 // or char will be lost. These two function is mutually exclusive.
510 CONSOLE_FLUSH_SET(false);
511
494 if (USB_DeviceState != DEVICE_STATE_Configured) 512 if (USB_DeviceState != DEVICE_STATE_Configured)
495 return -1; 513 return -1;
496 514
@@ -524,8 +542,12 @@ int8_t sendchar(uint8_t c)
524 Endpoint_Write_8(c); 542 Endpoint_Write_8(c);
525 543
526 // send when bank is full 544 // send when bank is full
527 if (!Endpoint_IsReadWriteAllowed()) 545 if (!Endpoint_IsReadWriteAllowed()) {
546 while (!(Endpoint_IsINReady()));
528 Endpoint_ClearIN(); 547 Endpoint_ClearIN();
548 } else {
549 CONSOLE_FLUSH_SET(true);
550 }
529 551
530 Endpoint_SelectEndpoint(ep); 552 Endpoint_SelectEndpoint(ep);
531 return 0; 553 return 0;