From 71059ad36386cc52cee60620fc356f615a9c2d0a Mon Sep 17 00:00:00 2001 From: jesse Date: Fri, 22 Nov 2013 05:32:35 -0800 Subject: [PATCH] The problem of layout definition being a little too obtuse can be solved by adding a layer of indirection --- Makefile | 3 ++ key_defs.h | 37 ++++++++++++------------ keymaps.h | 60 +++++++++++++++++++++------------------ layouts/qwerty.conf | 6 ++++ layouts/qwerty_fn2.conf | 6 ++++ tools/generate_keymaps.pl | 49 ++++++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 46 deletions(-) create mode 100644 layouts/qwerty.conf create mode 100644 layouts/qwerty_fn2.conf create mode 100644 tools/generate_keymaps.pl diff --git a/Makefile b/Makefile index fbf90c1a..fdacb300 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,6 @@ include build/arduino-mk/Arduino.mk astyle: astyle --style=linux ArduinoKeyboard.ino *.h + +generate-keymaps: + find layout -type f -name \*.conf |xargs perl generate-keymaps.pl < diff --git a/key_defs.h b/key_defs.h index 03fa513d..c6fd3ffa 100644 --- a/key_defs.h +++ b/key_defs.h @@ -27,29 +27,30 @@ #define LAYER_7 7 -#define NoKey (Key){ KEY_FLAGS,0 } +#define Key_NoKey (Key){ KEY_FLAGS,0 } +#define Key_skip (Key){ KEY_FLAGS,0 } -#define macroKey1 (Key){ KEY_FLAGS|SYNTHETIC_KEY|IS_MACRO, 1} +#define Key_macroKey1 (Key){ KEY_FLAGS|SYNTHETIC_KEY|IS_MACRO, 1} -#define mouseUpL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_L } -#define mouseUp (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP } -#define mouseUpR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_R } -#define mouseL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_L } -#define mouseR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_R } -#define mouseDnL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_L } -#define mouseDn (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN } -#define mouseDnR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_R } -#define mouseScrollUp -#define mouseScrollDn -#define mouseScrollL -#define mouseScrollR +#define Key_mouseUpL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_L } +#define Key_mouseUp (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP } +#define Key_mouseUpR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_R } +#define Key_mouseL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_L } +#define Key_mouseR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_R } +#define Key_mouseDnL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_L } +#define Key_mouseDn (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN } +#define Key_mouseDnR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_R } +#define Key_mouseScrollUp +#define Key_mouseScrollDn +#define Key_mouseScrollL +#define Key_mouseScrollR #define KEY_MOUSE_BTN_L 0x01 // Synthetic key #define KEY_MOUSE_BTN_M 0x04 // Synthetic key #define KEY_MOUSE_BTN_R 0x02 // Synthetic key -#define mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_L } -#define mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC_KEY , KEY_MOUSE_BTN_M } -#define mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_R } +#define Key_mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_L } +#define Key_mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC_KEY , KEY_MOUSE_BTN_M } +#define Key_mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_R } @@ -346,5 +347,5 @@ #define META_NEXT_KEYMAP_MOMENTARY 0xFF -#define NextKeymap (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 } +#define Key_NextKeymap (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 } diff --git a/keymaps.h b/keymaps.h index 56900439..b69815fa 100644 --- a/keymaps.h +++ b/keymaps.h @@ -1,49 +1,53 @@ - +#include "layouts-generated/qwerty.h" +#include "layouts-generated/qwerty_fn2.h" static const Key keymaps[LAYERS][ROWS][COLS] = { - { - { NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey }, - { Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, NoKey, NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals}, + KEYMAP_QWERTY +/* { + { Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }, + { Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_NoKey, Key_NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals}, { Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote }, { Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Return, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus}, - { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } + { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } }, - { - { NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey }, - { Key_Backtick, macroKey1, mouseBtnL, mouseBtnM, mouseBtnR, Key_T, NoKey, NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals}, - { Key_PageUp, mouseL, mouseUp, mouseDn, mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote}, - { Key_PageDn, Key_Z, mouseBtnL, mouseBtnM, mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus}, - { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } +*/ + KEYMAP_QWERTY_FN2 + /*{ + { Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }, + { Key_Backtick, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals}, + { Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote}, + { Key_PageDn, Key_Z, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus}, + { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } }, - +*/ { - { NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey }, - { Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, NoKey, NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals}, + { Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }, + { Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_NoKey, Key_NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals}, { Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote }, { Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Return, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus}, - { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } + { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } }, { - { NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey }, - { Key_Backtick, Key_Q, mouseBtnL, mouseBtnM, mouseBtnR, Key_T, NoKey, NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals}, - { Key_PageUp, mouseL, mouseUp, mouseDn, mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote}, - { Key_PageDn, Key_Z, mouseBtnL, mouseBtnM, mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus}, - { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } + { Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }, + { Key_Backtick, Key_Q, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals}, + { Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote}, + { Key_PageDn, Key_Z, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus}, + { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } }, { - { NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey }, - { Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, NoKey, NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals}, + { Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }, + { Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_NoKey, Key_NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals}, { Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote }, { Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Return, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus}, - { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } + { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } }, { - { NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey }, - { Key_Backtick, Key_Q, mouseBtnL, mouseBtnM, mouseBtnR, Key_T, NoKey, NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals}, - { Key_PageUp, mouseL, mouseUp, mouseDn, mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote}, - { Key_PageDn, Key_Z, mouseBtnL, mouseBtnM, mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus}, - { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } + { Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }, + { Key_Backtick, Key_Q, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals}, + { Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote}, + { Key_PageDn, Key_Z, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus}, + { Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt } }, diff --git a/layouts/qwerty.conf b/layouts/qwerty.conf new file mode 100644 index 00000000..ae5b22f2 --- /dev/null +++ b/layouts/qwerty.conf @@ -0,0 +1,6 @@ +#NAME: QWERTY +skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip +` Q W E R T skip skip Y U I O P = +PageUp A S D F G Tab Return H J K L ; ' +PageDn Z X C V B Esc Enter N M , . / - +LGUI Backspace LShift LCtrl NextKeymap skip skip skip skip NextKeymap RCtrl RShift Space RAlt diff --git a/layouts/qwerty_fn2.conf b/layouts/qwerty_fn2.conf new file mode 100644 index 00000000..f36d708f --- /dev/null +++ b/layouts/qwerty_fn2.conf @@ -0,0 +1,6 @@ +#NAME: QWERTY_FN2 +skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip +` macroKey1 mouseBtnL mouseBtnM mouseBtnR T NoKey NoKey { } [ ] P = +PageUp mouseL mouseUp mouseDn mouseR G Tab Return LArrow DnArrow UpArrow RArrow ; ' +PageDn Z mouseBtnL mouseBtnM mouseBtnR B Esc Enter | M , . \ - +LGUI Backspace LShift LCtrl NextKeymap skip skip skip skip NextKeymap RCtrl RShift Space RAlt diff --git a/tools/generate_keymaps.pl b/tools/generate_keymaps.pl new file mode 100644 index 00000000..81ff38cc --- /dev/null +++ b/tools/generate_keymaps.pl @@ -0,0 +1,49 @@ +use warnings; +use strict; + +my @data = ; + +use Data::Dumper; + +my $name = 'Unnamed'; +my @map; +for my $line (@data) { + chomp($line); + if ($line =~ /^#NAME: (.*)/i) { + $name = $1; + next + } + + my @keys = split(/\s+/, $line); + push @map, join(', ', map{ 'Key_'.lookup($_).'' } @keys); +} + +print "#define KEYMAP_$name { /* Generated keymap for $name */ "; +for my $line (@map) { + print "\t{". $line ."},\\\n"; +} +print "},\n"; + +sub lookup { + +my %table = ( +'{' => 'LCurlyBracket', +'}' => 'RCurlyBracket', +'['=> 'LSquareBracket', +']'=> 'RSquareBracket', +'|'=> 'Pipe', +'\\' => 'Backslash', + + ';' => 'Semicolon', + ',' => 'Comma', + '.' => 'Period', + '/' => 'Slash', + "'" => 'Quote', + '`' => 'Backtick', + '-' => 'Minus', + '=' => 'Equals'); + + my $x = shift; + return $x unless defined $table{$x}; + return $table{$x}; +}