From 5bc8b5dcb6a4e03a1ad7bceba2c22bb9f6eb81fb Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 4 Apr 2014 12:22:22 +0900 Subject: [PATCH 1/8] Add support for full-led revision of ghpad --- keyboard/ghpad/Makefile | 5 +- keyboard/ghpad/backlight.c | 76 ++++++++++++++++++++------- keyboard/ghpad/keymap_4x6_backlight.c | 54 +++++++++++++++++++ keyboard/ghpad/led.c | 8 +-- keyboard/ghpad/matrix.c | 2 +- 5 files changed, 118 insertions(+), 27 deletions(-) create mode 100644 keyboard/ghpad/keymap_4x6_backlight.c diff --git a/keyboard/ghpad/Makefile b/keyboard/ghpad/Makefile index 4b76788c..f1cecfb0 100644 --- a/keyboard/ghpad/Makefile +++ b/keyboard/ghpad/Makefile @@ -50,7 +50,8 @@ TARGET_DIR = . # project specific files SRC = keymap_common.c \ matrix.c \ - led.c + led.c \ + backlight.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) @@ -123,7 +124,7 @@ COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_EX_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor diff --git a/keyboard/ghpad/backlight.c b/keyboard/ghpad/backlight.c index 61282adb..f6b00317 100644 --- a/keyboard/ghpad/backlight.c +++ b/keyboard/ghpad/backlight.c @@ -1,5 +1,5 @@ /* -Copyright 2013 Kai Ryu +Copyright 2013,2014 Kai Ryu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,30 +17,66 @@ along with this program. If not, see . #include #include +#include #include "backlight.h" +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + +uint8_t softpwm_ocr = 0; + /* Backlight pin configuration - * PF7 PF6 PF5 + * PWM: PB5 (RevRS) + * GPIO: PF7 PF6 PF5 */ void backlight_set(uint8_t level) { - switch (level) { - case 0: - DDRF &= ~(1< 0) { + // Turn on PWM + cli(); + // Hard PWM + DDRB |= (1< +Copyright 2013,2014 Kai Ryu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by From ef8d03202923b3277f99c196fa5d79b3320a5e4a Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 8 Apr 2014 17:56:21 +0900 Subject: [PATCH 2/8] Add bootmagic and magic command support for ghpad --- keyboard/ghpad/Makefile | 7 ++++++- keyboard/ghpad/config.h | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/keyboard/ghpad/Makefile b/keyboard/ghpad/Makefile index f1cecfb0..09636010 100644 --- a/keyboard/ghpad/Makefile +++ b/keyboard/ghpad/Makefile @@ -112,6 +112,11 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # USBaspLoader 2048 OPT_DEFS += -DBOOTLOADER_SIZE=4096 +# Additional definitions from command line +ifdef DEFS + OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) +endif + # Build Options # comment out to disable the options. @@ -122,7 +127,7 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = yes # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend -#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA +NKRO_ENABLE = yes # USB Nkey Rollover #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_EX_ENABLE = yes # External keymap in eeprom diff --git a/keyboard/ghpad/config.h b/keyboard/ghpad/config.h index eed9cbc9..b710f42e 100644 --- a/keyboard/ghpad/config.h +++ b/keyboard/ghpad/config.h @@ -54,11 +54,15 @@ along with this program. If not, see . #define LOCKING_RESYNC_ENABLE /* key combination for command */ +#ifndef __ASSEMBLER__ +#include "matrix.h" #define IS_COMMAND() ( \ - keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ + matrix_is_on(0, 0) && matrix_is_on(0, MATRIX_COLS - 1) \ ) +#endif - +/* boot magic key */ +#define BOOTMAGIC_KEY_SALT KC_FN0 /* * Feature disable options From 8b75dd43ba1478904a75a10ce2db0f6195ceb828 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 8 Apr 2014 17:59:31 +0900 Subject: [PATCH 3/8] Extend reset eeconfig of bootmagic to reset keymap too --- common/bootmagic.c | 1 + common/eeconfig.c | 7 +++++++ common/keymap_ex.c | 6 +++++- common/keymap_ex.h | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/bootmagic.c b/common/bootmagic.c index 036d4904..311a02f2 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -30,6 +30,7 @@ void bootmagic(void) /* eeconfig clear */ if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) { + eeconfig_disable(); eeconfig_init(); } diff --git a/common/eeconfig.c b/common/eeconfig.c index 5bd47dc6..5aadf1c5 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -2,6 +2,7 @@ #include #include #include "eeconfig.h" +#include "keymap_ex.h" void eeconfig_init(void) { @@ -13,6 +14,9 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif +#ifdef KEYMAP_EX_ENABLE + keymap_ex_init(); +#endif } void eeconfig_enable(void) @@ -22,6 +26,9 @@ void eeconfig_enable(void) void eeconfig_disable(void) { +#ifdef KEYMAP_EX_ENABLE + keymap_ex_disable(); +#endif eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); } diff --git a/common/keymap_ex.c b/common/keymap_ex.c index 0c01f707..99859c06 100644 --- a/common/keymap_ex.c +++ b/common/keymap_ex.c @@ -23,12 +23,16 @@ along with this program. If not, see . #ifdef KEYMAP_EX_ENABLE -void keymap_init(void) { +void keymap_ex_init(void) { if (!check_keymap_in_eeprom()) { write_keymap_to_eeprom(); } } +void keymap_ex_disable(void) { + eeprom_write_word((void*)EECONFIG_KEYMAP_CHECKSUM, eeprom_read_word((void*)EECONFIG_KEYMAP_CHECKSUM) + 1); +} + bool check_keymap_in_eeprom(void) { uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum); uint16_t checksum = EECONFIG_MAGIC_NUMBER; diff --git a/common/keymap_ex.h b/common/keymap_ex.h index e64bace6..ee6ff8c6 100644 --- a/common/keymap_ex.h +++ b/common/keymap_ex.h @@ -47,7 +47,8 @@ typedef struct { #define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index) #define KEY_OFFSET(layer, row, col) (sizeof(uint8_t) * (layer * MATRIX_ROWS * MATRIX_COLS + row * MATRIX_COLS + col)) -void keymap_init(void); +void keymap_ex_init(void); +void keymap_ex_disable(void); bool check_keymap_in_eeprom(void); void write_keymap_to_eeprom(void); uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col); From d004baf7271b808143c87b8b8816a9525ace2e1f Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 8 Apr 2014 18:02:20 +0900 Subject: [PATCH 4/8] Add backlight level support for gh60 revB --- keyboard/gh60/backlight.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 25fbc833..ee5aad9a 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -72,14 +72,39 @@ void backlight_set(uint8_t level) } } #else +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + void backlight_set(uint8_t level) { if (level > 0) { - DDRF |= (1< Date: Tue, 8 Apr 2014 18:05:39 +0900 Subject: [PATCH 5/8] Add PS2 mouse support for gh60 --- common/keyboard.c | 10 +++++++--- keyboard/gh60/Makefile | 5 +++-- keyboard/gh60/config.h | 11 +++++++++++ keyboard/gh60/matrix.c | 24 ++++++++++++++++++++++++ protocol/ps2.h | 1 + 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/common/keyboard.c b/common/keyboard.c index c5de65ef..933eb780 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -68,7 +68,9 @@ void keyboard_init(void) #endif #ifdef PS2_MOUSE_ENABLE - ps2_mouse_init(); + if (ps2_enabled()) { + ps2_mouse_init(); + } #endif #ifdef BOOTMAGIC_ENABLE @@ -80,7 +82,7 @@ void keyboard_init(void) #endif #ifdef KEYMAP_EX_ENABLE - keymap_init(); + keymap_ex_init(); #endif } @@ -133,7 +135,9 @@ MATRIX_LOOP_END: #endif #ifdef PS2_MOUSE_ENABLE - ps2_mouse_task(); + if (ps2_enabled()) { + ps2_mouse_task(); + } #endif // update LED diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 8da7908d..33b6cc01 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -133,12 +133,12 @@ CONSOLE_ENABLE = yes # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA -#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_EX_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor - # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax @@ -147,5 +147,6 @@ VPATH += $(TARGET_DIR) VPATH += $(TOP_DIR) include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/protocol.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index dd9d21ae..f46c7413 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -66,7 +66,18 @@ along with this program. If not, see . keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ ) +/* PS2 mouse support */ +#ifdef PS2_MOUSE_ENABLE +#define PS2_CLOCK_PORT PORTF +#define PS2_CLOCK_PIN PINF +#define PS2_CLOCK_DDR DDRF +#define PS2_CLOCK_BIT PF7 +#define PS2_DATA_PORT PORTF +#define PS2_DATA_PIN PINF +#define PS2_DATA_DDR DDRF +#define PS2_DATA_BIT PF6 +#endif /* * Feature disable options diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index bb61f6ed..94cab02b 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c @@ -26,6 +26,9 @@ along with this program. If not, see . #include "debug.h" #include "util.h" #include "matrix.h" +#ifdef PS2_MOUSE_ENABLE +#include "ps2.h" +#endif #ifndef DEBOUNCE @@ -42,6 +45,14 @@ static void init_cols(void); static void unselect_rows(void); static void select_row(uint8_t row); +#ifdef PS2_MOUSE_ENABLE +static uint8_t ps2_mouse_detected; + +uint8_t ps2_enabled(void) +{ + return ps2_mouse_detected; +} +#endif inline uint8_t matrix_rows(void) @@ -61,6 +72,19 @@ void matrix_init(void) MCUCR = (1< Date: Wed, 9 Apr 2014 17:20:31 +0900 Subject: [PATCH 6/8] Disable PS/2 mouse feature by default --- keyboard/gh60/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 33b6cc01..97d84fbc 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -133,8 +133,8 @@ CONSOLE_ENABLE = yes # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA -PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -PS2_USE_BUSYWAIT = yes +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_EX_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor From 54028c2b653d0634c1cd6d046a4831ef4936b3b4 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 9 Apr 2014 17:21:09 +0900 Subject: [PATCH 7/8] Fix backlight issue for gh60 revB --- keyboard/gh60/backlight.c | 4 ++++ keyboard/gh60/config.h | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index ee5aad9a..91b38c11 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -82,6 +82,8 @@ void backlight_set(uint8_t level) DDRF |= (1<. #define DEBOUNCE 5 /* number of backlight levels */ -#if defined(GH60_REV_CHN) -# define BACKLIGHT_LEVELS 3 -#elif defined(GH60_REV_CNY) -# define BACKLIGHT_LEVELS 3 -#else -# define BACKLIGHT_LEVELS 1 -#endif +#define BACKLIGHT_LEVELS 3 #ifdef GH60_REV_CNY # define LED_MATRIX_ROWS 6 From 19ef3f825a181bb7e9b0220ac70b2cfa5d475621 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 11 Apr 2014 16:54:16 +0900 Subject: [PATCH 8/8] Add macro defination for led matrix --- keyboard/gh60/led_matrix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keyboard/gh60/led_matrix.c b/keyboard/gh60/led_matrix.c index bcd94218..e67b5d7b 100644 --- a/keyboard/gh60/led_matrix.c +++ b/keyboard/gh60/led_matrix.c @@ -18,6 +18,7 @@ along with this program. If not, see . #include #include "led_matrix.h" +#ifdef LED_MATRIX_ENABLE #if defined(GH60_REV_CNY) /* LED Column pin configuration @@ -90,3 +91,4 @@ void led_matrix_select_row(uint8_t row) } #endif +#endif