X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Flufa%2Flufa.c;h=076c8c8d9cf0846f03ef3e5f9fb35119a3b846aa;hb=8cab7e60a5400590edcaca29cbc91f568e15fe36;hp=beec6b2be31d3f30d926f0fbcc652f4bce839473;hpb=f37805e698a34ce07f10c7f5316f9bbd2a63563b;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index beec6b2b..076c8c8d 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2012 Jun Wako * This file is based on: * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse @@ -50,9 +50,18 @@ #include "suspend.h" #include "hook.h" +#ifdef LUFA_DEBUG_SUART +#include "avr/suart.h" +#endif + +#include "matrix.h" #include "descriptor.h" #include "lufa.h" + +//#define LUFA_DEBUG + + uint8_t keyboard_idle = 0; /* 0: Boot Protocol, 1: Report Protocol(default) */ uint8_t keyboard_protocol = 1; @@ -100,10 +109,10 @@ static void Console_Task(void) { /* Create a temporary buffer to hold the read in report from the host */ uint8_t ConsoleData[CONSOLE_EPSIZE]; - + /* Read Console Report Data */ Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL); - + /* Process Console Report Data */ //ProcessConsoleHIDReport(ConsoleData); } @@ -164,7 +173,7 @@ void EVENT_USB_Device_Disconnect(void) print("[D]"); /* For battery powered device */ USB_IsInitialized = false; -/* TODO: This doesn't work. After several plug in/outs can not be enumerated. +/* TODO: This doesn't work. After several plug in/outs can not be enumerated. if (USB_IsInitialized) { USB_Disable(); // Disable all interrupts USB_Controller_Enable(); @@ -175,18 +184,24 @@ void EVENT_USB_Device_Disconnect(void) void EVENT_USB_Device_Reset(void) { +#ifdef LUFA_DEBUG print("[R]"); +#endif } void EVENT_USB_Device_Suspend() { +#ifdef LUFA_DEBUG print("[S]"); +#endif hook_usb_suspend_entry(); } void EVENT_USB_Device_WakeUp() { +#ifdef LUFA_DEBUG print("[W]"); +#endif hook_usb_wakeup(); } @@ -217,6 +232,9 @@ void EVENT_USB_Device_StartOfFrame(void) */ void EVENT_USB_Device_ConfigurationChanged(void) { +#ifdef LUFA_DEBUG + print("[c]"); +#endif bool ConfigSuccess = true; /* Setup Keyboard HID Report Endpoints */ @@ -293,6 +311,9 @@ void EVENT_USB_Device_ControlRequest(void) /* Write the report data to the control endpoint */ Endpoint_Write_Control_Stream_LE(ReportData, ReportSize); Endpoint_ClearOUT(); +#ifdef LUFA_DEBUG + xprintf("[r%d]", USB_ControlRequest.wIndex); +#endif } break; @@ -316,6 +337,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearOUT(); Endpoint_ClearStatusStage(); +#ifdef LUFA_DEBUG + xprintf("[L%d]", USB_ControlRequest.wIndex); +#endif break; } @@ -332,6 +356,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_Write_8(keyboard_protocol); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); +#ifdef LUFA_DEBUG + print("[p]"); +#endif } } @@ -345,6 +372,9 @@ void EVENT_USB_Device_ControlRequest(void) keyboard_protocol = (USB_ControlRequest.wValue & 0xFF); clear_keyboard(); +#ifdef LUFA_DEBUG + print("[P]"); +#endif } } @@ -356,6 +386,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8); +#ifdef LUFA_DEBUG + xprintf("[I%d]%d", USB_ControlRequest.wIndex, (USB_ControlRequest.wValue & 0xFF00) >> 8); +#endif } break; @@ -367,6 +400,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_Write_8(keyboard_idle); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); +#ifdef LUFA_DEBUG + print("[i]"); +#endif } break; @@ -374,7 +410,7 @@ void EVENT_USB_Device_ControlRequest(void) } /******************************************************************************* - * Host driver + * Host driver ******************************************************************************/ static uint8_t keyboard_leds(void) { @@ -395,7 +431,7 @@ static void send_keyboard(report_keyboard_t *report) Endpoint_SelectEndpoint(NKRO_IN_EPNUM); /* Check if write ready for a polling interval around 1ms */ - while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4); + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(8); if (!Endpoint_IsReadWriteAllowed()) return; /* Write Keyboard Report Data */ @@ -494,6 +530,9 @@ static void send_consumer(uint16_t data) #define SEND_TIMEOUT 5 int8_t sendchar(uint8_t c) { +#ifdef LUFA_DEBUG_SUART + xmit(c); +#endif // Not wait once timeouted. // Because sendchar() is called so many times, waiting each call causes big lag. static bool timeouted = false; @@ -551,6 +590,9 @@ ERROR_EXIT: #else int8_t sendchar(uint8_t c) { +#ifdef LUFA_DEBUG_SUART + xmit(c); +#endif return 0; } #endif @@ -578,13 +620,20 @@ static void setup_usb(void) // for Console_Task USB_Device_EnableSOFEvents(); - print_set_sendchar(sendchar); } int main(void) __attribute__ ((weak)); int main(void) { setup_mcu(); + +#ifdef LUFA_DEBUG_SUART + SUART_OUT_DDR |= (1<