diff options
author | tmk <hasu@tmk-kbd.com> | 2015-05-22 18:10:28 +0900 |
---|---|---|
committer | tmk <hasu@tmk-kbd.com> | 2015-05-22 18:11:42 +0900 |
commit | fdce0c9cc0b7f8e9f1497cae3ea63a6672ceaf71 (patch) | |
tree | 06d0a22a0bd2a1c63b97a0c34e1909748dc61b9e /tmk_core/protocol/lufa | |
parent | 5b46031658a69104526ef43284acd943ba21b772 (diff) | |
download | qmk_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.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 391064c9b2..85fdeabdd1 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -197,10 +197,24 @@ void EVENT_USB_Device_WakeUp() #endif } +#ifdef CONSOLE_ENABLE +static bool console_flush = false; +#define CONSOLE_FLUSH_SET(b) do { \ + uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \ +} while (0) + +// called every 1ms void EVENT_USB_Device_StartOfFrame(void) { + static uint8_t count; + if (++count % 50) return; + count = 0; + + if (!console_flush) return; Console_Task(); + console_flush = false; } +#endif /** Event handler for the USB_ConfigurationChanged event. * 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) // Because sendchar() is called so many times, waiting each call causes big lag. static bool timeouted = false; + // prevents Console_Task() from running during sendchar() runs. + // or char will be lost. These two function is mutually exclusive. + CONSOLE_FLUSH_SET(false); + if (USB_DeviceState != DEVICE_STATE_Configured) return -1; @@ -524,8 +542,12 @@ int8_t sendchar(uint8_t c) Endpoint_Write_8(c); // send when bank is full - if (!Endpoint_IsReadWriteAllowed()) + if (!Endpoint_IsReadWriteAllowed()) { + while (!(Endpoint_IsINReady())); Endpoint_ClearIN(); + } else { + CONSOLE_FLUSH_SET(true); + } Endpoint_SelectEndpoint(ep); return 0; |