diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/action.c | 14 | ||||
| -rw-r--r-- | common/action.h | 200 | ||||
| -rw-r--r-- | common/keymap.c | 11 | ||||
| -rw-r--r-- | common/keymap.h | 17 |
4 files changed, 118 insertions, 124 deletions
diff --git a/common/action.c b/common/action.c index 710300eb3..840d70f34 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -26,6 +26,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 26 | #include "action.h" | 26 | #include "action.h" |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | /* default layer indicates base layer */ | ||
| 30 | uint8_t default_layer = 0; | ||
| 31 | /* current layer indicates active layer at this time */ | ||
| 32 | uint8_t current_layer = 0; | ||
| 33 | |||
| 34 | |||
| 29 | static void process_action(keyrecord_t *record); | 35 | static void process_action(keyrecord_t *record); |
| 30 | static bool process_tapping(keyrecord_t *record); | 36 | static bool process_tapping(keyrecord_t *record); |
| 31 | static void waiting_buffer_scan_tap(void); | 37 | static void waiting_buffer_scan_tap(void); |
| @@ -203,12 +209,12 @@ void action_exec(keyevent_t event) | |||
| 203 | 209 | ||
| 204 | static action_t get_action(key_t key) | 210 | static action_t get_action(key_t key) |
| 205 | { | 211 | { |
| 206 | action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); | 212 | action_t action = action_for_key(current_layer, key); |
| 207 | 213 | ||
| 208 | /* Transparently use default layer */ | 214 | /* Transparently use default layer */ |
| 209 | if (action.code == ACTION_TRANSPARENT) { | 215 | if (action.code == ACTION_TRANSPARENT) { |
| 210 | // TODO: layer stacking | 216 | // TODO: layer stacking |
| 211 | action = keymap_get_action(default_layer, key.pos.row, key.pos.col); | 217 | action = action_for_key(default_layer, key); |
| 212 | debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); | 218 | debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); |
| 213 | } | 219 | } |
| 214 | return action; | 220 | return action; |
| @@ -509,12 +515,12 @@ static void process_action(keyrecord_t *record) | |||
| 509 | 515 | ||
| 510 | /* Extentions */ | 516 | /* Extentions */ |
| 511 | case ACT_MACRO: | 517 | case ACT_MACRO: |
| 518 | // TODO | ||
| 512 | break; | 519 | break; |
| 513 | case ACT_COMMAND: | 520 | case ACT_COMMAND: |
| 514 | break; | 521 | break; |
| 515 | case ACT_FUNCTION: | 522 | case ACT_FUNCTION: |
| 516 | // TODO | 523 | action_function(record, action.func.id, action.func.opt); |
| 517 | keymap_call_function(record, action.func.id, action.func.opt); | ||
| 518 | break; | 524 | break; |
| 519 | default: | 525 | default: |
| 520 | break; | 526 | break; |
diff --git a/common/action.h b/common/action.h index bb44049ad..b9a6cb5b4 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -21,10 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | #include "keycode.h" | 21 | #include "keycode.h" |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | /* Execute action per keyevent */ | ||
| 25 | void action_exec(keyevent_t event); | ||
| 26 | |||
| 27 | |||
| 28 | /* Struct to record event and tap count */ | 24 | /* Struct to record event and tap count */ |
| 29 | typedef struct { | 25 | typedef struct { |
| 30 | keyevent_t event; | 26 | keyevent_t event; |
| @@ -33,7 +29,7 @@ typedef struct { | |||
| 33 | 29 | ||
| 34 | /* Action struct. | 30 | /* Action struct. |
| 35 | * | 31 | * |
| 36 | * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15). | 32 | * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15). |
| 37 | * AVR looks like a little endian in avr-gcc. | 33 | * AVR looks like a little endian in avr-gcc. |
| 38 | * | 34 | * |
| 39 | * NOTE: not portable across compiler/endianness? | 35 | * NOTE: not portable across compiler/endianness? |
| @@ -79,6 +75,21 @@ typedef union { | |||
| 79 | } action_t; | 75 | } action_t; |
| 80 | 76 | ||
| 81 | 77 | ||
| 78 | |||
| 79 | /* layer used currently */ | ||
| 80 | extern uint8_t current_layer; | ||
| 81 | /* layer to return or start with */ | ||
| 82 | extern uint8_t default_layer; | ||
| 83 | |||
| 84 | /* Execute action per keyevent */ | ||
| 85 | void action_exec(keyevent_t event); | ||
| 86 | |||
| 87 | /* action for key */ | ||
| 88 | action_t action_for_key(uint8_t layer, key_t key); | ||
| 89 | |||
| 90 | /* user defined special function */ | ||
| 91 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); | ||
| 92 | |||
| 82 | /* | 93 | /* |
| 83 | * Utilities for actions. | 94 | * Utilities for actions. |
| 84 | */ | 95 | */ |
| @@ -96,98 +107,97 @@ bool waiting_buffer_has_anykey_pressed(void); | |||
| 96 | 107 | ||
| 97 | 108 | ||
| 98 | 109 | ||
| 99 | |||
| 100 | /* | 110 | /* |
| 101 | * Action codes | 111 | * Action codes |
| 102 | * ============ | 112 | * ============ |
| 103 | * 16bit code: action_kind(4bit) + action_parameter(12bit) | 113 | * 16bit code: action_kind(4bit) + action_parameter(12bit) |
| 104 | * | 114 | * |
| 105 | Keyboard Keys | 115 | * Keyboard Keys |
| 106 | ------------- | 116 | * ------------- |
| 107 | ACT_LMODS(0000): | 117 | * ACT_LMODS(0000): |
| 108 | 0000|0000|000000|00 No action | 118 | * 0000|0000|000000|00 No action |
| 109 | 0000|0000|000000|01 Transparent | 119 | * 0000|0000|000000|01 Transparent |
| 110 | 0000|0000| keycode Key | 120 | * 0000|0000| keycode Key |
| 111 | 0000|mods|000000|00 Left mods | 121 | * 0000|mods|000000|00 Left mods |
| 112 | 0000|mods| keycode Key & Left mods | 122 | * 0000|mods| keycode Key & Left mods |
| 113 | 123 | * | |
| 114 | ACT_RMODS(0001): | 124 | * ACT_RMODS(0001): |
| 115 | 0001|0000|000000|00 No action(not used) | 125 | * 0001|0000|000000|00 No action(not used) |
| 116 | 0001|0000|000000|01 Transparent(not used) | 126 | * 0001|0000|000000|01 Transparent(not used) |
| 117 | 0001|0000| keycode Key(no used) | 127 | * 0001|0000| keycode Key(no used) |
| 118 | 0001|mods|000000|00 Right mods | 128 | * 0001|mods|000000|00 Right mods |
| 119 | 0001|mods| keycode Key & Right mods | 129 | * 0001|mods| keycode Key & Right mods |
| 120 | 130 | * | |
| 121 | ACT_LMODS_TAP(0010): | 131 | * ACT_LMODS_TAP(0010): |
| 122 | 0010|mods|000000|00 Left mods OneShot | 132 | * 0010|mods|000000|00 Left mods OneShot |
| 123 | 0010|mods|000000|01 (reserved) | 133 | * 0010|mods|000000|01 (reserved) |
| 124 | 0010|mods|000000|10 (reserved) | 134 | * 0010|mods|000000|10 (reserved) |
| 125 | 0010|mods|000000|11 (reserved) | 135 | * 0010|mods|000000|11 (reserved) |
| 126 | 0010|mods| keycode Left mods + tap Key | 136 | * 0010|mods| keycode Left mods + tap Key |
| 127 | 137 | * | |
| 128 | ACT_RMODS_TAP(0011): | 138 | * ACT_RMODS_TAP(0011): |
| 129 | 0011|mods|000000|00 Right mods OneShot | 139 | * 0011|mods|000000|00 Right mods OneShot |
| 130 | 0011|mods|000000|01 (reserved) | 140 | * 0011|mods|000000|01 (reserved) |
| 131 | 0011|mods|000000|10 (reserved) | 141 | * 0011|mods|000000|10 (reserved) |
| 132 | 0011|mods|000000|11 (reserved) | 142 | * 0011|mods|000000|11 (reserved) |
| 133 | 0011|mods| keycode Right mods + tap Key | 143 | * 0011|mods| keycode Right mods + tap Key |
| 134 | 144 | * | |
| 135 | 145 | * | |
| 136 | Other HID Usage | 146 | * Other HID Usage |
| 137 | --------------- | 147 | * --------------- |
| 138 | This action handles other usages than keyboard. | 148 | * This action handles other usages than keyboard. |
| 139 | ACT_USAGE(0100): | 149 | * ACT_USAGE(0100): |
| 140 | 0100|00| usage(10) System control(0x80) - General Desktop page(0x01) | 150 | * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01) |
| 141 | 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C) | 151 | * 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C) |
| 142 | 0100|10| usage(10) (reserved) | 152 | * 0100|10| usage(10) (reserved) |
| 143 | 0100|11| usage(10) (reserved) | 153 | * 0100|11| usage(10) (reserved) |
| 144 | 154 | * | |
| 145 | 155 | * | |
| 146 | Mouse Keys | 156 | * Mouse Keys |
| 147 | ---------- | 157 | * ---------- |
| 148 | TODO: can be combined with 'Other HID Usage'? to save action kind id. | 158 | * TODO: can be combined with 'Other HID Usage'? to save action kind id. |
| 149 | ACT_MOUSEKEY(0110): | 159 | * ACT_MOUSEKEY(0110): |
| 150 | 0101|XXXX| keycode Mouse key | 160 | * 0101|XXXX| keycode Mouse key |
| 151 | 161 | * | |
| 152 | 162 | * | |
| 153 | Layer Actions | 163 | * Layer Actions |
| 154 | ------------- | 164 | * ------------- |
| 155 | ACT_LAYER(1000): Set layer | 165 | * ACT_LAYER(1000): Set layer |
| 156 | ACT_LAYER_BIT(1001): Bit-op layer | 166 | * ACT_LAYER_BIT(1001): Bit-op layer |
| 157 | 167 | * | |
| 158 | 1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary) | 168 | * 1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary) |
| 159 | 1000|LLLL|0000 0001 set L to layer on press | 169 | * 1000|LLLL|0000 0001 set L to layer on press |
| 160 | 1000|LLLL|0000 0010 set L to layer on release | 170 | * 1000|LLLL|0000 0010 set L to layer on release |
| 161 | 1000|----|0000 0011 set default to layer on both(return to default layer) | 171 | * 1000|----|0000 0011 set default to layer on both(return to default layer) |
| 162 | 1000|LLLL| keycode set L to layer while hold and send key on tap | 172 | * 1000|LLLL| keycode set L to layer while hold and send key on tap |
| 163 | 1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps | 173 | * 1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps |
| 164 | 1000|LLLL|1111 1111 set L to default and layer(on press) | 174 | * 1000|LLLL|1111 1111 set L to default and layer(on press) |
| 165 | 175 | * | |
| 166 | 1001|BBBB|0000 0000 (not used) | 176 | * 1001|BBBB|0000 0000 (not used) |
| 167 | 1001|BBBB|0000 0001 bit-xor layer with B on press | 177 | * 1001|BBBB|0000 0001 bit-xor layer with B on press |
| 168 | 1001|BBBB|0000 0010 bit-xor layer with B on release | 178 | * 1001|BBBB|0000 0010 bit-xor layer with B on release |
| 169 | 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary) | 179 | * 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary) |
| 170 | 1001|BBBB| keycode bit-xor layer with B while hold and send key on tap | 180 | * 1001|BBBB| keycode bit-xor layer with B while hold and send key on tap |
| 171 | 1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps | 181 | * 1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps |
| 172 | 1001|BBBB|1111 1111 bit-xor default with B and set layer(on press) | 182 | * 1001|BBBB|1111 1111 bit-xor default with B and set layer(on press) |
| 173 | 183 | * | |
| 174 | 184 | * | |
| 175 | 185 | * | |
| 176 | Extensions(11XX) | 186 | * Extensions(11XX) |
| 177 | ---------------- | 187 | * ---------------- |
| 178 | NOTE: NOT FIXED | 188 | * NOTE: NOT FIXED |
| 179 | 189 | * | |
| 180 | ACT_MACRO(1100): | 190 | * ACT_MACRO(1100): |
| 181 | 1100|opt | id(8) Macro play? | 191 | * 1100|opt | id(8) Macro play? |
| 182 | 1100|1111| id(8) Macro record? | 192 | * 1100|1111| id(8) Macro record? |
| 183 | 193 | * | |
| 184 | ACT_COMMAND(1110): | 194 | * ACT_COMMAND(1110): |
| 185 | 1110|opt | id(8) Built-in Command exec | 195 | * 1110|opt | id(8) Built-in Command exec |
| 186 | 196 | * | |
| 187 | ACT_FUNCTION(1111): | 197 | * ACT_FUNCTION(1111): |
| 188 | 1111| address(12) Function? | 198 | * 1111| address(12) Function? |
| 189 | 1111|opt | id(8) Function? | 199 | * 1111|opt | id(8) Function? |
| 190 | 200 | * | |
| 191 | */ | 201 | */ |
| 192 | enum action_kind_id { | 202 | enum action_kind_id { |
| 193 | ACT_LMODS = 0b0000, | 203 | ACT_LMODS = 0b0000, |
| @@ -241,7 +251,7 @@ enum mods_codes { | |||
| 241 | #define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) | 251 | #define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) |
| 242 | 252 | ||
| 243 | 253 | ||
| 244 | /* | 254 | /* |
| 245 | * Switch layer | 255 | * Switch layer |
| 246 | */ | 256 | */ |
| 247 | enum layer_codes { | 257 | enum layer_codes { |
| @@ -258,7 +268,7 @@ enum layer_vals_default { | |||
| 258 | DEFAULT_ON_BOTH = 3, | 268 | DEFAULT_ON_BOTH = 3, |
| 259 | }; | 269 | }; |
| 260 | 270 | ||
| 261 | /* | 271 | /* |
| 262 | * return to default layer | 272 | * return to default layer |
| 263 | */ | 273 | */ |
| 264 | #define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R | 274 | #define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R |
| @@ -288,7 +298,7 @@ enum layer_vals_default { | |||
| 288 | /* set default layer on both press and release */ | 298 | /* set default layer on both press and release */ |
| 289 | #define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT) | 299 | #define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT) |
| 290 | 300 | ||
| 291 | /* | 301 | /* |
| 292 | * Bit-op layer | 302 | * Bit-op layer |
| 293 | */ | 303 | */ |
| 294 | /* bit-xor on both press and release */ | 304 | /* bit-xor on both press and release */ |
diff --git a/common/keymap.c b/common/keymap.c index 2782ea9d6..6bae17f99 100644 --- a/common/keymap.c +++ b/common/keymap.c | |||
| @@ -20,11 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 20 | #include "action.h" | 20 | #include "action.h" |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | /* layer */ | ||
| 24 | uint8_t default_layer = 0; | ||
| 25 | uint8_t current_layer = 0; | ||
| 26 | |||
| 27 | |||
| 28 | action_t keymap_keycode_to_action(uint8_t keycode) | 23 | action_t keymap_keycode_to_action(uint8_t keycode) |
| 29 | { | 24 | { |
| 30 | action_t action; | 25 | action_t action; |
| @@ -60,10 +55,10 @@ action_t keymap_keycode_to_action(uint8_t keycode) | |||
| 60 | #ifndef NO_LEGACY_KEYMAP_SUPPORT | 55 | #ifndef NO_LEGACY_KEYMAP_SUPPORT |
| 61 | /* legacy support with weak reference */ | 56 | /* legacy support with weak reference */ |
| 62 | __attribute__ ((weak)) | 57 | __attribute__ ((weak)) |
| 63 | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) | 58 | action_t action_for_key(uint8_t layer, key_t key) |
| 64 | { | 59 | { |
| 65 | /* convert from legacy keycode to action */ | 60 | /* convert from legacy keycode to action */ |
| 66 | uint8_t keycode = keymap_get_keycode(layer, row, col); | 61 | uint8_t keycode = keymap_get_keycode(layer, key.pos.row, key.pos.col); |
| 67 | action_t action; | 62 | action_t action; |
| 68 | switch (keycode) { | 63 | switch (keycode) { |
| 69 | case KC_FN0 ... KC_FN31: | 64 | case KC_FN0 ... KC_FN31: |
| @@ -84,6 +79,6 @@ action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) | |||
| 84 | #endif | 79 | #endif |
| 85 | 80 | ||
| 86 | __attribute__ ((weak)) | 81 | __attribute__ ((weak)) |
| 87 | void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt) | 82 | void action_function(keyrecord_t *event, uint8_t id, uint8_t opt) |
| 88 | { | 83 | { |
| 89 | } | 84 | } |
diff --git a/common/keymap.h b/common/keymap.h index ee36eab83..63bf14482 100644 --- a/common/keymap.h +++ b/common/keymap.h | |||
| @@ -23,13 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 23 | #include "action.h" | 23 | #include "action.h" |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | // TODO: move to action.h? | ||
| 27 | /* layer used currently */ | ||
| 28 | extern uint8_t current_layer; | ||
| 29 | /* layer to return or start with */ | ||
| 30 | extern uint8_t default_layer; | ||
| 31 | |||
| 32 | |||
| 33 | /* translates key_t to keycode */ | 26 | /* translates key_t to keycode */ |
| 34 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); | 27 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); |
| 35 | /* translates keycode to action */ | 28 | /* translates keycode to action */ |
| @@ -38,22 +31,12 @@ action_t keymap_keycode_to_action(uint8_t keycode); | |||
| 38 | action_t keymap_fn_to_action(uint8_t keycode); | 31 | action_t keymap_fn_to_action(uint8_t keycode); |
| 39 | 32 | ||
| 40 | 33 | ||
| 41 | /* action for key */ | ||
| 42 | // TODO: should use struct key_t? move to action.h? | ||
| 43 | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col); | ||
| 44 | |||
| 45 | /* user defined special function */ | ||
| 46 | void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt); | ||
| 47 | |||
| 48 | |||
| 49 | 34 | ||
| 50 | #ifndef NO_LEGACY_KEYMAP_SUPPORT | 35 | #ifndef NO_LEGACY_KEYMAP_SUPPORT |
| 51 | /* keycode of key */ | 36 | /* keycode of key */ |
| 52 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); | 37 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); |
| 53 | |||
| 54 | /* layer to move during press Fn key */ | 38 | /* layer to move during press Fn key */ |
| 55 | uint8_t keymap_fn_layer(uint8_t fn_bits); | 39 | uint8_t keymap_fn_layer(uint8_t fn_bits); |
| 56 | |||
| 57 | /* keycode to send when release Fn key without using */ | 40 | /* keycode to send when release Fn key without using */ |
| 58 | uint8_t keymap_fn_keycode(uint8_t fn_bits); | 41 | uint8_t keymap_fn_keycode(uint8_t fn_bits); |
| 59 | #endif | 42 | #endif |
