From 6b588eb7f7893500e18686e673dbf12b511dc975 Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 17 May 2015 19:34:34 +0900 Subject: Add keyboard_setup() and matrix_setup() --- tmk_core/protocol/lufa/lufa.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tmk_core/protocol/lufa') diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index cdfc7bc6ad..391064c9b2 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -544,7 +544,7 @@ int8_t sendchar(uint8_t c) /******************************************************************************* * main ******************************************************************************/ -static void SetupHardware(void) +static void setup_mcu(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); @@ -552,7 +552,10 @@ static void SetupHardware(void) /* Disable clock division */ clock_prescale_set(clock_div_1); +} +static void setup_usb(void) +{ // Leonardo needs. Without this USB device is not recognized. USB_Disable(); @@ -566,7 +569,9 @@ static void SetupHardware(void) int main(void) __attribute__ ((weak)); int main(void) { - SetupHardware(); + setup_mcu(); + keyboard_setup(); + setup_usb(); sei(); /* wait for USB startup & debug output */ -- cgit v1.2.3 From fdce0c9cc0b7f8e9f1497cae3ea63a6672ceaf71 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 22 May 2015 18:10:28 +0900 Subject: lufa: Fix console flush #223 Old console sent unneeded empty data every one milli sencond. After this fix console flushes endpoint data bank every 50ms only when needed. --- tmk_core/protocol/lufa/lufa.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/lufa') diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 391064c9b2..85fdeabdd1 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -197,10 +197,24 @@ void EVENT_USB_Device_WakeUp() #endif } +#ifdef CONSOLE_ENABLE +static bool console_flush = false; +#define CONSOLE_FLUSH_SET(b) do { \ + uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \ +} while (0) + +// called every 1ms void EVENT_USB_Device_StartOfFrame(void) { + static uint8_t count; + if (++count % 50) return; + count = 0; + + if (!console_flush) return; Console_Task(); + console_flush = false; } +#endif /** Event handler for the USB_ConfigurationChanged event. * This is fired when the host sets the current configuration of the USB device after enumeration. @@ -491,6 +505,10 @@ int8_t sendchar(uint8_t c) // Because sendchar() is called so many times, waiting each call causes big lag. static bool timeouted = false; + // prevents Console_Task() from running during sendchar() runs. + // or char will be lost. These two function is mutually exclusive. + CONSOLE_FLUSH_SET(false); + if (USB_DeviceState != DEVICE_STATE_Configured) return -1; @@ -524,8 +542,12 @@ int8_t sendchar(uint8_t c) Endpoint_Write_8(c); // send when bank is full - if (!Endpoint_IsReadWriteAllowed()) + if (!Endpoint_IsReadWriteAllowed()) { + while (!(Endpoint_IsINReady())); Endpoint_ClearIN(); + } else { + CONSOLE_FLUSH_SET(true); + } Endpoint_SelectEndpoint(ep); return 0; -- cgit v1.2.3 From 35203cad6ad4294409bd39dd85ff7858b353570d Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 23 Jul 2015 11:58:15 +0900 Subject: core: Fix lufa suspend callback(#234) With matrix_power_down() in suspend event HHKB JP doesn't start up for some reason. It is unneeded in actual and removed. --- tmk_core/protocol/lufa/lufa.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tmk_core/protocol/lufa') diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 85fdeabdd1..65c215bf85 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -179,7 +179,6 @@ void EVENT_USB_Device_Reset(void) void EVENT_USB_Device_Suspend() { print("[S]"); - matrix_power_down(); #ifdef SLEEP_LED_ENABLE sleep_led_enable(); #endif -- cgit v1.2.3 From bf3d4b3c06a0f379ce5f1112b5033faf1a69aeb6 Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 20 Sep 2015 10:48:47 +0900 Subject: lufa: Fix endpoint bank mode for ATMega32u2 --- tmk_core/protocol/lufa/lufa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tmk_core/protocol/lufa') diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 65c215bf85..188fb7b89b 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -217,6 +217,9 @@ void EVENT_USB_Device_StartOfFrame(void) /** Event handler for the USB_ConfigurationChanged event. * This is fired when the host sets the current configuration of the USB device after enumeration. + * + * ATMega32u2 supports dual bank(ping-pong mode) only on endpoint 3 and 4, + * it is safe to use singl bank for all endpoints. */ void EVENT_USB_Device_ConfigurationChanged(void) { @@ -241,7 +244,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) #ifdef CONSOLE_ENABLE /* Setup Console HID Report Endpoints */ ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, - CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); + CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); #if 0 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); -- cgit v1.2.3 From ed9766a7d44cd727dbd59008eff4258745ff87cf Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 20 Sep 2015 14:34:13 +0900 Subject: core: Fix for disabling NKRO in Boot protocol --- tmk_core/protocol/lufa/lufa.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'tmk_core/protocol/lufa') diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 188fb7b89b..345630aa90 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -53,6 +53,7 @@ #include "lufa.h" uint8_t keyboard_idle = 0; +/* 0: Boot Protocol, 1: Report Protocol(default) */ uint8_t keyboard_protocol = 1; static uint8_t keyboard_led_stats = 0; @@ -349,10 +350,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); Endpoint_ClearStatusStage(); - keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00); -#ifdef NKRO_ENABLE - keyboard_nkro = !!keyboard_protocol; -#endif + keyboard_protocol = (USB_ControlRequest.wValue & 0xFF); clear_keyboard(); } } @@ -399,7 +397,7 @@ static void send_keyboard(report_keyboard_t *report) /* Select the Keyboard Report Endpoint */ #ifdef NKRO_ENABLE - if (keyboard_nkro) { + if (keyboard_protocol && keyboard_nkro) { /* Report protocol - NKRO */ Endpoint_SelectEndpoint(NKRO_IN_EPNUM); -- cgit v1.2.3