Merge pull request #18 from algernon/f/keymap-refactor

Big Keymap Restructure
This commit is contained in:
László Monda
2016-12-13 14:50:04 +01:00
committed by GitHub
5 changed files with 284 additions and 158 deletions

View File

@@ -1,77 +1,205 @@
#include "default_layout.h"
#include "keyboard_layout.h"
KEYBOARD_LAYOUT(defaultKeyboardLayout)={
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_7_AND_AMPERSAND } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F7 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_8_AND_ASTERISK } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F8 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_9_AND_OPENING_PARENTHESIS } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F9 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F10 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MINUS_AND_UNDERSCORE } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F11 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_EQUAL_AND_PLUS } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F12 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_BACKSPACE } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DELETE } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_U } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_I } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_UP_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_O } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_P } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PRINT_SCREEN } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_OPENING_BRACKET_AND_OPENING_BRACE } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SCROLL_LOCK } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_CLOSING_BRACKET_AND_CLOSING_BRACE } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PAUSE } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_BACKSLASH_AND_PIPE } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_Y } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PAGE_UP } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_J } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_K } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DOWN_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_L } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SEMICOLON_AND_COLON } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_APOSTROPHE_AND_QUOTE } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_ENTER } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_H } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PAGE_DOWN } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_N } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_MUTE } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_M } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_COMMA_AND_LESS_THAN_SIGN } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DOT_AND_GREATER_THAN_SIGN } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SLASH_AND_QUESTION_MARK } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_SHIFT } }},
{Key_NoKey}, //??
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SPACE } }},
{Key_NoKey}, //??
{{.type = UHK_KEY_LAYER, .layer = { .target = LAYER_FN }}}, //Fn
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_ALT } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_GUI } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_CONTROL } }},
uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE] = {
// Layer 0
{
// Right
{
// Row 1
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_7_AND_AMPERSAND }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_8_AND_ASTERISK }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_9_AND_OPENING_PARENTHESIS }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MINUS_AND_UNDERSCORE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_EQUAL_AND_PLUS }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_BACKSPACE }},
// Row 2
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_U }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_I }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_O }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_P }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_OPENING_BRACKET_AND_OPENING_BRACE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_CLOSING_BRACKET_AND_CLOSING_BRACE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_BACKSLASH_AND_PIPE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_Y }},
// Row 3
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_J }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_K }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_L }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SEMICOLON_AND_COLON }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_APOSTROPHE_AND_QUOTE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_ENTER }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_H }},
// Row 4
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_N }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_M }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_COMMA_AND_LESS_THAN_SIGN }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DOT_AND_GREATER_THAN_SIGN }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SLASH_AND_QUESTION_MARK }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_SHIFT }},
{ .type = UHK_KEY_NONE },
// Row 5
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SPACE }},
{ .type = UHK_KEY_LAYER, .layer = { .target = LAYER_ID_MOD }},
{ .type = UHK_KEY_LAYER, .layer = { .target = LAYER_ID_FN }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_ALT }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_GUI }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_CONTROL }},
},
// Left
{
// Row 1
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_GRAVE_ACCENT_AND_TILDE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_1_AND_EXCLAMATION }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_2_AND_AT }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_3_AND_HASHMARK }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_4_AND_DOLLAR }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_5_AND_PERCENTAGE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_6_AND_CARET }},
// Row 2
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_TAB }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_Q }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_W }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_E }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_R }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_T }},
// Row 3
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_CAPS_LOCK }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_A }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_S }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_D }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_G }},
// Row 4
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_SHIFT }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_NON_US_BACKSLASH_AND_PIPE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_Z }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_X }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_C }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_V }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_B }},
// Row 5
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_CONTROL }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_GUI }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_ALT }},
{ .type = UHK_KEY_LAYER, .layer = { .target = LAYER_ID_FN }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SPACE }},
{ .type = UHK_KEY_LAYER, .layer = { .target = LAYER_ID_MOD }},
{ .type = UHK_KEY_NONE },
}
},
// Layer 1: MOD
{
// Right
{
// Row 1
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F7 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F8 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F9 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F10 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F11 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F12 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DELETE }},
// Row 2
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_UP_ARROW }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PRINT_SCREEN }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_SCROLL_LOCK }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PAUSE }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PAGE_UP }},
// Row 3
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_ARROW }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DOWN_ARROW }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_ARROW }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_PAGE_DOWN }},
// Row 4
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_MUTE }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
// Row 5
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_LAYER, .layer = { .target = LAYER_ID_MOD }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
},
// Left
{
// Row 1
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_ESCAPE }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F1 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F2 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F3 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F4 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F5 }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F6 }},
// Row 2
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_UP_ARROW }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_HOME }},
// Row 3
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_ARROW }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DOWN_ARROW }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_ARROW }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DELETE }},
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_END }},
// Row 4
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_BACKWARD }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_PLAY }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_FORWARD }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN }},
{ .type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_VOLUME_UP }},
// Row 5
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_NONE },
{ .type = UHK_KEY_LAYER, .layer = { .target = LAYER_ID_MOD }},
{ .type = UHK_KEY_NONE },
}
},
// Layer 2: FN
// Layer 3: Mouse
//Left half
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_GRAVE_ACCENT_AND_TILDE } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_ESCAPE } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_1_AND_EXCLAMATION } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F1 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_2_AND_AT } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F2 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_3_AND_HASHMARK } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F3 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_4_AND_DOLLAR } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F4 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_5_AND_PERCENTAGE } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F5 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_6_AND_CARET } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F6 } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_TAB } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_Q } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_W } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_UP_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_E } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_R } }},
{Key_NoKey}, //??
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_T } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_HOME } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_CAPS_LOCK } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_A } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_S } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DOWN_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_D } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_RIGHT_ARROW } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_F } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_DELETE } }},
{Key_NoKey}, //??
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_G } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_END } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_SHIFT } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_NON_US_BACKSLASH_AND_PIPE } }}, //no idea if this is the right one},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_Z } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_BACKWARD } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_X } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_PLAY } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_C } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_FORWARD } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_V } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_B } }, {.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_MEDIA_VOLUME_UP } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_CONTROL } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_GUI } }},
{{.type = UHK_KEY_SIMPLE, .simple = { .key = HID_KEYBOARD_SC_LEFT_ALT } }},
{{.type = UHK_KEY_LAYER, .layer = { .target = LAYER_FN }}}, //Fn
{Key_NoKey}, //??
{{.type = UHK_KEY_LAYER, .layer = { .target = LAYER_MOD }}}, //Mod
{Key_NoKey} //??
};

