X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Flufa%2Flufa.c;h=aecaa050af52572fd2c56c7b06b14b7211d19610;hb=dd7b75040a7f3cc62fe58d6d4b3cc2a331d487b3;hp=93fe9a2facd586e369a34ef2daf6eefc6525a913;hpb=024f0c8d3881828a173a7a335c7ffafa0eee0908;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 93fe9a2f..aecaa050 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -43,17 +43,23 @@ #include "action.h" #include "led.h" #include "sendchar.h" +#include "ringbuf.h" #include "debug.h" #ifdef SLEEP_LED_ENABLE #include "sleep_led.h" #endif #include "suspend.h" #include "hook.h" +#include "timer.h" #ifdef LUFA_DEBUG_SUART #include "avr/suart.h" #endif +#ifdef LUFA_DEBUG_UART +#include "uart.h" +#endif + #include "matrix.h" #include "descriptor.h" #include "lufa.h" @@ -89,60 +95,117 @@ host_driver_t lufa_driver = { * Console ******************************************************************************/ #ifdef CONSOLE_ENABLE -static void Console_Task(void) +#define SENDBUF_SIZE 256 +static uint8_t sbuf[SENDBUF_SIZE]; +static ringbuf_t sendbuf = { + .buffer = sbuf, + .head = 0, + .tail = 0, + .size_mask = SENDBUF_SIZE - 1 +}; + +// TODO: Around 2500ms delay often works anyhoo but proper startup would be better +// 1000ms delay of hid_listen affects this probably +/* wait for Console startup */ +static bool console_is_ready(void) +{ + static bool hid_listen_ready = false; + if (!hid_listen_ready) { + if (timer_read32() < 2500) + return false; + hid_listen_ready = true; + } + return true; +} + +static bool console_putc(uint8_t c) { - /* Device must be connected and configured for the task to run */ + if (!console_is_ready()) + goto EXIT; + + // return immediately if called while interrupt + if (!(SREG & (1<