Features | Features | ||||
-------- | -------- | ||||
* Multi-layer keymap - Multiple keyboard layouts with layer switching. | |||||
* Multi-layer Keymap - Multiple keyboard layouts with layer switching. | |||||
* Mouse key - Mouse control with keyboard | * Mouse key - Mouse control with keyboard | ||||
* System Control Key - Power Down, Sleep, Wake Up and USB Remote Wake up | * System Control Key - Power Down, Sleep, Wake Up and USB Remote Wake up | ||||
* Media Control Key - Volume Down/Up, Mute, Next/Prev track, Play, Stop and etc | * Media Control Key - Volume Down/Up, Mute, Next/Prev track, Play, Stop and etc | ||||
***In `KEYMAP` definition you need to omit prefix part `KC_` of keycode to keep keymap compact.*** For example, just use `A` instead you place `KC_A` in `KEYMAP`. Some keycodes has 4-letter short name in addition to descriptive name, you'll prefer short one in `KEYMAP`. | ***In `KEYMAP` definition you need to omit prefix part `KC_` of keycode to keep keymap compact.*** For example, just use `A` instead you place `KC_A` in `KEYMAP`. Some keycodes has 4-letter short name in addition to descriptive name, you'll prefer short one in `KEYMAP`. | ||||
#### 1.1 Normal key | |||||
#### 1.0 Other key | |||||
- `KC_NO` for no aciton | - `KC_NO` for no aciton | ||||
- `KC_TRNS` for transparent layer | |||||
#### 1.1 Normal key | |||||
- `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key | - `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key | ||||
- `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT` | - `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT` | ||||
- `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS` | - `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS` | ||||
- `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac | - `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac | ||||
#### 1.3 Fn key | #### 1.3 Fn key | ||||
**`KC_FNnn`** are `Fn` keys which not given any action at the beginning unlike most of keycodes has its own action. To use these keys in `KEYMAP` you need to assign action you want at first. Action of `Fn` is defined in `fn_actions[]` and index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` designates action defined in first element of the array. ***32 `Fn` keys can be defined at most.*** | |||||
`KC_FNnn` are `Fn` keys which not given any action at the beginning unlike most of keycodes has its own action. To use these keys in `KEYMAP` you need to assign action you want at first. Action of `Fn` is defined in `fn_actions[]` and index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` designates action defined in first element of the array. ***32 `Fn` keys can be defined at most.*** | |||||
#### 1.4 Mousekey | #### 1.4 Mousekey | ||||
- `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor | - `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor | ||||
ACTION_LAYER_SET_TAP_KEY(layer, key) | ACTION_LAYER_SET_TAP_KEY(layer, key) | ||||
ACTION_LAYER_SET_TAP_TOGGLE(layer) | ACTION_LAYER_SET_TAP_TOGGLE(layer) | ||||
`Layer Bit` action XOR bits with `current layer`. `Layer Bit` action can take 0 to 8 as argument. | |||||
`Layer Bit` action XOR given bits with `current layer`. `Layer Bit` action can take 0 to 15 as argument. | |||||
ACTION_LAYER_BIT(bits) | ACTION_LAYER_BIT(bits) | ||||
ACTION_LAYER_BIT_TOGGLE(bits) | ACTION_LAYER_BIT_TOGGLE(bits) | ||||
License | License | ||||
------- | ------- | ||||
Under `GPL` 2 or later. Some protocol files are under `Modified BSD License`. | Under `GPL` 2 or later. Some protocol files are under `Modified BSD License`. | ||||
LUFA and PJRC stack have their own license respectively. | |||||
LUFA, PJRC and V-USB stack have their own license respectively. |
} | } | ||||
} | } | ||||
static action_t get_action(key_t key) | |||||
{ | |||||
action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); | |||||
/* Transparently use default layer */ | |||||
if (action.code == ACTION_TRANSPARENT) { | |||||
// TODO: layer stacking | |||||
action = keymap_get_action(default_layer, key.pos.row, key.pos.col); | |||||
debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); | |||||
} | |||||
return action; | |||||
} | |||||
static void process_action(keyrecord_t *record) | static void process_action(keyrecord_t *record) | ||||
{ | { | ||||
keyevent_t event = record->event; | keyevent_t event = record->event; | ||||
if (IS_NOEVENT(event)) { return; } | if (IS_NOEVENT(event)) { return; } | ||||
action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col); | |||||
//debug("action: "); debug_hex16(action.code); if (event.pressed) debug("d\n"); else debug("u\n"); | |||||
action_t action = get_action(event.key); | |||||
debug("ACTION: "); debug_action(action); debug("\n"); | debug("ACTION: "); debug_action(action); debug("\n"); | ||||
switch (action.kind.id) { | switch (action.kind.id) { | ||||
bool is_tap_key(key_t key) | bool is_tap_key(key_t key) | ||||
{ | { | ||||
action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); | |||||
action_t action = get_action(key); | |||||
switch (action.kind.id) { | switch (action.kind.id) { | ||||
case ACT_LMODS_TAP: | case ACT_LMODS_TAP: | ||||
case ACT_RMODS_TAP: | case ACT_RMODS_TAP: |
------------- | ------------- | ||||
ACT_LMODS(0000): | ACT_LMODS(0000): | ||||
0000|0000|000000|00 No action | 0000|0000|000000|00 No action | ||||
0000|0000|000000|01 Transparent | |||||
0000|0000| keycode Key | 0000|0000| keycode Key | ||||
0000|mods|000000|00 Left mods | 0000|mods|000000|00 Left mods | ||||
0000|mods| keycode Key & Left mods | 0000|mods| keycode Key & Left mods | ||||
ACT_RMODS(0001): | ACT_RMODS(0001): | ||||
0001|0000|000000|00 No action | |||||
0001|0000|000000|00 No action(not used) | |||||
0001|0000|000000|01 Transparent(not used) | |||||
0001|0000| keycode Key(no used) | 0001|0000| keycode Key(no used) | ||||
0001|mods|000000|00 Right mods | 0001|mods|000000|00 Right mods | ||||
0001|mods| keycode Key & Right mods | 0001|mods| keycode Key & Right mods | ||||
/* action utility */ | /* action utility */ | ||||
#define ACTION_NO 0 | #define ACTION_NO 0 | ||||
#define ACTION_TRANSPARENT 1 | |||||
#define ACTION(kind, param) ((kind)<<12 | (param)) | #define ACTION(kind, param) ((kind)<<12 | (param)) | ||||
#define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) | #define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) | ||||
#define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) | #define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) | ||||
#define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) | #define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) | ||||
#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) | |||||
#define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) | |||||
#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) | |||||
#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) | #define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) | ||||
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) | #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) | ||||
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) | #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) | ||||
#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) | #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) | ||||
#define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) | #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) | ||||
#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) | |||||
#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) | |||||
#define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) | |||||
#define MOD_BIT(code) (1<<MOD_INDEX(code)) | #define MOD_BIT(code) (1<<MOD_INDEX(code)) | ||||
#define MOD_INDEX(code) ((code) & 0x07) | #define MOD_INDEX(code) ((code) & 0x07) | ||||
#define FN_BIT(code) (1<<FN_INDEX(code)) | #define FN_BIT(code) (1<<FN_INDEX(code)) | ||||
#define KC_WSTP KC_WWW_STOP | #define KC_WSTP KC_WWW_STOP | ||||
#define KC_WREF KC_WWW_REFRESH | #define KC_WREF KC_WWW_REFRESH | ||||
#define KC_WFAV KC_WWW_FAVORITES | #define KC_WFAV KC_WWW_FAVORITES | ||||
/* Transparent */ | |||||
#define KC_TRANSPARENT 1 | |||||
#define KC_TRNS KC_TRANSPARENT | |||||
/* USB HID Keyboard/Keypad Usage(0x07) */ | /* USB HID Keyboard/Keypad Usage(0x07) */ |
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { | ||||
uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)])); | uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)])); | ||||
// TODO: move to action.c ? | |||||
/* Transparently use default layer */ | |||||
if (key == KC_TRANSPARENT) { | |||||
key = (pgm_read_byte(&keymaps[(default_layer)][(row)][(col)])); | |||||
} | |||||
action_t action; | action_t action; | ||||
switch (key) { | switch (key) { | ||||
case KC_A ... KC_EXSEL: | case KC_A ... KC_EXSEL: | ||||
action.code = ACTION_NO; | action.code = ACTION_NO; | ||||
} | } | ||||
break; | break; | ||||
case KC_NO ... KC_UNDEFINED: | |||||
case KC_TRNS: | |||||
action.code = ACTION_TRANSPARENT; | |||||
break; | |||||
default: | default: | ||||
action.code = ACTION_NO; | action.code = ACTION_NO; | ||||
break; | break; |