From: tmk Date: Wed, 28 Sep 2016 07:57:24 +0000 (+0900) Subject: core: Fix suspend/wake for converters #386 X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=9818d54d26e2900bf91b288bc6f268adc8e0b8fd;p=max%2Ftmk_keyboard.git core: Fix suspend/wake for converters #386 --- diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index af99f52b..580d69e4 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -102,6 +102,7 @@ bool suspend_wakeup_condition(void) void suspend_wakeup_init(void) { // clear keyboard state + matrix_init(); clear_keyboard(); #ifdef BACKLIGHT_ENABLE backlight_init(); diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index c16fd177..f5fc4cb7 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 @@ -54,9 +54,14 @@ #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; @@ -104,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); } @@ -168,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(); @@ -179,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(); } @@ -221,7 +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 */ @@ -275,7 +288,6 @@ Other Device Required Optional Optional Optional Optional Opti */ void EVENT_USB_Device_ControlRequest(void) { - print("[r]"); uint8_t* ReportData = NULL; uint8_t ReportSize = 0; @@ -299,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; @@ -322,6 +337,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearOUT(); Endpoint_ClearStatusStage(); +#ifdef LUFA_DEBUG + xprintf("[L%d]", USB_ControlRequest.wIndex); +#endif break; } @@ -338,6 +356,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_Write_8(keyboard_protocol); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); +#ifdef LUFA_DEBUG + print("[p]"); +#endif } } @@ -351,6 +372,9 @@ void EVENT_USB_Device_ControlRequest(void) keyboard_protocol = (USB_ControlRequest.wValue & 0xFF); clear_keyboard(); +#ifdef LUFA_DEBUG + print("[P]"); +#endif } } @@ -362,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; @@ -373,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; @@ -380,7 +410,7 @@ void EVENT_USB_Device_ControlRequest(void) } /******************************************************************************* - * Host driver + * Host driver ******************************************************************************/ static uint8_t keyboard_leds(void) { @@ -595,11 +625,15 @@ static void setup_usb(void) int main(void) __attribute__ ((weak)); int main(void) { + setup_mcu(); + #ifdef LUFA_DEBUG_SUART - DDRD |= (1<