View File

@@ -1,9 +0,0 @@
#ifndef SRC_DEFAULT_LAYOUT_H_
#define SRC_DEFAULT_LAYOUT_H_
#include <stdint.h>
#include "keyboard_layout.h"
extern KEYBOARD_LAYOUT(defaultKeyboardLayout);
#endif

View File

@@ -1,39 +1,37 @@
#include "keyboard_layout.h"
#include "led_driver.h"
static uint8_t keyMasks[LAYOUT_KEY_COUNT];
static uint8_t keyMasks[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
static uint8_t modifierState = 0;
static inline __attribute__((always_inline)) uhk_key_t getKeycode(KEYBOARD_LAYOUT(layout), uint8_t keyId)
uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
static inline __attribute__((always_inline)) uhk_key_t getKeycode(uint8_t slotId, uint8_t keyId)
{
if (keyId < LAYOUT_KEY_COUNT) {
if (keyMasks[keyId]!=0 && keyMasks[keyId]!=modifierState) {
if (keyId < MAX_KEY_COUNT_PER_MODULE) {
if (keyMasks[slotId][keyId]!=0 && keyMasks[slotId][keyId]!=modifierState) {
// Mask out key presses after releasing modifier keys
return (uhk_key_t){.raw=0};
return (uhk_key_t){.type = UHK_KEY_NONE};
}
uhk_key_t k = layout[keyId][modifierState];
keyMasks[keyId] = modifierState;
if (k.raw == 0) {
k = layout[keyId][0];
}
uhk_key_t k = CurrentKeymap[modifierState][slotId][keyId];
keyMasks[slotId][keyId] = modifierState;
return k;
} else {
return (uhk_key_t){.raw=0};
return (uhk_key_t){.type = UHK_KEY_NONE};
}
}
static void clearKeymasks(const uint8_t *leftKeyStates, const uint8_t *rightKeyStates){
int i;
for (i=0; i<KEY_STATE_COUNT; i++){
for (i=0; i < MAX_KEY_COUNT_PER_MODULE; i++){
if (rightKeyStates[i]==0){
keyMasks[i] = 0;
keyMasks[SLOT_ID_RIGHT_KEYBOARD_HALF][i] = 0;
}
if (leftKeyStates[i]==0) {
keyMasks[LAYOUT_LEFT_OFFSET+i] = 0;
keyMasks[SLOT_ID_LEFT_KEYBOARD_HALF][i] = 0;
}
}
}
@@ -67,18 +65,32 @@ bool layerOff(uhk_key_t key) {
return false;
}
bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, uint8_t keyState) {
bool key_toggled_on(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) {
return (!prevKeyStates[keyId]) && currKeyStates[keyId];
}
bool key_is_pressed(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) {
return currKeyStates[keyId];
}
bool key_toggled_off(const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) {
return (!currKeyStates[keyId]) && prevKeyStates[keyId];
}
bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) {
switch (key.type) {
case UHK_KEY_SIMPLE:
if (keyState) {
return pressKey (key, scancodeIdx, report);
if (key_is_pressed(prevKeyStates, currKeyStates, keyId)) {
return pressKey(key, scancodeIdx, report);
}
break;
case UHK_KEY_LAYER:
if (keyState) {
if (key_toggled_on(prevKeyStates, currKeyStates, keyId)) {
return layerOn(key);
}
return layerOff(key);
if (key_toggled_off(prevKeyStates, currKeyStates, keyId)) {
return layerOff(key);
}
break;
default:
break;
@@ -86,7 +98,7 @@ bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, ui
return false;
}
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates, KEYBOARD_LAYOUT(layout)) {
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates) {
int scancodeIdx = 0;
clearKeymasks(leftKeyStates, rightKeyStates);
@@ -96,9 +108,9 @@ void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeySta
break;
}
uhk_key_t code = getKeycode(layout, keyId);
uhk_key_t code = getKeycode(SLOT_ID_RIGHT_KEYBOARD_HALF, keyId);
if (handleKey(code, scancodeIdx, report, rightKeyStates[keyId])) {
if (handleKey(code, scancodeIdx, report, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId)) {
scancodeIdx++;
}
}
@@ -108,10 +120,13 @@ void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeySta
break;
}
uhk_key_t code = getKeycode(layout, LAYOUT_LEFT_OFFSET+keyId);
uhk_key_t code = getKeycode(SLOT_ID_LEFT_KEYBOARD_HALF, keyId);
if (handleKey(code, scancodeIdx, report, leftKeyStates[keyId])) {
if (handleKey(code, scancodeIdx, report, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId)) {
scancodeIdx++;
}
}
memcpy(prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, KEY_STATE_COUNT);
memcpy(prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, KEY_STATE_COUNT);
}

View File

@@ -5,6 +5,8 @@
#include "lufa/HIDClassCommon.h"
#include "usb_composite_device.h"
#include "module.h"
// Keyboard layout is a 2D array of scan codes.
//
// First dimension is the Key ID of a given key. Key IDs are the indices of the
@@ -19,12 +21,8 @@
#define KEY_STATE_COUNT (5*7)
#define LAYOUT_KEY_COUNT 70
#define LAYOUT_MOD_COUNT 4
#define LAYOUT_LEFT_OFFSET KEY_STATE_COUNT
typedef enum {
UHK_KEY_NONE,
UHK_KEY_SIMPLE,
UHK_KEY_MOUSE,
UHK_KEY_LAYER,
@@ -35,53 +33,47 @@ typedef enum {
UHK_KEY_LPRESSLAYER,
} uhk_key_type_t;
typedef union {
struct {
typedef struct {
uint8_t type;
union {
struct {
uint8_t __unused_bits;
uint8_t mods;
uint8_t key;
} __attribute__ ((packed)) simple;
struct {
uint8_t __unused_bits;
uint8_t scrollActions; // bitfield
uint8_t moveActions; // bitfield
} __attribute__ ((packed)) mouse;
struct {
uint16_t __unused_bits;
uint8_t target;
} __attribute__ ((packed)) layer;
struct {
uint16_t __unused_bits;
uint8_t target;
} __attribute__ ((packed)) keymap;
struct {
uint8_t __unused_bits;
uint16_t index;
} __attribute__ ((packed)) macro;
struct {
uint8_t longPressMod; // single mod, or bitfield?
uint8_t mods; // for the alternate action
uint8_t key;
} __attribute__ ((packed)) longpressMod;
struct {
uint8_t longPressLayer;
uint8_t mods;
uint8_t key;
} __attribute__ ((packed)) longpressLayer;
};
} __attribute__ ((packed));
uint32_t raw;
union {
struct {
uint8_t __unused_bits;
uint8_t mods;
uint8_t key;
} __attribute__ ((packed)) simple;
struct {
uint8_t __unused_bits;
uint8_t scrollActions; // bitfield
uint8_t moveActions; // bitfield
} __attribute__ ((packed)) mouse;
struct {
uint16_t __unused_bits;
uint8_t target;
} __attribute__ ((packed)) layer;
struct {
uint16_t __unused_bits;
uint8_t target;
} __attribute__ ((packed)) keymap;
struct {
uint8_t __unused_bits;
uint16_t index;
} __attribute__ ((packed)) macro;
struct {
uint8_t longPressMod; // single mod, or bitfield?
uint8_t mods; // for the alternate action
uint8_t key;
} __attribute__ ((packed)) longpressMod;
struct {
uint8_t longPressLayer;
uint8_t mods;
uint8_t key;
} __attribute__ ((packed)) longpressLayer;
};
} __attribute__ ((packed)) uhk_key_t;
#define Key_NoKey {.raw = 0}
#define KEYBOARD_LAYOUT(name) const uhk_key_t name[LAYOUT_KEY_COUNT][LAYOUT_MOD_COUNT]
extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
extern uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
#define LAYER_MOD 1
#define LAYER_FN 2
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates, KEYBOARD_LAYOUT(layout));
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates);
#endif

View File

@@ -6,7 +6,7 @@
#include "fsl_i2c.h"
#include "i2c.h"
#include "i2c_addresses.h"
#include "default_layout.h"
#include "keyboard_layout.h"
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{
USB_KEYBOARD_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
@@ -100,7 +100,7 @@ void UsbKeyboadTask(){
readLeftKeys(leftKeyStates);
fillKeyboardReport(&UsbKeyboardReport[newLayout], leftKeyStates, keyMatrix.keyStates, defaultKeyboardLayout);
fillKeyboardReport(&UsbKeyboardReport[newLayout], leftKeyStates, keyMatrix.keyStates);
// Change to the new layout in atomic operation (int copy). Even if
// the copy is not atomic itself, only single bit changes. So it can