From 27f9bd493c50b9e57ea1e2abd25f1c0fcaeaa365 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 6 Dec 2013 13:12:15 -0500 Subject: [PATCH] add colemak support. add sticky toggling to colemak check in our generated layout files --- ArduinoKeyboard.ino | 29 +++++++++++++++++- key_defs.h | 13 ++++++++- keymaps.h | 52 ++++----------------------------- layouts-generated/colemak.h | 6 ++++ layouts-generated/colemak_fn2.h | 6 ++++ layouts-generated/qwerty.h | 6 ++++ layouts-generated/qwerty_fn2.h | 6 ++++ layouts/colemak.conf | 6 ++++ layouts/colemak_fn2.conf | 6 ++++ layouts/qwerty.conf | 4 +-- layouts/qwerty_fn2.conf | 4 +-- 11 files changed, 85 insertions(+), 53 deletions(-) create mode 100644 layouts-generated/colemak.h create mode 100644 layouts-generated/colemak_fn2.h create mode 100644 layouts-generated/qwerty.h create mode 100644 layouts-generated/qwerty_fn2.h create mode 100644 layouts/colemak.conf create mode 100644 layouts/colemak_fn2.conf diff --git a/ArduinoKeyboard.ino b/ArduinoKeyboard.ino index c2ccb430..7801ea0e 100644 --- a/ArduinoKeyboard.ino +++ b/ArduinoKeyboard.ino @@ -19,6 +19,7 @@ #include #include +#include @@ -55,6 +56,25 @@ float carriedOverY =0; #include "keymaps.h" +#define EEPROM_LAYER_LOCATION 0 + +void save_current_layer(byte layer) { + Serial.print("telling eeprom thinks we're on layer "); + Serial.println(layer); + EEPROM.write(EEPROM_LAYER_LOCATION, layer); +} + +byte load_current_layer() { + byte layer = EEPROM.read(EEPROM_LAYER_LOCATION); + Serial.print("eeprom thinks we're on layer "); + Serial.println(layer); + if (layer >= LAYERS ) { + return 0; // undefined positions get saved as 255 + } + return layer; +} + + void release_keys_not_being_pressed() { @@ -282,8 +302,14 @@ void scan_matrix() if (key_is_pressed(matrixState[row][col])) { active_layer = keymaps[current_layer][row][col].rawKey; - } + } } + else if (! (keymaps[active_layer][row][col].flags ^ ( SWITCH_TO_LAYER))) { // switch layer and stay there + if (key_toggled_on(matrixState[row][col])) { + current_layer = active_layer = keymaps[current_layer][row][col].rawKey; + save_current_layer(current_layer); } + } + } digitalWrite(rowPins[row], HIGH); } @@ -330,6 +356,7 @@ void setup() Serial.begin(115200); #endif setup_matrix(); + current_layer = load_current_layer(); } void loop() diff --git a/key_defs.h b/key_defs.h index c6fd3ffa..9b7c008c 100644 --- a/key_defs.h +++ b/key_defs.h @@ -347,5 +347,16 @@ #define META_NEXT_KEYMAP_MOMENTARY 0xFF -#define Key_NextKeymap (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 } +#define Key_Keymap0 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_0 } +#define Key_Keymap1 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_1 } +#define Key_Keymap2 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_2 } +#define Key_Keymap3 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_3 } +#define Key_Keymap4 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_4 } +#define Key_Keymap5 (Key){ KEY_FLAGS | SWITCH_TO_LAYER , LAYER_5 } +#define Key_Keymap0_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_0 } +#define Key_Keymap1_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 } +#define Key_Keymap2_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_2 } +#define Key_Keymap3_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_3 } +#define Key_Keymap4_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_4 } +#define Key_Keymap5_Momentary (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_5 } diff --git a/keymaps.h b/keymaps.h index b69815fa..82ac6aa9 100644 --- a/keymaps.h +++ b/keymaps.h @@ -1,54 +1,12 @@ #include "layouts-generated/qwerty.h" #include "layouts-generated/qwerty_fn2.h" +#include "layouts-generated/colemak.h" +#include "layouts-generated/colemak_fn2.h" static const Key keymaps[LAYERS][ROWS][COLS] = { 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, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_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 } - }, -*/ - { - { 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, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_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 } - }, - - - { - { 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, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_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 } - }, + KEYMAP_QWERTY_FN2 + KEYMAP_COLEMAK + KEYMAP_COLEMAK_FN2 diff --git a/layouts-generated/colemak.h b/layouts-generated/colemak.h new file mode 100644 index 00000000..0e97c1f8 --- /dev/null +++ b/layouts-generated/colemak.h @@ -0,0 +1,6 @@ +#define KEYMAP_COLEMAK { /* Generated keymap for COLEMAK */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\ + {Key_Backtick, Key_Q, Key_W, Key_F, Key_P, Key_G, Key_skip, Key_skip, Key_J, Key_L, Key_U, Key_Y, Key_Semicolon, Key_Equals},\ + {Key_PageUp, Key_A, Key_R, Key_S, Key_T, Key_D, Key_Tab, Key_Return, Key_H, Key_N, Key_E, Key_I, Key_O, Key_Quote},\ + {Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Keymap0, Key_K, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\ + {Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_Keymap3_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_Keymap3_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ +}, diff --git a/layouts-generated/colemak_fn2.h b/layouts-generated/colemak_fn2.h new file mode 100644 index 00000000..2da393e0 --- /dev/null +++ b/layouts-generated/colemak_fn2.h @@ -0,0 +1,6 @@ +#define KEYMAP_COLEMAK_FN2 { /* Generated keymap for COLEMAK_FN2 */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\ + {Key_Backtick, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_NoKey, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_NoKey, Key_Equals},\ + {Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_NoKey, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},\ + {Key_PageDn, Key_Keymap0, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_NoKey, Key_Esc, Key_Enter, Key_Pipe, Key_NoKey, Key_Comma, Key_Period, Key_Backslash, Key_Minus},\ + {Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NoKey, Key_skip, Key_skip, Key_skip, Key_skip, Key_NoKey, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ +}, diff --git a/layouts-generated/qwerty.h b/layouts-generated/qwerty.h new file mode 100644 index 00000000..e34d1b47 --- /dev/null +++ b/layouts-generated/qwerty.h @@ -0,0 +1,6 @@ +#define KEYMAP_QWERTY { /* Generated keymap for QWERTY */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\ + {Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_skip, Key_skip, 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_Keymap2, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\ + {Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_Keymap1_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_Keymap1_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ +}, diff --git a/layouts-generated/qwerty_fn2.h b/layouts-generated/qwerty_fn2.h new file mode 100644 index 00000000..00afba43 --- /dev/null +++ b/layouts-generated/qwerty_fn2.h @@ -0,0 +1,6 @@ +#define KEYMAP_QWERTY_FN2 { /* Generated keymap for QWERTY_FN2 */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\ + {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_Keymap2, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Enter, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},\ + {Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NoKey, Key_skip, Key_skip, Key_skip, Key_skip, Key_NoKey, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ +}, diff --git a/layouts/colemak.conf b/layouts/colemak.conf new file mode 100644 index 00000000..c1a4900d --- /dev/null +++ b/layouts/colemak.conf @@ -0,0 +1,6 @@ +#NAME: COLEMAK +skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip +` Q W F P G skip skip J L U Y ; = +PageUp A R S T D Tab Return H N E I O ' +PageDn Z X C V B Esc Keymap0 K M , . / - +LGUI Backspace LShift LCtrl Keymap3_Momentary skip skip skip skip Keymap3_Momentary RCtrl RShift Space RAlt diff --git a/layouts/colemak_fn2.conf b/layouts/colemak_fn2.conf new file mode 100644 index 00000000..2aab0762 --- /dev/null +++ b/layouts/colemak_fn2.conf @@ -0,0 +1,6 @@ +#NAME: COLEMAK_FN2 +skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip +` macroKey1 mouseBtnL mouseBtnM mouseBtnR NoKey NoKey NoKey { } [ ] NoKey = +PageUp mouseL mouseUp mouseDn mouseR NoKey Tab Return LArrow DnArrow UpArrow RArrow ; ' +PageDn Keymap0 mouseBtnL mouseBtnM mouseBtnR NoKey Esc Enter | NoKey , . \ - +LGUI Backspace LShift LCtrl NoKey skip skip skip skip NoKey RCtrl RShift Space RAlt diff --git a/layouts/qwerty.conf b/layouts/qwerty.conf index ae5b22f2..05bfa29f 100644 --- a/layouts/qwerty.conf +++ b/layouts/qwerty.conf @@ -2,5 +2,5 @@ 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 +PageDn Z X C V B Esc Keymap2 N M , . / - +LGUI Backspace LShift LCtrl Keymap1_Momentary skip skip skip skip Keymap1_Momentary RCtrl RShift Space RAlt diff --git a/layouts/qwerty_fn2.conf b/layouts/qwerty_fn2.conf index f36d708f..b83f8ee9 100644 --- a/layouts/qwerty_fn2.conf +++ b/layouts/qwerty_fn2.conf @@ -2,5 +2,5 @@ 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 +PageDn Keymap2 mouseBtnL mouseBtnM mouseBtnR B Esc Enter | M , . \ - +LGUI Backspace LShift LCtrl NoKey skip skip skip skip NoKey RCtrl RShift Space RAlt