1
0
Fork 0
forked from forks/qmk_firmware

add my keymap

This commit is contained in:
shela 2016-08-12 21:24:43 +09:00
parent 97cd7afc32
commit 1c8d64d3b3
7 changed files with 395 additions and 0 deletions

View file

@ -0,0 +1 @@
SRC += action_pseudo_lut.c

View file

@ -0,0 +1,142 @@
#include "quantum.h"
#include "action_pseudo_lut.h"
static uint8_t send_key_shift_bit[SHIFT_BIT_SIZE];
/*
* Pseudo layout action.
* This action converts a keycode in order to output the character according to the keymap you specified
* still your keyboard layout recognized wrongly on your OS.
* Memo: Using other layer keymap to get keycode
*/
void action_pseudo_lut(keyrecord_t *record, uint8_t base_keymap_id, const uint16_t (*keymap)[2]) {
static uint8_t prev_shift;
uint16_t keycode;
uint16_t pseudo_keycode;
/* get keycode from keymap you specified */
keycode = keymap_key_to_keycode(base_keymap_id, record->event.key);
prev_shift = keyboard_report->mods & (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT));
if (record->event.pressed) {
/* when magic commands entered, keycode does not converted */
if (IS_COMMAND()) {
if (prev_shift) {
add_shift_bit(keycode);
}
register_code(keycode);
return;
}
if (prev_shift) {
pseudo_keycode = convert_keycode(keymap, keycode, true);
dprintf("pressed: %02X, converted: %04X\n", keycode, pseudo_keycode);
add_shift_bit(keycode);
if (IS_LSFT(pseudo_keycode)) {
register_code(QK_LSFT ^ pseudo_keycode);
} else {
/* delete shift mod temporarily */
del_mods(prev_shift);
send_keyboard_report();
register_code(pseudo_keycode);
add_mods(prev_shift);
send_keyboard_report();
}
} else {
pseudo_keycode = convert_keycode(keymap, keycode, false);
dprintf("pressed: %02X, converted: %04X\n", keycode, pseudo_keycode);
if (IS_LSFT(pseudo_keycode)) {
add_weak_mods(MOD_BIT(KC_LSFT));
send_keyboard_report();
register_code(QK_LSFT ^ pseudo_keycode);
/* on Windows, prevent key repeat to avoid unintended output */
unregister_code(QK_LSFT ^ pseudo_keycode);
del_weak_mods(MOD_BIT(KC_LSFT));
send_keyboard_report();
} else {
register_code(pseudo_keycode);
}
}
} else {
if (get_shift_bit(keycode)) {
del_shift_bit(keycode);
pseudo_keycode = convert_keycode(keymap, keycode, true);
} else {
pseudo_keycode = convert_keycode(keymap, keycode, false);
}
dprintf("released: %02X, converted: %04X\n", keycode, pseudo_keycode);
if (IS_LSFT(pseudo_keycode)) {
unregister_code(QK_LSFT ^ pseudo_keycode);
} else {
unregister_code(pseudo_keycode);
}
}
}
uint16_t convert_keycode(const uint16_t (*keymap)[2], uint16_t keycode, bool shift_modded)
{
uint16_t pseudo_keycode;
switch (keycode) {
case KC_A ... KC_CAPSLOCK:
#if defined(__AVR__)
if (shift_modded) {
pseudo_keycode = pgm_read_word(&keymap[keycode][1]);
} else {
pseudo_keycode = pgm_read_word(&keymap[keycode][0]);
}
#else
if (shift_modded) {
pseudo_keycode = keymap[keycode][1];
} else {
pseudo_keycode = keymap[keycode][0];
}
#endif
/* if undefined, use got keycode as it is */
if (pseudo_keycode == 0x00) {
if (shift_modded) {
pseudo_keycode = S(keycode);
} else {
pseudo_keycode = keycode;
}
}
break;
default:
if (shift_modded) {
pseudo_keycode = S(keycode);
} else {
pseudo_keycode = keycode;
}
break;
}
return pseudo_keycode;
}
uint8_t get_shift_bit(uint16_t keycode) {
if ((keycode >> 3) < SHIFT_BIT_SIZE) {
return send_key_shift_bit[keycode >> 3] & (1 << (keycode & 7));
} else {
dprintf("get_shift_bit: Can't get shift bit. keycode: %02X\n", keycode);
return 0;
}
}
void add_shift_bit(uint16_t keycode) {
if ((keycode >> 3) < SHIFT_BIT_SIZE) {
send_key_shift_bit[keycode >> 3] |= (1 << (keycode & 7));
} else {
dprintf("add_shift_bit: Can't add shift bit. keycode: %02X\n", keycode);
}
}
void del_shift_bit(uint16_t keycode) {
if ((keycode >> 3) < SHIFT_BIT_SIZE) {
send_key_shift_bit[keycode >> 3] &= ~(1 << (keycode & 7));
} else {
dprintf("del_shift_bit: Can't delete shift bit. keycode: %02X\n", keycode);
}
}

