From 05795cb0034e885bec37f782cfc6bddcae262637 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 26 Nov 2014 11:25:45 +0900 Subject: Compensate timer during prower down --- protocol/lufa/lufa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocol') diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 6802f3b63..ee15b7f45 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -587,7 +587,7 @@ int main(void) print("Keyboard start.\n"); while (1) { while (USB_DeviceState == DEVICE_STATE_Suspended) { - suspend_power_down(WDTO_120MS); + suspend_power_down(); if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { USB_Device_SendRemoteWakeup(); } -- cgit v1.2.3 From 20caf673d8ba7fb7675e2559bfebad6ddb9d6fd0 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 29 Nov 2014 20:47:15 +0900 Subject: Fix lufa sendchar() infinite wait loop - FrameNumber is not updated when adapter powered - can be blocked in sendchar() when pluged into AC adapter --- keyboard/hhkb_rn42/rn42/main.c | 3 ++- protocol/lufa/lufa.c | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'protocol') diff --git a/keyboard/hhkb_rn42/rn42/main.c b/keyboard/hhkb_rn42/rn42/main.c index a3a37c074..42b09d8c8 100644 --- a/keyboard/hhkb_rn42/rn42/main.c +++ b/keyboard/hhkb_rn42/rn42/main.c @@ -17,8 +17,8 @@ static int8_t sendchar_func(uint8_t c) { - sendchar(c); // LUFA xmit(c); // SUART + sendchar(c); // LUFA return 0; } @@ -85,6 +85,7 @@ int main(void) print("Keyboard start.\n"); while (1) { while (USB_DeviceState == DEVICE_STATE_Suspended) { + print("[s]"); suspend_power_down(); if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { USB_Device_SendRemoteWakeup(); diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index ee15b7f45..3d6b3ea00 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -148,6 +148,7 @@ static void Console_Task(void) */ void EVENT_USB_Device_Connect(void) { + print("[C]"); /* For battery powered device */ if (!USB_IsInitialized) { USB_Init(); @@ -157,6 +158,7 @@ void EVENT_USB_Device_Connect(void) void EVENT_USB_Device_Disconnect(void) { + print("[D]"); /* For battery powered device */ /* TODO: This doesn't work. After several plug in/outs can not be enumerated. if (USB_IsInitialized) { @@ -169,10 +171,12 @@ void EVENT_USB_Device_Disconnect(void) void EVENT_USB_Device_Reset(void) { + print("[R]"); } void EVENT_USB_Device_Suspend() { + print("[S]"); #ifdef SLEEP_LED_ENABLE sleep_led_enable(); #endif @@ -180,6 +184,7 @@ void EVENT_USB_Device_Suspend() void EVENT_USB_Device_WakeUp() { + print("[W]"); suspend_wakeup_init(); #ifdef SLEEP_LED_ENABLE @@ -489,37 +494,28 @@ int8_t sendchar(uint8_t c) uint8_t ep = Endpoint_GetCurrentEndpoint(); Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) { - Endpoint_SelectEndpoint(ep); - return -1; + goto ERROR_EXIT; } if (timeouted && !Endpoint_IsReadWriteAllowed()) { - Endpoint_SelectEndpoint(ep); - return - 1; + goto ERROR_EXIT; } timeouted = false; uint8_t timeout = SEND_TIMEOUT; - uint16_t prevFN = USB_Device_GetFrameNumber(); while (!Endpoint_IsReadWriteAllowed()) { - switch (USB_DeviceState) { - case DEVICE_STATE_Unattached: - case DEVICE_STATE_Suspended: - return -1; + if (USB_DeviceState != DEVICE_STATE_Configured) { + goto ERROR_EXIT; } if (Endpoint_IsStalled()) { - Endpoint_SelectEndpoint(ep); - return -1; + goto ERROR_EXIT; } - if (prevFN != USB_Device_GetFrameNumber()) { - if (!(timeout--)) { - timeouted = true; - Endpoint_SelectEndpoint(ep); - return -1; - } - prevFN = USB_Device_GetFrameNumber(); + if (!(timeout--)) { + timeouted = true; + goto ERROR_EXIT; } + _delay_ms(1); } Endpoint_Write_8(c); @@ -530,6 +526,9 @@ int8_t sendchar(uint8_t c) Endpoint_SelectEndpoint(ep); return 0; +ERROR_EXIT: + Endpoint_SelectEndpoint(ep); + return -1; } #else int8_t sendchar(uint8_t c) @@ -587,6 +586,7 @@ int main(void) print("Keyboard start.\n"); while (1) { while (USB_DeviceState == DEVICE_STATE_Suspended) { + print("[s]"); suspend_power_down(); if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { USB_Device_SendRemoteWakeup(); -- cgit v1.2.3 From ebe437325872045e0b99469f83cb9e877e98112c Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 3 Dec 2014 15:50:02 +0900 Subject: Fix power saving while USB suspended - doesn't pwoer save while Bluetooth turns on --- keyboard/hhkb_rn42/hhkb_avr.h | 4 +++- keyboard/hhkb_rn42/matrix.c | 21 ++++++++++----------- keyboard/hhkb_rn42/rn42/main.c | 14 +++++++++++--- protocol/lufa/lufa.c | 3 +++ 4 files changed, 27 insertions(+), 15 deletions(-) (limited to 'protocol') diff --git a/keyboard/hhkb_rn42/hhkb_avr.h b/keyboard/hhkb_rn42/hhkb_avr.h index f007d7667..0321977d1 100644 --- a/keyboard/hhkb_rn42/hhkb_avr.h +++ b/keyboard/hhkb_rn42/hhkb_avr.h @@ -53,9 +53,11 @@ static inline void KEY_POWER_OFF(void) { DDRB = 0x00; PORTB = 0xFF; // change pins input with pull-up DDRD |= (1<<4); PORTD &= ~(1<<4); // MOS FET switch off } +static inline bool KEY_POWER_STATE(void) { return PORTD & (1<<4); } #else static inline void KEY_POWER_ON(void) {} static inline void KEY_POWER_OFF(void) {} +static inline bool KEY_POWER_STATE(void) { return true; } #endif static inline void KEY_INIT(void) { @@ -73,7 +75,7 @@ static inline void KEY_INIT(void) KEY_UNABLE(); KEY_PREV_OFF(); - KEY_POWER_ON(); + KEY_POWER_OFF(); } static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) { diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c index 22becd105..fb9699794 100644 --- a/keyboard/hhkb_rn42/matrix.c +++ b/keyboard/hhkb_rn42/matrix.c @@ -35,7 +35,6 @@ along with this program. If not, see . // matrix power saving #define MATRIX_POWER_SAVE 10000 static uint32_t matrix_last_modified = 0; -static bool matrix_power = true; // matrix state buffer(1:on, 0:off) static matrix_row_t *matrix; @@ -80,7 +79,8 @@ uint8_t matrix_scan(void) matrix_prev = matrix; matrix = tmp; - matrix_power_up(); + // power on + if (!KEY_POWER_STATE()) KEY_POWER_ON(); for (uint8_t row = 0; row < MATRIX_ROWS; row++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { KEY_SELECT(row, col); @@ -136,7 +136,14 @@ uint8_t matrix_scan(void) } if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32(); } - matrix_power_down(); + // power off + if (KEY_POWER_STATE() && + (USB_DeviceState == DEVICE_STATE_Suspended || + USB_DeviceState == DEVICE_STATE_Unattached ) && + timer_elapsed32(matrix_last_modified) > MATRIX_POWER_SAVE) { + KEY_POWER_OFF(); + suspend_power_down(); + } return 1; } @@ -176,16 +183,8 @@ void matrix_print(void) } void matrix_power_up(void) { - if (matrix_power) return; KEY_POWER_ON(); - matrix_power = true; } void matrix_power_down(void) { - if (!matrix_power) return; - // doesn't power save while USB connection is active - if (USB_DeviceState != DEVICE_STATE_Unattached) return; - if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return; KEY_POWER_OFF(); - suspend_power_down(); - matrix_power = false; } diff --git a/keyboard/hhkb_rn42/rn42/main.c b/keyboard/hhkb_rn42/rn42/main.c index 42b09d8c8..83d995038 100644 --- a/keyboard/hhkb_rn42/rn42/main.c +++ b/keyboard/hhkb_rn42/rn42/main.c @@ -63,7 +63,7 @@ int main(void) USB_USBTask(); #endif } - print("USB configured.\n"); + print("\nUSB init\n"); rn42_init(); rn42_task_init(); @@ -82,10 +82,18 @@ int main(void) sleep_led_init(); #endif - print("Keyboard start.\n"); + print("Keyboard start\n"); while (1) { - while (USB_DeviceState == DEVICE_STATE_Suspended) { + while (rn42_rts() && // RN42 is off + USB_DeviceState == DEVICE_STATE_Suspended) { print("[s]"); + matrix_power_down(); + suspend_power_down(); + suspend_power_down(); + suspend_power_down(); + suspend_power_down(); + suspend_power_down(); + suspend_power_down(); suspend_power_down(); if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { USB_Device_SendRemoteWakeup(); diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 3d6b3ea00..cdfc7bc6a 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -151,6 +151,7 @@ void EVENT_USB_Device_Connect(void) print("[C]"); /* For battery powered device */ if (!USB_IsInitialized) { + USB_Disable(); USB_Init(); USB_Device_EnableSOFEvents(); } @@ -160,6 +161,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. if (USB_IsInitialized) { USB_Disable(); // Disable all interrupts @@ -177,6 +179,7 @@ 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 1cda7b79fbae90b3dc40ac862f3c14bfd2f1f679 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 19 Jan 2015 10:35:06 +0900 Subject: Fix typo 'keyobard' #166 --- converter/adb_usb/README.md | 2 +- keyboard/hhkb/rn42/MEMO.txt | 2 +- protocol/adb.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'protocol') diff --git a/converter/adb_usb/README.md b/converter/adb_usb/README.md index defc477e2..21ad318c1 100644 --- a/converter/adb_usb/README.md +++ b/converter/adb_usb/README.md @@ -88,7 +88,7 @@ modifiers except for GUI key(Windows/Command). And most ADB keyboard has no diodes in its matrix so they are not NKRO, though ADB protocol itself supports it. See protocol/adb.c for more info. -If keyobard has ISO layout you need to use ISO keymap with `make KEYMAP=iso`. With ANSI +If keyboard has ISO layout you need to use ISO keymap with `make KEYMAP=iso`. With ANSI keymap you will suffer from swapped keys problem. https://github.com/tmk/tmk_keyboard/issues/35 diff --git a/keyboard/hhkb/rn42/MEMO.txt b/keyboard/hhkb/rn42/MEMO.txt index f772c4cb5..0363c2f43 100644 --- a/keyboard/hhkb/rn42/MEMO.txt +++ b/keyboard/hhkb/rn42/MEMO.txt @@ -161,7 +161,7 @@ TROUBLE SHOOT 07/16 After fix of voltage dividor on GPIO6, had a trouble that it could not send a char to BT module, though could receive. Found R8 had wrong 1K resistor and changed to 10K, after that it can send to the module again. Not sure how it had sent with the wrong 1K before. -07/18 On Linux, had an USB related trouble; keyobard or console didn't work for some reason. Changing PID cured this problem. Very annoying, took very long time before resolved it. +07/18 On Linux, had an USB related trouble; keyboard or console didn't work for some reason. Changing PID cured this problem. Very annoying, took very long time before resolved it. 12/07 rn42_rts() read 1 every time. R12 broke in open mode(no coductive), idk why, too much heat with soldering? and PF1 pin was not soldered. It resolved with resoldering PF1 and new resistor on R12. diff --git a/protocol/adb.c b/protocol/adb.c index f57afac93..bbff66df0 100644 --- a/protocol/adb.c +++ b/protocol/adb.c @@ -360,7 +360,7 @@ Commands 3: mice Registers: - 0: application(keyobard uses this to store its data.) + 0: application(keyboard uses this to store its data.) 1: application 2: application(keyboard uses this for LEDs and state of modifiers) 3: status and command -- cgit v1.2.3 From abf482de8e62880f27c377c2bdbcb664fda0df0b Mon Sep 17 00:00:00 2001 From: Jun Wako Date: Mon, 26 Jan 2015 11:25:22 +0900 Subject: Fix call parameter of suspend_power_down() --- protocol/bluefruit/main.c | 2 +- protocol/pjrc/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'protocol') diff --git a/protocol/bluefruit/main.c b/protocol/bluefruit/main.c index 094fdb366..871062ab1 100644 --- a/protocol/bluefruit/main.c +++ b/protocol/bluefruit/main.c @@ -104,7 +104,7 @@ int main(void) dprintf("Starting main loop"); while (1) { while (suspend) { - suspend_power_down(WDTO_120MS); + suspend_power_down(); if (remote_wakeup && suspend_wakeup_condition()) { usb_remote_wakeup(); } diff --git a/protocol/pjrc/main.c b/protocol/pjrc/main.c index 4f87a1736..e7bdcc059 100644 --- a/protocol/pjrc/main.c +++ b/protocol/pjrc/main.c @@ -61,7 +61,7 @@ int main(void) #endif while (1) { while (suspend) { - suspend_power_down(WDTO_120MS); + suspend_power_down(); if (remote_wakeup && suspend_wakeup_condition()) { usb_remote_wakeup(); } -- cgit v1.2.3