diff options
| -rw-r--r-- | README.md | 13 | ||||
| -rw-r--r-- | common/action.c | 19 | ||||
| -rw-r--r-- | common/action.h | 5 | ||||
| -rw-r--r-- | common/keycode.h | 12 | ||||
| -rw-r--r-- | keyboard/gh60/keymap.c | 10 |
5 files changed, 39 insertions, 20 deletions
| @@ -7,7 +7,7 @@ Source code is available here: <http://github.com/tmk/tmk_keyboard> | |||
| 7 | 7 | ||
| 8 | Features | 8 | Features |
| 9 | -------- | 9 | -------- |
| 10 | * Multi-layer keymap - Multiple keyboard layouts with layer switching. | 10 | * Multi-layer Keymap - Multiple keyboard layouts with layer switching. |
| 11 | * Mouse key - Mouse control with keyboard | 11 | * Mouse key - Mouse control with keyboard |
| 12 | * System Control Key - Power Down, Sleep, Wake Up and USB Remote Wake up | 12 | * System Control Key - Power Down, Sleep, Wake Up and USB Remote Wake up |
| 13 | * Media Control Key - Volume Down/Up, Mute, Next/Prev track, Play, Stop and etc | 13 | * Media Control Key - Volume Down/Up, Mute, Next/Prev track, Play, Stop and etc |
| @@ -283,8 +283,11 @@ See `common/keycode.h`. Keycode is 8bit internal code to inidicate action perfor | |||
| 283 | 283 | ||
| 284 | ***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`. | 284 | ***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`. |
| 285 | 285 | ||
| 286 | #### 1.1 Normal key | 286 | #### 1.0 Other key |
| 287 | - `KC_NO` for no aciton | 287 | - `KC_NO` for no aciton |
| 288 | - `KC_TRNS` for transparent layer | ||
| 289 | |||
| 290 | #### 1.1 Normal key | ||
| 288 | - `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key | 291 | - `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key |
| 289 | - `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT` | 292 | - `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT` |
| 290 | - `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS` | 293 | - `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS` |
| @@ -301,7 +304,7 @@ There are 8 modifiers which has discrimination between left and right. | |||
| 301 | - `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac | 304 | - `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac |
| 302 | 305 | ||
| 303 | #### 1.3 Fn key | 306 | #### 1.3 Fn key |
| 304 | **`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.*** | 307 | `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.*** |
| 305 | 308 | ||
| 306 | #### 1.4 Mousekey | 309 | #### 1.4 Mousekey |
| 307 | - `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor | 310 | - `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor |
| @@ -359,7 +362,7 @@ This sets `default layer` into `current layer`. With this action you can return | |||
| 359 | ACTION_LAYER_SET_TAP_KEY(layer, key) | 362 | ACTION_LAYER_SET_TAP_KEY(layer, key) |
| 360 | ACTION_LAYER_SET_TAP_TOGGLE(layer) | 363 | ACTION_LAYER_SET_TAP_TOGGLE(layer) |
| 361 | 364 | ||
| 362 | `Layer Bit` action XOR bits with `current layer`. `Layer Bit` action can take 0 to 8 as argument. | 365 | `Layer Bit` action XOR given bits with `current layer`. `Layer Bit` action can take 0 to 15 as argument. |
| 363 | 366 | ||
| 364 | ACTION_LAYER_BIT(bits) | 367 | ACTION_LAYER_BIT(bits) |
| 365 | ACTION_LAYER_BIT_TOGGLE(bits) | 368 | ACTION_LAYER_BIT_TOGGLE(bits) |
| @@ -659,4 +662,4 @@ Files & Directories | |||
| 659 | License | 662 | License |
| 660 | ------- | 663 | ------- |
| 661 | Under `GPL` 2 or later. Some protocol files are under `Modified BSD License`. | 664 | Under `GPL` 2 or later. Some protocol files are under `Modified BSD License`. |
| 662 | LUFA and PJRC stack have their own license respectively. | 665 | LUFA, PJRC and V-USB stack have their own license respectively. |
diff --git a/common/action.c b/common/action.c index aadf5e16e..710300eb3 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -201,6 +201,19 @@ void action_exec(keyevent_t event) | |||
| 201 | } | 201 | } |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | static action_t get_action(key_t key) | ||
| 205 | { | ||
| 206 | action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); | ||
| 207 | |||
| 208 | /* Transparently use default layer */ | ||
| 209 | if (action.code == ACTION_TRANSPARENT) { | ||
| 210 | // TODO: layer stacking | ||
| 211 | action = keymap_get_action(default_layer, key.pos.row, key.pos.col); | ||
| 212 | debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); | ||
| 213 | } | ||
| 214 | return action; | ||
| 215 | } | ||
| 216 | |||
| 204 | static void process_action(keyrecord_t *record) | 217 | static void process_action(keyrecord_t *record) |
| 205 | { | 218 | { |
| 206 | keyevent_t event = record->event; | 219 | keyevent_t event = record->event; |
| @@ -208,8 +221,7 @@ static void process_action(keyrecord_t *record) | |||
| 208 | 221 | ||
| 209 | if (IS_NOEVENT(event)) { return; } | 222 | if (IS_NOEVENT(event)) { return; } |
| 210 | 223 | ||
| 211 | action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col); | 224 | action_t action = get_action(event.key); |
| 212 | //debug("action: "); debug_hex16(action.code); if (event.pressed) debug("d\n"); else debug("u\n"); | ||
| 213 | debug("ACTION: "); debug_action(action); debug("\n"); | 225 | debug("ACTION: "); debug_action(action); debug("\n"); |
| 214 | 226 | ||
| 215 | switch (action.kind.id) { | 227 | switch (action.kind.id) { |
| @@ -809,7 +821,8 @@ void layer_switch(uint8_t new_layer) | |||
| 809 | 821 | ||
| 810 | bool is_tap_key(key_t key) | 822 | bool is_tap_key(key_t key) |
| 811 | { | 823 | { |
| 812 | action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); | 824 | action_t action = get_action(key); |
| 825 | |||
| 813 | switch (action.kind.id) { | 826 | switch (action.kind.id) { |
| 814 | case ACT_LMODS_TAP: | 827 | case ACT_LMODS_TAP: |
| 815 | case ACT_RMODS_TAP: | 828 | case ACT_RMODS_TAP: |
diff --git a/common/action.h b/common/action.h index ac44b1a79..bb44049ad 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -106,12 +106,14 @@ Keyboard Keys | |||
| 106 | ------------- | 106 | ------------- |
| 107 | ACT_LMODS(0000): | 107 | ACT_LMODS(0000): |
| 108 | 0000|0000|000000|00 No action | 108 | 0000|0000|000000|00 No action |
| 109 | 0000|0000|000000|01 Transparent | ||
| 109 | 0000|0000| keycode Key | 110 | 0000|0000| keycode Key |
| 110 | 0000|mods|000000|00 Left mods | 111 | 0000|mods|000000|00 Left mods |
| 111 | 0000|mods| keycode Key & Left mods | 112 | 0000|mods| keycode Key & Left mods |
| 112 | 113 | ||
| 113 | ACT_RMODS(0001): | 114 | ACT_RMODS(0001): |
| 114 | 0001|0000|000000|00 No action | 115 | 0001|0000|000000|00 No action(not used) |
| 116 | 0001|0000|000000|01 Transparent(not used) | ||
| 115 | 0001|0000| keycode Key(no used) | 117 | 0001|0000| keycode Key(no used) |
| 116 | 0001|mods|000000|00 Right mods | 118 | 0001|mods|000000|00 Right mods |
| 117 | 0001|mods| keycode Key & Right mods | 119 | 0001|mods| keycode Key & Right mods |
| @@ -207,6 +209,7 @@ enum action_kind_id { | |||
| 207 | 209 | ||
| 208 | /* action utility */ | 210 | /* action utility */ |
| 209 | #define ACTION_NO 0 | 211 | #define ACTION_NO 0 |
| 212 | #define ACTION_TRANSPARENT 1 | ||
| 210 | #define ACTION(kind, param) ((kind)<<12 | (param)) | 213 | #define ACTION(kind, param) ((kind)<<12 | (param)) |
| 211 | #define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) | 214 | #define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) |
| 212 | 215 | ||
diff --git a/common/keycode.h b/common/keycode.h index 4f57a5887..364679994 100644 --- a/common/keycode.h +++ b/common/keycode.h | |||
| @@ -28,6 +28,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 28 | #define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) | 28 | #define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) |
| 29 | #define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) | 29 | #define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) |
| 30 | 30 | ||
| 31 | |||
| 32 | #define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) | ||
| 33 | #define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) | ||
| 34 | #define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) | ||
| 31 | #define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) | 35 | #define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) |
| 32 | #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) | 36 | #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) |
| 33 | #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) | 37 | #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) |
| @@ -35,10 +39,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 35 | #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) | 39 | #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) |
| 36 | #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) | 40 | #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) |
| 37 | 41 | ||
| 38 | #define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) | ||
| 39 | #define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) | ||
| 40 | #define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) | ||
| 41 | |||
| 42 | #define MOD_BIT(code) (1<<MOD_INDEX(code)) | 42 | #define MOD_BIT(code) (1<<MOD_INDEX(code)) |
| 43 | #define MOD_INDEX(code) ((code) & 0x07) | 43 | #define MOD_INDEX(code) ((code) & 0x07) |
| 44 | #define FN_BIT(code) (1<<FN_INDEX(code)) | 44 | #define FN_BIT(code) (1<<FN_INDEX(code)) |
| @@ -149,6 +149,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 149 | #define KC_WSTP KC_WWW_STOP | 149 | #define KC_WSTP KC_WWW_STOP |
| 150 | #define KC_WREF KC_WWW_REFRESH | 150 | #define KC_WREF KC_WWW_REFRESH |
| 151 | #define KC_WFAV KC_WWW_FAVORITES | 151 | #define KC_WFAV KC_WWW_FAVORITES |
| 152 | /* Transparent */ | ||
| 153 | #define KC_TRANSPARENT 1 | ||
| 154 | #define KC_TRNS KC_TRANSPARENT | ||
| 155 | |||
| 152 | 156 | ||
| 153 | 157 | ||
| 154 | /* USB HID Keyboard/Keypad Usage(0x07) */ | 158 | /* USB HID Keyboard/Keypad Usage(0x07) */ |
diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c index 7e4f945f6..39bb474c4 100644 --- a/keyboard/gh60/keymap.c +++ b/keyboard/gh60/keymap.c | |||
| @@ -166,12 +166,6 @@ static const uint16_t PROGMEM fn_actions[] = { | |||
| 166 | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { | 166 | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { |
| 167 | uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)])); | 167 | uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)])); |
| 168 | 168 | ||
| 169 | // TODO: move to action.c ? | ||
| 170 | /* Transparently use default layer */ | ||
| 171 | if (key == KC_TRANSPARENT) { | ||
| 172 | key = (pgm_read_byte(&keymaps[(default_layer)][(row)][(col)])); | ||
| 173 | } | ||
| 174 | |||
| 175 | action_t action; | 169 | action_t action; |
| 176 | switch (key) { | 170 | switch (key) { |
| 177 | case KC_A ... KC_EXSEL: | 171 | case KC_A ... KC_EXSEL: |
| @@ -199,7 +193,9 @@ action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { | |||
| 199 | action.code = ACTION_NO; | 193 | action.code = ACTION_NO; |
| 200 | } | 194 | } |
| 201 | break; | 195 | break; |
| 202 | case KC_NO ... KC_UNDEFINED: | 196 | case KC_TRNS: |
| 197 | action.code = ACTION_TRANSPARENT; | ||
| 198 | break; | ||
| 203 | default: | 199 | default: |
| 204 | action.code = ACTION_NO; | 200 | action.code = ACTION_NO; |
| 205 | break; | 201 | break; |