View file

@ -0,0 +1,15 @@
#ifndef ACTION_PSEUDO_LUT_H
#define ACTION_PSEUDO_LUT_H
#define SHIFT_BIT_SIZE (0xE7 / 8 + 1) // 1bit per 1key
#define IS_LSFT(kc) ((QK_LSFT & (kc)) == QK_LSFT)
void action_pseudo_lut(keyrecord_t *, uint8_t, const uint16_t (*)[2]);
uint16_t convert_keycode(const uint16_t (*)[2], uint16_t, bool);
uint8_t get_shift_bit(uint16_t);
void add_shift_bit(uint16_t);
void del_shift_bit(uint16_t);
#endif

View file

@ -0,0 +1,12 @@
#ifndef CONFIG_SHELA_H
#define CONFIG_SHELA_H
#include "../../config.h"
#undef TAPPING_TERM
#define TAPPING_TERM 230
#define ONESHOT_TAP_TOGGLE 2
#define ONESHOT_TIMEOUT 2000
#endif

View file

@ -0,0 +1,179 @@
/*
* HHKB Pro 2 US Layout for shela
*/
#include "hhkb.h"
#include "keymap_jis2us.h"
#include "action_pseudo_lut.h"
enum keymap_layout {
BASE = 0,
PSEUDO_US,
DVORAK,
MOUSE,
TENKEY,
HHKB,
SPACE_FN,
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Layer 0: Default Layer
* ,-----------------------------------------------------------------------------------------.
* | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | ` | BSp |
* |-----------------------------------------------------------------------------------------|
* | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \ |
* |-----------------------------------------------------------------------------------------|
* | Control | A | S | D | F | G | H | J | K | L | ; | ' | Enter |
* |-----------------------------------------------------------------------------------------|
* | Shift | Z | X | C | V | B | N | M | , | . | / | Shift | Fn0 |
* `-----------------------------------------------------------------------------------------'
* |LAlt | LGui | SpaceFN | RGui |RAlt |
* `-----------------------------------------------------------------'
*/
[BASE] =
KEYMAP(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_GRV, KC_BSPC, \
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, \
KC_LCTL,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_ENT, \
OSM(MOD_LSFT),KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH,KC_RSFT,KC_FN0, \
KC_LALT,KC_LGUI, KC_FN2, KC_RGUI,KC_RALT),
/* Layer 1: Pseudo US Layout Layer */
[PSEUDO_US] =
KEYMAP(KC_ESC, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_BSPC, \
KC_TAB, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, \
KC_LCTL,KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_ENT, \
OSM(MOD_LSFT),KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_FN1, KC_RSFT,KC_FN0, \
KC_LGUI,KC_FN3, KC_FN2, KC_FN4 ,KC_RGUI),
/* Layer 2: Dvorak Layer
* ,-----------------------------------------------------------------------------------------.
* | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | [ | ] | ` | BSp |
* |-----------------------------------------------------------------------------------------|
* | Tab | ' | , | . | P | Y | F | G | C | R | L | / | = | \ |
* |-----------------------------------------------------------------------------------------|
* | Control | A | O | E | U | I | D | H | T | N | S | - | Enter |
* |-----------------------------------------------------------------------------------------|
* | Shift | ; | Q | J | K | X | B | M | W | V | Z | Shift | Fn0 |
* `-----------------------------------------------------------------------------------------'
* |LAlt | LGui | SpaceFN | RGui |RAlt |
* `-----------------------------------------------------------------'
*/
[DVORAK] =
KEYMAP(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_LBRC,KC_RBRC,KC_GRV, KC_BSPC, \
KC_TAB, KC_QUOT,KC_COMM,KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_SLSH,KC_EQL, KC_BSLS, \
KC_LCTL,KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_MINS,KC_ENT, \
KC_LSFT,KC_SCLN,KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_RSFT,KC_FN0, \
KC_LALT,KC_LGUI, KC_FN2, KC_RGUI,KC_RALT),
/* Layer 3: Mouse layer
* ,-----------------------------------------------------------------------------------------.
* | Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | | |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | MwL | MwD | MwU | MwR | | | | |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | McL | McD | McU | McR | | | |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | Mb1 | Mb2 | Mb3 | | | | Fn0 |
* `-----------------------------------------------------------------------------------------'
* | | | Mb1 | | |
* `-----------------------------------------------------------------'
*/
[MOUSE] =
KEYMAP(KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NO, KC_TRNS, \
KC_TRNS,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_WH_L,KC_WH_D,KC_WH_U,KC_WH_R,KC_NO, KC_NO, KC_NO, KC_NO, \
KC_TRNS,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_MS_L,KC_MS_D,KC_MS_U,KC_MS_R,KC_NO, KC_NO, KC_TRNS, \
KC_TRNS,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_BTN1,KC_BTN2,KC_BTN3,KC_NO, KC_NO, KC_TRNS,KC_FN0, \
KC_TRNS,KC_TRNS, KC_BTN1, KC_TRNS,KC_TRNS),
/* Layer 4: Tenkey layer
* ,-----------------------------------------------------------------------------------------.
* | Esc | | | | | | | | | | / | * | - | | BSp |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | | | | 7 | 8 | 9 | + | |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | | | | 4 | 5 | 6 | Enter |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | | | 1 | 2 | 3 | + | Fn0 |
* `-----------------------------------------------------------------------------------------'
* | | | SpaceFN | 0 | . |
* `-----------------------------------------------------------------'
*/
[TENKEY] =
KEYMAP(KC_ESC, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_PSLS,KC_PAST,KC_PMNS,KC_NO, KC_BSPC, \
KC_TRNS,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_KP_7,KC_KP_8,KC_KP_9,KC_PPLS,KC_NO, \
KC_TRNS,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_KP_4,KC_KP_5,KC_KP_6,KC_PENT, \
KC_TRNS,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_KP_1,KC_KP_2,KC_KP_3,KC_PPLS,KC_FN0, \
KC_TRNS,KC_TRNS, KC_FN2, KC_KP_0,KC_PDOT),
/* Layer 5: HHKB mode (HHKB Fn)
* ,-----------------------------------------------------------------------------------------.
* | Pwr | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | Ins | Del |
* |-----------------------------------------------------------------------------------------|
* | Caps | Fn5 | Fn6 | Fn7 | Fn8 | Fn9 | | | Psc | Slk | Pus | Up | | BSp |
* |-----------------------------------------------------------------------------------------|
* | | VoD | VoU | Mut | | | * | / | Hom | PgU | Lef | Rig | Enter |
* |-----------------------------------------------------------------------------------------|
* | | | | | | | + | - | End | PgD | Dow | | |
* `-----------------------------------------------------------------------------------------'
* | | | | | |
* `-----------------------------------------------------------------'
*/
[HHKB] =
KEYMAP(KC_PWR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, \
KC_CAPS,KC_FN5, KC_FN6, KC_FN7, KC_FN8, KC_FN9, KC_TRNS,KC_TRNS,KC_PSCR,KC_SLCK,KC_PAUS,KC_UP, KC_TRNS,KC_BSPC, \
KC_TRNS,KC_VOLD,KC_VOLU,KC_MUTE,KC_TRNS,KC_TRNS,KC_PAST,KC_PSLS,KC_HOME,KC_PGUP,KC_LEFT,KC_RGHT,KC_PENT, \
KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_PPLS,KC_PMNS,KC_END, KC_PGDN,KC_DOWN,KC_TRNS,KC_TRNS, \
KC_TRNS,KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS),
/* Layer 6: SpaceFN
* ,-----------------------------------------------------------------------------------------.
* | ` | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | | Del |
* |-----------------------------------------------------------------------------------------|
* | | End | Up | Hom | | | | Hom | Up | End | Psc | Slk | Pau | Ins |
* |-----------------------------------------------------------------------------------------|
* | | Lef | Dow | Rig | PgU | | PgU | Lef | Dow | Rig | | | |
* |-----------------------------------------------------------------------------------------|
* | | | | PgD | | Spc | PgD | ` | ~ | | | | |
* `-----------------------------------------------------------------------------------------'
* | | | | | |
* `-----------------------------------------------------------------'
*/
[SPACE_FN] =
KEYMAP(KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NO, KC_DEL, \
KC_TRNS,KC_END, KC_UP, KC_HOME,KC_NO, KC_NO, KC_NO, KC_HOME,KC_UP, KC_END, KC_PSCR,KC_SLCK,KC_PAUS,KC_INS, \
KC_TRNS,KC_LEFT,KC_DOWN,KC_RGHT,KC_PGUP,KC_NO, KC_PGUP,KC_LEFT,KC_DOWN,KC_RGHT,KC_NO, KC_NO, KC_TRNS, \
KC_TRNS,KC_NO, KC_NO, KC_PGDN,KC_NO, KC_SPC, KC_PGDN,KC_GRV, KC_TILD,KC_NO, KC_NO, KC_TRNS,KC_NO, \
KC_TRNS,KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS),
};
/*
* user defined action function
*/
enum function_id {
PSEUDO_US_FUNCTION,
};
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
switch (id) {
case PSEUDO_US_FUNCTION:
action_pseudo_lut(record, BASE, keymap_jis2us);
break;
}
}
/*
* Fn action definition
*/
const uint16_t PROGMEM fn_actions[] = {
[0] = ACTION_LAYER_MOMENTARY(HHKB),
[1] = ACTION_FUNCTION(PSEUDO_US_FUNCTION),
[2] = ACTION_LAYER_TAP_KEY(SPACE_FN, KC_SPACE),
[3] = ACTION_MODS_TAP_KEY(MOD_LALT, KC_MHEN),
[4] = ACTION_MODS_TAP_KEY(MOD_RALT, KC_KANA),
[5] = ACTION_DEFAULT_LAYER_SET(BASE),
[6] = ACTION_DEFAULT_LAYER_SET(PSEUDO_US),
[7] = ACTION_DEFAULT_LAYER_SET(MOUSE),
[8] = ACTION_DEFAULT_LAYER_SET(TENKEY),
[9] = ACTION_DEFAULT_LAYER_SET(DVORAK),
};

