aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/action.c14
-rw-r--r--common/action.h200
-rw-r--r--common/keymap.c11
-rw-r--r--common/keymap.h17
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 */
30uint8_t default_layer = 0;
31/* current layer indicates active layer at this time */
32uint8_t current_layer = 0;
33
34
29static void process_action(keyrecord_t *record); 35static void process_action(keyrecord_t *record);
30static bool process_tapping(keyrecord_t *record); 36static bool process_tapping(keyrecord_t *record);
31static void waiting_buffer_scan_tap(void); 37static void waiting_buffer_scan_tap(void);
@@ -203,12 +209,12 @@ void action_exec(keyevent_t event)
203 209
204static action_t get_action(key_t key) 210static 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 */
25void action_exec(keyevent_t event);
26
27
28/* Struct to record event and tap count */ 24/* Struct to record event and tap count */
29typedef struct { 25typedef 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 */
80extern uint8_t current_layer;
81/* layer to return or start with */
82extern uint8_t default_layer;
83
84/* Execute action per keyevent */
85void action_exec(keyevent_t event);
86
87/* action for key */
88action_t action_for_key(uint8_t layer, key_t key);
89
90/* user defined special function */
91void 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 *
105Keyboard Keys 115 * Keyboard Keys
106------------- 116 * -------------
107ACT_LMODS(0000): 117 * ACT_LMODS(0000):
1080000|0000|000000|00 No action 118 * 0000|0000|000000|00 No action
1090000|0000|000000|01 Transparent 119 * 0000|0000|000000|01 Transparent
1100000|0000| keycode Key 120 * 0000|0000| keycode Key
1110000|mods|000000|00 Left mods 121 * 0000|mods|000000|00 Left mods
1120000|mods| keycode Key & Left mods 122 * 0000|mods| keycode Key & Left mods
113 123 *
114ACT_RMODS(0001): 124 * ACT_RMODS(0001):
1150001|0000|000000|00 No action(not used) 125 * 0001|0000|000000|00 No action(not used)
1160001|0000|000000|01 Transparent(not used) 126 * 0001|0000|000000|01 Transparent(not used)
1170001|0000| keycode Key(no used) 127 * 0001|0000| keycode Key(no used)
1180001|mods|000000|00 Right mods 128 * 0001|mods|000000|00 Right mods
1190001|mods| keycode Key & Right mods 129 * 0001|mods| keycode Key & Right mods
120 130 *
121ACT_LMODS_TAP(0010): 131 * ACT_LMODS_TAP(0010):
1220010|mods|000000|00 Left mods OneShot 132 * 0010|mods|000000|00 Left mods OneShot
1230010|mods|000000|01 (reserved) 133 * 0010|mods|000000|01 (reserved)
1240010|mods|000000|10 (reserved) 134 * 0010|mods|000000|10 (reserved)
1250010|mods|000000|11 (reserved) 135 * 0010|mods|000000|11 (reserved)
1260010|mods| keycode Left mods + tap Key 136 * 0010|mods| keycode Left mods + tap Key
127 137 *
128ACT_RMODS_TAP(0011): 138 * ACT_RMODS_TAP(0011):
1290011|mods|000000|00 Right mods OneShot 139 * 0011|mods|000000|00 Right mods OneShot
1300011|mods|000000|01 (reserved) 140 * 0011|mods|000000|01 (reserved)
1310011|mods|000000|10 (reserved) 141 * 0011|mods|000000|10 (reserved)
1320011|mods|000000|11 (reserved) 142 * 0011|mods|000000|11 (reserved)
1330011|mods| keycode Right mods + tap Key 143 * 0011|mods| keycode Right mods + tap Key
134 144 *
135 145 *
136Other HID Usage 146 * Other HID Usage
137--------------- 147 * ---------------
138This action handles other usages than keyboard. 148 * This action handles other usages than keyboard.
139ACT_USAGE(0100): 149 * ACT_USAGE(0100):
1400100|00| usage(10) System control(0x80) - General Desktop page(0x01) 150 * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01)
1410100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C) 151 * 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C)
1420100|10| usage(10) (reserved) 152 * 0100|10| usage(10) (reserved)
1430100|11| usage(10) (reserved) 153 * 0100|11| usage(10) (reserved)
144 154 *
145 155 *
146Mouse Keys 156 * Mouse Keys
147---------- 157 * ----------
148TODO: 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.
149ACT_MOUSEKEY(0110): 159 * ACT_MOUSEKEY(0110):
1500101|XXXX| keycode Mouse key 160 * 0101|XXXX| keycode Mouse key
151 161 *
152 162 *
153Layer Actions 163 * Layer Actions
154------------- 164 * -------------
155ACT_LAYER(1000): Set layer 165 * ACT_LAYER(1000): Set layer
156ACT_LAYER_BIT(1001): Bit-op layer 166 * ACT_LAYER_BIT(1001): Bit-op layer
157 167 *
1581000|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)
1591000|LLLL|0000 0001 set L to layer on press 169 * 1000|LLLL|0000 0001 set L to layer on press
1601000|LLLL|0000 0010 set L to layer on release 170 * 1000|LLLL|0000 0010 set L to layer on release
1611000|----|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)
1621000|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
1631000|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
1641000|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 *
1661001|BBBB|0000 0000 (not used) 176 * 1001|BBBB|0000 0000 (not used)
1671001|BBBB|0000 0001 bit-xor layer with B on press 177 * 1001|BBBB|0000 0001 bit-xor layer with B on press
1681001|BBBB|0000 0010 bit-xor layer with B on release 178 * 1001|BBBB|0000 0010 bit-xor layer with B on release
1691001|BBBB|0000 0011 bit-xor layer with B on both(momentary) 179 * 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary)
1701001|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
1711001|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
1721001|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 *
176Extensions(11XX) 186 * Extensions(11XX)
177---------------- 187 * ----------------
178NOTE: NOT FIXED 188 * NOTE: NOT FIXED
179 189 *
180ACT_MACRO(1100): 190 * ACT_MACRO(1100):
1811100|opt | id(8) Macro play? 191 * 1100|opt | id(8) Macro play?
1821100|1111| id(8) Macro record? 192 * 1100|1111| id(8) Macro record?
183 193 *
184ACT_COMMAND(1110): 194 * ACT_COMMAND(1110):
1851110|opt | id(8) Built-in Command exec 195 * 1110|opt | id(8) Built-in Command exec
186 196 *
187ACT_FUNCTION(1111): 197 * ACT_FUNCTION(1111):
1881111| address(12) Function? 198 * 1111| address(12) Function?
1891111|opt | id(8) Function? 199 * 1111|opt | id(8) Function?
190 200 *
191 */ 201 */
192enum action_kind_id { 202enum 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 */
247enum layer_codes { 257enum 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 */
24uint8_t default_layer = 0;
25uint8_t current_layer = 0;
26
27
28action_t keymap_keycode_to_action(uint8_t keycode) 23action_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))
63action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) 58action_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))
87void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt) 82void 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 */
28extern uint8_t current_layer;
29/* layer to return or start with */
30extern uint8_t default_layer;
31
32
33/* translates key_t to keycode */ 26/* translates key_t to keycode */
34uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); 27uint8_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);
38action_t keymap_fn_to_action(uint8_t keycode); 31action_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?
43action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col);
44
45/* user defined special function */
46void 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 */
52uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); 37uint8_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 */
55uint8_t keymap_fn_layer(uint8_t fn_bits); 39uint8_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 */
58uint8_t keymap_fn_keycode(uint8_t fn_bits); 41uint8_t keymap_fn_keycode(uint8_t fn_bits);
59#endif 42#endif