X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Flufa%2Flufa.c;h=54221591b388b3729077b68ac23cabe6b624ae7e;hb=842b3f29b6d09adcc2d0b6c5a1a525b6c4f7e2f8;hp=b1567fa9bdac242dfbe9a12395c7db8212177748;hpb=e3d7b50f63dfc71b5488928093f2d641589518b0;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index b1567fa9..54221591 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -50,17 +50,22 @@ #endif #include "suspend.h" #include "hook.h" +#include "timer.h" -#ifdef LUFA_DEBUG_SUART +#ifdef TMK_LUFA_DEBUG_SUART #include "avr/suart.h" #endif +#ifdef TMK_LUFA_DEBUG_UART +#include "uart.h" +#endif + #include "matrix.h" #include "descriptor.h" #include "lufa.h" -//#define LUFA_DEBUG +//#define TMK_LUFA_DEBUG uint8_t keyboard_idle = 0; @@ -99,19 +104,51 @@ 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) { // return immediately if called while interrupt if (!(SREG & (1<> 8); -#ifdef LUFA_DEBUG +#ifdef TMK_LUFA_DEBUG xprintf("[I%d]%d", USB_ControlRequest.wIndex, (USB_ControlRequest.wValue & 0xFF00) >> 8); #endif } @@ -424,7 +490,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_Write_8(keyboard_idle); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); -#ifdef LUFA_DEBUG +#ifdef TMK_LUFA_DEBUG print("[i]"); #endif } @@ -514,7 +580,7 @@ static void send_system(uint16_t data) report_extra_t r = { .report_id = REPORT_ID_SYSTEM, - .usage = data + .usage = data - SYSTEM_POWER_DOWN + 1 }; Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); @@ -554,25 +620,22 @@ static void send_consumer(uint16_t data) /******************************************************************************* * sendchar ******************************************************************************/ -#ifdef CONSOLE_ENABLE int8_t sendchar(uint8_t c) { - #ifdef LUFA_DEBUG_SUART + #ifdef TMK_LUFA_DEBUG_SUART xmit(c); #endif - bool r = console_putc(c); - return (r ? 0 : -1); -} -#else -int8_t sendchar(uint8_t c) -{ - #ifdef LUFA_DEBUG_SUART - xmit(c); + #ifdef TMK_LUFA_DEBUG_UART + uart_putchar(c); + #endif + + #ifdef CONSOLE_ENABLE + console_putc(c); #endif + return 0; } -#endif /******************************************************************************* @@ -594,8 +657,6 @@ static void setup_usb(void) USB_Disable(); USB_Init(); - - USB_Device_EnableSOFEvents(); } int main(void) __attribute__ ((weak)); @@ -603,16 +664,20 @@ int main(void) { setup_mcu(); -#ifdef LUFA_DEBUG_SUART +#ifdef TMK_LUFA_DEBUG_SUART SUART_OUT_DDR |= (1<