From 4f3b84f4c5721b6bef54257a997b7e722f9e69f1 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 21 Nov 2013 12:33:03 +0900 Subject: [PATCH 01/64] Add custom backlight feature --- common/backlight.c | 23 +++++++++++++++++ keyboard/gh60/backlight.c | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 keyboard/gh60/backlight.c diff --git a/common/backlight.c b/common/backlight.c index 00dc04a0..f13d9dbc 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -33,6 +33,16 @@ void backlight_init(void) void backlight_increase(void) { +#ifdef BACKLIGHT_CUSTOM + if (backlight_config.enable) { + if (backlight_config.level < BACKLIGHT_LEVELS) { + backlight_config.level++; + eeconfig_write_backlight(backlight_config.raw); + } + dprintf("backlight custom increase: %u\n", backlight_config.level); + backlight_set(backlight_config.level); + } +#else if(backlight_config.level < BACKLIGHT_LEVELS) { backlight_config.level++; @@ -41,10 +51,22 @@ void backlight_increase(void) } dprintf("backlight increase: %u\n", backlight_config.level); backlight_set(backlight_config.level); +#endif } void backlight_decrease(void) { +#ifdef BACKLIGHT_CUSTOM + if (backlight_config.enable) { + if(backlight_config.level > 1) + { + backlight_config.level--; + eeconfig_write_backlight(backlight_config.raw); + } + dprintf("backlight custom decrease: %u\n", backlight_config.level); + backlight_set(backlight_config.level); + } +#else if(backlight_config.level > 0) { backlight_config.level--; @@ -53,6 +75,7 @@ void backlight_decrease(void) } dprintf("backlight decrease: %u\n", backlight_config.level); backlight_set(backlight_config.level); +#endif } void backlight_toggle(void) diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c new file mode 100644 index 00000000..9a248b52 --- /dev/null +++ b/keyboard/gh60/backlight.c @@ -0,0 +1,54 @@ +/* +Copyright 2013 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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include +#include "backlight.h" + +#ifdef GH60_REV_C +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + +/* Backlight pin configuration + * PWM: PB7 + */ +void backlight_set(uint8_t level) +{ + if (level > 0) { + // Turn on PWM + cli(); + DDRB |= (1< Date: Thu, 21 Nov 2013 12:35:34 +0900 Subject: [PATCH 02/64] Add *.swp to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c25d41d2..36d378de 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ *.map *.sym tags +*.swp From bcc9b518f51e07d9720e2f1dd4422b6a2cbd28ce Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 21 Nov 2013 12:41:09 +0900 Subject: [PATCH 03/64] Add support for GH60 PCB revB and revC --- keyboard/gh60/matrix.c | 99 +++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 26 deletions(-) diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index a2bd70e4..516afe3b 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c @@ -135,40 +135,87 @@ uint8_t matrix_key_count(void) } /* Column pin configuration - * col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 - * pin: F0 F1 E6 C7 C6 B6 D4 B1 B0 B5 B4 D7 D6 B3 + * revC pin: F1 F0 E6 D7 D6 D4 C7 C6 B7 B5 B4 B3 B1 B0 + * revB pin: F1 F0 E6 D7 D6 D4 C7 C6 B7 B6 B5 B4 B3 B1 + * revA pin: F1 F0 E6 D7 D6 D4 C7 C6 B6 B5 B4 B3 B1 B0 */ static void init_cols(void) { // Input with pull-up(DDR:0, PORT:1) - DDRF &= ~(1<<0 | 1<<1); - PORTF |= (1<<0 | 1<<1); - DDRE &= ~(1<<6); - PORTE |= (1<<6); - DDRD &= ~(1<<7 | 1<<6 | 1<<4); - PORTD |= (1<<7 | 1<<6 | 1<<4); - DDRC &= ~(1<<7 | 1<<6); - PORTC |= (1<<7 | 1<<6); - DDRB &= ~(1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0); - PORTB |= (1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0); + DDRF &= ~(1< Date: Thu, 21 Nov 2013 13:00:45 +0900 Subject: [PATCH 04/64] New feature to support external keymap in eeprom --- common.mk | 11 ++++- common/keyboard.c | 5 +++ common/keymap_ex.c | 102 +++++++++++++++++++++++++++++++++++++++++++++ common/keymap_ex.h | 62 +++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 common/keymap_ex.c create mode 100644 common/keymap_ex.h diff --git a/common.mk b/common.mk index 5b70db94..350558f8 100644 --- a/common.mk +++ b/common.mk @@ -53,7 +53,11 @@ ifdef PS2_MOUSE_ENABLE OPT_DEFS += -DPS2_MOUSE_ENABLE endif -ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) +ifdef MOUSEKEY_ENABLE + OPT_DEFS += -DMOUSE_ENABLE +endif + +ifdef PS4_MOUSE_ENABLE OPT_DEFS += -DMOUSE_ENABLE endif @@ -73,6 +77,11 @@ ifdef KEYMAP_SECTION_ENABLE EXTRALDFLAGS = -Wl,-L$(TOP_DIR),-Tldscript_keymap_avr5.x endif +ifdef KEYMAP_EX_ENABLE + SRC += $(COMMON_DIR)/keymap_ex.c + OPT_DEFS += -DKEYMAP_EX_ENABLE +endif + # Version string OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null) diff --git a/common/keyboard.c b/common/keyboard.c index 601e3abe..4ad92eb6 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -32,6 +32,7 @@ along with this program. If not, see . #include "eeconfig.h" #include "mousekey.h" #include "backlight.h" +#include "keymap_ex.h" #ifdef MATRIX_HAS_GHOST @@ -67,6 +68,10 @@ void keyboard_init(void) #ifdef BACKLIGHT_ENABLE backlight_init(); #endif + +#ifdef KEYMAP_EX_ENABLE + keymap_init(); +#endif } /* diff --git a/common/keymap_ex.c b/common/keymap_ex.c new file mode 100644 index 00000000..082e3207 --- /dev/null +++ b/common/keymap_ex.c @@ -0,0 +1,102 @@ +/* +Copyright 2013 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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include "eeconfig.h" +#include "keymap_ex.h" +#include "debug.h" + +#ifdef KEYMAP_EX_ENABLE + +void keymap_init(void) { + if (!check_keymap_in_eeprom()) { + write_keymap_to_eeprom(); + } +} + +bool check_keymap_in_eeprom(void) { + return false; +} + +void write_keymap_to_eeprom(void) { + uint16_t checksum = EECONFIG_MAGIC_NUMBER; + const uint16_t *fn_actions = fn_actions_pointer(); + const uint8_t *keymaps = keymaps_pointer(); + // write fn_actions + if (fn_actions != NULL) { + uint16_t size_of_fn_actions = fn_actions_size(); + for (uint16_t i = 0; i < FN_ACTIONS_SIZE_EX; i++) { + uint16_t fn_action = 0; + if (i < size_of_fn_actions) { + fn_action = pgm_read_word(fn_actions + i); + } + eeconfig_write_keymap_fn_action(i, fn_action); + checksum ^= fn_action; + } + } + // write keymaps + if (keymaps != NULL) { + uint16_t size_of_keymaps = keymaps_size(); + for (uint16_t i = 0; i < KEYMAPS_SIZE_EX; i++) { + uint8_t keymap = 0; + if (i < size_of_keymaps) { + keymap = pgm_read_byte(keymaps + i); + } + eeconfig_write_keymap_key_by_index(i, keymap); + uint16_t keymap_word = keymap; + if (i & 1) { + keymap_word = keymap << 8; + } + checksum ^= keymap_word; + } + } + // write checksum + eeprom_write_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum, checksum); +} + +uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col) { + //return eeprom_read_byte(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->keymaps[layer][row][col]); + return eeprom_read_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + KEY_OFFSET(layer, row, col))); +} + +void eeconfig_write_keymap_key(uint8_t layer, uint8_t row, uint8_t col, uint8_t key) { + //return eeprom_write_byte(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->keymaps[layer][row][col], key); + return eeprom_write_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + KEY_OFFSET(layer, row, col)), key); +} + +uint8_t eeconfig_read_keymap_key_by_index(uint16_t index) { + //return eeprom_read_byte(((keymap_ex_t*)(EECONFIG_KEYMAP_EX)) + index); + return eeprom_read_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + index)); +} + +void eeconfig_write_keymap_key_by_index(uint16_t index, uint8_t key) { + //return eeprom_write_byte(((keymap_ex_t*)(EECONFIG_KEYMAP_EX)) + index, key); + return eeprom_write_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + index), key); +} + +uint16_t eeconfig_read_keymap_fn_action(uint8_t index) { + //return eeprom_read_word(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->fn_actions[index]); + return eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + FN_ACTION_OFFSET(index))); +} + +void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action) { + //return eeprom_write_word(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->fn_actions[index], fn_action); + return eeprom_write_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + FN_ACTION_OFFSET(index)), fn_action); +} + +#endif diff --git a/common/keymap_ex.h b/common/keymap_ex.h new file mode 100644 index 00000000..b15c3fe1 --- /dev/null +++ b/common/keymap_ex.h @@ -0,0 +1,62 @@ +/* +Copyright 2013 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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef KEYMAP_EX_H +#define KEYMAP_EX_H + +#ifdef KEYMAP_EX_ENABLE + +#include +#include + +#define EECONFIG_KEYMAP_EX 0x10 +#define FN_ACTIONS_COUNT 8 +#define KEYMAPS_COUNT 8 + +typedef struct { + uint16_t checksum; + uint16_t fn_actions[FN_ACTIONS_COUNT]; + uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; +} keymap_ex_t; + +#define EECONFIG_KEYMAP_CHECKSUM (EECONFIG_KEYMAP_EX) +#define EECONFIG_KEYMAP_FN_ACTIONS (EECONFIG_KEYMAP_EX + sizeof(uint16_t)) +#define EECONFIG_KEYMAP_KEYMAPS (EECONFIG_KEYMAP_FN_ACTIONS + sizeof(uint16_t) * FN_ACTIONS_COUNT) + +#define FN_ACTIONS_SIZE_EX (sizeof(uint16_t) * FN_ACTIONS_COUNT) +#define KEYMAPS_SIZE_EX (sizeof(uint8_t) * KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS) +#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); +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); +void eeconfig_write_keymap_key(uint8_t layer, uint8_t row, uint8_t col, uint8_t key); +uint8_t eeconfig_read_keymap_key_by_index(uint16_t index); +void eeconfig_write_keymap_key_by_index(uint16_t index, uint8_t key); +uint16_t eeconfig_read_keymap_fn_action(uint8_t index); +void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action); + +const uint8_t* keymaps_pointer(void); +const uint16_t* fn_actions_pointer(void); +uint16_t keymaps_size(void); +uint16_t fn_actions_size(void); + +#endif + +#endif From 2afa7e162bde986872e990cfa055e4fe04fa4492 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 21 Nov 2013 13:08:32 +0900 Subject: [PATCH 05/64] Add poker2-like keymap for gh60 --- keyboard/gh60/Makefile.lufa | 16 +++++++--- keyboard/gh60/keymap.c | 41 +++++++++++++++++++++--- keyboard/gh60/keymap_poker2.h | 60 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 keyboard/gh60/keymap_poker2.h diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa index ad7d219e..67b95a39 100644 --- a/keyboard/gh60/Makefile.lufa +++ b/keyboard/gh60/Makefile.lufa @@ -48,9 +48,10 @@ TOP_DIR = ../.. TARGET_DIR = . # project specific files -SRC = keymap.c \ +SRC += keymap.c \ matrix.c \ - led.c + led.c \ + backlight.c CONFIG_H = config.h @@ -112,9 +113,13 @@ BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = yes # Mouse keys(+4700) 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 +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 +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" @@ -139,3 +144,6 @@ poker_set: all poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT poker_bit: all + +poker2: OPT_DEFS += -DKEYMAP_POKER2 -DBACKLIGHT_CUSTOM -DGH60_REV_C +poker2: all diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c index edc1caf1..8b7a3b11 100644 --- a/keyboard/gh60/keymap.c +++ b/keyboard/gh60/keymap.c @@ -25,6 +25,7 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "keymap.h" +#include "keymap_ex.h" /* GH60 keymap definition macro @@ -35,13 +36,13 @@ along with this program. If not, see . K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, \ K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \ - K40, K41, K42, K45, K4A, K4B, K4C, K4D \ + K40, K41, K42, K45, K49, K4A, K4B, K4C, K4D \ ) { \ { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \ { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \ { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \ { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \ - { KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_NO, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \ + { KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \ } /* ANSI valiant. No extra keys for ISO */ @@ -56,7 +57,7 @@ along with this program. If not, see . K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO, K2D, \ K30, NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, NO, K3D, \ - K40, K41, K42, K45, K4A, K4B, K4C, K4D \ + K40, K41, K42, K45, NO, K4A, K4B, K4C, K4D \ ) @@ -68,6 +69,8 @@ along with this program. If not, see . #include "keymap_poker_set.h" #elif defined(KEYMAP_POKER_BIT) #include "keymap_poker_bit.h" +#elif defined(KEYMAP_POKER2) + #include "keymap_poker2.h" #else static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* @@ -214,21 +217,45 @@ static const uint16_t PROGMEM fn_actions[] = { }; #endif - - #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) +#ifdef KEYMAP_EX_ENABLE +const uint8_t* keymaps_pointer(void) { + return (const uint8_t*)keymaps; +} + +const uint16_t* fn_actions_pointer(void) { + return fn_actions; +} + +uint16_t keymaps_size(void) { + return KEYMAPS_SIZE * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_size(void) { + return FN_ACTIONS_SIZE; +} +#endif + /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { if (layer < KEYMAPS_SIZE) { +#ifndef KEYMAP_EX_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(layer, key.row, key.col); +#endif } else { // XXX: this may cuaes bootlaoder_jump inconsistent fail. //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n"); // fall back to layer 0 +#ifndef KEYMAP_EX_ENABLE return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(0, key.row, key.col); +#endif } } @@ -237,7 +264,11 @@ action_t keymap_fn_to_action(uint8_t keycode) { action_t action; if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { +#ifndef KEYMAP_EX_ENABLE action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); +#else + action.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)); +#endif } else { action.code = ACTION_NO; } diff --git a/keyboard/gh60/keymap_poker2.h b/keyboard/gh60/keymap_poker2.h new file mode 100644 index 00000000..5d8b09a9 --- /dev/null +++ b/keyboard/gh60/keymap_poker2.h @@ -0,0 +1,60 @@ +// Poker2 +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,-----------------------------------------------------------. + * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| + * |-----------------------------------------------------------| + * |Caps | A| S| D| F| G| H| J| K| L|Fn3| '|Return | + * |-----------------------------------------------------------| + * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | + * |-----------------------------------------------------------| + * |Ctrl|Gui |Alt | Space |Alt |Fn0 |Gui |Ctrl| + * `-----------------------------------------------------------' + */ + KEYMAP_ANSI( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ + LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ + LCTL,LGUI,LALT, SPC, RALT,FN0, RGUI,RCTL), + /* Keymap 1: Fn Layer + * ,-----------------------------------------------------------. + * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | + * |-----------------------------------------------------------| + * | | |Up | | | |Cal| |Ins| |Psc|Slk|Pau| | + * |-----------------------------------------------------------| + * | |Lef|Dow|Rig| | | | | | |Hom|PgU| | + * |-----------------------------------------------------------| + * | | |App|Fn1|Fn2|Fn3|VoD|VoU|Mut|End|PgD| | + * |-----------------------------------------------------------| + * | | | | | | | | | + * `-----------------------------------------------------------' + */ + KEYMAP_ANSI( + GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ + TRNS,TRNS,UP, TRNS,TRNS,TRNS,CALC,TRNS,INS, TRNS,PSCR,SLCK,PAUS,TRNS, \ + TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,HOME,PGUP, TRNS, \ + TRNS,TRNS,APP, FN1, FN2, FN3, VOLD,VOLU,MUTE,END, PGDN, TRNS, \ + TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS), +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +static const uint16_t fn_actions[] PROGMEM = { +#endif + /* Poker2 Layout */ + [0] = ACTION_LAYER_MOMENTARY(1), + [1] = ACTION_BACKLIGHT_DECREASE(), + [2] = ACTION_BACKLIGHT_TOGGLE(), + [3] = ACTION_BACKLIGHT_INCREASE() +}; From d923f5aef1676b73ae535b2a61f0da5e92281e99 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 21 Nov 2013 13:13:07 +0900 Subject: [PATCH 06/64] Fix misdefine of BACKLIGHT_LEVELS --- keyboard/gh60/config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index e9c0f436..93deaa98 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -37,8 +37,12 @@ along with this program. If not, see . /* Set 0 if debouncing isn't needed */ #define DEBOUNCE 5 +/* number of backlight levels */ +#define BACKLIGHT_LEVELS 3 + /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ #define LOCKING_SUPPORT_ENABLE + /* Locking resynchronize hack */ #define LOCKING_RESYNC_ENABLE From e5a48615ec5b3de228cf5536c29d29d0c0c82b5a Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 21 Nov 2013 13:44:32 +0900 Subject: [PATCH 07/64] Fix confusion of size and count --- common/keymap_ex.c | 16 +++++++++------- common/keymap_ex.h | 7 +++---- keyboard/gh60/keymap.c | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/common/keymap_ex.c b/common/keymap_ex.c index 082e3207..cb67e8f4 100644 --- a/common/keymap_ex.c +++ b/common/keymap_ex.c @@ -30,7 +30,9 @@ void keymap_init(void) { } bool check_keymap_in_eeprom(void) { - return false; + uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum); + uint16_t checksum = EECONFIG_MAGIC_NUMBER; + return (checksum_in_eeprom == checksum); } void write_keymap_to_eeprom(void) { @@ -39,10 +41,10 @@ void write_keymap_to_eeprom(void) { const uint8_t *keymaps = keymaps_pointer(); // write fn_actions if (fn_actions != NULL) { - uint16_t size_of_fn_actions = fn_actions_size(); - for (uint16_t i = 0; i < FN_ACTIONS_SIZE_EX; i++) { + uint16_t fn_actions_count_in_flash = fn_actions_count(); + for (uint16_t i = 0; i < FN_ACTIONS_COUNT; i++) { uint16_t fn_action = 0; - if (i < size_of_fn_actions) { + if (i < fn_actions_count_in_flash) { fn_action = pgm_read_word(fn_actions + i); } eeconfig_write_keymap_fn_action(i, fn_action); @@ -51,10 +53,10 @@ void write_keymap_to_eeprom(void) { } // write keymaps if (keymaps != NULL) { - uint16_t size_of_keymaps = keymaps_size(); - for (uint16_t i = 0; i < KEYMAPS_SIZE_EX; i++) { + uint16_t keys_count_in_flash = keys_count(); + for (uint16_t i = 0; i < KEYS_COUNT; i++) { uint8_t keymap = 0; - if (i < size_of_keymaps) { + if (i < keys_count_in_flash) { keymap = pgm_read_byte(keymaps + i); } eeconfig_write_keymap_key_by_index(i, keymap); diff --git a/common/keymap_ex.h b/common/keymap_ex.h index b15c3fe1..be229b10 100644 --- a/common/keymap_ex.h +++ b/common/keymap_ex.h @@ -37,8 +37,7 @@ typedef struct { #define EECONFIG_KEYMAP_FN_ACTIONS (EECONFIG_KEYMAP_EX + sizeof(uint16_t)) #define EECONFIG_KEYMAP_KEYMAPS (EECONFIG_KEYMAP_FN_ACTIONS + sizeof(uint16_t) * FN_ACTIONS_COUNT) -#define FN_ACTIONS_SIZE_EX (sizeof(uint16_t) * FN_ACTIONS_COUNT) -#define KEYMAPS_SIZE_EX (sizeof(uint8_t) * KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS) +#define KEYS_COUNT (KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS) #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)) @@ -54,8 +53,8 @@ void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action); const uint8_t* keymaps_pointer(void); const uint16_t* fn_actions_pointer(void); -uint16_t keymaps_size(void); -uint16_t fn_actions_size(void); +uint16_t keys_count(void); +uint16_t fn_actions_count(void); #endif diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c index 8b7a3b11..ac887c82 100644 --- a/keyboard/gh60/keymap.c +++ b/keyboard/gh60/keymap.c @@ -229,11 +229,11 @@ const uint16_t* fn_actions_pointer(void) { return fn_actions; } -uint16_t keymaps_size(void) { +uint16_t keys_count(void) { return KEYMAPS_SIZE * MATRIX_ROWS * MATRIX_COLS; } -uint16_t fn_actions_size(void) { +uint16_t fn_actions_count(void) { return FN_ACTIONS_SIZE; } #endif From 09d924931086c13f2e24e2b51f69c8aed513a4fe Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 22 Nov 2013 10:58:02 +0900 Subject: [PATCH 08/64] Fix some debug codes --- common/keymap_ex.c | 6 ++++++ common/keymap_ex.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/common/keymap_ex.c b/common/keymap_ex.c index cb67e8f4..3d55c08c 100644 --- a/common/keymap_ex.c +++ b/common/keymap_ex.c @@ -32,6 +32,12 @@ void keymap_init(void) { 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; + for (uint16_t i = 0; i < KEYMAP_SIZE; i += 2) { + checksum ^= eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + i)); + } +#ifdef DEBUG + eeprom_write_word((void*)(EECONFIG_KEYMAP_DEBUG), checksum); +#endif return (checksum_in_eeprom == checksum); } diff --git a/common/keymap_ex.h b/common/keymap_ex.h index be229b10..435547a0 100644 --- a/common/keymap_ex.h +++ b/common/keymap_ex.h @@ -33,11 +33,13 @@ typedef struct { uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; } keymap_ex_t; +#define EECONFIG_KEYMAP_DEBUG (EECONFIG_KEYMAP_EX - sizeof(uint16_t)) #define EECONFIG_KEYMAP_CHECKSUM (EECONFIG_KEYMAP_EX) #define EECONFIG_KEYMAP_FN_ACTIONS (EECONFIG_KEYMAP_EX + sizeof(uint16_t)) #define EECONFIG_KEYMAP_KEYMAPS (EECONFIG_KEYMAP_FN_ACTIONS + sizeof(uint16_t) * FN_ACTIONS_COUNT) #define KEYS_COUNT (KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS) +#define KEYMAP_SIZE (sizeof(uint16_t) * FN_ACTIONS_COUNT + sizeof(uint8_t) * KEYS_COUNT) #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)) From 17bf466ab5c3e3dbdf960e20a2793b12cdb3a7ce Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 2 Dec 2013 11:22:34 +0900 Subject: [PATCH 09/64] Change checksum algorism --- common/keymap_ex.c | 6 +++--- keyboard/gh60/keymap_poker2.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/keymap_ex.c b/common/keymap_ex.c index 3d55c08c..0c01f707 100644 --- a/common/keymap_ex.c +++ b/common/keymap_ex.c @@ -33,7 +33,7 @@ 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; for (uint16_t i = 0; i < KEYMAP_SIZE; i += 2) { - checksum ^= eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + i)); + checksum += eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + i)); } #ifdef DEBUG eeprom_write_word((void*)(EECONFIG_KEYMAP_DEBUG), checksum); @@ -54,7 +54,7 @@ void write_keymap_to_eeprom(void) { fn_action = pgm_read_word(fn_actions + i); } eeconfig_write_keymap_fn_action(i, fn_action); - checksum ^= fn_action; + checksum += fn_action; } } // write keymaps @@ -70,7 +70,7 @@ void write_keymap_to_eeprom(void) { if (i & 1) { keymap_word = keymap << 8; } - checksum ^= keymap_word; + checksum += keymap_word; } } // write checksum diff --git a/keyboard/gh60/keymap_poker2.h b/keyboard/gh60/keymap_poker2.h index 5d8b09a9..eba6799a 100644 --- a/keyboard/gh60/keymap_poker2.h +++ b/keyboard/gh60/keymap_poker2.h @@ -10,7 +10,7 @@ static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { * |-----------------------------------------------------------| * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| * |-----------------------------------------------------------| - * |Caps | A| S| D| F| G| H| J| K| L|Fn3| '|Return | + * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return | * |-----------------------------------------------------------| * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | * |-----------------------------------------------------------| From 50d5106d667cc7b13a032ff8e8c061773dc07387 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 2 Dec 2013 16:10:34 +0900 Subject: [PATCH 10/64] New branch to support GHPad --- keyboard/ghpad/Makefile.lufa | 137 ++++++++++++++++++++++ keyboard/ghpad/Makefile.pjrc | 101 +++++++++++++++++ keyboard/ghpad/config.h | 74 ++++++++++++ keyboard/ghpad/keymap.c | 157 +++++++++++++++++++++++++ keyboard/ghpad/keymap_plain.h | 38 +++++++ keyboard/ghpad/led.c | 34 ++++++ keyboard/ghpad/matrix.c | 208 ++++++++++++++++++++++++++++++++++ 7 files changed, 749 insertions(+) create mode 100644 keyboard/ghpad/Makefile.lufa create mode 100644 keyboard/ghpad/Makefile.pjrc create mode 100644 keyboard/ghpad/config.h create mode 100644 keyboard/ghpad/keymap.c create mode 100644 keyboard/ghpad/keymap_plain.h create mode 100644 keyboard/ghpad/led.c create mode 100644 keyboard/ghpad/matrix.c diff --git a/keyboard/ghpad/Makefile.lufa b/keyboard/ghpad/Makefile.lufa new file mode 100644 index 00000000..16bd46ca --- /dev/null +++ b/keyboard/ghpad/Makefile.lufa @@ -0,0 +1,137 @@ +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = ghpad_lufa + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC += keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name +#MCU = at90usb1287 +MCU = atmega32u4 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 16000000 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + +# Interrupt driven control endpoint task(+60) +#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Build Options +# comment out to disable the options. +# +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +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 +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#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 + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk + +plain: OPT_DEFS += -DKEYMAP_PLAIN +plain: all + diff --git a/keyboard/ghpad/Makefile.pjrc b/keyboard/ghpad/Makefile.pjrc new file mode 100644 index 00000000..83ca6c91 --- /dev/null +++ b/keyboard/ghpad/Makefile.pjrc @@ -0,0 +1,101 @@ +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = ghpad_pjrc + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name, you MUST set this to match the board you are using +# type "make clean" after changing this, so all files will be rebuilt +MCU = atmega32u4 +#MCU = at90usb1286 + + +# Processor frequency. +# Normally the first thing your program should do is set the clock prescaler, +# so your program will run at the correct speed. You should also set this +# variable to same clock speed. The _delay_ms() macro uses this, and many +# examples use this variable to calculate timings. Do not add a "UL" here. +F_CPU = 16000000 + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Build Options +# comment out to disable the options. +# +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+5000) +EXTRAKEY_ENABLE = yes # Audio control and System control(+600) +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration +SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +NKRO_ENABLE = yes # USB Nkey Rollover(+500) +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk + +plain: OPT_DEFS += -DKEYMAP_PLAIN +plain: all diff --git a/keyboard/ghpad/config.h b/keyboard/ghpad/config.h new file mode 100644 index 00000000..dfad09b1 --- /dev/null +++ b/keyboard/ghpad/config.h @@ -0,0 +1,74 @@ +/* +Copyright 2012 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6060 +#define DEVICE_VER 0x0002 +#define MANUFACTURER geekhack +#define PRODUCT GHPad +#define DESCRIPTION t.m.k. keyboard firmware for GHPad + +/* key matrix size */ +#define MATRIX_ROWS 6 +#define MATRIX_COLS 4 + +/* define if matrix has ghost */ +//#define MATRIX_HAS_GHOST + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCE 5 + +/* number of backlight levels */ +//#define BACKLIGHT_LEVELS 3 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +#define LOCKING_SUPPORT_ENABLE + +/* Locking resynchronize hack */ +#define LOCKING_RESYNC_ENABLE + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + + + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +#endif diff --git a/keyboard/ghpad/keymap.c b/keyboard/ghpad/keymap.c new file mode 100644 index 00000000..3b0a272a --- /dev/null +++ b/keyboard/ghpad/keymap.c @@ -0,0 +1,157 @@ +/* +Copyright 2012,2013 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#include +#include +#include +#include "keycode.h" +#include "action.h" +#include "action_macro.h" +#include "report.h" +#include "host.h" +#include "print.h" +#include "debug.h" +#include "keymap.h" +#include "keymap_ex.h" + + +/* GHPad keymap definition macro + */ +#define KEYMAP( \ + K0A, K0B, K0C, K0D, \ + K1A, K1B, K1C, K1D, \ + K2A, K2B, K2C, K2D, \ + K3A, K3B, K3C, K3D, \ + K4A, K4B, K4C, K4D, \ + K5A, K5B, K5C, K5D \ +) { \ + { KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \ + { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \ + { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \ + { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \ + { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D }, \ + { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D } \ +} + +#if defined(KEYMAP_PLAIN) + #include "keymap_plain.h" +#else +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,---------------. + * |Num|/ |* |- | + * |---+---+---+---| + * |7 |8 |9 |+ | + * |---+---+---| | + * |4 |5 |6 | | + * |---+---+---+---| + * |1 |2 |3 |Ent| + * |---+---+---| | + * |0 |Up |. | | + * |---+---+---+---| + * |Lef|Dow|Rig|Fn0| + * `---------------' + */ + [0] = KEYMAP( + NLCK,PSLS,PAST,PMNS, \ + P7, P8, P9, PPLS, \ + P4, P5, P6, NO, \ + P1, P2, P3, PENT, \ + P0, UP, PDOT,NO, \ + LEFT,DOWN,RGHT,FN0), + /* Keymap 1: */ + [1] = KEYMAP( + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS), +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +static const uint16_t fn_actions[] PROGMEM = { +#endif + [0] = ACTION_LAYER_MOMENTARY(1) +}; +#endif + +#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) +#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) + +#ifdef KEYMAP_EX_ENABLE +const uint8_t* keymaps_pointer(void) { + return (const uint8_t*)keymaps; +} + +const uint16_t* fn_actions_pointer(void) { + return fn_actions; +} + +uint16_t keys_count(void) { + return KEYMAPS_SIZE * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return FN_ACTIONS_SIZE; +} +#endif + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + if (layer < KEYMAPS_SIZE) { +#ifndef KEYMAP_EX_ENABLE + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(layer, key.row, key.col); +#endif + } else { + // XXX: this may cuaes bootlaoder_jump inconsistent fail. + //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n"); + // fall back to layer 0 +#ifndef KEYMAP_EX_ENABLE + return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(0, key.row, key.col); +#endif + } +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + action_t action; + if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { +#ifndef KEYMAP_EX_ENABLE + action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); +#else + action.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)); +#endif + } else { + action.code = ACTION_NO; + } + return action; +} diff --git a/keyboard/ghpad/keymap_plain.h b/keyboard/ghpad/keymap_plain.h new file mode 100644 index 00000000..b4e2aad3 --- /dev/null +++ b/keyboard/ghpad/keymap_plain.h @@ -0,0 +1,38 @@ +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,---------------. + * |Esc|Tab|= |Bs | + * |---+---+---+---| + * |Num|/ |* |- | + * |---+---+---+---| + * |7 |8 |9 |+ | + * |---+---+---| | + * |4 |5 |6 | | + * |---+---+---+---| + * |1 |2 |3 |Ent| + * |---+---+---| | + * |0 |. | | + * `---------------' + */ + [0] = KEYMAP( + ESC, TAB, PEQL,BSPC, \ + NLCK,PSLS,PAST,PMNS, \ + P7, P8, P9, PPLS, \ + P4, P5, P6, PENT, \ + P1, P2, P3, PENT, \ + P0, NO, PDOT,NO) +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +static const uint16_t fn_actions[] PROGMEM = { +#endif +}; diff --git a/keyboard/ghpad/led.c b/keyboard/ghpad/led.c new file mode 100644 index 00000000..eac65559 --- /dev/null +++ b/keyboard/ghpad/led.c @@ -0,0 +1,34 @@ +/* +Copyright 2012 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include "stdint.h" +#include "led.h" + + +void led_set(uint8_t usb_led) +{ + if (usb_led & (1< + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" + + +#ifndef DEBOUNCE +# define DEBOUNCE 5 +#endif +static uint8_t debouncing = DEBOUNCE; + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +static matrix_row_t read_cols(void); +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); + + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + // initialize row and col + unselect_rows(); + init_cols(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; + } +} + +uint8_t matrix_scan(void) +{ + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + select_row(i); + _delay_us(30); // without this wait read unstable value. + matrix_row_t cols = read_cols(); + if (matrix_debouncing[i] != cols) { + matrix_debouncing[i] = cols; + if (debouncing) { + debug("bounce!: "); debug_hex(debouncing); debug("\n"); + } + debouncing = DEBOUNCE; + } + unselect_rows(); + } + + if (debouncing) { + if (--debouncing) { + _delay_ms(1); + } else { + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + matrix[i] = matrix_debouncing[i]; + } + } + } + + return 1; +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1< Date: Thu, 12 Dec 2013 12:58:14 +0900 Subject: [PATCH 11/64] Compatibility change for separated right shift --- keyboard/gh60/Makefile.lufa | 2 +- keyboard/gh60/keymap_poker2.h | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa index 67b95a39..cf588b74 100644 --- a/keyboard/gh60/Makefile.lufa +++ b/keyboard/gh60/Makefile.lufa @@ -145,5 +145,5 @@ poker_set: all poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT poker_bit: all -poker2: OPT_DEFS += -DKEYMAP_POKER2 -DBACKLIGHT_CUSTOM -DGH60_REV_C +poker2: OPT_DEFS += -DKEYMAP_POKER2 -DBACKLIGHT_CUSTOM -DGH60_REV_C -DDEBUG poker2: all diff --git a/keyboard/gh60/keymap_poker2.h b/keyboard/gh60/keymap_poker2.h index eba6799a..0eae7364 100644 --- a/keyboard/gh60/keymap_poker2.h +++ b/keyboard/gh60/keymap_poker2.h @@ -12,17 +12,17 @@ static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { * |-----------------------------------------------------------| * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return | * |-----------------------------------------------------------| - * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | + * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0| * |-----------------------------------------------------------| * |Ctrl|Gui |Alt | Space |Alt |Fn0 |Gui |Ctrl| * `-----------------------------------------------------------' */ - KEYMAP_ANSI( + KEYMAP( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ - CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ - LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ - LCTL,LGUI,LALT, SPC, RALT,FN0, RGUI,RCTL), + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, \ + LSFT,NO, Z, X, C, V, B, N, M, COMM,DOT, SLSH,FN0, RSFT, \ + LCTL,LGUI,LALT, SPC, NO, RALT,FN0, RGUI,RCTL), /* Keymap 1: Fn Layer * ,-----------------------------------------------------------. * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | @@ -31,17 +31,17 @@ static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { * |-----------------------------------------------------------| * | |Lef|Dow|Rig| | | | | | |Hom|PgU| | * |-----------------------------------------------------------| - * | | |App|Fn1|Fn2|Fn3|VoD|VoU|Mut|End|PgD| | + * | | |App|Fn1|Fn2|Fn3|VoD|VoU|Mut|End|PgD| | | * |-----------------------------------------------------------| * | | | | | | | | | * `-----------------------------------------------------------' */ - KEYMAP_ANSI( + KEYMAP( GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ TRNS,TRNS,UP, TRNS,TRNS,TRNS,CALC,TRNS,INS, TRNS,PSCR,SLCK,PAUS,TRNS, \ - TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,HOME,PGUP, TRNS, \ - TRNS,TRNS,APP, FN1, FN2, FN3, VOLD,VOLU,MUTE,END, PGDN, TRNS, \ - TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS), + TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,NO, TRNS, \ + TRNS,NO, TRNS,APP, FN1, FN2, FN3, VOLD,VOLU,MUTE,END, PGDN,TRNS,TRNS, \ + TRNS,TRNS,TRNS, TRNS, NO, TRNS,TRNS,TRNS,TRNS), }; /* From 2bcd17110497b299f9f5cb5859241196d678a771 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 12 Dec 2013 17:06:29 +0900 Subject: [PATCH 12/64] Fix for tmk's changes --- keyboard/gh60/Makefile | 7 ++++++ keyboard/gh60/backlight.c | 4 +++- keyboard/gh60/keymap_common.c | 23 +++++++++++++++++-- keyboard/gh60/keymap_common.h | 8 +++++++ keyboard/gh60/keymap_poker.c | 10 ++++++++ .../gh60/{keymap_poker2.h => keymap_poker2.c} | 20 ++++++++++++---- 6 files changed, 65 insertions(+), 7 deletions(-) rename keyboard/gh60/{keymap_poker2.h => keymap_poker2.c} (82%) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 70768548..f158fe6d 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -59,6 +59,7 @@ else SRC := keymap_poker.c $(SRC) endif + CONFIG_H = config.h @@ -111,6 +112,12 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # USBaspLoader 2048 OPT_DEFS += -DBOOTLOADER_SIZE=4096 +# PCB Revision +ifdef REV + OPT_DEFS += -DGH60_REV_$(REV) +endif + +OPT_DEFS += -DBACKLIGHT_CUSTOM # Build Options # comment out to disable the options. diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 9a248b52..2cf129c3 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -20,7 +20,7 @@ along with this program. If not, see . #include #include "backlight.h" -#ifdef GH60_REV_C +#ifdef GH60_REV_CHN static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; @@ -51,4 +51,6 @@ void backlight_set(uint8_t level) OCR1B = 0; } } +#else +void backlight_set(uint8_t level) {} #endif diff --git a/keyboard/gh60/keymap_common.c b/keyboard/gh60/keymap_common.c index 7b6379f6..ae934eea 100644 --- a/keyboard/gh60/keymap_common.c +++ b/keyboard/gh60/keymap_common.c @@ -16,15 +16,34 @@ along with this program. If not, see . */ #include "keymap_common.h" - /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { +#ifndef KEYMAP_EX_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(layer, key.row, key.col); +#endif } /* translates Fn keycode to action */ action_t keymap_fn_to_action(uint8_t keycode) { - return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) }; + return (action_t) { +#ifndef KEYMAP_EX_ENABLE + .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) +#else + .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) +#endif + }; } + +#ifdef KEYMAP_EX_ENABLE +const uint8_t* keymaps_pointer(void) { + return (const uint8_t*)keymaps; +} + +const uint16_t* fn_actions_pointer(void) { + return fn_actions; +} +#endif diff --git a/keyboard/gh60/keymap_common.h b/keyboard/gh60/keymap_common.h index 896badd7..e94f013c 100644 --- a/keyboard/gh60/keymap_common.h +++ b/keyboard/gh60/keymap_common.h @@ -28,10 +28,18 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "keymap.h" +#include "keymap_ex.h" +/* +#ifdef KEYMAP_EX_ENABLE +extern const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; +extern const uint16_t fn_actions[FN_ACTIONS_COUNT]; +#else +*/ extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; extern const uint16_t fn_actions[]; +//#endif /* GH60 keymap definition macro diff --git a/keyboard/gh60/keymap_poker.c b/keyboard/gh60/keymap_poker.c index 7a612ee4..f2035b43 100644 --- a/keyboard/gh60/keymap_poker.c +++ b/keyboard/gh60/keymap_poker.c @@ -102,3 +102,13 @@ const uint16_t PROGMEM fn_actions[] = { [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout [8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout }; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif diff --git a/keyboard/gh60/keymap_poker2.h b/keyboard/gh60/keymap_poker2.c similarity index 82% rename from keyboard/gh60/keymap_poker2.h rename to keyboard/gh60/keymap_poker2.c index 0eae7364..cfcadccf 100644 --- a/keyboard/gh60/keymap_poker2.h +++ b/keyboard/gh60/keymap_poker2.c @@ -1,8 +1,10 @@ +#include "keymap_common.h" + // Poker2 #ifdef KEYMAP_SECTION_ENABLE -const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { #else -static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { #endif /* Keymap 0: Default Layer * ,-----------------------------------------------------------. @@ -48,9 +50,9 @@ static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { * Fn action definition */ #ifdef KEYMAP_SECTION_ENABLE -const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = { +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { #else -static const uint16_t fn_actions[] PROGMEM = { +const uint16_t fn_actions[] PROGMEM = { #endif /* Poker2 Layout */ [0] = ACTION_LAYER_MOMENTARY(1), @@ -58,3 +60,13 @@ static const uint16_t fn_actions[] PROGMEM = { [2] = ACTION_BACKLIGHT_TOGGLE(), [3] = ACTION_BACKLIGHT_INCREASE() }; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif From dbf5430c5f91a575c3aa132d4afde987f2d68913 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 12 Dec 2013 17:15:35 +0900 Subject: [PATCH 13/64] Add additional definitions --- keyboard/gh60/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index f158fe6d..83363311 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -117,7 +117,10 @@ ifdef REV OPT_DEFS += -DGH60_REV_$(REV) endif -OPT_DEFS += -DBACKLIGHT_CUSTOM +# Additional definitions from command line +ifdef DEFS + OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) +endif # Build Options # comment out to disable the options. From abdd40441992bb42e8e380a76f31b120c111b9b2 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 13 Dec 2013 21:38:36 +0900 Subject: [PATCH 14/64] Update keymaps for ghpad --- keyboard/ghpad/{Makefile.lufa => Makefile} | 15 +- keyboard/ghpad/keymap.c | 157 ------------------ .../ghpad/{keymap_plain.h => keymap_4x6.c} | 21 ++- keyboard/ghpad/keymap_arrow.c | 60 +++++++ keyboard/ghpad/keymap_common.c | 49 ++++++ keyboard/ghpad/keymap_common.h | 54 ++++++ 6 files changed, 189 insertions(+), 167 deletions(-) rename keyboard/ghpad/{Makefile.lufa => Makefile} (96%) delete mode 100644 keyboard/ghpad/keymap.c rename keyboard/ghpad/{keymap_plain.h => keymap_4x6.c} (53%) create mode 100644 keyboard/ghpad/keymap_arrow.c create mode 100644 keyboard/ghpad/keymap_common.c create mode 100644 keyboard/ghpad/keymap_common.h diff --git a/keyboard/ghpad/Makefile.lufa b/keyboard/ghpad/Makefile similarity index 96% rename from keyboard/ghpad/Makefile.lufa rename to keyboard/ghpad/Makefile index 16bd46ca..4b76788c 100644 --- a/keyboard/ghpad/Makefile.lufa +++ b/keyboard/ghpad/Makefile @@ -48,10 +48,17 @@ TOP_DIR = ../.. TARGET_DIR = . # project specific files -SRC += keymap.c \ +SRC = keymap_common.c \ matrix.c \ led.c +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_4x6.c $(SRC) +endif + + CONFIG_H = config.h @@ -93,7 +100,7 @@ ARCH = AVR8 F_USB = $(F_CPU) # Interrupt driven control endpoint task(+60) -#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Boot Section Size in *bytes* @@ -131,7 +138,3 @@ VPATH += $(TOP_DIR) include $(TOP_DIR)/protocol/lufa.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk - -plain: OPT_DEFS += -DKEYMAP_PLAIN -plain: all - diff --git a/keyboard/ghpad/keymap.c b/keyboard/ghpad/keymap.c deleted file mode 100644 index 3b0a272a..00000000 --- a/keyboard/ghpad/keymap.c +++ /dev/null @@ -1,157 +0,0 @@ -/* -Copyright 2012,2013 Jun Wako - -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 -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#include -#include -#include -#include "keycode.h" -#include "action.h" -#include "action_macro.h" -#include "report.h" -#include "host.h" -#include "print.h" -#include "debug.h" -#include "keymap.h" -#include "keymap_ex.h" - - -/* GHPad keymap definition macro - */ -#define KEYMAP( \ - K0A, K0B, K0C, K0D, \ - K1A, K1B, K1C, K1D, \ - K2A, K2B, K2C, K2D, \ - K3A, K3B, K3C, K3D, \ - K4A, K4B, K4C, K4D, \ - K5A, K5B, K5C, K5D \ -) { \ - { KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \ - { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \ - { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \ - { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \ - { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D }, \ - { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D } \ -} - -#if defined(KEYMAP_PLAIN) - #include "keymap_plain.h" -#else -#ifdef KEYMAP_SECTION_ENABLE -const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { -#else -static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { -#endif - /* Keymap 0: Default Layer - * ,---------------. - * |Num|/ |* |- | - * |---+---+---+---| - * |7 |8 |9 |+ | - * |---+---+---| | - * |4 |5 |6 | | - * |---+---+---+---| - * |1 |2 |3 |Ent| - * |---+---+---| | - * |0 |Up |. | | - * |---+---+---+---| - * |Lef|Dow|Rig|Fn0| - * `---------------' - */ - [0] = KEYMAP( - NLCK,PSLS,PAST,PMNS, \ - P7, P8, P9, PPLS, \ - P4, P5, P6, NO, \ - P1, P2, P3, PENT, \ - P0, UP, PDOT,NO, \ - LEFT,DOWN,RGHT,FN0), - /* Keymap 1: */ - [1] = KEYMAP( - TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS), -}; - -/* - * Fn action definition - */ -#ifdef KEYMAP_SECTION_ENABLE -const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = { -#else -static const uint16_t fn_actions[] PROGMEM = { -#endif - [0] = ACTION_LAYER_MOMENTARY(1) -}; -#endif - -#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) -#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) - -#ifdef KEYMAP_EX_ENABLE -const uint8_t* keymaps_pointer(void) { - return (const uint8_t*)keymaps; -} - -const uint16_t* fn_actions_pointer(void) { - return fn_actions; -} - -uint16_t keys_count(void) { - return KEYMAPS_SIZE * MATRIX_ROWS * MATRIX_COLS; -} - -uint16_t fn_actions_count(void) { - return FN_ACTIONS_SIZE; -} -#endif - -/* translates key to keycode */ -uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) -{ - if (layer < KEYMAPS_SIZE) { -#ifndef KEYMAP_EX_ENABLE - return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); -#else - return eeconfig_read_keymap_key(layer, key.row, key.col); -#endif - } else { - // XXX: this may cuaes bootlaoder_jump inconsistent fail. - //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n"); - // fall back to layer 0 -#ifndef KEYMAP_EX_ENABLE - return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); -#else - return eeconfig_read_keymap_key(0, key.row, key.col); -#endif - } -} - -/* translates Fn keycode to action */ -action_t keymap_fn_to_action(uint8_t keycode) -{ - action_t action; - if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { -#ifndef KEYMAP_EX_ENABLE - action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); -#else - action.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)); -#endif - } else { - action.code = ACTION_NO; - } - return action; -} diff --git a/keyboard/ghpad/keymap_plain.h b/keyboard/ghpad/keymap_4x6.c similarity index 53% rename from keyboard/ghpad/keymap_plain.h rename to keyboard/ghpad/keymap_4x6.c index b4e2aad3..c70ff7a7 100644 --- a/keyboard/ghpad/keymap_plain.h +++ b/keyboard/ghpad/keymap_4x6.c @@ -1,7 +1,10 @@ +#include "keymap_common.h" + +// 4x6 Keypad #ifdef KEYMAP_SECTION_ENABLE -const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { #else -static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { #endif /* Keymap 0: Default Layer * ,---------------. @@ -31,8 +34,18 @@ static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { * Fn action definition */ #ifdef KEYMAP_SECTION_ENABLE -const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = { +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { #else -static const uint16_t fn_actions[] PROGMEM = { +const uint16_t fn_actions[] PROGMEM = { #endif }; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif diff --git a/keyboard/ghpad/keymap_arrow.c b/keyboard/ghpad/keymap_arrow.c new file mode 100644 index 00000000..5e00ace3 --- /dev/null +++ b/keyboard/ghpad/keymap_arrow.c @@ -0,0 +1,60 @@ +#include "keymap_common.h" + +// Keypad with Arrow +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,---------------. + * |Num|/ |* |- | + * |---+---+---+---| + * |7 |8 |9 |+ | + * |---+---+---| | + * |4 |5 |6 | | + * |---+---+---+---| + * |1 |2 |3 |Ent| + * |---+---+---| | + * |0 |Up |. | | + * |---+---+---+---| + * |Lef|Dow|Rig|Fn0| + * `---------------' + */ + [0] = KEYMAP( + NLCK,PSLS,PAST,PMNS, \ + P7, P8, P9, PPLS, \ + P4, P5, P6, NO, \ + P1, P2, P3, PENT, \ + P0, UP, PDOT,NO, \ + LEFT,DOWN,RGHT,FN0), + /* Keymap 1: */ + [1] = KEYMAP( + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS), +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +const uint16_t fn_actions[] PROGMEM = { +#endif + [0] = ACTION_LAYER_MOMENTARY(1) +}; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif diff --git a/keyboard/ghpad/keymap_common.c b/keyboard/ghpad/keymap_common.c new file mode 100644 index 00000000..ae934eea --- /dev/null +++ b/keyboard/ghpad/keymap_common.c @@ -0,0 +1,49 @@ +/* +Copyright 2012,2013 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#include "keymap_common.h" + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ +#ifndef KEYMAP_EX_ENABLE + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(layer, key.row, key.col); +#endif +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + return (action_t) { +#ifndef KEYMAP_EX_ENABLE + .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) +#else + .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) +#endif + }; +} + +#ifdef KEYMAP_EX_ENABLE +const uint8_t* keymaps_pointer(void) { + return (const uint8_t*)keymaps; +} + +const uint16_t* fn_actions_pointer(void) { + return fn_actions; +} +#endif diff --git a/keyboard/ghpad/keymap_common.h b/keyboard/ghpad/keymap_common.h new file mode 100644 index 00000000..32f4019f --- /dev/null +++ b/keyboard/ghpad/keymap_common.h @@ -0,0 +1,54 @@ +/* +Copyright 2012,2013 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#ifndef KEYMAP_COMMON_H +#define KEYMAP_COMMON_H + +#include +#include +#include +#include "keycode.h" +#include "action.h" +#include "action_macro.h" +#include "report.h" +#include "host.h" +#include "print.h" +#include "debug.h" +#include "keymap.h" +#include "keymap_ex.h" + +extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +extern const uint16_t fn_actions[]; + +/* GHPad keymap definition macro + */ +#define KEYMAP( \ + K0A, K0B, K0C, K0D, \ + K1A, K1B, K1C, K1D, \ + K2A, K2B, K2C, K2D, \ + K3A, K3B, K3C, K3D, \ + K4A, K4B, K4C, K4D, \ + K5A, K5B, K5C, K5D \ +) { \ + { KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \ + { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \ + { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \ + { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \ + { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D }, \ + { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D } \ +} + +#endif From 0410064f502c92fad754bcb21adf4b31c6ef821d Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 13 Dec 2013 21:40:00 +0900 Subject: [PATCH 15/64] Update Makefile.pjrc --- keyboard/gh60/Makefile.pjrc | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/keyboard/gh60/Makefile.pjrc b/keyboard/gh60/Makefile.pjrc index 9655ff65..0ddce925 100644 --- a/keyboard/gh60/Makefile.pjrc +++ b/keyboard/gh60/Makefile.pjrc @@ -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) @@ -81,18 +82,31 @@ F_CPU = 16000000 # LUFA bootloader 4096 OPT_DEFS += -DBOOTLOADER_SIZE=4096 +# PCB Revision +ifdef REV + OPT_DEFS += -DGH60_REV_$(REV) +endif + +# Additional definitions from command line +ifdef DEFS + OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) +endif # Build Options # comment out to disable the options. # BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) -MOUSEKEY_ENABLE = yes # Mouse keys(+5000) -EXTRAKEY_ENABLE = yes # Audio control and System control(+600) -CONSOLE_ENABLE = yes # Console for debug -COMMAND_ENABLE = yes # Commands for debug and configuration -SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend -NKRO_ENABLE = yes # USB Nkey Rollover(+500) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +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 #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +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 + # Search Path @@ -102,15 +116,3 @@ VPATH += $(TOP_DIR) include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk - -plain: OPT_DEFS += -DKEYMAP_PLAIN -plain: all - -poker: OPT_DEFS += -DKEYMAP_POKER -poker: all - -poker_set: OPT_DEFS += -DKEYMAP_POKER_SET -poker_set: all - -poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT -poker_bit: all From 3c50f78dbe15af60393063588ab03410f86b2d8b Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 10 Jan 2014 09:14:11 +0900 Subject: [PATCH 16/64] Add some flexible define for keymap_ex --- common/keymap_ex.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/keymap_ex.h b/common/keymap_ex.h index 435547a0..e64bace6 100644 --- a/common/keymap_ex.h +++ b/common/keymap_ex.h @@ -24,8 +24,12 @@ along with this program. If not, see . #include #define EECONFIG_KEYMAP_EX 0x10 -#define FN_ACTIONS_COUNT 8 +#ifndef FN_ACTIONS_COUNT +#define FN_ACTIONS_COUNT 32 +#endif +#ifndef KEYMAPS_COUNT #define KEYMAPS_COUNT 8 +#endif typedef struct { uint16_t checksum; From ffaff2845a8c047fe9fb81de1f7d344c63937b27 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 10 Jan 2014 09:15:41 +0900 Subject: [PATCH 17/64] Enable NKRO by default --- keyboard/gh60/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 83363311..99b62f1f 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -131,7 +131,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 - not yet supported in LUFA #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_EX_ENABLE = yes # External keymap in eeprom From e35fdfc5c70299281105b231ea147ea2271997af Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 10 Jan 2014 09:17:28 +0900 Subject: [PATCH 18/64] Support backlight for GH60 revB --- keyboard/gh60/backlight.c | 11 ++++++++++- keyboard/gh60/config.h | 8 ++++++++ keyboard/gh60/matrix.c | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 2cf129c3..06af677c 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -52,5 +52,14 @@ void backlight_set(uint8_t level) } } #else -void backlight_set(uint8_t level) {} +void backlight_set(uint8_t level) +{ + if (level > 0) { + DDRF |= (1<. #define MATRIX_ROWS 5 #define MATRIX_COLS 14 +/* keymap in eeprom */ +#define FN_ACTIONS_COUNT 32 +#define KEYMAPS_COUNT 8 + /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST @@ -38,7 +42,11 @@ along with this program. If not, see . #define DEBOUNCE 5 /* number of backlight levels */ +#ifdef GH60_REV_CHN #define BACKLIGHT_LEVELS 3 +#else +#define BACKLIGHT_LEVELS 1 +#endif /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ #define LOCKING_SUPPORT_ENABLE diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index 9a65a236..ed3270f2 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c @@ -57,6 +57,10 @@ uint8_t matrix_cols(void) void matrix_init(void) { + // disable JTAG + MCUCR = (1< Date: Fri, 10 Jan 2014 09:18:52 +0900 Subject: [PATCH 19/64] Add a simple backlight support for ghpad --- keyboard/ghpad/backlight.c | 46 +++++++++++++++++++++++++++++++++++ keyboard/ghpad/config.h | 7 ++++++ keyboard/ghpad/keymap_arrow.c | 6 +++-- keyboard/ghpad/matrix.c | 4 +++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 keyboard/ghpad/backlight.c diff --git a/keyboard/ghpad/backlight.c b/keyboard/ghpad/backlight.c new file mode 100644 index 00000000..61282adb --- /dev/null +++ b/keyboard/ghpad/backlight.c @@ -0,0 +1,46 @@ +/* +Copyright 2013 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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include "backlight.h" + +/* Backlight pin configuration + * PF7 PF6 PF5 + */ +void backlight_set(uint8_t level) +{ + switch (level) { + case 0: + DDRF &= ~(1<. #define MATRIX_ROWS 6 #define MATRIX_COLS 4 +/* keymap in eeprom */ +#define FN_ACTIONS_COUNT 32 +#define KEYMAPS_COUNT 32 + /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST /* Set 0 if debouncing isn't needed */ #define DEBOUNCE 5 +/* number of backlight levels */ +#define BACKLIGHT_LEVELS 3 + /* number of backlight levels */ //#define BACKLIGHT_LEVELS 3 diff --git a/keyboard/ghpad/keymap_arrow.c b/keyboard/ghpad/keymap_arrow.c index 5e00ace3..0bf98ed6 100644 --- a/keyboard/ghpad/keymap_arrow.c +++ b/keyboard/ghpad/keymap_arrow.c @@ -35,7 +35,7 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { TRNS,TRNS,TRNS,TRNS, \ TRNS,TRNS,TRNS,TRNS, \ TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS), + FN1, TRNS,FN2, TRNS), }; /* @@ -46,7 +46,9 @@ const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn #else const uint16_t fn_actions[] PROGMEM = { #endif - [0] = ACTION_LAYER_MOMENTARY(1) + [0] = ACTION_LAYER_MOMENTARY(1), + [1] = ACTION_BACKLIGHT_DECREASE(), + [2] = ACTION_BACKLIGHT_INCREASE() }; #ifdef KEYMAP_EX_ENABLE diff --git a/keyboard/ghpad/matrix.c b/keyboard/ghpad/matrix.c index b259d253..32cf4b6a 100644 --- a/keyboard/ghpad/matrix.c +++ b/keyboard/ghpad/matrix.c @@ -57,6 +57,10 @@ uint8_t matrix_cols(void) void matrix_init(void) { + // disable JTAG + MCUCR = (1< Date: Sat, 11 Jan 2014 22:17:36 +0900 Subject: [PATCH 20/64] Fix for an issue about backlight on --- common/backlight.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/backlight.c b/common/backlight.c index f13d9dbc..a0b2ce50 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -81,6 +81,12 @@ void backlight_decrease(void) void backlight_toggle(void) { backlight_config.enable ^= 1; + if (backlight_config.enable) + { + if (backlight_config.level == 0) { + backlight_config.level = 1; + } + } eeconfig_write_backlight(backlight_config.raw); dprintf("backlight toggle: %u\n", backlight_config.enable); backlight_set(backlight_config.enable ? backlight_config.level : 0); From fd4959b8b68b63af7cb69d90e38a307f4e2bd87e Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Sat, 11 Jan 2014 22:23:49 +0900 Subject: [PATCH 21/64] Add support for GH60 rev.CNY --- keyboard/gh60/backlight.c | 2 +- keyboard/gh60/config.h | 9 ++++++++- keyboard/gh60/matrix.c | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 06af677c..3d8f6279 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/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 diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index 9e5d028c..6bb2e4ee 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -42,12 +42,19 @@ along with this program. If not, see . #define DEBOUNCE 5 /* number of backlight levels */ -#ifdef GH60_REV_CHN +#if defined(GH60_REV_CHN) +#define BACKLIGHT_LEVELS 3 +#elif defined(GH60_REV_CNY) #define BACKLIGHT_LEVELS 3 #else #define BACKLIGHT_LEVELS 1 #endif +#ifdef GH60_REV_CNY +#define LED_MATRIX_ROWS 6 +#define LED_MATRIX_COLS 14 +#endif + /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ #define LOCKING_SUPPORT_ENABLE diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index ed3270f2..e82fe196 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c @@ -141,7 +141,7 @@ uint8_t matrix_key_count(void) /* Column pin configuration * pin: F1 F0 E6 D7 D6 D4 C7 C6 B6 B5 B4 B3 B1 B0 (Rev.A) * pin: F1 F0 E6 D7 D6 D4 C7 C6 B7 B6 B5 B4 B3 B1 (Rev.B) - * pin: F1 F0 E6 D7 D6 D4 C7 C6 B7 B5 B4 B3 B1 B0 (Rev.CHN) + * pin: F1 F0 E6 D7 D6 D4 C7 C6 B7 B5 B4 B3 B1 B0 (Rev.CHN/CNY) */ static void init_cols(void) { @@ -154,7 +154,7 @@ static void init_cols(void) PORTD |= (1< Date: Sat, 11 Jan 2014 22:24:32 +0900 Subject: [PATCH 22/64] Add files for led matrix --- common/led_matrix.c | 20 ++++++++++++++++++++ common/led_matrix.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 common/led_matrix.c create mode 100644 common/led_matrix.h diff --git a/common/led_matrix.c b/common/led_matrix.c new file mode 100644 index 00000000..2a1e83d2 --- /dev/null +++ b/common/led_matrix.c @@ -0,0 +1,20 @@ +/* +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include "led_matrix.h" diff --git a/common/led_matrix.h b/common/led_matrix.h new file mode 100644 index 00000000..f683ff09 --- /dev/null +++ b/common/led_matrix.h @@ -0,0 +1,41 @@ +/* +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef LED_MATRIX_H +#define LED_MATRIX_H + +#include +#include + +typedef struct { + union { + int8_t delta; + struct { + bool direction:1; + } + } + uint8_t value; +} led_matrix_element_t; + +uint8_t led_matrix_rows(void); +uint8_t led_matrix_cols(void); +void led_matrix_init(void); +void led_matrix_enable(void); +void led_matrix_disable(void); +uint8_t led_matrix_scan(void); + +#endif From be407eb8d3d7102e0761e475f92b5dc3e19fb05a Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 13 Jan 2014 22:04:24 +0900 Subject: [PATCH 23/64] Some implementations of led matrix --- common/led_matrix.c | 29 +++++++++++++++++++++++++++++ common/led_matrix.h | 6 ++++++ keyboard/gh60/led_matrix.c | 17 +++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 keyboard/gh60/led_matrix.c diff --git a/common/led_matrix.c b/common/led_matrix.c index 2a1e83d2..77e52e48 100644 --- a/common/led_matrix.c +++ b/common/led_matrix.c @@ -18,3 +18,32 @@ along with this program. If not, see . #include #include #include "led_matrix.h" + +#define LED_MATRIX_TIMER_TOP F_CPU/(256*64)/LED_MATRIX_ROWS + +void led_matrix_init(void) +{ + /* Timer1 setup */ + /* CTC mode */ + TCCR1B |= (1<> 8) & 0xFF; + OCR1AL = LED_MATRIX_TIMER_TOP & 0xFF; + SREG = sreg; +} + +void led_matrix_enable(void) +{ + /* Enable Compare Match Interrupt */ + TIMSK1 |= _BV(OCIE1A); +} + +void led_matrix_disable(void) +{ + /* Disable Compare Match Interrupt */ + TIMSK1 &= ~_BV(OCIE1A); +} diff --git a/common/led_matrix.h b/common/led_matrix.h index f683ff09..eb242446 100644 --- a/common/led_matrix.h +++ b/common/led_matrix.h @@ -31,11 +31,17 @@ typedef struct { uint8_t value; } led_matrix_element_t; +#ifdef LED_MATRIX_ENABLE uint8_t led_matrix_rows(void); uint8_t led_matrix_cols(void); void led_matrix_init(void); void led_matrix_enable(void); void led_matrix_disable(void); uint8_t led_matrix_scan(void); +#else +#define led_matrix_rows() +#define led_matrix_cols() +#define led_matrix_init() +#endif #endif diff --git a/keyboard/gh60/led_matrix.c b/keyboard/gh60/led_matrix.c new file mode 100644 index 00000000..a3525cc3 --- /dev/null +++ b/keyboard/gh60/led_matrix.c @@ -0,0 +1,17 @@ +/* +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + From 2e30e38479deb911a4f7ff3c392a0ff39bccacac Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 14 Jan 2014 16:12:21 +0900 Subject: [PATCH 24/64] Some more implementation of led matrix --- common.mk | 5 +++++ common/keyboard.c | 5 +++++ common/led_matrix.c | 42 ++++++++++++++++++++++++++++++++++++++++++ common/led_matrix.h | 32 +++++++++++++++++++++++++------- 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/common.mk b/common.mk index c8809c0c..bef00a3c 100644 --- a/common.mk +++ b/common.mk @@ -69,6 +69,11 @@ ifdef KEYMAP_EX_ENABLE OPT_DEFS += -DKEYMAP_EX_ENABLE endif +ifdef LED_MATRIX_ENABLE + SRC += $(COMMON_DIR)/led_matrix.c + OPT_DEFS += -DLED_MATRIX_ENABLE +endif + # Version string OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null) diff --git a/common/keyboard.c b/common/keyboard.c index 48a67e4a..c5de65ef 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -62,6 +62,11 @@ void keyboard_init(void) { timer_init(); matrix_init(); + +#ifdef LED_MATRIX_ENABLE + led_matrix_init(); +#endif + #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif diff --git a/common/led_matrix.c b/common/led_matrix.c index 77e52e48..e5a4629f 100644 --- a/common/led_matrix.c +++ b/common/led_matrix.c @@ -17,12 +17,17 @@ along with this program. If not, see . #include #include +#include #include "led_matrix.h" #define LED_MATRIX_TIMER_TOP F_CPU/(256*64)/LED_MATRIX_ROWS +static led_matrix_element_t led_matrix[LED_MATRIX_ROWS][LED_MATRIX_COLS]; + void led_matrix_init(void) { + led_matrix_unselect_rows(); + led_matrix_write_cols(0); /* Timer1 setup */ /* CTC mode */ TCCR1B |= (1<. #include #include +#if (LED_MATRIX_COLS <= 8) +typedef uint8_t led_matrix_row_t; +#elif (LED_MATRIX_COLS <= 16) +typedef uint16_t led_matrix_row_t; +#elif (LED_MATRIX_COLS <= 32) +typedef uint32_t led_matrix_row_t; +#else +#error "LED_MATRIX_COLS: invalid value" +#endif + typedef struct { union { int8_t delta; struct { bool direction:1; - } - } + }; + }; uint8_t value; } led_matrix_element_t; #ifdef LED_MATRIX_ENABLE -uint8_t led_matrix_rows(void); -uint8_t led_matrix_cols(void); void led_matrix_init(void); void led_matrix_enable(void); void led_matrix_disable(void); -uint8_t led_matrix_scan(void); +void led_matrix_init_cols(void); +led_matrix_row_t led_matrix_make_cols(uint8_t row, uint8_t pwm); +void led_matrix_set_value(uint8_t row, uint8_t col, uint8_t value); +void led_matrix_set_delta(uint8_t row, uint8_t col, int8_t delta); +extern void led_matrix_write_cols(led_matrix_row_t cols); +extern void led_matrix_unselect_rows(void); +extern void led_matrix_select_row(uint8_t row); #else -#define led_matrix_rows() -#define led_matrix_cols() #define led_matrix_init() +#define led_matrix_enable() +#define led_matrix_disable() +#define led_matrix_init_cols() +#define led_matrix_write_cols() +#define led_matrix_unselect_rows() +#define led_matrix_select_row() #endif #endif From 91d22894b0ccf7657592bbda840f7ab1bfc0a6b4 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 14 Jan 2014 16:13:01 +0900 Subject: [PATCH 25/64] Impement led matrix for GH60 rev.CNY --- keyboard/gh60/Makefile | 3 +- keyboard/gh60/backlight.c | 22 ++++++++++- keyboard/gh60/config.h | 10 ++--- keyboard/gh60/led_matrix.c | 75 ++++++++++++++++++++++++++++++++++++++ keyboard/gh60/matrix.c | 3 ++ 5 files changed, 106 insertions(+), 7 deletions(-) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 99b62f1f..8da7908d 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -51,7 +51,8 @@ TARGET_DIR = . SRC = keymap_common.c \ matrix.c \ led.c \ - backlight.c + backlight.c \ + led_matrix.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 3d8f6279..25fbc833 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -20,7 +20,7 @@ along with this program. If not, see . #include #include "backlight.h" -#ifdef GH60_REV_CHN +#if defined(GH60_REV_CHN) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; @@ -51,6 +51,26 @@ void backlight_set(uint8_t level) OCR1B = 0; } } +#elif #defined(GH60_REV_CNY) +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + +void backlight_set(uint8_t level) +{ + if (level > 0) { + led_matrix_disable(); + for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < LED_MATRIX_COLS; col++) { + led_matrix_set_value(row, col, pgm_read_byte(&backlight_table[level])); + } + } + led_matrix_enable(); + } + else { + led_matrix_disable(); + } +} #else void backlight_set(uint8_t level) { diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index 6bb2e4ee..dd9d21ae 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -43,16 +43,16 @@ along with this program. If not, see . /* number of backlight levels */ #if defined(GH60_REV_CHN) -#define BACKLIGHT_LEVELS 3 +# define BACKLIGHT_LEVELS 3 #elif defined(GH60_REV_CNY) -#define BACKLIGHT_LEVELS 3 +# define BACKLIGHT_LEVELS 3 #else -#define BACKLIGHT_LEVELS 1 +# define BACKLIGHT_LEVELS 1 #endif #ifdef GH60_REV_CNY -#define LED_MATRIX_ROWS 6 -#define LED_MATRIX_COLS 14 +# define LED_MATRIX_ROWS 6 +# define LED_MATRIX_COLS 14 #endif /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ diff --git a/keyboard/gh60/led_matrix.c b/keyboard/gh60/led_matrix.c index a3525cc3..bcd94218 100644 --- a/keyboard/gh60/led_matrix.c +++ b/keyboard/gh60/led_matrix.c @@ -15,3 +15,78 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include +#include "led_matrix.h" + +#if defined(GH60_REV_CNY) + +/* LED Column pin configuration + * pin: F0 F1 E6 C7 C6 B7 D4 B0 B1 B5 B4 D7 D6 B3 (Rev.CNY) + */ +void led_matrix_write_cols(led_matrix_row_t cols) +{ + (cols & (1<<0)) ? (PORTF |= (1< Date: Mon, 10 Feb 2014 19:26:00 +0900 Subject: [PATCH 26/64] New branch for led_matrix --- keyboard/gh60/Makefile | 1 + keyboard/gh60/led_matrix.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 8da7908d..f535bd73 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -137,6 +137,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA 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 +LED_MATRIX_ENABLE = yes # Optimize size but this may cause error "relocation truncated to fit" diff --git a/keyboard/gh60/led_matrix.c b/keyboard/gh60/led_matrix.c index bcd94218..2d3e544f 100644 --- a/keyboard/gh60/led_matrix.c +++ b/keyboard/gh60/led_matrix.c @@ -47,10 +47,14 @@ void led_matrix_write_cols(led_matrix_row_t cols) */ void led_matrix_unselect_rows(void) { - // bit 76543210 + // unselect key matrix rows + //DDRD &= ~0b00101111; + //PORTD &= ~0b00101111; + + // bit 76543210 DDRB &= ~0b01000100; PORTB &= ~0b01000100; - // bit 76543210 + // bit 76543210 DDRF &= ~0b11110000; PORTF &= ~0b11110000; } From 5ca3bde10aa5d8057895475840800544599ea33f Mon Sep 17 00:00:00 2001 From: Ralf Schmitt Date: Tue, 18 Mar 2014 20:06:24 +0100 Subject: [PATCH 27/64] Support for Lightsaber keyboard --- keyboard/lightsaber/Makefile.lufa | 125 ++++++++++++ keyboard/lightsaber/Makefile.pjrc | 101 ++++++++++ keyboard/lightsaber/README.md | 110 +++++++++++ keyboard/lightsaber/config.h | 43 ++++ keyboard/lightsaber/keymap.c | 77 ++++++++ keyboard/lightsaber/keymap_winkey.h | 12 ++ keyboard/lightsaber/led.c | 24 +++ keyboard/lightsaber/matrix.c | 292 ++++++++++++++++++++++++++++ 8 files changed, 784 insertions(+) create mode 100644 keyboard/lightsaber/Makefile.lufa create mode 100644 keyboard/lightsaber/Makefile.pjrc create mode 100644 keyboard/lightsaber/README.md create mode 100644 keyboard/lightsaber/config.h create mode 100644 keyboard/lightsaber/keymap.c create mode 100644 keyboard/lightsaber/keymap_winkey.h create mode 100644 keyboard/lightsaber/led.c create mode 100644 keyboard/lightsaber/matrix.c diff --git a/keyboard/lightsaber/Makefile.lufa b/keyboard/lightsaber/Makefile.lufa new file mode 100644 index 00000000..6982b51f --- /dev/null +++ b/keyboard/lightsaber/Makefile.lufa @@ -0,0 +1,125 @@ +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = lightsaber_lufa + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + + +# List C source files here. (C dependencies are automatically generated.) +SRC += keymap.c \ + led.c \ + matrix.c + +CONFIG_H = config.h + + +# MCU name +MCU = atmega32u4 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 8000000 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + + +# Build Options +# comment out to disable the options. +# +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +#MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +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 +#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality + + +# Boot Section Size in bytes +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk + +winkey: OPT_DEFS += -DLAYOUT_WINKEY +winkey: all diff --git a/keyboard/lightsaber/Makefile.pjrc b/keyboard/lightsaber/Makefile.pjrc new file mode 100644 index 00000000..1c5a9710 --- /dev/null +++ b/keyboard/lightsaber/Makefile.pjrc @@ -0,0 +1,101 @@ +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = lightsaber_pjrc + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# keyboard dependent files +SRC = keymap.c \ + matrix.c \ + led.c \ + backlight.c + +CONFIG_H = config.h + + +# MCU name, you MUST set this to match the board you are using +# type "make clean" after changing this, so all files will be rebuilt +#MCU = at90usb162 # Teensy 1.0 +MCU = atmega32u4 # Teensy 2.0 +#MCU = at90usb646 # Teensy++ 1.0 +#MCU = at90usb1286 # Teensy++ 2.0 + + +# Processor frequency. +# Normally the first thing your program should do is set the clock prescaler, +# so your program will run at the correct speed. You should also set this +# variable to same clock speed. The _delay_ms() macro uses this, and many +# examples use this variable to calculate timings. Do not add a "UL" here. +F_CPU = 8000000 + + +# Build Options +# comment out to disable the options. +# +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +#MOUSEKEY_ENABLE = yes # Mouse keys(+5000) +EXTRAKEY_ENABLE = yes # Audio control and System control(+600) +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration +#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +#NKRO_ENABLE = yes # USB Nkey Rollover(+500) +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk + +winkey: OPT_DEFS += -DLAYOUT_WINKEY +winkey: all + +winkeyless: OPT_DEFS += -DLAYOUT_WINKEYLESS +winkeyless: all diff --git a/keyboard/lightsaber/README.md b/keyboard/lightsaber/README.md new file mode 100644 index 00000000..dc35870c --- /dev/null +++ b/keyboard/lightsaber/README.md @@ -0,0 +1,110 @@ +KMAC keyboard firmware +====================== +Korean custom keyboard designed by Byungho Kim and KBDMania community. + +*Note that this is not the official firmware* + +Supported models +---------------- +At the moment only the TKL models is supported. + + +Build +----- +Move to this directory then just run `make` like: + + $ make -f Makefile.[pjrc|lufa] [winkey|winkeyless] + +Use `Makefile.pjrc` if you want to use PJRC stack or use `Makefile.lufa` for LUFA stack. + + +Bootloader +--------- +The PCB is hardwired to run the bootloader if the key at the `Caps Lock` position is held down when connecting the keyboard. + +It is still possible to use Boot Magic and Command to access the bootloader though. + + +Keymap +------ +There are 2 different types of PCB. +They each have their own keymap file. + +To customize a keymap: + 1. Edit the file that corresponds to your PCB. + 2. Specify your layout when building. + +### 1. Winkey +This is the default keymap. + +See [keymap_winkey.h](keymap_winkey.h) for detail. + +#### 1.0. Winkey Default Layer + ,---. ,---------------. ,---------------. ,---------------. ,-----------. + |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| + `---' `---------------' `---------------' `---------------' `-----------' + ,-----------------------------------------------------------. ,-----------. + |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU| + |-----------------------------------------------------------| |-----------| + |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| + |-----------------------------------------------------------| '-----------' + |Fn0 | A| S| D| F| G| H| J| K| L| ;| '|Return | + |-----------------------------------------------------------| ,---. + |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | + |-----------------------------------------------------------| ,-----------. + |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig| + `-----------------------------------------------------------' `-----------' + +#### 1.1. Winkey Media Layer + ,---. ,---------------. ,---------------. ,---------------. ,-----------. + |Led| | | | | | | | | | | | | | | | | | |Slp| + `---' `---------------' `---------------' `---------------' `-----------' + ,-----------------------------------------------------------. ,-----------. + | | | | | | | | | | |Mut|V- |V+ | | | | | | + |-----------------------------------------------------------| |-----------| + | | | | | | | | | |Stp|Ply|Prv|Nxt|Media| | | | | + |-----------------------------------------------------------| '-----------' + | | | | | | | | | | | | | | + |-----------------------------------------------------------| ,---. + | | | |Clc| | | | | | | |Caps | | | + |-----------------------------------------------------------| ,-----------. + | | | | | | | | | | | | | + `-----------------------------------------------------------' `-----------' + + +### 2. Winkeyless +Layout with 1.5 unit modifiers. + +See [keymap_winkeyless.h](keymap_winkeyless.h) for detail. + +#### 2.0. Winkeyless Default Layer + ,---. ,---------------. ,---------------. ,---------------. ,-----------. + |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| + `---' `---------------' `---------------' `---------------' `-----------' + ,-----------------------------------------------------------. ,-----------. + |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU| + |-----------------------------------------------------------| |-----------| + |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| + |-----------------------------------------------------------| '-----------' + |Fn0 | A| S| D| F| G| H| J| K| L| ;| '|Return | + |-----------------------------------------------------------| ,---. + |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | + |-----------------------------------------------------------| ,-----------. + |Ctl |Gui|Alt | Space |Alt |Gui|Ctl | |Lef|Dow|Rig| + `-----------------------------------------------------------' `-----------' + +#### 2.1. Winkeyless Media Layer + ,---. ,---------------. ,---------------. ,---------------. ,-----------. + |Led| | | | | | | | | | | | | | | | | | |Slp| + `---' `---------------' `---------------' `---------------' `-----------' + ,-----------------------------------------------------------. ,-----------. + | | | | | | | | | | |Mut|V- |V+ | | | | | | + |-----------------------------------------------------------| |-----------| + | | | | | | | | | |Stp|Ply|Prv|Nxt|Media| | | | | + |-----------------------------------------------------------| '-----------' + | | | | | | | | | | | | | | + |-----------------------------------------------------------| ,---. + | | | |Clc| | | | | | | |Caps | | | + |-----------------------------------------------------------| ,-----------. + | | | | | | | | | | | | + `-----------------------------------------------------------' `-----------' diff --git a/keyboard/lightsaber/config.h b/keyboard/lightsaber/config.h new file mode 100644 index 00000000..b8de6adb --- /dev/null +++ b/keyboard/lightsaber/config.h @@ -0,0 +1,43 @@ +/* +Copyright 2013 Mathias Andersson + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6050 +#define DEVICE_VER 0x0104 +#define MANUFACTURER Duck +#define PRODUCT Lightsaber + +/* message strings */ +#define DESCRIPTION t.m.k. keyboard firmware for Lightsaber + +/* matrix size */ +#define MATRIX_ROWS 6 +#define MATRIX_COLS 18 + +/* Set 0 if need no debouncing */ +#define DEBOUNCE 5 + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +#endif diff --git a/keyboard/lightsaber/keymap.c b/keyboard/lightsaber/keymap.c new file mode 100644 index 00000000..398e51ec --- /dev/null +++ b/keyboard/lightsaber/keymap.c @@ -0,0 +1,77 @@ +/* +Copyright 2014 Ralf Schmitt + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * Keymap for Lightsaber controller + */ +#include +#include +#include +#include "keycode.h" +#include "action.h" +#include "action_macro.h" +#include "report.h" +#include "host.h" +#include "debug.h" +#include "keymap.h" + +// Convert physical keyboard layout to matrix array. +// This is a macro to define keymap easily in keyboard layout form. +#define KEYMAP( \ + K5A, K5B, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5O, K5P, K5Q, K5R, \ + K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4O, K4P, K4Q, K4R, \ + K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3O, K3P, K3Q, K3R, \ + K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2M, K2N, K2O, K2P, K2Q, K2R, \ + K1A, K1C, K1D, K1E, K1F, K1G, K1H, K1I, K1J, K1K, K1L, K1M, K1N, K1O, K1P, K1Q, K1R, \ + K0A, K0B, K0C, K0G, K0K, K0L, K0M, K0N, K0O, K0P, K0Q, K0R \ +) { \ +/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 */ \ +/* 5 */ { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D, KC_##K5E, KC_##K5F, KC_##K5G, KC_##K5H, KC_##K5I, KC_##K5J, KC_##K5K, KC_##K5L, KC_##K5M, KC_##K5N, KC_##K5O, KC_##K5P, KC_##K5Q, KC_##K5R}, \ +/* 4 */ { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F, KC_##K4G, KC_##K4H, KC_##K4I, KC_##K4J, KC_##K4K, KC_##K4L, KC_##K4M, KC_##K4N, KC_##K4O, KC_##K4P, KC_##K4Q, KC_##K4R}, \ +/* 3 */ { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F, KC_##K3G, KC_##K3H, KC_##K3I, KC_##K3J, KC_##K3K, KC_##K3L, KC_##K3M, KC_##K3N, KC_##K3O, KC_##K3P, KC_##K3Q, KC_##K3R}, \ +/* 2 */ { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F, KC_##K2G, KC_##K2H, KC_##K2I, KC_##K2J, KC_##K2K, KC_##K2L, KC_##K2M, KC_##K2N, KC_##K2O, KC_##K2P, KC_##K2Q, KC_##K2R}, \ +/* 1 */ { KC_##K1A, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F, KC_##K1G, KC_##K1H, KC_##K1I, KC_##K1J, KC_##K1K, KC_##K1L, KC_NO, KC_##K1M, KC_##K1N, KC_##K1O, KC_##K1P, KC_##K1Q, KC_##K1R}, \ +/* 0 */ { KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, KC_NO, KC_##K0G, KC_NO, KC_NO, KC_##K0K, KC_NO, KC_##K0L, KC_NO, KC_##K0M, KC_##K0N, KC_##K0O, KC_##K0P, KC_##K0Q, KC_##K0R} \ +} + +#include "keymap_winkey.h" + +#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) +#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + if (layer < KEYMAPS_SIZE) { + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); + } else { + // fall back to layer 0 + return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); + } +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + action_t action; + if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { + action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); + } else { + action.code = ACTION_NO; + } + return action; +} diff --git a/keyboard/lightsaber/keymap_winkey.h b/keyboard/lightsaber/keymap_winkey.h new file mode 100644 index 00000000..510fa7f7 --- /dev/null +++ b/keyboard/lightsaber/keymap_winkey.h @@ -0,0 +1,12 @@ +static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + KEYMAP(\ + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \ + GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, NUMLOCK,KP_SLASH,KP_ASTERISK,KP_MINUS, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, KP_7, KP_8, KP_9, KP_PLUS, \ + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, KP_4, KP_5, KP_6, NO, \ + LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, KP_1, KP_2, KP_3, KP_ENTER, \ + LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO) +}; + +static const uint16_t PROGMEM fn_actions[] = { +}; diff --git a/keyboard/lightsaber/led.c b/keyboard/lightsaber/led.c new file mode 100644 index 00000000..9c98f9db --- /dev/null +++ b/keyboard/lightsaber/led.c @@ -0,0 +1,24 @@ +/* +Copyright 2012 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include "stdint.h" +#include "led.h" + +void led_set(uint8_t usb_led) +{ +} diff --git a/keyboard/lightsaber/matrix.c b/keyboard/lightsaber/matrix.c new file mode 100644 index 00000000..e3eca84d --- /dev/null +++ b/keyboard/lightsaber/matrix.c @@ -0,0 +1,292 @@ +/* +Copyright 2014 Ralf Schmitt + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" + + +#ifndef DEBOUNCE +# define DEBOUNCE 0 +#endif +static uint8_t debouncing = DEBOUNCE; + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +static uint8_t read_rows(void); +static uint8_t read_fwkey(void); +static void init_rows(void); +static void unselect_cols(void); +static void select_col(uint8_t col); + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + unselect_cols(); + init_rows(); + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; + } +} + +uint8_t matrix_scan(void) +{ + for (uint8_t col = 0; col < MATRIX_COLS; col++) { // 0-17 + select_col(col); + _delay_us(3); // TODO: Determine the correct value needed here. + uint8_t rows = read_rows(); + // Use the otherwise unused col: 12 row: 3 for firmware. + if(col == 12) { + rows |= read_fwkey(); + } + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5 + bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1< Date: Wed, 19 Mar 2014 00:21:45 +0100 Subject: [PATCH 28/64] Updated Lightsaber read me --- keyboard/lightsaber/README.md | 92 ++--------------------------------- 1 file changed, 4 insertions(+), 88 deletions(-) diff --git a/keyboard/lightsaber/README.md b/keyboard/lightsaber/README.md index dc35870c..bd2b3fb5 100644 --- a/keyboard/lightsaber/README.md +++ b/keyboard/lightsaber/README.md @@ -1,12 +1,12 @@ -KMAC keyboard firmware +Lightsaber keyboard firmware ====================== -Korean custom keyboard designed by Byungho Kim and KBDMania community. +Korean custom keyboard designed by Duck. *Note that this is not the official firmware* Supported models ---------------- -At the moment only the TKL models is supported. +All pcb options are supported. Build @@ -20,91 +20,7 @@ Use `Makefile.pjrc` if you want to use PJRC stack or use `Makefile.lufa` for LUF Bootloader --------- -The PCB is hardwired to run the bootloader if the key at the `Caps Lock` position is held down when connecting the keyboard. +The PCB is hardwired to run the bootloader if the key at the `one above backspace` position is held down when connecting the keyboard. It is still possible to use Boot Magic and Command to access the bootloader though. - -Keymap ------- -There are 2 different types of PCB. -They each have their own keymap file. - -To customize a keymap: - 1. Edit the file that corresponds to your PCB. - 2. Specify your layout when building. - -### 1. Winkey -This is the default keymap. - -See [keymap_winkey.h](keymap_winkey.h) for detail. - -#### 1.0. Winkey Default Layer - ,---. ,---------------. ,---------------. ,---------------. ,-----------. - |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| - `---' `---------------' `---------------' `---------------' `-----------' - ,-----------------------------------------------------------. ,-----------. - |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU| - |-----------------------------------------------------------| |-----------| - |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| - |-----------------------------------------------------------| '-----------' - |Fn0 | A| S| D| F| G| H| J| K| L| ;| '|Return | - |-----------------------------------------------------------| ,---. - |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | - |-----------------------------------------------------------| ,-----------. - |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig| - `-----------------------------------------------------------' `-----------' - -#### 1.1. Winkey Media Layer - ,---. ,---------------. ,---------------. ,---------------. ,-----------. - |Led| | | | | | | | | | | | | | | | | | |Slp| - `---' `---------------' `---------------' `---------------' `-----------' - ,-----------------------------------------------------------. ,-----------. - | | | | | | | | | | |Mut|V- |V+ | | | | | | - |-----------------------------------------------------------| |-----------| - | | | | | | | | | |Stp|Ply|Prv|Nxt|Media| | | | | - |-----------------------------------------------------------| '-----------' - | | | | | | | | | | | | | | - |-----------------------------------------------------------| ,---. - | | | |Clc| | | | | | | |Caps | | | - |-----------------------------------------------------------| ,-----------. - | | | | | | | | | | | | | - `-----------------------------------------------------------' `-----------' - - -### 2. Winkeyless -Layout with 1.5 unit modifiers. - -See [keymap_winkeyless.h](keymap_winkeyless.h) for detail. - -#### 2.0. Winkeyless Default Layer - ,---. ,---------------. ,---------------. ,---------------. ,-----------. - |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| - `---' `---------------' `---------------' `---------------' `-----------' - ,-----------------------------------------------------------. ,-----------. - |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU| - |-----------------------------------------------------------| |-----------| - |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| - |-----------------------------------------------------------| '-----------' - |Fn0 | A| S| D| F| G| H| J| K| L| ;| '|Return | - |-----------------------------------------------------------| ,---. - |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | - |-----------------------------------------------------------| ,-----------. - |Ctl |Gui|Alt | Space |Alt |Gui|Ctl | |Lef|Dow|Rig| - `-----------------------------------------------------------' `-----------' - -#### 2.1. Winkeyless Media Layer - ,---. ,---------------. ,---------------. ,---------------. ,-----------. - |Led| | | | | | | | | | | | | | | | | | |Slp| - `---' `---------------' `---------------' `---------------' `-----------' - ,-----------------------------------------------------------. ,-----------. - | | | | | | | | | | |Mut|V- |V+ | | | | | | - |-----------------------------------------------------------| |-----------| - | | | | | | | | | |Stp|Ply|Prv|Nxt|Media| | | | | - |-----------------------------------------------------------| '-----------' - | | | | | | | | | | | | | | - |-----------------------------------------------------------| ,---. - | | | |Clc| | | | | | | |Caps | | | - |-----------------------------------------------------------| ,-----------. - | | | | | | | | | | | | - `-----------------------------------------------------------' `-----------' From 526d988a0caadc1a48bea862f605c9cee90c3dd3 Mon Sep 17 00:00:00 2001 From: Ralf Schmitt Date: Wed, 19 Mar 2014 23:58:08 +0100 Subject: [PATCH 29/64] Added basic led+backlight support --- keyboard/lightsaber/Makefile.lufa | 3 +- keyboard/lightsaber/backlight.c | 56 +++++++++++++++++++++++++++++ keyboard/lightsaber/config.h | 3 ++ keyboard/lightsaber/keymap_winkey.h | 3 +- keyboard/lightsaber/led.c | 32 ++++++++++++++++- 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 keyboard/lightsaber/backlight.c diff --git a/keyboard/lightsaber/Makefile.lufa b/keyboard/lightsaber/Makefile.lufa index 6982b51f..25816ac0 100644 --- a/keyboard/lightsaber/Makefile.lufa +++ b/keyboard/lightsaber/Makefile.lufa @@ -51,6 +51,7 @@ TARGET_DIR = . # List C source files here. (C dependencies are automatically generated.) SRC += keymap.c \ led.c \ + backlight.c \ matrix.c CONFIG_H = config.h @@ -103,7 +104,7 @@ 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 -#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality # Boot Section Size in bytes diff --git a/keyboard/lightsaber/backlight.c b/keyboard/lightsaber/backlight.c new file mode 100644 index 00000000..b2820080 --- /dev/null +++ b/keyboard/lightsaber/backlight.c @@ -0,0 +1,56 @@ +/* +Copyright 2014 Ralf Schmitt + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include "backlight.h" + +/* Backlight pin configuration + * + * Alphas PB1 (high) + * Numeric PB2 (high) + * Mod+Num PB3 (high) + * Backside PD6 (high) + * TopRight PD7 (low) + * F-Row PE6 (high) + * + */ +void backlight_set(uint8_t level) +{ + // Set as output. + DDRB |= (1<<1) | (1<<2) | (1<<3); + DDRD |= (1<<6) | (1<<7); + DDRE |= (1<<6); + + if(level & (1<<0)) + { + PORTB &= ~(1<<1); + PORTB &= ~(1<<2); + PORTB &= ~(1<<3); + PORTD &= ~(1<<6); + PORTD |= (1<<7); + PORTE &= ~(1<<6); + } + else + { + PORTB |= (1<<1); + PORTB |= (1<<2); + PORTB |= (1<<3); + PORTD |= (1<<6); + PORTD &= ~(1<<7); + PORTE |= (1<<6); + } +} diff --git a/keyboard/lightsaber/config.h b/keyboard/lightsaber/config.h index b8de6adb..d971d038 100644 --- a/keyboard/lightsaber/config.h +++ b/keyboard/lightsaber/config.h @@ -32,6 +32,9 @@ along with this program. If not, see . #define MATRIX_ROWS 6 #define MATRIX_COLS 18 +/* number of backlight levels */ +#define BACKLIGHT_LEVELS 1 + /* Set 0 if need no debouncing */ #define DEBOUNCE 5 diff --git a/keyboard/lightsaber/keymap_winkey.h b/keyboard/lightsaber/keymap_winkey.h index 510fa7f7..9d558ae7 100644 --- a/keyboard/lightsaber/keymap_winkey.h +++ b/keyboard/lightsaber/keymap_winkey.h @@ -3,10 +3,11 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \ GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, NUMLOCK,KP_SLASH,KP_ASTERISK,KP_MINUS, \ TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, KP_7, KP_8, KP_9, KP_PLUS, \ - CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, KP_4, KP_5, KP_6, NO, \ + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,FN0, ENT, KP_4, KP_5, KP_6, NO, \ LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, KP_1, KP_2, KP_3, KP_ENTER, \ LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO) }; static const uint16_t PROGMEM fn_actions[] = { + [0] = ACTION_BACKLIGHT_STEP() }; diff --git a/keyboard/lightsaber/led.c b/keyboard/lightsaber/led.c index 9c98f9db..c3f85427 100644 --- a/keyboard/lightsaber/led.c +++ b/keyboard/lightsaber/led.c @@ -1,5 +1,5 @@ /* -Copyright 2012 Jun Wako +Copyright 2014 Ralf Schmitt 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 @@ -19,6 +19,36 @@ along with this program. If not, see . #include "stdint.h" #include "led.h" +/* LED pin configuration + * + * Caps PB0 (low) + * NumLock PB4 (low) + * + */ void led_set(uint8_t usb_led) { + // Set as output. + DDRB |= (1<<0) | (1<<4); + + if (usb_led & (1< Date: Sat, 22 Mar 2014 12:41:45 +0100 Subject: [PATCH 30/64] Lightsaber clean ups --- README.md | 1 + keyboard/lightsaber/Makefile.lufa | 6 +++--- keyboard/lightsaber/Makefile.pjrc | 11 ++--------- keyboard/lightsaber/README.md | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a561b38e..6596dc33 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ You can find some keyboard specific projects under `converter` and `keyboard` di * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) * [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] * [KMAC](keyboard/kmac/) - Korean custom keyboard +* [Lightsaber](keyboard/lightsaber/) - Korean custom keyboard [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 diff --git a/keyboard/lightsaber/Makefile.lufa b/keyboard/lightsaber/Makefile.lufa index 25816ac0..b430efd2 100644 --- a/keyboard/lightsaber/Makefile.lufa +++ b/keyboard/lightsaber/Makefile.lufa @@ -49,10 +49,10 @@ TARGET_DIR = . # List C source files here. (C dependencies are automatically generated.) -SRC += keymap.c \ +SRC = keymap.c \ + matrix.c \ led.c \ - backlight.c \ - matrix.c + backlight.c CONFIG_H = config.h diff --git a/keyboard/lightsaber/Makefile.pjrc b/keyboard/lightsaber/Makefile.pjrc index 1c5a9710..58735a7e 100644 --- a/keyboard/lightsaber/Makefile.pjrc +++ b/keyboard/lightsaber/Makefile.pjrc @@ -56,12 +56,8 @@ SRC = keymap.c \ CONFIG_H = config.h -# MCU name, you MUST set this to match the board you are using -# type "make clean" after changing this, so all files will be rebuilt -#MCU = at90usb162 # Teensy 1.0 -MCU = atmega32u4 # Teensy 2.0 -#MCU = at90usb646 # Teensy++ 1.0 -#MCU = at90usb1286 # Teensy++ 2.0 +# MCU name +MCU = atmega32u4 # Processor frequency. @@ -96,6 +92,3 @@ include $(TOP_DIR)/rules.mk winkey: OPT_DEFS += -DLAYOUT_WINKEY winkey: all - -winkeyless: OPT_DEFS += -DLAYOUT_WINKEYLESS -winkeyless: all diff --git a/keyboard/lightsaber/README.md b/keyboard/lightsaber/README.md index bd2b3fb5..9dcd6930 100644 --- a/keyboard/lightsaber/README.md +++ b/keyboard/lightsaber/README.md @@ -13,7 +13,7 @@ Build ----- Move to this directory then just run `make` like: - $ make -f Makefile.[pjrc|lufa] [winkey|winkeyless] + $ make -f Makefile.[pjrc|lufa] Use `Makefile.pjrc` if you want to use PJRC stack or use `Makefile.lufa` for LUFA stack. From 1482fe92a0c5af6f0a84396a3f9fee73d59bb48f Mon Sep 17 00:00:00 2001 From: Ralf Schmitt Date: Sat, 22 Mar 2014 13:13:37 +0100 Subject: [PATCH 31/64] Added Lightsaber FN-layer --- keyboard/lightsaber/keymap_winkey.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/keyboard/lightsaber/keymap_winkey.h b/keyboard/lightsaber/keymap_winkey.h index 9d558ae7..59ffd4a8 100644 --- a/keyboard/lightsaber/keymap_winkey.h +++ b/keyboard/lightsaber/keymap_winkey.h @@ -1,13 +1,21 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KEYMAP(\ - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \ - GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, NUMLOCK,KP_SLASH,KP_ASTERISK,KP_MINUS, \ - TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, KP_7, KP_8, KP_9, KP_PLUS, \ - CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,FN0, ENT, KP_4, KP_5, KP_6, NO, \ - LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, KP_1, KP_2, KP_3, KP_ENTER, \ - LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO) + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \ + GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, NUMLOCK,KP_SLASH,KP_ASTERISK,KP_MINUS, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, KP_7, KP_8, KP_9, KP_PLUS, \ + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,FN0, ENT, KP_4, KP_5, KP_6, NO, \ + LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, KP_1, KP_2, KP_3, KP_ENTER, \ + LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO), \ + KEYMAP(\ + CALC,MYCM,WSCH,WHOM,MAIL,MUTE,VOLD,VOLU,MSEL,MSTP,MPLY,MPRV,MNXT,TRNS, TRNS, WAKE, PWR, SLEP, \ + TRNS,TRNS,TRNS,TRNS,END ,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ + TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ + TRNS,TRNS,TRNS,TRNS,PGDN,TRNS,LEFT,DOWN,UP ,RGHT,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ + TRNS, TRNS,TRNS,TRNS,TRNS,PGUP,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ + TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS) }; static const uint16_t PROGMEM fn_actions[] = { - [0] = ACTION_BACKLIGHT_STEP() + [0] = ACTION_LAYER_MOMENTARY(1), + [1] = ACTION_BACKLIGHT_STEP() }; From 13fbab9d8b2015f4b81316bbdfba0705d459a480 Mon Sep 17 00:00:00 2001 From: Johan Isacsson Date: Thu, 27 Mar 2014 23:59:25 +0100 Subject: [PATCH 32/64] Show correct function name for default layer set --- doc/keymap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/keymap.md b/doc/keymap.md index 7ef7430c..3d78fc9c 100644 --- a/doc/keymap.md +++ b/doc/keymap.md @@ -269,7 +269,7 @@ Default Layer is a layer which always is valid and referred to when actions is n This sets Default Layer to given parameter `layer` and activate it. - ACTION_DEFAULT_LAYER(layer) + ACTION_DEFAULT_LAYER_SET(layer) #### 2.2.2 Momentary From 5bc8b5dcb6a4e03a1ad7bceba2c22bb9f6eb81fb Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 4 Apr 2014 12:22:22 +0900 Subject: [PATCH 33/64] 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 34/64] 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 35/64] 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 36/64] 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 37/64] 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: Tue, 8 Apr 2014 21:02:46 +0200 Subject: [PATCH 38/64] New macro: ACTION_BACKLIGHT_LEVEL(level) To have full control of the backlight level. --- common/action.c | 5 ++- common/action_code.h | 18 ++++++----- common/backlight.c | 8 +++++ common/backlight.h | 7 ++--- doc/keymap.md | 4 +++ keyboard/lightsaber/backlight.c | 48 +++++++++++++++++++++++------ keyboard/lightsaber/backlight.h | 9 ++++++ keyboard/lightsaber/keymap_winkey.h | 14 +++++++-- 8 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 keyboard/lightsaber/backlight.h diff --git a/common/action.c b/common/action.c index e6938f5a..fddb97c5 100644 --- a/common/action.c +++ b/common/action.c @@ -294,7 +294,7 @@ void process_action(keyrecord_t *record) #ifdef BACKLIGHT_ENABLE case ACT_BACKLIGHT: if (!event.pressed) { - switch (action.backlight.id) { + switch (action.backlight.opt) { case BACKLIGHT_INCREASE: backlight_increase(); break; @@ -307,6 +307,9 @@ void process_action(keyrecord_t *record) case BACKLIGHT_STEP: backlight_step(); break; + case BACKLIGHT_LEVEL: + backlight_level(action.backlight.level); + break; } } break; diff --git a/common/action_code.h b/common/action_code.h index 8df86b11..50112d4d 100644 --- a/common/action_code.h +++ b/common/action_code.h @@ -87,7 +87,7 @@ along with this program. If not, see . * 1100|1111| id(8) Macro record? * * ACT_BACKLIGHT(1101): - * 1101|xxxx| id(8) Backlight commands + * 1101|opt |level(8) Backlight commands * * ACT_COMMAND(1110): * 1110|opt | id(8) Built-in Command exec @@ -163,7 +163,9 @@ typedef union { uint8_t kind :4; } usage; struct action_backlight { - uint8_t id :8; + uint8_t level :8; + uint8_t opt :4; + uint8_t kind :4; } backlight; struct action_command { uint8_t id :8; @@ -282,21 +284,23 @@ enum layer_pram_tap_op { /* * Extensions */ -enum backlight_id { +enum backlight_opt { BACKLIGHT_INCREASE = 0, BACKLIGHT_DECREASE = 1, BACKLIGHT_TOGGLE = 2, BACKLIGHT_STEP = 3, + BACKLIGHT_LEVEL = 4, }; /* Macro */ #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) /* Backlight */ -#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE) -#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE) -#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE) -#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP) +#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8) +#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8) +#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8) +#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) +#define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | level) /* Command */ #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) /* Function */ diff --git a/common/backlight.c b/common/backlight.c index 00dc04a0..558ad9b0 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -75,3 +75,11 @@ void backlight_step(void) dprintf("backlight step: %u\n", backlight_config.level); backlight_set(backlight_config.level); } + +void backlight_level(uint8_t level) +{ + backlight_config.level ^= level; + backlight_config.enable = !!backlight_config.level; + eeconfig_write_backlight(backlight_config.raw); + backlight_set(backlight_config.level); +} diff --git a/common/backlight.h b/common/backlight.h index 685c422a..525ec8bb 100644 --- a/common/backlight.h +++ b/common/backlight.h @@ -24,18 +24,17 @@ along with this program. If not, see . typedef union { uint8_t raw; struct { - bool enable:1; - uint8_t level:7; + bool enable :1; + uint8_t level :7; }; } backlight_config_t; void backlight_init(void); - void backlight_increase(void); void backlight_decrease(void); void backlight_toggle(void); void backlight_step(void); - void backlight_set(uint8_t level); +void backlight_level(uint8_t level); #endif diff --git a/doc/keymap.md b/doc/keymap.md index 3d78fc9c..11feeac2 100644 --- a/doc/keymap.md +++ b/doc/keymap.md @@ -444,6 +444,10 @@ Step through backlight levels. ACTION_BACKLIGHT_STEP() +Turn a specific backlight level on or off. + + ACTION_BACKLIGHT_LEVEL(1) + #### 2.5.2 Turn on / off backlight Turn the backlight on and off without changing level. diff --git a/keyboard/lightsaber/backlight.c b/keyboard/lightsaber/backlight.c index b2820080..59b8b4a6 100644 --- a/keyboard/lightsaber/backlight.c +++ b/keyboard/lightsaber/backlight.c @@ -26,8 +26,8 @@ along with this program. If not, see . * Backside PD6 (high) * TopRight PD7 (low) * F-Row PE6 (high) - * */ + void backlight_set(uint8_t level) { // Set as output. @@ -35,22 +35,52 @@ void backlight_set(uint8_t level) DDRD |= (1<<6) | (1<<7); DDRE |= (1<<6); - if(level & (1<<0)) + if (level & BACKLIGHT_ALPHA) { - PORTB &= ~(1<<1); - PORTB &= ~(1<<2); - PORTB &= ~(1<<3); - PORTD &= ~(1<<6); - PORTD |= (1<<7); - PORTE &= ~(1<<6); + PORTB |= (1<<1); } else { - PORTB |= (1<<1); + PORTB &= ~(1<<1); + } + if (level & BACKLIGHT_NUMERIC) + { PORTB |= (1<<2); + } + else + { + PORTB &= ~(1<<2); + } + if (level & BACKLIGHT_MODNUM) + { PORTB |= (1<<3); + } + else + { + PORTB &= ~(1<<3); + } + if (level & BACKLIGHT_BACKSIDE) + { PORTD |= (1<<6); + } + else + { + PORTD &= ~(1<<6); + } + if (level & BACKLIGHT_TOPRIGHT) + { PORTD &= ~(1<<7); + } + else + { + PORTD |= (1<<7); + } + if (level & BACKLIGHT_FROW) + { PORTE |= (1<<6); } + else + { + PORTE &= ~(1<<6); + } } diff --git a/keyboard/lightsaber/backlight.h b/keyboard/lightsaber/backlight.h new file mode 100644 index 00000000..6dc7967a --- /dev/null +++ b/keyboard/lightsaber/backlight.h @@ -0,0 +1,9 @@ + +enum backlight_level { + BACKLIGHT_ALPHA = 0b0000001, + BACKLIGHT_NUMERIC = 0b0000010, + BACKLIGHT_MODNUM = 0b0000100, + BACKLIGHT_BACKSIDE = 0b0001000, + BACKLIGHT_TOPRIGHT = 0b0010000, + BACKLIGHT_FROW = 0b0100000, +}; diff --git a/keyboard/lightsaber/keymap_winkey.h b/keyboard/lightsaber/keymap_winkey.h index 59ffd4a8..3e836708 100644 --- a/keyboard/lightsaber/keymap_winkey.h +++ b/keyboard/lightsaber/keymap_winkey.h @@ -1,3 +1,5 @@ +#include "backlight.h" + static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KEYMAP(\ ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \ @@ -8,14 +10,20 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO), \ KEYMAP(\ CALC,MYCM,WSCH,WHOM,MAIL,MUTE,VOLD,VOLU,MSEL,MSTP,MPLY,MPRV,MNXT,TRNS, TRNS, WAKE, PWR, SLEP, \ - TRNS,TRNS,TRNS,TRNS,END ,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ + FN1, FN2, FN3, FN4, FN5, FN6, FN7, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ TRNS,TRNS,TRNS,TRNS,PGDN,TRNS,LEFT,DOWN,UP ,RGHT,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ TRNS, TRNS,TRNS,TRNS,TRNS,PGUP,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \ - TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS) + TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS) }; static const uint16_t PROGMEM fn_actions[] = { [0] = ACTION_LAYER_MOMENTARY(1), - [1] = ACTION_BACKLIGHT_STEP() + [1] = ACTION_BACKLIGHT_TOGGLE(), + [2] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_ALPHA), + [3] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_MODNUM), + [4] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_NUMERIC), + [5] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FROW), + [6] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_BACKSIDE), + [7] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_TOPRIGHT) }; From ab3349724efe7f71d42e5beb4d458f77a5673389 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 9 Apr 2014 17:20:31 +0900 Subject: [PATCH 39/64] 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 40/64] 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 41/64] 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 From f56f9030f604ea4fd7397952249a2e315d5daacd Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 11 Apr 2014 17:29:57 +0900 Subject: [PATCH 42/64] Add macro for compiling with led matrix disabled --- keyboard/gh60/Makefile | 2 +- keyboard/gh60/backlight.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index d8374676..5bdd7e46 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -138,7 +138,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA 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 -LED_MATRIX_ENABLE = yes +#LED_MATRIX_ENABLE = yes # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 91b38c11..bc524f6d 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -51,13 +51,14 @@ void backlight_set(uint8_t level) OCR1B = 0; } } -#elif #defined(GH60_REV_CNY) +#elif defined(GH60_REV_CNY) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; void backlight_set(uint8_t level) { +#ifdef LED_MATRIX_ENABLE if (level > 0) { led_matrix_disable(); for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) { @@ -70,6 +71,7 @@ void backlight_set(uint8_t level) else { led_matrix_disable(); } +#endif } #else static const uint8_t backlight_table[] PROGMEM = { From 91b149f785b5554092e90d238012f161f20a0cff Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 15 Apr 2014 16:28:48 +0900 Subject: [PATCH 43/64] New branch for breathing led feature --- common.mk | 5 ++ common/backlight.c | 36 +++++++++++-- common/backlight.h | 3 ++ common/breathing_led.c | 106 ++++++++++++++++++++++++++++++++++++ common/breathing_led.h | 39 ++++++++++++++ common/eeconfig.c | 8 +++ common/eeconfig.h | 6 +++ keyboard/gh60/Makefile | 2 +- keyboard/gh60/backlight.c | 110 ++++++++++++++++---------------------- keyboard/gh60/config.h | 1 + 10 files changed, 246 insertions(+), 70 deletions(-) create mode 100644 common/breathing_led.c create mode 100644 common/breathing_led.h diff --git a/common.mk b/common.mk index bef00a3c..09561cba 100644 --- a/common.mk +++ b/common.mk @@ -54,6 +54,11 @@ ifdef SLEEP_LED_ENABLE OPT_DEFS += -DNO_SUSPEND_POWER_DOWN endif +ifdef BREATHING_LED_ENABLE + SRC += $(COMMON_DIR)/breathing_led.c + OPT_DEFS += -DBREATHING_LED_ENABLE +endif + ifdef BACKLIGHT_ENABLE SRC += $(COMMON_DIR)/backlight.c OPT_DEFS += -DBACKLIGHT_ENABLE diff --git a/common/backlight.c b/common/backlight.c index a0b2ce50..ee8169c6 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -16,6 +16,7 @@ along with this program. If not, see . */ #include "backlight.h" +#include "breathing_led.h" #include "eeconfig.h" #include "debug.h" @@ -33,7 +34,7 @@ void backlight_init(void) void backlight_increase(void) { -#ifdef BACKLIGHT_CUSTOM +#if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE) if (backlight_config.enable) { if (backlight_config.level < BACKLIGHT_LEVELS) { backlight_config.level++; @@ -42,6 +43,9 @@ void backlight_increase(void) dprintf("backlight custom increase: %u\n", backlight_config.level); backlight_set(backlight_config.level); } +#ifdef BREATHING_LED_ENABLE + breathing_led_increase(); +#endif #else if(backlight_config.level < BACKLIGHT_LEVELS) { @@ -56,7 +60,7 @@ void backlight_increase(void) void backlight_decrease(void) { -#ifdef BACKLIGHT_CUSTOM +#if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE) if (backlight_config.enable) { if(backlight_config.level > 1) { @@ -66,6 +70,9 @@ void backlight_decrease(void) dprintf("backlight custom decrease: %u\n", backlight_config.level); backlight_set(backlight_config.level); } +#ifdef BREATHING_LED_ENABLE + breathing_led_decrease(); +#endif #else if(backlight_config.level > 0) { @@ -80,16 +87,37 @@ void backlight_decrease(void) void backlight_toggle(void) { +#ifdef BREATHING_LED_ENABLE + if (breathing_led_is_enabled()) { + breathing_led_disable(); + backlight_disable(); + return; + } +#endif backlight_config.enable ^= 1; - if (backlight_config.enable) - { + if (backlight_config.enable) { +#if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE) + backlight_enable(); +#endif if (backlight_config.level == 0) { backlight_config.level = 1; } } + else { +#ifndef BREATHING_LED_ENABLE +#ifdef BACKLIGHT_CUSTOM + backlight_disable(); +#endif +#endif + } eeconfig_write_backlight(backlight_config.raw); dprintf("backlight toggle: %u\n", backlight_config.enable); backlight_set(backlight_config.enable ? backlight_config.level : 0); +#ifdef BREATHING_LED_ENABLE + if (!backlight_config.enable) { + breathing_led_enable(); + } +#endif } void backlight_step(void) diff --git a/common/backlight.h b/common/backlight.h index 685c422a..a33c727a 100644 --- a/common/backlight.h +++ b/common/backlight.h @@ -36,6 +36,9 @@ void backlight_decrease(void); void backlight_toggle(void); void backlight_step(void); +void backlight_enable(void); +void backlight_disable(void); void backlight_set(uint8_t level); +void backlight_set_raw(uint8_t raw); #endif diff --git a/common/breathing_led.c b/common/breathing_led.c new file mode 100644 index 00000000..d71bf5b8 --- /dev/null +++ b/common/breathing_led.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include "led.h" +#include "breathing_led.h" +#include "backlight.h" +#include "debug.h" + +#define BREATHING_LED_TIMER_TOP F_CPU/64 + +breathing_led_config_t breathing_led_config; + +void breathing_led_init(void) +{ + /* Timer3 setup */ + /* CTC mode */ + TCCR3B |= _BV(WGM12); + /* Clock selelct: clk/1 */ + TCCR3B |= _BV(CS10); + /* Set TOP value */ + uint8_t sreg = SREG; + cli(); + OCR3AH = (BREATHING_LED_TIMER_TOP>>8)&0xff; + OCR3AL = BREATHING_LED_TIMER_TOP&0xff; + SREG = sreg; +} + +bool breathing_led_is_enabled(void) +{ + return breathing_led_config.enable; +} + +void breathing_led_enable(void) +{ + /* Enable Compare Match Interrupt */ + TIMSK3 |= _BV(OCIE3A); + breathing_led_config.enable = true; + dprintf("breathing led on: %u\n", breathing_led_config.enable); + eeconfig_write_breathing_led(breathing_led_config.raw); +} + +void breathing_led_disable(void) +{ + /* Disable Compare Match Interrupt */ + TIMSK3 &= ~_BV(OCIE3A); + breathing_led_config.enable = false; + dprintf("breathing led off: %u\n", breathing_led_config.enable); + eeconfig_write_breathing_led(breathing_led_config.raw); +} + +void breathing_led_toggle(void) +{ + /* Disable Compare Match Interrupt */ + TIMSK3 ^= _BV(OCIE3A); + breathing_led_config.enable ^= 1; + dprintf("breathing led toggle: %u\n", breathing_led_config.enable); + eeconfig_write_breathing_led(breathing_led_config.raw); +} + +void breathing_led_increase(void) +{ + if (breathing_led_config.enable) { + if (breathing_led_config.level < BREATHING_LED_LEVELS) { + breathing_led_config.level++; + eeconfig_write_breathing_led(breathing_led_config.raw); + } + dprintf("breathing led speed increase: %u\n", breathing_led_config.level); + } +} + +void breathing_led_decrease(void) +{ + if (breathing_led_config.enable) { + if (breathing_led_config.level > 0) + { + breathing_led_config.level--; + eeconfig_write_breathing_led(breathing_led_config.raw); + } + dprintf("breathing led speed decrease: %u\n", breathing_led_config.level); + } +} + +/* Breathing LED brighness(PWM On period) table + * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle + * + * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 + * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } + */ +static const uint8_t breathing_table[64] PROGMEM = { +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, +15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, +255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, +15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +ISR(TIMER3_COMPA_vect) +{ + uint8_t index = 0; + uint8_t step = 0; + step++; + if (step >= BREATHING_LED_LEVELS - breathing_led_config.level) { + step = 0; + index++; + backlight_set_raw(pgm_read_byte(&breathing_table[index])); + } +} diff --git a/common/breathing_led.h b/common/breathing_led.h new file mode 100644 index 00000000..fb31668f --- /dev/null +++ b/common/breathing_led.h @@ -0,0 +1,39 @@ +#ifndef BREATHING_LED_H +#define BREATHING_LED_H + + +#ifdef BREATHING_LED_ENABLE + +#include +#include + +#ifndef BREATHING_LED_LEVEL +#define BREATHING_LED_LEVEL 1 +#endif + +typedef union { + uint8_t raw; + struct { + bool enable:1; + uint8_t level:7; + }; +} breathing_led_config_t; + +void breathing_led_init(void); +bool breathing_led_is_enabled(void); +void breathing_led_enable(void); +void breathing_led_disable(void); +void breathing_led_toggle(void); +void breathing_led_increase(void); +void breathing_led_decrease(void); + +#else + +#define breathing_led_init() +#define breathing_led_enable() +#define breathing_led_disable() +#define breathing_led_toggle() + +#endif + +#endif diff --git a/common/eeconfig.c b/common/eeconfig.c index 5aadf1c5..ab9bae3c 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -14,6 +14,9 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif +#ifdef BREATHING_LED_ENABLE + eeprom_write_byte(EECONFIG_BREATHING_LED, 0); +#endif #ifdef KEYMAP_EX_ENABLE keymap_ex_init(); #endif @@ -50,3 +53,8 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } #endif + +#ifdef BREATHING_LED_ENABLE +uint8_t eeconfig_read_breathing_led(void) { return eeprom_read_byte(EECONFIG_BREATHING_LED); } +void eeconfig_write_breathing_led(uint8_t val) { eeprom_write_byte(EECONFIG_BREATHING_LED, val); } +#endif diff --git a/common/eeconfig.h b/common/eeconfig.h index e1b5ae28..36c18143 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h @@ -31,6 +31,7 @@ along with this program. If not, see . #define EECONFIG_KEYMAP (uint8_t *)4 #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 #define EECONFIG_BACKLIGHT (uint8_t *)6 +#define EECONFIG_BREATHING_LED (uint8_t *)7 /* debug bit */ @@ -71,4 +72,9 @@ uint8_t eeconfig_read_backlight(void); void eeconfig_write_backlight(uint8_t val); #endif +#ifdef BREATHING_LED_ENABLE +uint8_t eeconfig_read_breathing_led(void); +void eeconfig_write_breathing_led(uint8_t val); +#endif + #endif diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 5bdd7e46..56da7779 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -138,7 +138,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA 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 -#LED_MATRIX_ENABLE = yes +BREATHING_LED_ENABLE = yes # Enable breathing backlight # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index bc524f6d..eabb1c34 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -20,7 +20,6 @@ along with this program. If not, see . #include #include "backlight.h" -#if defined(GH60_REV_CHN) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; @@ -28,81 +27,62 @@ static const uint8_t backlight_table[] PROGMEM = { /* Backlight pin configuration * PWM: PB7 */ -void backlight_set(uint8_t level) +void backlight_enable(void) { - if (level > 0) { - // Turn on PWM - cli(); - DDRB |= (1< 0) { - led_matrix_disable(); - for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) { - for (uint8_t col = 0; col < LED_MATRIX_COLS; col++) { - led_matrix_set_value(row, col, pgm_read_byte(&backlight_table[level])); - } - } - led_matrix_enable(); - } - else { - led_matrix_disable(); - } +#if defined(GH60_REV_CHN) + // Turn on PWM + cli(); + DDRB |= (1< 0) { - DDRF |= (1<. /* number of backlight levels */ #define BACKLIGHT_LEVELS 3 +#define BREATHING_LED_LEVELS 4 #ifdef GH60_REV_CNY # define LED_MATRIX_ROWS 6 From 3c8412b1e552d6b6a44f223444f9a15dcf8310fd Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 16 Apr 2014 12:12:15 +0900 Subject: [PATCH 44/64] Bug fix and optimization of breathing led --- common/breathing_led.c | 25 ++++------ common/keyboard.c | 4 ++ keyboard/gh60/backlight.c | 102 +++++++++++++++++++++++++++++++++++++- keyboard/gh60/config.h | 2 +- 4 files changed, 117 insertions(+), 16 deletions(-) diff --git a/common/breathing_led.c b/common/breathing_led.c index d71bf5b8..80bb9d59 100644 --- a/common/breathing_led.c +++ b/common/breathing_led.c @@ -6,7 +6,7 @@ #include "backlight.h" #include "debug.h" -#define BREATHING_LED_TIMER_TOP F_CPU/64 +#define BREATHING_LED_TIMER_TOP F_CPU/256 breathing_led_config_t breathing_led_config; @@ -14,9 +14,9 @@ void breathing_led_init(void) { /* Timer3 setup */ /* CTC mode */ - TCCR3B |= _BV(WGM12); - /* Clock selelct: clk/1 */ - TCCR3B |= _BV(CS10); + TCCR3B |= _BV(WGM32); + /* Clock selelct: clk/8 */ + TCCR3B |= _BV(CS30); /* Set TOP value */ uint8_t sreg = SREG; cli(); @@ -81,22 +81,19 @@ void breathing_led_decrease(void) } /* Breathing LED brighness(PWM On period) table - * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle * - * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 - * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } + * http://www.wolframalpha.com/input/?i=Table%5Bfloor%28%28exp%28sin%28x%2F256*2*pi%2B3%2F2*pi%29%29-1%2Fe%29*%28256%2F%28e-1%2Fe%29%29%29%2C+%7Bx%2C0%2C255%2C1%7D%5D + * Table[floor((exp(sin(x/256*2*pi+3/2*pi))-1/e)*(256/(e-1/e))), {x,0,255,1}] + * (0..255).each {|x| print ((exp(sin(x/256.0*2*PI+3.0/2*PI))-1/E)*(256/(E-1/E))).to_i, ', ' } */ -static const uint8_t breathing_table[64] PROGMEM = { -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, -15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, -255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, -15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +static const uint8_t breathing_table[256] PROGMEM = { +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 56, 58, 61, 63, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 102, 105, 108, 112, 116, 119, 123, 126, 130, 134, 138, 142, 145, 149, 153, 157, 161, 165, 169, 173, 176, 180, 184, 188, 192, 195, 199, 203, 206, 210, 213, 216, 219, 223, 226, 228, 231, 234, 236, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 254, 253, 252, 251, 250, 248, 247, 245, 243, 241, 239, 236, 234, 231, 228, 226, 223, 219, 216, 213, 210, 206, 203, 199, 195, 192, 188, 184, 180, 176, 173, 169, 165, 161, 157, 153, 149, 145, 142, 138, 134, 130, 126, 123, 119, 116, 112, 108, 105, 102, 98, 95, 92, 89, 86, 83, 80, 77, 74, 71, 68, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 34, 32, 30, 29, 27, 26, 25, 23, 22, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 11, 10, 9, 8, 8, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; ISR(TIMER3_COMPA_vect) { - uint8_t index = 0; - uint8_t step = 0; + static uint8_t index = 0; + static uint8_t step = 0; step++; if (step >= BREATHING_LED_LEVELS - breathing_led_config.level) { step = 0; diff --git a/common/keyboard.c b/common/keyboard.c index 933eb780..29155cfe 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -81,6 +81,10 @@ void keyboard_init(void) backlight_init(); #endif +#ifdef BREATHING_LED_ENABLE + breathing_led_init(); +#endif + #ifdef KEYMAP_EX_ENABLE keymap_ex_init(); #endif diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index eabb1c34..62a6e2ca 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -19,13 +19,15 @@ along with this program. If not, see . #include #include #include "backlight.h" +#include "debug.h" +#if defined(BREATHING_LED_ENABLE) || defined(BACKLIGHT_CUSTOM) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; /* Backlight pin configuration - * PWM: PB7 + * PWM: PB6 */ void backlight_enable(void) { @@ -79,7 +81,11 @@ void backlight_set(uint8_t level) void backlight_set_raw(uint8_t raw) { +#if defined(GH60_REV_CHN) + OCR1B = raw; +#else OCR1A = raw; +#endif } #ifndef GH60_REV_CHN @@ -94,3 +100,97 @@ ISR(TIMER1_OVF_vect) PORTF &= ~(1< 0) { + // Turn on PWM + cli(); + DDRB |= (1< 0) { + led_matrix_disable(); + for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < LED_MATRIX_COLS; col++) { + led_matrix_set_value(row, col, pgm_read_byte(&backlight_table[level])); + } + } + led_matrix_enable(); + } + else { + led_matrix_disable(); + } +} +#else +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + +void backlight_set(uint8_t level) +{ + if (level > 0) { + DDRF |= (1<. /* number of backlight levels */ #define BACKLIGHT_LEVELS 3 -#define BREATHING_LED_LEVELS 4 +#define BREATHING_LED_LEVELS 5 #ifdef GH60_REV_CNY # define LED_MATRIX_ROWS 6 From e26869d70ac3e78d3c07d312c8f07b190b0c3325 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 18 Apr 2014 12:12:59 +0900 Subject: [PATCH 45/64] Change software pwm method to fix blink issue --- common/breathing_led.c | 2 +- keyboard/gh60/backlight.c | 58 +++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/common/breathing_led.c b/common/breathing_led.c index 80bb9d59..497f9a6d 100644 --- a/common/breathing_led.c +++ b/common/breathing_led.c @@ -97,7 +97,7 @@ ISR(TIMER3_COMPA_vect) step++; if (step >= BREATHING_LED_LEVELS - breathing_led_config.level) { step = 0; - index++; backlight_set_raw(pgm_read_byte(&breathing_table[index])); + index++; } } diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 62a6e2ca..9b9c190b 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -21,6 +21,12 @@ along with this program. If not, see . #include "backlight.h" #include "debug.h" +#ifndef GH60_REV_CHN +#define SOFTPWM_TIMER_TOP F_CPU/(256*64) +uint8_t softpwm_ocr = 0; +uint8_t softpwm_ocr_buff = 0; +#endif + #if defined(BREATHING_LED_ENABLE) || defined(BACKLIGHT_CUSTOM) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 @@ -33,19 +39,20 @@ void backlight_enable(void) { #if defined(GH60_REV_CHN) // Turn on PWM - cli(); DDRB |= (1<>8)&0xff; + OCR1AL = SOFTPWM_TIMER_TOP&0xff; + TIMSK1 |= (1< 15) { + PORTF &= ~(1< Date: Fri, 18 Apr 2014 14:33:57 +0900 Subject: [PATCH 46/64] Simplifiy breathing led feature and code --- common/backlight.c | 36 +-------- common/backlight.h | 3 - common/breathing_led.c | 60 ++++----------- common/breathing_led.h | 22 +----- common/eeconfig.c | 8 -- common/eeconfig.h | 6 -- keyboard/gh60/backlight.c | 155 ++++++++++---------------------------- keyboard/gh60/config.h | 9 ++- 8 files changed, 70 insertions(+), 229 deletions(-) diff --git a/common/backlight.c b/common/backlight.c index ee8169c6..a0b2ce50 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -16,7 +16,6 @@ along with this program. If not, see . */ #include "backlight.h" -#include "breathing_led.h" #include "eeconfig.h" #include "debug.h" @@ -34,7 +33,7 @@ void backlight_init(void) void backlight_increase(void) { -#if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE) +#ifdef BACKLIGHT_CUSTOM if (backlight_config.enable) { if (backlight_config.level < BACKLIGHT_LEVELS) { backlight_config.level++; @@ -43,9 +42,6 @@ void backlight_increase(void) dprintf("backlight custom increase: %u\n", backlight_config.level); backlight_set(backlight_config.level); } -#ifdef BREATHING_LED_ENABLE - breathing_led_increase(); -#endif #else if(backlight_config.level < BACKLIGHT_LEVELS) { @@ -60,7 +56,7 @@ void backlight_increase(void) void backlight_decrease(void) { -#if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE) +#ifdef BACKLIGHT_CUSTOM if (backlight_config.enable) { if(backlight_config.level > 1) { @@ -70,9 +66,6 @@ void backlight_decrease(void) dprintf("backlight custom decrease: %u\n", backlight_config.level); backlight_set(backlight_config.level); } -#ifdef BREATHING_LED_ENABLE - breathing_led_decrease(); -#endif #else if(backlight_config.level > 0) { @@ -87,37 +80,16 @@ void backlight_decrease(void) void backlight_toggle(void) { -#ifdef BREATHING_LED_ENABLE - if (breathing_led_is_enabled()) { - breathing_led_disable(); - backlight_disable(); - return; - } -#endif backlight_config.enable ^= 1; - if (backlight_config.enable) { -#if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE) - backlight_enable(); -#endif + if (backlight_config.enable) + { if (backlight_config.level == 0) { backlight_config.level = 1; } } - else { -#ifndef BREATHING_LED_ENABLE -#ifdef BACKLIGHT_CUSTOM - backlight_disable(); -#endif -#endif - } eeconfig_write_backlight(backlight_config.raw); dprintf("backlight toggle: %u\n", backlight_config.enable); backlight_set(backlight_config.enable ? backlight_config.level : 0); -#ifdef BREATHING_LED_ENABLE - if (!backlight_config.enable) { - breathing_led_enable(); - } -#endif } void backlight_step(void) diff --git a/common/backlight.h b/common/backlight.h index a33c727a..685c422a 100644 --- a/common/backlight.h +++ b/common/backlight.h @@ -36,9 +36,6 @@ void backlight_decrease(void); void backlight_toggle(void); void backlight_step(void); -void backlight_enable(void); -void backlight_disable(void); void backlight_set(uint8_t level); -void backlight_set_raw(uint8_t raw); #endif diff --git a/common/breathing_led.c b/common/breathing_led.c index 497f9a6d..4e4822f8 100644 --- a/common/breathing_led.c +++ b/common/breathing_led.c @@ -1,22 +1,20 @@ #include #include -#include #include "led.h" #include "breathing_led.h" -#include "backlight.h" #include "debug.h" #define BREATHING_LED_TIMER_TOP F_CPU/256 -breathing_led_config_t breathing_led_config; +static uint8_t breathing_led_duration = 0; void breathing_led_init(void) { /* Timer3 setup */ /* CTC mode */ - TCCR3B |= _BV(WGM32); + TCCR3B |= (1< 0) - { - breathing_led_config.level--; - eeconfig_write_breathing_led(breathing_led_config.raw); - } - dprintf("breathing led speed decrease: %u\n", breathing_led_config.level); - } + breathing_led_duration = dur; + dprintf("breathing led set duration: %u\n", breathing_led_duration); } /* Breathing LED brighness(PWM On period) table @@ -87,7 +57,7 @@ void breathing_led_decrease(void) * (0..255).each {|x| print ((exp(sin(x/256.0*2*PI+3.0/2*PI))-1/E)*(256/(E-1/E))).to_i, ', ' } */ static const uint8_t breathing_table[256] PROGMEM = { -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 56, 58, 61, 63, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 102, 105, 108, 112, 116, 119, 123, 126, 130, 134, 138, 142, 145, 149, 153, 157, 161, 165, 169, 173, 176, 180, 184, 188, 192, 195, 199, 203, 206, 210, 213, 216, 219, 223, 226, 228, 231, 234, 236, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 254, 253, 252, 251, 250, 248, 247, 245, 243, 241, 239, 236, 234, 231, 228, 226, 223, 219, 216, 213, 210, 206, 203, 199, 195, 192, 188, 184, 180, 176, 173, 169, 165, 161, 157, 153, 149, 145, 142, 138, 134, 130, 126, 123, 119, 116, 112, 108, 105, 102, 98, 95, 92, 89, 86, 83, 80, 77, 74, 71, 68, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 34, 32, 30, 29, 27, 26, 25, 23, 22, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 11, 10, 9, 8, 8, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 56, 58, 61, 63, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 102, 105, 108, 112, 116, 119, 123, 126, 130, 134, 138, 142, 145, 149, 153, 157, 161, 165, 169, 173, 176, 180, 184, 188, 192, 195, 199, 203, 206, 210, 213, 216, 219, 223, 226, 228, 231, 234, 236, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 254, 253, 252, 251, 250, 248, 247, 245, 243, 241, 239, 236, 234, 231, 228, 226, 223, 219, 216, 213, 210, 206, 203, 199, 195, 192, 188, 184, 180, 176, 173, 169, 165, 161, 157, 153, 149, 145, 142, 138, 134, 130, 126, 123, 119, 116, 112, 108, 105, 102, 98, 95, 92, 89, 86, 83, 80, 77, 74, 71, 68, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 34, 32, 30, 29, 27, 26, 25, 23, 22, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 11, 10, 9, 8, 8, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ISR(TIMER3_COMPA_vect) @@ -95,9 +65,9 @@ ISR(TIMER3_COMPA_vect) static uint8_t index = 0; static uint8_t step = 0; step++; - if (step >= BREATHING_LED_LEVELS - breathing_led_config.level) { + if (step > breathing_led_duration) { step = 0; - backlight_set_raw(pgm_read_byte(&breathing_table[index])); + breathing_led_set_raw(pgm_read_byte(&breathing_table[index])); index++; } } diff --git a/common/breathing_led.h b/common/breathing_led.h index fb31668f..b3a9e775 100644 --- a/common/breathing_led.h +++ b/common/breathing_led.h @@ -4,28 +4,12 @@ #ifdef BREATHING_LED_ENABLE -#include -#include - -#ifndef BREATHING_LED_LEVEL -#define BREATHING_LED_LEVEL 1 -#endif - -typedef union { - uint8_t raw; - struct { - bool enable:1; - uint8_t level:7; - }; -} breathing_led_config_t; - void breathing_led_init(void); -bool breathing_led_is_enabled(void); void breathing_led_enable(void); void breathing_led_disable(void); void breathing_led_toggle(void); -void breathing_led_increase(void); -void breathing_led_decrease(void); +void breathing_led_set_duration(uint8_t dur); +void breathing_led_set_raw(uint8_t raw); #else @@ -33,6 +17,8 @@ void breathing_led_decrease(void); #define breathing_led_enable() #define breathing_led_disable() #define breathing_led_toggle() +#define breathing_led_set_duration() +#define breathing_led_set_raw() #endif diff --git a/common/eeconfig.c b/common/eeconfig.c index ab9bae3c..5aadf1c5 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -14,9 +14,6 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif -#ifdef BREATHING_LED_ENABLE - eeprom_write_byte(EECONFIG_BREATHING_LED, 0); -#endif #ifdef KEYMAP_EX_ENABLE keymap_ex_init(); #endif @@ -53,8 +50,3 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } #endif - -#ifdef BREATHING_LED_ENABLE -uint8_t eeconfig_read_breathing_led(void) { return eeprom_read_byte(EECONFIG_BREATHING_LED); } -void eeconfig_write_breathing_led(uint8_t val) { eeprom_write_byte(EECONFIG_BREATHING_LED, val); } -#endif diff --git a/common/eeconfig.h b/common/eeconfig.h index 36c18143..e1b5ae28 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h @@ -31,7 +31,6 @@ along with this program. If not, see . #define EECONFIG_KEYMAP (uint8_t *)4 #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 #define EECONFIG_BACKLIGHT (uint8_t *)6 -#define EECONFIG_BREATHING_LED (uint8_t *)7 /* debug bit */ @@ -72,9 +71,4 @@ uint8_t eeconfig_read_backlight(void); void eeconfig_write_backlight(uint8_t val); #endif -#ifdef BREATHING_LED_ENABLE -uint8_t eeconfig_read_breathing_led(void); -void eeconfig_write_breathing_led(uint8_t val); -#endif - #endif diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 9b9c190b..4c96d041 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -19,21 +19,22 @@ along with this program. If not, see . #include #include #include "backlight.h" -#include "debug.h" +#include "breathing_led.h" -#ifndef GH60_REV_CHN +#ifdef GH60_REV_CHN +#else #define SOFTPWM_TIMER_TOP F_CPU/(256*64) uint8_t softpwm_ocr = 0; uint8_t softpwm_ocr_buff = 0; #endif -#if defined(BREATHING_LED_ENABLE) || defined(BACKLIGHT_CUSTOM) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; /* Backlight pin configuration - * PWM: PB6 + * PWM: PB6 (Rev.CHN) + * GPIO: PF7 PF6 PF5 PF4 (Rev.B) */ void backlight_enable(void) { @@ -80,16 +81,50 @@ void backlight_disable(void) void backlight_set(uint8_t level) { +#ifdef BREATHING_LED_ENABLE + switch (level) { + case 1: + case 2: + case 3: + backlight_enable(); + breathing_led_disable(); + backlight_set_raw(pgm_read_byte(&backlight_table[level])); + break; + case 4: + case 5: + case 6: + backlight_enable(); + breathing_led_enable(); + breathing_led_set_duration(6 - level); + break; + case 0: + default: + breathing_led_disable(); + backlight_disable(); + break; + } +#else if (level > 0) { + backlight_enable(); backlight_set_raw(pgm_read_byte(&backlight_table[level])); } + else { + backlight_disable(); + } +#endif } -void backlight_set_raw(uint8_t raw) +#ifdef BREATHING_LED_ENABLE +void breathing_led_set_raw(uint8_t raw) +{ + backlight_set_raw(raw); +} +#endif + +inline void backlight_set_raw(uint8_t raw) { #if defined(GH60_REV_CHN) OCR1B = raw; - #else softpwm_ocr_buff = raw; #endif @@ -113,112 +148,4 @@ ISR(TIMER1_COMPA_vect) PORTF |= (1< 15) { - PORTF &= ~(1< 0) { - // Turn on PWM - cli(); - DDRB |= (1< 0) { - led_matrix_disable(); - for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) { - for (uint8_t col = 0; col < LED_MATRIX_COLS; col++) { - led_matrix_set_value(row, col, pgm_read_byte(&backlight_table[level])); - } - } - led_matrix_enable(); - } - else { - led_matrix_disable(); - } -} -#else -static const uint8_t backlight_table[] PROGMEM = { - 0, 16, 128, 255 -}; - -void backlight_set(uint8_t level) -{ - if (level > 0) { - DDRF |= (1<. #define DEBOUNCE 5 /* number of backlight levels */ +#ifdef BREATHING_LED_ENABLE +#define BACKLIGHT_LEVELS 6 +#else #define BACKLIGHT_LEVELS 3 -#define BREATHING_LED_LEVELS 5 +#endif #ifdef GH60_REV_CNY -# define LED_MATRIX_ROWS 6 -# define LED_MATRIX_COLS 14 +#define LED_MATRIX_ROWS 6 +#define LED_MATRIX_COLS 14 #endif /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ From c97edcdb3098b6afab8a3c982ad60f40ca96aab5 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 18 Apr 2014 15:10:49 +0900 Subject: [PATCH 47/64] Add a custom keymap for ghpad rev.RS --- keyboard/ghpad/keymap_redscarf.c | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 keyboard/ghpad/keymap_redscarf.c diff --git a/keyboard/ghpad/keymap_redscarf.c b/keyboard/ghpad/keymap_redscarf.c new file mode 100644 index 00000000..0bf8c591 --- /dev/null +++ b/keyboard/ghpad/keymap_redscarf.c @@ -0,0 +1,52 @@ +#include "keymap_common.h" + +// 4x6 Keypad +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,---------------. + * |Esc|F5 |Fn0|BS | + * |---+---+---+---| + * |Num|/ |* |- | + * |---+---+---+---| + * |7 |8 |9 |+ | + * |---+---+---| | + * |4 |5 |6 | | + * |---+---+---+---| + * |1 |2 |3 |Ent| + * |---+---+---| | + * |0 |. | | + * `---------------' + */ + [0] = KEYMAP( + ESC, F5, FN0, BSPC, \ + NLCK,PSLS,PAST,PMNS, \ + P7, P8, P9, PPLS, \ + P4, P5, P6, PENT, \ + P1, P2, P3, PENT, \ + P0, NO, PDOT,NO) +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +const uint16_t fn_actions[] PROGMEM = { +#endif + [0] = ACTION_BACKLIGHT_STEP(), +}; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif From c6902681e72411fbe293657a9d75a2168021a6d8 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 21 Apr 2014 12:18:12 +0900 Subject: [PATCH 48/64] Change PollingIntervalMS to 10ms(Fix #114) --- protocol/lufa/descriptor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index a46ba3ec..f9f6b953 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -306,7 +306,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = KEYBOARD_EPSIZE, - .PollingIntervalMS = 0x01 + .PollingIntervalMS = 0x0A }, /* From a5d4a1f3e1f09a79ad949e7e90199548992f0e37 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 21 Apr 2014 22:17:42 +0900 Subject: [PATCH 49/64] Return when ready check loop is timeouted(Fix #115) --- protocol/lufa/descriptor.c | 4 ++-- protocol/lufa/lufa.c | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index f9f6b953..d97f5d86 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -347,7 +347,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = MOUSE_EPSIZE, - .PollingIntervalMS = 0x01 + .PollingIntervalMS = 0x0A }, #endif @@ -389,7 +389,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = (ENDPOINT_DIR_IN | EXTRAKEY_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = EXTRAKEY_EPSIZE, - .PollingIntervalMS = 0x01 + .PollingIntervalMS = 0x0A }, #endif diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index eca51c87..68119d5e 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -351,7 +351,7 @@ static uint8_t keyboard_leds(void) static void send_keyboard(report_keyboard_t *report) { - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -360,15 +360,20 @@ static void send_keyboard(report_keyboard_t *report) #ifdef NKRO_ENABLE if (keyboard_nkro) { Endpoint_SelectEndpoint(NKRO_IN_EPNUM); + + /* Check if write ready for a polling interval around 1ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4); + if (!Endpoint_IsReadWriteAllowed()) return; } else #endif { Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); - } - /* Check if Keyboard Endpoint Ready for Read/Write */ - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + } /* Write Keyboard Report Data */ #ifdef NKRO_ENABLE @@ -391,7 +396,7 @@ static void send_keyboard(report_keyboard_t *report) static void send_mouse(report_mouse_t *report) { #ifdef MOUSE_ENABLE - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -399,8 +404,9 @@ static void send_mouse(report_mouse_t *report) /* Select the Mouse Report Endpoint */ Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); - /* Check if Mouse Endpoint Ready for Read/Write */ - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; /* Write Mouse Report Data */ Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL); @@ -412,7 +418,7 @@ static void send_mouse(report_mouse_t *report) static void send_system(uint16_t data) { - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -422,14 +428,18 @@ static void send_system(uint16_t data) .usage = data }; Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_ClearIN(); } static void send_consumer(uint16_t data) { - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -439,7 +449,11 @@ static void send_consumer(uint16_t data) .usage = data }; Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_ClearIN(); } From 3c5add5f800daaeaf0abc28eae8b3c244bcc1126 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 24 Apr 2014 11:26:06 +0900 Subject: [PATCH 50/64] Change LUFA build options --- keyboard/hhkb/Makefile | 2 +- protocol/lufa.mk | 10 +++++++--- protocol/lufa/descriptor.c | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/keyboard/hhkb/Makefile b/keyboard/hhkb/Makefile index 89d05ba1..0a256874 100644 --- a/keyboard/hhkb/Makefile +++ b/keyboard/hhkb/Makefile @@ -102,7 +102,7 @@ ARCH = AVR8 F_USB = $(F_CPU) # Interrupt driven control endpoint task -OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT +#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Boot Section Size in *bytes* diff --git a/protocol/lufa.mk b/protocol/lufa.mk index 3489f19c..10a922f9 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk @@ -2,6 +2,7 @@ LUFA_DIR = protocol/lufa # Path to the LUFA library LUFA_PATH ?= protocol/lufa/LUFA-120730 +#LUFA_PATH ?= protocol/lufa/LUFA-130901 # Create the LUFA source path variables by including the LUFA makefile ifneq (, $(wildcard $(TOP_DIR)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk)) @@ -30,9 +31,12 @@ VPATH += $(TOP_DIR)/$(LUFA_PATH) #endif # LUFA library compile-time options and predefined tokens -LUFA_OPTS = -D USB_DEVICE_ONLY -LUFA_OPTS += -D USE_FLASH_DESCRIPTORS -LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +LUFA_OPTS = -DUSB_DEVICE_ONLY +LUFA_OPTS += -DUSE_FLASH_DESCRIPTORS +LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +#LUFA_OPTS += -DINTERRUPT_CONTROL_ENDPOINT +LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1 OPT_DEFS += -DF_USB=$(F_USB)UL OPT_DEFS += -DARCH=ARCH_$(ARCH) diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index d97f5d86..d88b5965 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -235,7 +235,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .SubClass = USB_CSCP_NoDeviceSubclass, .Protocol = USB_CSCP_NoDeviceProtocol, - .Endpoint0Size = 8, + .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, /* specified in config.h */ .VendorID = VENDOR_ID, @@ -246,7 +246,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .ProductStrIndex = 0x02, .SerialNumStrIndex = NO_DESCRIPTOR, - .NumberOfConfigurations = 1 + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS }; /******************************************************************************* From 00e9a342df752f06888d3093110a703c70985128 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 24 Apr 2014 11:27:33 +0900 Subject: [PATCH 51/64] Fix 'Shift Parentheses' example --- keyboard/hhkb/keymap_hasu.c | 91 +++++++++++-------------------------- 1 file changed, 27 insertions(+), 64 deletions(-) diff --git a/keyboard/hhkb/keymap_hasu.c b/keyboard/hhkb/keymap_hasu.c index 0297d3b7..2f6be63e 100644 --- a/keyboard/hhkb/keymap_hasu.c +++ b/keyboard/hhkb/keymap_hasu.c @@ -25,7 +25,7 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \ TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN4, \ - FN5, Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ + FN11,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ LGUI,LALT, FN6, RALT,RGUI), /* Layer 1: HHKB mode (HHKB Fn) @@ -131,12 +131,9 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { /* id for user defined functions */ enum function_id { LSHIFT_LPAREN, - RSHIFT_RPAREN, }; enum macro_id { - LSHIFT_PAREN, - RSHIFT_PAREN, HELLO, VOLUP, }; @@ -163,10 +160,7 @@ const uint16_t fn_actions[] PROGMEM = { // [8] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace // [9] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc - [11] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '(' - [12] = ACTION_FUNCTION_TAP(RSHIFT_RPAREN), // Function: RShift with tap ')' -// [13] = ACTION_MACRO_TAP(LSHIFT_PAREN), // Macro: LShift with tap '(' -// [14] = ACTION_MACRO_TAP(RSHIFT_PAREN), // Macro: RShift with tap ')' + [11] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '(' // [15] = ACTION_MACRO(HELLO), // Macro: say hello // [9] = ACTION_MACRO(VOLUP), // Macro: media key }; @@ -177,32 +171,13 @@ const uint16_t fn_actions[] PROGMEM = { */ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { - keyevent_t event = record->event; - tap_t tap = record->tap; - switch (id) { - case LSHIFT_PAREN: - if (tap.count > 0 && !tap.interrupted) { - return (event.pressed ? - MACRO( D(LSHIFT), D(9), U(9), U(LSHIFT), END ) : MACRO_NONE); - } else { - return (event.pressed ? - MACRO( D(LSHIFT), END ) : MACRO( U(LSHIFT), END ) ); - } - case RSHIFT_PAREN: - if (tap.count > 0 && !tap.interrupted) { - return (event.pressed ? - MACRO( D(RSHIFT), D(0), U(0), U(RSHIFT), END ) : MACRO_NONE); - } else { - return (event.pressed ? - MACRO( D(RSHIFT), END ) : MACRO( U(RSHIFT), END ) ); - } case HELLO: - return (event.pressed ? + return (record->event.pressed ? MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) : MACRO_NONE ); case VOLUP: - return (event.pressed ? + return (record->event.pressed ? MACRO( D(VOLU), U(VOLU), END ) : MACRO_NONE ); } @@ -216,48 +191,36 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) */ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { - keyevent_t event = record->event; - tap_t tap = record->tap; + if (record->event.pressed) dprint("P"); else dprint("R"); + dprintf("%d", record->tap.count); + if (record->tap.interrupted) dprint("i"); + dprint("\n"); switch (id) { case LSHIFT_LPAREN: - // LShft + tap '(' - // NOTE: cant use register_code to avoid conflicting with magic key bind - if (event.pressed) { - if (tap.count == 0 || tap.interrupted) { - //add_mods(MOD_BIT(KC_LSHIFT)); - layer_on(1); + // Shift parentheses example: LShft + tap '(' + // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses + // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899 + if (record->event.pressed) { + if (record->tap.count > 0 && !record->tap.interrupted) { + if (record->tap.interrupted) { + dprint("tap interrupted\n"); + register_mods(MOD_BIT(KC_LSHIFT)); + } } else { - add_mods(MOD_BIT(KC_LSHIFT)); - add_key(KC_9); - send_keyboard_report(); - del_mods(MOD_BIT(KC_LSHIFT)); - del_key(KC_9); - send_keyboard_report(); + register_mods(MOD_BIT(KC_LSHIFT)); } } else { - if (tap.count == 0 || tap.interrupted) { - //del_mods(MOD_BIT(KC_LSHIFT)); - layer_off(1); - } - } - break; - case RSHIFT_RPAREN: - // RShift + tap ')' - if (event.pressed) { - if (tap.count == 0 || tap.interrupted) { - add_mods(MOD_BIT(KC_RSHIFT)); + if (record->tap.count > 0 && !(record->tap.interrupted)) { + add_weak_mods(MOD_BIT(KC_LSHIFT)); + send_keyboard_report(); + register_code(KC_9); + unregister_code(KC_9); + del_weak_mods(MOD_BIT(KC_LSHIFT)); + send_keyboard_report(); + record->tap.count = 0; // ad hoc: cancel tap } else { - add_mods(MOD_BIT(KC_RSHIFT)); - add_key(KC_0); - send_keyboard_report(); - del_mods(MOD_BIT(KC_RSHIFT)); - del_key(KC_0); - send_keyboard_report(); - } - } else { - if (tap.count == 0 || tap.interrupted) { - del_mods(MOD_BIT(KC_RSHIFT)); + unregister_mods(MOD_BIT(KC_LSHIFT)); } } break; From ad4cba172b2eea37697ca531016c4c3b4defaeb7 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Apr 2014 12:19:14 +0900 Subject: [PATCH 52/64] Move macro definitions from lufa.c to lufa.h --- protocol/lufa/lufa.c | 9 --------- protocol/lufa/lufa.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 68119d5e..86e9f23d 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -184,15 +184,6 @@ 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. */ -#if LUFA_VERSION_INTEGER < 0x120730 - /* old API 120219 */ - #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank) -#else - /* new API >= 120730 */ - #define ENDPOINT_BANK_SINGLE 1 - #define ENDPOINT_BANK_DOUBLE 2 - #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank) -#endif void EVENT_USB_Device_ConfigurationChanged(void) { bool ConfigSuccess = true; diff --git a/protocol/lufa/lufa.h b/protocol/lufa/lufa.h index bcee060d..195123c0 100644 --- a/protocol/lufa/lufa.h +++ b/protocol/lufa/lufa.h @@ -66,4 +66,15 @@ typedef struct { uint16_t usage; } __attribute__ ((packed)) report_extra_t; + +#if LUFA_VERSION_INTEGER < 0x120730 + /* old API 120219 */ + #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank) +#else + /* new API >= 120730 */ + #define ENDPOINT_BANK_SINGLE 1 + #define ENDPOINT_BANK_DOUBLE 2 + #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank) +#endif + #endif From fc3a20c534c370944b7471adc60b8982d586d69c Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Apr 2014 12:52:47 +0900 Subject: [PATCH 53/64] Add LUFA git repository(release 140302) --- .gitmodules | 3 +++ protocol/lufa.mk | 8 ++++++-- protocol/lufa/LUFA-git | 1 + protocol/lufa/descriptor.c | 12 ++++++------ protocol/lufa/descriptor.h | 9 +++++++++ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 160000 protocol/lufa/LUFA-git diff --git a/.gitmodules b/.gitmodules index 3e34a635..17a20dec 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "protocol/usb_hid/USB_Host_Shield_2.0"] path = protocol/usb_hid/USB_Host_Shield_2.0 url = git@github.com:tmk/USB_Host_Shield_2.0.git +[submodule "protocol/lufa/LUFA-git"] + path = protocol/lufa/LUFA-git + url = https://github.com/abcminiuser/lufa.git diff --git a/protocol/lufa.mk b/protocol/lufa.mk index 10a922f9..48ce9ae8 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk @@ -1,8 +1,12 @@ LUFA_DIR = protocol/lufa # Path to the LUFA library -LUFA_PATH ?= protocol/lufa/LUFA-120730 -#LUFA_PATH ?= protocol/lufa/LUFA-130901 +ifeq (, $(wildcard $(TOP_DIR)/$(LUFA_DIR)/LUFA-git)) + LUFA_PATH ?= $(LUFA_DIR)/LUFA-120730 +else + LUFA_PATH ?= $(LUFA_DIR)/LUFA-git +endif + # Create the LUFA source path variables by including the LUFA makefile ifneq (, $(wildcard $(TOP_DIR)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk)) diff --git a/protocol/lufa/LUFA-git b/protocol/lufa/LUFA-git new file mode 160000 index 00000000..b6c18b2a --- /dev/null +++ b/protocol/lufa/LUFA-git @@ -0,0 +1 @@ +Subproject commit b6c18b2a7c544653efbe12a1d4e8ba65e7d83c35 diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index d88b5965..c13a81bd 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -230,7 +230,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, - .USBSpecification = VERSION_BCD(01.10), + .USBSpecification = VERSION_BCD(1,1,0), .Class = USB_CSCP_NoDeviceClass, .SubClass = USB_CSCP_NoDeviceSubclass, .Protocol = USB_CSCP_NoDeviceProtocol, @@ -292,7 +292,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -333,7 +333,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -375,7 +375,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -417,7 +417,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -469,7 +469,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index 9ee1c04d..e0acec80 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h @@ -159,4 +159,13 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); + +/* new API */ +#if LUFA_VERSION_INTEGER < 0x140302 + #define VERSION_BCD(Major, Minor, Revision) \ + CPU_TO_LE16( ((Major & 0xFF) << 8) | \ + ((Minor & 0x0F) << 4) | \ + (Revision & 0x0F) ) +#endif + #endif From 2db27ecedd92f79b96b5e4db3d8d0fd4822d2de0 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Apr 2014 15:16:12 +0900 Subject: [PATCH 54/64] Fix description of pin usage --- converter/pc98_usb/README | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/converter/pc98_usb/README b/converter/pc98_usb/README index a010dee2..c9bdf3d8 100644 --- a/converter/pc98_usb/README +++ b/converter/pc98_usb/README @@ -20,7 +20,7 @@ Wiring: You can change this with editing config.h. Pin mini DIN MCU ---------------------------------- - 1 ~RST PD1 + 1 ~RST(TXD) PD3 2 GND GND 3 ~RDY PD4 4 RXD PD2 @@ -37,9 +37,6 @@ Protocol Signal: Asynchronous, Positive logic, 19200baud, Least bit first Frame format: 1-Start bit(Lo), 8-Data bits, Odd-Parity, 1-Stop bit -This converter uses software method for testing purpose. AVR UART engine will work better. - - Build Firmware From 62117e7ea77bf036e4e08bb02d682311e3c3d401 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Apr 2014 15:25:21 +0900 Subject: [PATCH 55/64] Change MCU setting to ATmega32U2 --- converter/sun_usb/Makefile | 3 ++- converter/sun_usb/matrix.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/converter/sun_usb/Makefile b/converter/sun_usb/Makefile index 73a83e93..35c4bb12 100644 --- a/converter/sun_usb/Makefile +++ b/converter/sun_usb/Makefile @@ -20,9 +20,10 @@ CONFIG_H = config.h # MCU name, you MUST set this to match the board you are using # type "make clean" after changing this, so all files will be rebuilt #MCU = at90usb162 # Teensy 1.0 -MCU = atmega32u4 # Teensy 2.0 +#MCU = atmega32u4 # Teensy 2.0 #MCU = at90usb646 # Teensy++ 1.0 #MCU = at90usb1286 # Teensy++ 2.0 +MCU = atmega32u2 # Processor frequency. diff --git a/converter/sun_usb/matrix.c b/converter/sun_usb/matrix.c index a61e3a2d..988622bc 100644 --- a/converter/sun_usb/matrix.c +++ b/converter/sun_usb/matrix.c @@ -63,6 +63,8 @@ uint8_t matrix_cols(void) void matrix_init(void) { + DDRD |= (1<<6); + PORTD |= (1<<6); debug_enable = true; serial_init(); From 5e3f2d2b2e5065a04495f2c55fae0849966b5d23 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Apr 2014 15:32:21 +0900 Subject: [PATCH 56/64] Make NKRO deafult when it is available - NKRO is used only when keyboard_protocol = 1(report) --- common/action_util.c | 6 ++-- common/command.c | 4 +-- common/host.c | 2 +- common/host.h | 3 ++ protocol/lufa/lufa.c | 55 ++++++++++++++++++------------------ protocol/pjrc/usb.c | 18 ++++++------ protocol/pjrc/usb_keyboard.c | 11 +++----- protocol/pjrc/usb_keyboard.h | 2 -- 8 files changed, 51 insertions(+), 50 deletions(-) diff --git a/common/action_util.c b/common/action_util.c index 99a3adaa..ebe7150d 100644 --- a/common/action_util.c +++ b/common/action_util.c @@ -67,7 +67,7 @@ void send_keyboard_report(void) { void add_key(uint8_t key) { #ifdef NKRO_ENABLE - if (keyboard_nkro) { + if (keyboard_nkro && keyboard_protocol) { add_key_bit(key); return; } @@ -78,7 +78,7 @@ void add_key(uint8_t key) void del_key(uint8_t key) { #ifdef NKRO_ENABLE - if (keyboard_nkro) { + if (keyboard_nkro && keyboard_protocol) { del_key_bit(key); return; } @@ -151,7 +151,7 @@ uint8_t has_anymod(void) uint8_t get_first_key(void) { #ifdef NKRO_ENABLE - if (keyboard_nkro) { + if (keyboard_nkro && keyboard_protocol) { uint8_t i = 0; for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) ; diff --git a/common/command.c b/common/command.c index f6f27695..d2f8eb83 100644 --- a/common/command.c +++ b/common/command.c @@ -301,13 +301,13 @@ static bool command_common(uint8_t code) case KC_S: print("\n\n----- Status -----\n"); print_val_hex8(host_keyboard_leds()); + print_val_hex8(keyboard_protocol); + print_val_hex8(keyboard_idle); #ifdef PROTOCOL_PJRC print_val_hex8(UDCON); print_val_hex8(UDIEN); print_val_hex8(UDINT); print_val_hex8(usb_keyboard_leds); - print_val_hex8(usb_keyboard_protocol); - print_val_hex8(usb_keyboard_idle_config); print_val_hex8(usb_keyboard_idle_count); #endif diff --git a/common/host.c b/common/host.c index 1eafef75..2e56971b 100644 --- a/common/host.c +++ b/common/host.c @@ -24,7 +24,7 @@ along with this program. If not, see . #ifdef NKRO_ENABLE -bool keyboard_nkro = false; +bool keyboard_nkro = true; #endif static host_driver_t *driver; diff --git a/common/host.h b/common/host.h index 8ff26298..a56e6c3b 100644 --- a/common/host.h +++ b/common/host.h @@ -32,6 +32,9 @@ extern "C" { extern bool keyboard_nkro; #endif +uint8_t keyboard_idle; +uint8_t keyboard_protocol; + /* host driver */ void host_set_driver(host_driver_t *driver); diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 86e9f23d..a43a552a 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -52,8 +52,8 @@ #include "descriptor.h" #include "lufa.h" -static uint8_t idle_duration = 0; -static uint8_t protocol_report = 1; +uint8_t keyboard_idle = 0; +uint8_t keyboard_protocol = 1; static uint8_t keyboard_led_stats = 0; static report_keyboard_t keyboard_report_sent; @@ -290,21 +290,26 @@ void EVENT_USB_Device_ControlRequest(void) case HID_REQ_GetProtocol: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { - Endpoint_ClearSETUP(); - while (!(Endpoint_IsINReady())); - Endpoint_Write_8(protocol_report); - Endpoint_ClearIN(); - Endpoint_ClearStatusStage(); + if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) { + Endpoint_ClearSETUP(); + while (!(Endpoint_IsINReady())); + Endpoint_Write_8(keyboard_protocol); + Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); + } } break; case HID_REQ_SetProtocol: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { - Endpoint_ClearSETUP(); - Endpoint_ClearStatusStage(); + if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) { + Endpoint_ClearSETUP(); + Endpoint_ClearStatusStage(); - protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00); + keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00); + clear_keyboard(); + } } break; @@ -314,7 +319,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); Endpoint_ClearStatusStage(); - idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8); + keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8); } break; @@ -323,7 +328,7 @@ void EVENT_USB_Device_ControlRequest(void) { Endpoint_ClearSETUP(); while (!(Endpoint_IsINReady())); - Endpoint_Write_8(idle_duration); + Endpoint_Write_8(keyboard_idle); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } @@ -349,32 +354,28 @@ static void send_keyboard(report_keyboard_t *report) /* Select the Keyboard Report Endpoint */ #ifdef NKRO_ENABLE - if (keyboard_nkro) { + if (keyboard_nkro && keyboard_protocol) { + /* Report protocol - NKRO */ Endpoint_SelectEndpoint(NKRO_IN_EPNUM); /* Check if write ready for a polling interval around 1ms */ while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4); if (!Endpoint_IsReadWriteAllowed()) return; - } - else -#endif - { - Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); - /* Check if write ready for a polling interval around 10ms */ - while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); - if (!Endpoint_IsReadWriteAllowed()) return; - } - - /* Write Keyboard Report Data */ -#ifdef NKRO_ENABLE - if (keyboard_nkro) { + /* Write Keyboard Report Data */ Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL); } else #endif { - /* boot mode */ + /* Boot protocol */ + Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); + + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + + /* Write Keyboard Report Data */ Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL); } diff --git a/protocol/pjrc/usb.c b/protocol/pjrc/usb.c index 393b36f7..b09ad3f2 100644 --- a/protocol/pjrc/usb.c +++ b/protocol/pjrc/usb.c @@ -38,6 +38,7 @@ #include "sleep_led.h" #endif #include "suspend.h" +#include "action.h" #include "action_util.h" @@ -692,20 +693,20 @@ ISR(USB_GEN_vect) } /* TODO: should keep IDLE rate on each keyboard interface */ #ifdef NKRO_ENABLE - if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) { + if (!keyboard_nkro && keyboard_idle && (++div4 & 3) == 0) { #else - if (usb_keyboard_idle_config && (++div4 & 3) == 0) { + if (keyboard_idle && (++div4 & 3) == 0) { #endif UENUM = KBD_ENDPOINT; if (UEINTX & (1<mods; UEDATX = 0; - uint8_t keys = usb_keyboard_protocol ? KBD_REPORT_KEYS : 6; + uint8_t keys = keyboard_protocol ? KBD_REPORT_KEYS : 6; for (uint8_t i=0; ikeys[i]; } @@ -901,13 +902,13 @@ ISR(USB_COM_vect) } if (bRequest == HID_GET_IDLE) { usb_wait_in_ready(); - UEDATX = usb_keyboard_idle_config; + UEDATX = keyboard_idle; usb_send_in(); return; } if (bRequest == HID_GET_PROTOCOL) { usb_wait_in_ready(); - UEDATX = usb_keyboard_protocol; + UEDATX = keyboard_protocol; usb_send_in(); return; } @@ -921,14 +922,15 @@ ISR(USB_COM_vect) return; } if (bRequest == HID_SET_IDLE) { - usb_keyboard_idle_config = (wValue >> 8); + keyboard_idle = (wValue >> 8); usb_keyboard_idle_count = 0; //usb_wait_in_ready(); usb_send_in(); return; } if (bRequest == HID_SET_PROTOCOL) { - usb_keyboard_protocol = wValue; + keyboard_protocol = wValue; + clear_keyboard(); //usb_wait_in_ready(); usb_send_in(); return; diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c index de798fcc..c11995db 100644 --- a/protocol/pjrc/usb_keyboard.c +++ b/protocol/pjrc/usb_keyboard.c @@ -34,12 +34,12 @@ // protocol setting from the host. We use exactly the same report // either way, so this variable only stores the setting since we // are required to be able to report which setting is in use. -uint8_t usb_keyboard_protocol=1; +uint8_t keyboard_protocol=1; // the idle configuration, how often we send the report to the // host (ms * 4) even when it hasn't changed // Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request. -uint8_t usb_keyboard_idle_config=125; +uint8_t keyobard_idle=125; // count until idle timeout uint8_t usb_keyboard_idle_count=0; @@ -56,15 +56,12 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report) int8_t result = 0; #ifdef NKRO_ENABLE - if (keyboard_nkro) + if (keyboard_nkro && keyboard_protocol) result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE); else #endif { - if (usb_keyboard_protocol) - result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE); - else - result = send_report(report, KBD_ENDPOINT, 0, 6); + result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE); } if (result) return result; diff --git a/protocol/pjrc/usb_keyboard.h b/protocol/pjrc/usb_keyboard.h index c362ca3b..9b798e9a 100644 --- a/protocol/pjrc/usb_keyboard.h +++ b/protocol/pjrc/usb_keyboard.h @@ -30,8 +30,6 @@ #include "host.h" -extern uint8_t usb_keyboard_protocol; -extern uint8_t usb_keyboard_idle_config; extern uint8_t usb_keyboard_idle_count; extern volatile uint8_t usb_keyboard_leds; From 22854eb71b84a10ebad0f85841f2b99d38e1da8c Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 27 Apr 2014 05:07:27 +0900 Subject: [PATCH 57/64] NKRO is disable when SET_PROTOCOL(boot) - Command can force to enable NKRO even when boot mode - After boot keyboard may be in boot mode due to BIOS' request --- common/action_util.c | 6 +++--- protocol/lufa/lufa.c | 5 ++++- protocol/pjrc/usb.c | 3 +++ protocol/pjrc/usb_keyboard.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/action_util.c b/common/action_util.c index ebe7150d..99a3adaa 100644 --- a/common/action_util.c +++ b/common/action_util.c @@ -67,7 +67,7 @@ void send_keyboard_report(void) { void add_key(uint8_t key) { #ifdef NKRO_ENABLE - if (keyboard_nkro && keyboard_protocol) { + if (keyboard_nkro) { add_key_bit(key); return; } @@ -78,7 +78,7 @@ void add_key(uint8_t key) void del_key(uint8_t key) { #ifdef NKRO_ENABLE - if (keyboard_nkro && keyboard_protocol) { + if (keyboard_nkro) { del_key_bit(key); return; } @@ -151,7 +151,7 @@ uint8_t has_anymod(void) uint8_t get_first_key(void) { #ifdef NKRO_ENABLE - if (keyboard_nkro && keyboard_protocol) { + if (keyboard_nkro) { uint8_t i = 0; for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) ; diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index a43a552a..db05702a 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -308,6 +308,9 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00); +#ifdef NKRO_ENABLE + keyboard_nkro = !!keyboard_protocol; +#endif clear_keyboard(); } } @@ -354,7 +357,7 @@ static void send_keyboard(report_keyboard_t *report) /* Select the Keyboard Report Endpoint */ #ifdef NKRO_ENABLE - if (keyboard_nkro && keyboard_protocol) { + if (keyboard_nkro) { /* Report protocol - NKRO */ Endpoint_SelectEndpoint(NKRO_IN_EPNUM); diff --git a/protocol/pjrc/usb.c b/protocol/pjrc/usb.c index b09ad3f2..2b267d48 100644 --- a/protocol/pjrc/usb.c +++ b/protocol/pjrc/usb.c @@ -930,6 +930,9 @@ ISR(USB_COM_vect) } if (bRequest == HID_SET_PROTOCOL) { keyboard_protocol = wValue; +#ifdef NKRO_ENABLE + keyboard_nkro = !!keyboard_protocol; +#endif clear_keyboard(); //usb_wait_in_ready(); usb_send_in(); diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c index c11995db..d1683318 100644 --- a/protocol/pjrc/usb_keyboard.c +++ b/protocol/pjrc/usb_keyboard.c @@ -56,7 +56,7 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report) int8_t result = 0; #ifdef NKRO_ENABLE - if (keyboard_nkro && keyboard_protocol) + if (keyboard_nkro) result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE); else #endif From 37cf2607648a40bbac0b37f7e0838f240e66450a Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 28 Apr 2014 08:55:07 +0900 Subject: [PATCH 58/64] Check if LUFA-git really exists(Fix #118) --- protocol/lufa.mk | 2 +- protocol/lufa/descriptor.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/protocol/lufa.mk b/protocol/lufa.mk index 48ce9ae8..ac70ac03 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk @@ -1,7 +1,7 @@ LUFA_DIR = protocol/lufa # Path to the LUFA library -ifeq (, $(wildcard $(TOP_DIR)/$(LUFA_DIR)/LUFA-git)) +ifeq (, $(wildcard $(TOP_DIR)/$(LUFA_DIR)/LUFA-git/LUFA/Version.h)) LUFA_PATH ?= $(LUFA_DIR)/LUFA-120730 else LUFA_PATH ?= $(LUFA_DIR)/LUFA-git diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index e0acec80..a2db4bfd 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h @@ -162,6 +162,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, /* new API */ #if LUFA_VERSION_INTEGER < 0x140302 + #undef VERSION_BCD #define VERSION_BCD(Major, Minor, Revision) \ CPU_TO_LE16( ((Major & 0xFF) << 8) | \ ((Minor & 0x0F) << 4) | \ From 110eea578b561f7169ea19927c54533c2b93b3a3 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 28 Apr 2014 15:21:42 +0900 Subject: [PATCH 59/64] Fix remotewakeup of PJRC stack(Fix #121) - without this fix wakeup often fails - keyboard can wakeup once or twice but fails after that --- protocol/pjrc/usb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/protocol/pjrc/usb.c b/protocol/pjrc/usb.c index 2b267d48..1e6ba871 100644 --- a/protocol/pjrc/usb.c +++ b/protocol/pjrc/usb.c @@ -629,6 +629,7 @@ uint8_t usb_configured(void) void usb_remote_wakeup(void) { UDCON |= (1< Date: Tue, 29 Apr 2014 19:42:24 +0900 Subject: [PATCH 60/64] Add Makefiles for TMK converters. --- converter/ps2_usb/Makefile | 7 +- converter/ps2_usb/Makefile.jis | 75 -------------- converter/ps2_usb/Makefile.tmk_rev1 | 98 +++++++++++++++++++ converter/ps2_usb/Makefile.tmk_rev2 | 98 +++++++++++++++++++ converter/ps2_usb/README.md | 73 ++++++++------ converter/ps2_usb/config_tmk_rev1.h | 147 ++++++++++++++++++++++++++++ converter/ps2_usb/config_tmk_rev2.h | 86 ++++++++++++++++ 7 files changed, 475 insertions(+), 109 deletions(-) delete mode 100644 converter/ps2_usb/Makefile.jis create mode 100644 converter/ps2_usb/Makefile.tmk_rev1 create mode 100644 converter/ps2_usb/Makefile.tmk_rev2 create mode 100644 converter/ps2_usb/config_tmk_rev1.h create mode 100644 converter/ps2_usb/config_tmk_rev2.h diff --git a/converter/ps2_usb/Makefile b/converter/ps2_usb/Makefile index db0912eb..1dd23c15 100644 --- a/converter/ps2_usb/Makefile +++ b/converter/ps2_usb/Makefile @@ -1,3 +1,6 @@ +# +# Makefile for Teensy +# # Target file name (without extension). TARGET = ps2_usb_lufa @@ -59,7 +62,7 @@ ARCH = AVR8 F_USB = $(F_CPU) # Interrupt driven control endpoint task(+60) -OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT +#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Boot Section Size in *bytes* @@ -68,7 +71,7 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Atmel DFU loader 4096 # LUFA bootloader 4096 # USBaspLoader 2048 -OPT_DEFS += -DBOOTLOADER_SIZE=4096 +OPT_DEFS += -DBOOTLOADER_SIZE=512 # Build Options diff --git a/converter/ps2_usb/Makefile.jis b/converter/ps2_usb/Makefile.jis deleted file mode 100644 index 4e091e8e..00000000 --- a/converter/ps2_usb/Makefile.jis +++ /dev/null @@ -1,75 +0,0 @@ -# Target file name (without extension). -TARGET = ps2_usb_jis - -# Directory common source filess exist -TOP_DIR = ../.. - -# Directory keyboard dependent files exist -TARGET_DIR = . - - -# MCU name, you MUST set this to match the board you are using -# type "make clean" after changing this, so all files will be rebuilt -#MCU = at90usb162 # Teensy 1.0 -MCU = atmega32u4 # Teensy 2.0 -#MCU = at90usb646 # Teensy++ 1.0 -#MCU = at90usb1286 # Teensy++ 2.0 - - -# Processor frequency. -# Normally the first thing your program should do is set the clock prescaler, -# so your program will run at the correct speed. You should also set this -# variable to same clock speed. The _delay_ms() macro uses this, and many -# examples use this variable to calculate timings. Do not add a "UL" here. -F_CPU = 16000000 - - -# Build Options -# *Comment out* to disable the options. -# -MOUSEKEY_ENABLE = yes # Mouse keys -EXTRAKEY_ENABLE = yes # Audio control and System control -NKRO_ENABLE = yes # USB Nkey Rollover - -#PS2_USE_USART = yes # uses hardware USART engine for PS/2 signal receive(recomened) -#PS2_USE_INT = yes # uses external interrupt for falling edge of PS/2 clock pin -PS2_USE_BUSYWAIT = yes # uses primitive reference code - - -# keyboard dependent files -SRC = keymap_jis.c \ - matrix.c \ - led.c - - -ifdef PS2_USE_USART - SRC += protocol/ps2_usart.c - OPT_DEFS += -DPS2_USE_USART -endif -ifdef PS2_USE_INT - SRC += protocol/ps2.c - OPT_DEFS += -DPS2_USE_INT -endif -ifdef PS2_USE_BUSYWAIT - SRC += protocol/ps2.c - OPT_DEFS += -DPS2_USE_BUSYWAIT -endif - - -#CONFIG_H = config_pjrc_usart.h -CONFIG_H = config.h - - -#---------------- Programming Options -------------------------- -PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex - - -# Search Path -VPATH += $(TARGET_DIR) -VPATH += $(TOP_DIR) - - -include $(TOP_DIR)/protocol/pjrc.mk -include $(TOP_DIR)/protocol.mk -include $(TOP_DIR)/common.mk -include $(TOP_DIR)/rules.mk diff --git a/converter/ps2_usb/Makefile.tmk_rev1 b/converter/ps2_usb/Makefile.tmk_rev1 new file mode 100644 index 00000000..59c44f75 --- /dev/null +++ b/converter/ps2_usb/Makefile.tmk_rev1 @@ -0,0 +1,98 @@ +# +# Makefile for TMK keyboard converter rev2 +# https://github.com/tmk/keyboard_converter#pcb-rev1 +# +# Target file name (without extension). +TARGET = ps2_usb_tmk_rev1 + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap_common.c \ + matrix.c \ + led.c + +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_plain.c $(SRC) +endif + +CONFIG_H = config_tmk_rev1.h + + +# MCU name +MCU = atmega32u4 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 16000000 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Build Options +# comment out to disable the options. +# +#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = yes # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA + + +# PS/2 Options +# +PS2_USE_USART = yes # uses hardware USART engine for PS/2 signal receive(recomened) +#PS2_USE_BUSYWAIT = yes # uses primitive reference code + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/converter/ps2_usb/Makefile.tmk_rev2 b/converter/ps2_usb/Makefile.tmk_rev2 new file mode 100644 index 00000000..bad958c3 --- /dev/null +++ b/converter/ps2_usb/Makefile.tmk_rev2 @@ -0,0 +1,98 @@ +# +# Makefile for TMK keyboard converter rev2 +# https://github.com/tmk/keyboard_converter#pcb-rev2 +# +# Target file name (without extension). +TARGET = ps2_usb_tmk_rev2 + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap_common.c \ + matrix.c \ + led.c + +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_plain.c $(SRC) +endif + +CONFIG_H = config_tmk_rev2.h + + +# MCU name +MCU = atmega32u2 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 16000000 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# Build Options +# comment out to disable the options. +# +#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = yes # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA + + +# PS/2 Options +# +PS2_USE_INT = yes # uses external interrupt for falling edge of PS/2 clock pin +#PS2_USE_BUSYWAIT = yes # uses primitive reference code + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/converter/ps2_usb/README.md b/converter/ps2_usb/README.md index 8f06fdd0..537e92e6 100644 --- a/converter/ps2_usb/README.md +++ b/converter/ps2_usb/README.md @@ -1,11 +1,50 @@ PS/2 to USB keyboard converter ============================== -This firmware converts PS/2 keyboard protocol to USB and supports only Scan Code Set 2. +This firmware converts PS/2 keyboard protocol to USB.(It supports Scan Code Set 2.) + + +Connect Wires +------------- +In case of Teensy2.0(ATMega32U4): + +1. Connect **Vcc** and **GND**. +2. Connect **Clock** and **Data** line. + - **Interrupt**: **Clock** is on `PD1` and **Data** on `PD0`.(Recommended. Soarer's converter compatible) + - **Busywait**: **Clock** is on `PD1` and **Data** on `PD0`. + - **USART**: **Clock** is on `PD5` and **Data** on `PD2`. +3. Optionally you need pull-up register. 1K-10K Ohm is OK. + +To change pin configuration edit config.h. + + +Build Firmware +-------------- +For **PJRC Teensy** just run `make`: + + $ make clean + $ make + +To select keymap: + + $ make clean + $ make KEYMAP=[plain|jis|spacefn|...] + +After that you will find HEX file `ps2_usb_lufa.hex` in current directory. + + +- For **TMK converter Rev.1** use `make -f Makefile.tmk_rev1` instead of `make` and HEX file is `ps2_usb_tmk_rev1.hex`. + +- For **TMK converter Rev.2** use `make -f Makefile.tmk_rev2` instead of `make` and HEX file is `ps2_usb_tmk_rev2.hex`. + + +Keymap +------ +Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create file named `keymap_.c` and see keymap document(you can find in README.md of top directory) and existent keymap files. PS/2 signal handling implementations ------------------------------------ -Following three methods are used to implement PS/2 signal handling. +Following three methods can be used to implement PS/2 signal handling. ### Simple and stupid busy-wait(ps2_busywait.c) This is expected to implemented with portable C code for reference. @@ -17,36 +56,6 @@ Following three methods are used to implement PS/2 signal handling. To select method edit Makefile. -Connect Wires -------------- -In case of Teensy2.0(ATMega32U4): - -1. Connect Vcc and GND. -2. Connect Clock and Data line. - - Busywait: Clock is on PD5 and Data on PD2. - - Interrupt: Clock is on PD1 and Data on PD2. - - USART: Clock is on PD5 and Data on PD2. -3. Optionally you need pull-up register. 1K-10K Ohm is OK. - -To change pin configuration edit config.h. - - -Build Firmware --------------- -Just run `make`: - - $ make - -To select keymap: - - $ make KEYMAP=[plain|jis|spacefn|...] - - -Keymap ------- -Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create file named `keymap_.c` and see keymap document(you can find in top README.md) and existent keymap files. - - V-USB Support ------------- You can also use this converter on ATmega(168/328) with V-USB instead of Teensy. diff --git a/converter/ps2_usb/config_tmk_rev1.h b/converter/ps2_usb/config_tmk_rev1.h new file mode 100644 index 00000000..75dc97df --- /dev/null +++ b/converter/ps2_usb/config_tmk_rev1.h @@ -0,0 +1,147 @@ +/* +Copyright 2012 Jun Wako + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6512 +#define DEVICE_VER 0x0001 +#define MANUFACTURER t.m.k. +#define PRODUCT PS/2 keyboard converter +#define DESCRIPTION convert PS/2 keyboard to USB + + +/* matrix size */ +#define MATRIX_ROWS 32 // keycode bit: 3-0 +#define MATRIX_COLS 8 // keycode bit: 6-4 + + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \ + keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \ +) + + +//#define NO_SUSPEND_POWER_DOWN + + +/* + * PS/2 Busywait + */ +#ifdef PS2_USE_BUSYWAIT +#define PS2_CLOCK_PORT PORTD +#define PS2_CLOCK_PIN PIND +#define PS2_CLOCK_DDR DDRD +#define PS2_CLOCK_BIT 5 +#define PS2_DATA_PORT PORTD +#define PS2_DATA_PIN PIND +#define PS2_DATA_DDR DDRD +#define PS2_DATA_BIT 2 +#endif + +/* + * PS/2 USART + */ +#ifdef PS2_USE_USART +#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) +/* XCK for clock line and RXD for data line */ +#define PS2_CLOCK_PORT PORTD +#define PS2_CLOCK_PIN PIND +#define PS2_CLOCK_DDR DDRD +#define PS2_CLOCK_BIT 5 +#define PS2_DATA_PORT PORTD +#define PS2_DATA_PIN PIND +#define PS2_DATA_DDR DDRD +#define PS2_DATA_BIT 2 +/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ +/* set DDR of CLOCK as input to be slave */ +#define PS2_USART_INIT() do { \ + PS2_CLOCK_DDR &= ~(1< + +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 +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x6512 +#define DEVICE_VER 0x0001 +#define MANUFACTURER t.m.k. +#define PRODUCT PS/2 keyboard converter +#define DESCRIPTION convert PS/2 keyboard to USB + + +/* matrix size */ +#define MATRIX_ROWS 32 // keycode bit: 3-0 +#define MATRIX_COLS 8 // keycode bit: 6-4 + + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \ + keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \ +) + + +//#define NO_SUSPEND_POWER_DOWN + + +/* + * PS/2 Busywait + */ +#ifdef PS2_USE_BUSYWAIT +#define PS2_CLOCK_PORT PORTD +#define PS2_CLOCK_PIN PIND +#define PS2_CLOCK_DDR DDRD +#define PS2_CLOCK_BIT 1 +#define PS2_DATA_PORT PORTD +#define PS2_DATA_PIN PIND +#define PS2_DATA_DDR DDRD +#define PS2_DATA_BIT 0 +#endif + +/* + * PS/2 Pin interrupt + */ +#ifdef PS2_USE_INT +/* uses INT1 for clock line(ATMega32U4) */ +#define PS2_CLOCK_PORT PORTD +#define PS2_CLOCK_PIN PIND +#define PS2_CLOCK_DDR DDRD +#define PS2_CLOCK_BIT 1 +#define PS2_DATA_PORT PORTD +#define PS2_DATA_PIN PIND +#define PS2_DATA_DDR DDRD +#define PS2_DATA_BIT 0 +#define PS2_INT_INIT() do { \ + EICRA |= ((1< Date: Tue, 29 Apr 2014 19:45:01 +0900 Subject: [PATCH 61/64] Unused endpoint of console OUT is commentout'd --- protocol/lufa/descriptor.h | 6 +++++- protocol/lufa/lufa.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index a2db4bfd..42af0791 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h @@ -137,13 +137,17 @@ typedef struct #ifdef CONSOLE_ENABLE # define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1) -# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2) +# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 1) +//# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2) #else # define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM #endif #ifdef NKRO_ENABLE # define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1) +# if defined(__AVR_ATmega32U2__) && NKRO_IN_EPNUM > 4 +# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO)" +# endif #endif diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index db05702a..9f8e50c4 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -208,9 +208,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) /* Setup Console HID Report Endpoints */ ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); +#if 0 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); #endif +#endif #ifdef NKRO_ENABLE /* Setup NKRO HID Report Endpoints */ From abe5edcaa7c6391cb313a672910d7beb9b7d8fa2 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 29 Apr 2014 19:46:37 +0900 Subject: [PATCH 62/64] Fix set LED for NKRO keyboard interface --- protocol/lufa/lufa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 9f8e50c4..d60aecc3 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -272,6 +272,7 @@ void EVENT_USB_Device_ControlRequest(void) // Interface switch (USB_ControlRequest.wIndex) { case KEYBOARD_INTERFACE: + case NKRO_INTERFACE: Endpoint_ClearSETUP(); while (!(Endpoint_IsOUTReceived())) { From 8748b6080f0254d59df6549443162b16daa5f5fc Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 7 May 2014 11:39:07 +0900 Subject: [PATCH 63/64] Fix some definition and declaration --- common/keyboard.c | 1 + keyboard/gh60/backlight.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/common/keyboard.c b/common/keyboard.c index 29155cfe..6b3f6427 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -31,6 +31,7 @@ along with this program. If not, see . #include "bootmagic.h" #include "eeconfig.h" #include "backlight.h" +#include "breathing_led.h" #include "keymap_ex.h" #ifdef MOUSEKEY_ENABLE # include "mousekey.h" diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 4c96d041..3a8f6c0e 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -21,6 +21,12 @@ along with this program. If not, see . #include "backlight.h" #include "breathing_led.h" +#ifdef BACKLIGHT_ENABLE + +void backlight_enable(void); +void backlight_disable(void); +inline void backlight_set_raw(uint8_t raw); + #ifdef GH60_REV_CHN #else #define SOFTPWM_TIMER_TOP F_CPU/(256*64) @@ -149,3 +155,5 @@ ISR(TIMER1_COMPA_vect) } } #endif + +#endif From d37b6d7d5b986e55c7e52db2a09570cbd12f4ef1 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 26 May 2014 12:04:31 +0900 Subject: [PATCH 64/64] Remove keymap_ex changes --- common.mk | 7 +-- common/keyboard.c | 5 -- common/keymap_ex.c | 114 ---------------------------------- common/keymap_ex.h | 68 -------------------- keyboard/gh60/Makefile | 1 - keyboard/gh60/Makefile.pjrc | 1 - keyboard/gh60/keymap_common.c | 23 +------ keyboard/gh60/keymap_common.h | 27 +------- keyboard/gh60/keymap_poker.c | 10 --- 9 files changed, 5 insertions(+), 251 deletions(-) delete mode 100644 common/keymap_ex.c delete mode 100644 common/keymap_ex.h diff --git a/common.mk b/common.mk index 09561cba..f6e9f262 100644 --- a/common.mk +++ b/common.mk @@ -22,7 +22,7 @@ ifdef BOOTMAGIC_ENABLE OPT_DEFS += -DBOOTMAGIC_ENABLE endif -ifdef MOUSEKEY_ENABLE +ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) SRC += $(COMMON_DIR)/mousekey.c OPT_DEFS += -DMOUSEKEY_ENABLE OPT_DEFS += -DMOUSE_ENABLE @@ -69,11 +69,6 @@ ifdef KEYMAP_SECTION_ENABLE EXTRALDFLAGS = -Wl,-L$(TOP_DIR),-Tldscript_keymap_avr5.x endif -ifdef KEYMAP_EX_ENABLE - SRC += $(COMMON_DIR)/keymap_ex.c - OPT_DEFS += -DKEYMAP_EX_ENABLE -endif - ifdef LED_MATRIX_ENABLE SRC += $(COMMON_DIR)/led_matrix.c OPT_DEFS += -DLED_MATRIX_ENABLE diff --git a/common/keyboard.c b/common/keyboard.c index 6b3f6427..7928741a 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -32,7 +32,6 @@ along with this program. If not, see . #include "eeconfig.h" #include "backlight.h" #include "breathing_led.h" -#include "keymap_ex.h" #ifdef MOUSEKEY_ENABLE # include "mousekey.h" #endif @@ -85,10 +84,6 @@ void keyboard_init(void) #ifdef BREATHING_LED_ENABLE breathing_led_init(); #endif - -#ifdef KEYMAP_EX_ENABLE - keymap_ex_init(); -#endif } /* diff --git a/common/keymap_ex.c b/common/keymap_ex.c deleted file mode 100644 index 99859c06..00000000 --- a/common/keymap_ex.c +++ /dev/null @@ -1,114 +0,0 @@ -/* -Copyright 2013 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 -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include -#include -#include "eeconfig.h" -#include "keymap_ex.h" -#include "debug.h" - -#ifdef KEYMAP_EX_ENABLE - -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; - for (uint16_t i = 0; i < KEYMAP_SIZE; i += 2) { - checksum += eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + i)); - } -#ifdef DEBUG - eeprom_write_word((void*)(EECONFIG_KEYMAP_DEBUG), checksum); -#endif - return (checksum_in_eeprom == checksum); -} - -void write_keymap_to_eeprom(void) { - uint16_t checksum = EECONFIG_MAGIC_NUMBER; - const uint16_t *fn_actions = fn_actions_pointer(); - const uint8_t *keymaps = keymaps_pointer(); - // write fn_actions - if (fn_actions != NULL) { - uint16_t fn_actions_count_in_flash = fn_actions_count(); - for (uint16_t i = 0; i < FN_ACTIONS_COUNT; i++) { - uint16_t fn_action = 0; - if (i < fn_actions_count_in_flash) { - fn_action = pgm_read_word(fn_actions + i); - } - eeconfig_write_keymap_fn_action(i, fn_action); - checksum += fn_action; - } - } - // write keymaps - if (keymaps != NULL) { - uint16_t keys_count_in_flash = keys_count(); - for (uint16_t i = 0; i < KEYS_COUNT; i++) { - uint8_t keymap = 0; - if (i < keys_count_in_flash) { - keymap = pgm_read_byte(keymaps + i); - } - eeconfig_write_keymap_key_by_index(i, keymap); - uint16_t keymap_word = keymap; - if (i & 1) { - keymap_word = keymap << 8; - } - checksum += keymap_word; - } - } - // write checksum - eeprom_write_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum, checksum); -} - -uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col) { - //return eeprom_read_byte(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->keymaps[layer][row][col]); - return eeprom_read_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + KEY_OFFSET(layer, row, col))); -} - -void eeconfig_write_keymap_key(uint8_t layer, uint8_t row, uint8_t col, uint8_t key) { - //return eeprom_write_byte(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->keymaps[layer][row][col], key); - return eeprom_write_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + KEY_OFFSET(layer, row, col)), key); -} - -uint8_t eeconfig_read_keymap_key_by_index(uint16_t index) { - //return eeprom_read_byte(((keymap_ex_t*)(EECONFIG_KEYMAP_EX)) + index); - return eeprom_read_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + index)); -} - -void eeconfig_write_keymap_key_by_index(uint16_t index, uint8_t key) { - //return eeprom_write_byte(((keymap_ex_t*)(EECONFIG_KEYMAP_EX)) + index, key); - return eeprom_write_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + index), key); -} - -uint16_t eeconfig_read_keymap_fn_action(uint8_t index) { - //return eeprom_read_word(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->fn_actions[index]); - return eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + FN_ACTION_OFFSET(index))); -} - -void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action) { - //return eeprom_write_word(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->fn_actions[index], fn_action); - return eeprom_write_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + FN_ACTION_OFFSET(index)), fn_action); -} - -#endif diff --git a/common/keymap_ex.h b/common/keymap_ex.h deleted file mode 100644 index ee6ff8c6..00000000 --- a/common/keymap_ex.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright 2013 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 -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef KEYMAP_EX_H -#define KEYMAP_EX_H - -#ifdef KEYMAP_EX_ENABLE - -#include -#include - -#define EECONFIG_KEYMAP_EX 0x10 -#ifndef FN_ACTIONS_COUNT -#define FN_ACTIONS_COUNT 32 -#endif -#ifndef KEYMAPS_COUNT -#define KEYMAPS_COUNT 8 -#endif - -typedef struct { - uint16_t checksum; - uint16_t fn_actions[FN_ACTIONS_COUNT]; - uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; -} keymap_ex_t; - -#define EECONFIG_KEYMAP_DEBUG (EECONFIG_KEYMAP_EX - sizeof(uint16_t)) -#define EECONFIG_KEYMAP_CHECKSUM (EECONFIG_KEYMAP_EX) -#define EECONFIG_KEYMAP_FN_ACTIONS (EECONFIG_KEYMAP_EX + sizeof(uint16_t)) -#define EECONFIG_KEYMAP_KEYMAPS (EECONFIG_KEYMAP_FN_ACTIONS + sizeof(uint16_t) * FN_ACTIONS_COUNT) - -#define KEYS_COUNT (KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS) -#define KEYMAP_SIZE (sizeof(uint16_t) * FN_ACTIONS_COUNT + sizeof(uint8_t) * KEYS_COUNT) -#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_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); -void eeconfig_write_keymap_key(uint8_t layer, uint8_t row, uint8_t col, uint8_t key); -uint8_t eeconfig_read_keymap_key_by_index(uint16_t index); -void eeconfig_write_keymap_key_by_index(uint16_t index, uint8_t key); -uint16_t eeconfig_read_keymap_fn_action(uint8_t index); -void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action); - -const uint8_t* keymaps_pointer(void); -const uint16_t* fn_actions_pointer(void); -uint16_t keys_count(void); -uint16_t fn_actions_count(void); - -#endif - -#endif diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 56da7779..bb939a84 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -136,7 +136,6 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #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 BREATHING_LED_ENABLE = yes # Enable breathing backlight diff --git a/keyboard/gh60/Makefile.pjrc b/keyboard/gh60/Makefile.pjrc index 0ddce925..81ababb4 100644 --- a/keyboard/gh60/Makefile.pjrc +++ b/keyboard/gh60/Makefile.pjrc @@ -104,7 +104,6 @@ COMMAND_ENABLE = yes # Commands for debug and configuration #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 -KEYMAP_EX_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor diff --git a/keyboard/gh60/keymap_common.c b/keyboard/gh60/keymap_common.c index ae934eea..7b6379f6 100644 --- a/keyboard/gh60/keymap_common.c +++ b/keyboard/gh60/keymap_common.c @@ -16,34 +16,15 @@ along with this program. If not, see . */ #include "keymap_common.h" + /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { -#ifndef KEYMAP_EX_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); -#else - return eeconfig_read_keymap_key(layer, key.row, key.col); -#endif } /* translates Fn keycode to action */ action_t keymap_fn_to_action(uint8_t keycode) { - return (action_t) { -#ifndef KEYMAP_EX_ENABLE - .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) -#else - .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) -#endif - }; + return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) }; } - -#ifdef KEYMAP_EX_ENABLE -const uint8_t* keymaps_pointer(void) { - return (const uint8_t*)keymaps; -} - -const uint16_t* fn_actions_pointer(void) { - return fn_actions; -} -#endif diff --git a/keyboard/gh60/keymap_common.h b/keyboard/gh60/keymap_common.h index e94f013c..2105caab 100644 --- a/keyboard/gh60/keymap_common.h +++ b/keyboard/gh60/keymap_common.h @@ -28,18 +28,10 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "keymap.h" -#include "keymap_ex.h" -/* -#ifdef KEYMAP_EX_ENABLE -extern const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS]; -extern const uint16_t fn_actions[FN_ACTIONS_COUNT]; -#else -*/ extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; extern const uint16_t fn_actions[]; -//#endif /* GH60 keymap definition macro @@ -50,13 +42,13 @@ extern const uint16_t fn_actions[]; K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, \ K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \ - K40, K41, K42, K45, K49, K4A, K4B, K4C, K4D \ + K40, K41, K42, K45, K4A, K4B, K4C, K4D \ ) { \ { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \ { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \ { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \ { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \ - { KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \ + { KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_NO, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \ } /* ANSI valiant. No extra keys for ISO */ @@ -71,22 +63,7 @@ extern const uint16_t fn_actions[]; K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO, K2D, \ K30, NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, NO, K3D, \ - K40, K41, K42, K45, NO, K4A, K4B, K4C, K4D \ -) - - -#define KEYMAP_HHKB( \ - K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K49,\ - K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ - K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, \ - K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3C, \ K40, K41, K42, K45, K4A, K4B, K4C, K4D \ -) KEYMAP( \ - K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \ - K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ - K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO, K2D, \ - K30, NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \ - K40, K41, K42, K45, K49, K4A, K4B, K4C, K4D \ ) #endif diff --git a/keyboard/gh60/keymap_poker.c b/keyboard/gh60/keymap_poker.c index f2035b43..7a612ee4 100644 --- a/keyboard/gh60/keymap_poker.c +++ b/keyboard/gh60/keymap_poker.c @@ -102,13 +102,3 @@ const uint16_t PROGMEM fn_actions[] = { [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout [8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout }; - -#ifdef KEYMAP_EX_ENABLE -uint16_t keys_count(void) { - return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; -} - -uint16_t fn_actions_count(void) { - return sizeof(fn_actions) / sizeof(fn_actions[0]); -} -#endif