View file

@ -0,0 +1,32 @@
#ifndef KEYMAP_JIS2US_H
#define KEYMAP_JIS2US_H
/* keymap for convert from JIS to US */
const uint16_t PROGMEM keymap_jis2us[][2] = {
[KC_A ... KC_CAPS] = { 0x00, 0x00 }, /* default value */
[KC_1] = { KC_1, KC_EXLM }, /* 1 and ! -> 1 and ! */
[KC_2] = { KC_2, KC_LBRC }, /* 2 and " -> 2 and @ */
[KC_3] = { KC_3, KC_HASH }, /* 3 and # -> 3 and # */
[KC_4] = { KC_4, KC_DLR }, /* 4 and $ -> 4 and $ */
[KC_5] = { KC_5, KC_PERC }, /* 5 and % -> 5 and % */
[KC_6] = { KC_6, KC_EQL }, /* 6 and & -> 6 and ^ */
[KC_7] = { KC_7, KC_CIRC }, /* 7 and ' -> 7 and & */
[KC_8] = { KC_8, KC_DQT }, /* 8 and ( -> 8 and * */
[KC_9] = { KC_9, KC_ASTR }, /* 9 and ) -> 9 and ( */
[KC_0] = { KC_0, KC_LPRN }, /* 0 and (no assign) -> 0 and ) */
[KC_MINS] = { KC_MINS, S(KC_RO) }, /* - and = -> - and _ */
[KC_EQL] = { KC_UNDS, KC_COLN }, /* ^ and ~ -> = and + */
[KC_LBRC] = { KC_RBRC, KC_RCBR }, /* @ and ` -> [ and { */
[KC_RBRC] = { KC_BSLS, KC_PIPE }, /* [ and { -> ] and } */
[KC_BSLS] = { KC_JYEN, S(KC_JYEN) }, /* ] and } -> / and | */
[KC_NUHS] = { KC_NUHS, S(KC_NUHS) }, /* (no assign) */
[KC_SCLN] = { KC_SCLN, KC_QUOT }, /* ; and + -> ; and : */
[KC_QUOT] = { KC_AMPR, KC_AT }, /* : and * -> ' and " */
[KC_GRV] = { KC_LCBR, KC_PLUS }, /* (no assign) -> ` and ~ */
[KC_COMM] = { KC_COMM, KC_LT }, /* , and < -> , and < */
[KC_DOT] = { KC_DOT, KC_GT }, /* . and > -> . and > */
[KC_SLSH] = { KC_SLSH, KC_QUES }, /* / and ? -> / and ? */
};
#endif

View file

@ -0,0 +1,14 @@
# Shela's HHKB Layout
Layer 0: US Layout
Layer 1: Pseudo US Layout
Layer 2: Dvorak Layout
Layer 3: Mouse
Layer 4: Tenkey
Layer 5: HHKB Fn Key
Layer 6: SpaceFN
## Pseudo US Layout
On japanese Windows, HHKB Professional 2 US layout model recognized wrongly as JIS layout without changing OS settings.
But, you can use HHKB like a US layout keyboard as it is.