From 00f5ed3210e1241da04b7c6970bb53ce912cf3f4 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 16 Oct 2018 00:40:14 +0900 Subject: [PATCH] core: Update console startup for hid_listen --- tmk_core/protocol/lufa/lufa.c | 42 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index b1567fa9..a709d1f1 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -50,6 +50,7 @@ #endif #include "suspend.h" #include "hook.h" +#include "timer.h" #ifdef LUFA_DEBUG_SUART #include "avr/suart.h" @@ -99,14 +100,31 @@ static ringbuf_t sendbuf = { .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) { + if (!console_is_ready()) + goto EXIT; + // return immediately if called while interrupt if (!(SREG & (1<