aboutsummaryrefslogtreecommitdiff
path: root/common/action.h
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-01-27 16:38:19 +0900
committertmk <nobody@nowhere>2013-01-27 16:38:19 +0900
commitbfd7fe586297d70f824a402fd476c3daa889fa56 (patch)
treec903d4a878aa7317ca3c2bb62ece03fdb745d51b /common/action.h
parent66d5dd284271d85da4c161529e12526b50b0f71d (diff)
downloadqmk_firmware-bfd7fe586297d70f824a402fd476c3daa889fa56.tar.gz
qmk_firmware-bfd7fe586297d70f824a402fd476c3daa889fa56.zip
Add oneshot modifier action.
Diffstat (limited to 'common/action.h')
-rw-r--r--common/action.h198
1 files changed, 95 insertions, 103 deletions
diff --git a/common/action.h b/common/action.h
index 327a009ef..1b5b30d86 100644
--- a/common/action.h
+++ b/common/action.h
@@ -3,10 +3,79 @@
3 3
4#include "keyboard.h" 4#include "keyboard.h"
5 5
6
7/* Action struct.
8 *
9 * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15).
10 * AVR looks like a little endian in avr-gcc.
11 *
12 * TODO: not portable across compiler/endianness?
13 * Byte order and bit order of 0x1234:
14 * Big endian: 15 ... 8 7 ... 210
15 * | 0x12 | 0x34 |
16 * 0001 0010 0011 0100
17 * Little endian: 012 ... 7 8 ... 15
18 * | 0x34 | 0x12 |
19 * 0010 1100 0100 1000
20 */
21typedef union {
22 uint16_t code;
23 struct action_kind {
24 uint16_t param :12;
25 uint16_t id :4;
26 } kind;
27 struct action_key {
28 uint16_t code :8;
29 uint16_t mods :4;
30 uint16_t kind :4;
31 } key;
32 struct action_layer {
33 uint16_t code :8;
34 uint16_t opt :4;
35 uint16_t kind :4;
36 } layer;
37 struct action_usage {
38 uint16_t code :10;
39 uint16_t page :2;
40 uint16_t kind :4;
41 } usage;
42 struct action_command {
43 uint16_t id :8;
44 uint16_t option :4;
45 uint16_t kind :4;
46 } command;
47 struct action_function {
48 uint8_t id :8;
49 uint8_t opt :4;
50 uint8_t kind :4;
51 } func;
52} action_t;
53
54/* Action record. For internal use. */
55typedef struct {
56 keyevent_t event;
57 uint8_t tap_count;
58} keyrecord_t;
59
60
61/* Tap count: Tap is comprised of press and release within TAP_TERM.
62 * 0 means no tap.
63 * >1 means tap.
64 */
6extern uint8_t tap_count; 65extern uint8_t tap_count;
66
67/* current tap key event */
7extern keyevent_t tapping_event; 68extern keyevent_t tapping_event;
8 69
9 70
71/* action function */
72typedef void (*action_func_t)(keyevent_t event, uint8_t opt);
73
74// TODO: legacy keymap support
75void action_exec(keyevent_t event);
76void action_call_function(keyevent_t event, uint8_t id);
77
78
10/* 79/*
11 * Utilities for actions. 80 * Utilities for actions.
12 */ 81 */
@@ -25,33 +94,36 @@ bool is_tap_key(key_t key);
25 94
26 95
27/* 96/*
28Action codes 97 * Action codes
2916bit code: action_kind(4bit) + action_parameter(12bit) 98 * ============
30 99 * 16bit code: action_kind(4bit) + action_parameter(12bit)
100 *
31Keyboard Keys 101Keyboard Keys
32------------- 102-------------
33ACT_LMODS(0000): 103ACT_LMODS(0000):
340000|0000|000000|00 No action 1040000|0000|000000|00 No action
350000|mods|000000|00 Left mods Momentary
360000|mods|000000|01 Left mods OneShot
370000|mods|000000|10 (reserved)
380000|mods|000000|11 (reserved)
390000|0000| keycode Key 1050000|0000| keycode Key
1060010|mods|000000|00 Left mods Momentary
400000|mods| keycode Key+Left mods 1070000|mods| keycode Key+Left mods
41 108
42ACT_RMODS(0001): 109ACT_RMODS(0001):
430001|0000|000000|00 No action 1100001|0000|000000|00 No action
1110001|0000| keycode Key(no used)
440001|mods|000000|00 Right mods Momentary 1120001|mods|000000|00 Right mods Momentary
450001|mods|000000|01 Right mods OneShot
460001|mods|000000|10 (reserved)
470001|mods|000000|11 (reserved)
480001|0000| keycode Key
490001|mods| keycode Key+Right mods 1130001|mods| keycode Key+Right mods
50 114
51ACT_LMODS_TAP(0010): 115ACT_LMODS_TAP(0010):
1160010|mods|000000|00 Left mods OneShot
1170010|mods|000000|01 (reserved)
1180010|mods|000000|10 (reserved)
1190010|mods|000000|11 (reserved)
520010|mods| keycode Left mods+tap Key 1200010|mods| keycode Left mods+tap Key
53 121
54ACT_RMODS_TAP(0011): 122ACT_RMODS_TAP(0011):
1230011|mods|000000|00 Right mods OneShot
1240011|mods|000000|01 (reserved)
1250011|mods|000000|10 (reserved)
1260011|mods|000000|11 (reserved)
550011|mods| keycode Right mods+tap Key 1270011|mods| keycode Right mods+tap Key
56 128
57 129
@@ -108,24 +180,22 @@ Extensions(11XX)
108NOTE: NOT FIXED 180NOTE: NOT FIXED
109 181
110ACT_MACRO(1100): 182ACT_MACRO(1100):
1111100|opt | id(8) Macro play 1831100|opt | id(8) Macro play?
1121100|1111| id(8) Macro record 1841100|1111| id(8) Macro record?
113 185
114ACT_COMMAND(1110): 186ACT_COMMAND(1110):
1151110|opt | id(8) Built-in Command exec 1871110|opt | id(8) Built-in Command exec
116 188
117ACT_FUNCTION(1111): 189ACT_FUNCTION(1111):
1181111| address(12) Function 1901111| address(12) Function?
1191111|opt | id(8) Function 1911111|opt | id(8) Function?
120 Macro record(dynamicly) 192
121 Macro play(dynamicly) 193TODO: modifier + function by tap?
122TODO: modifier + [tap key /w mod]
123 : layerkey + [tap key /w mod]
124 for example: LShift + '('[Shift+9] and RShift + ')'[Shift+0] 194 for example: LShift + '('[Shift+9] and RShift + ')'[Shift+0]
125 http://deskthority.net/workshop-f7/tmk-keyboard-firmware-collection-t4478.html#p90052 195 http://deskthority.net/workshop-f7/tmk-keyboard-firmware-collection-t4478.html#p90052
126*/ 196 */
127 197
128enum action_id { 198enum action_kind_id {
129 ACT_LMODS = 0b0000, 199 ACT_LMODS = 0b0000,
130 ACT_RMODS = 0b0001, 200 ACT_RMODS = 0b0001,
131 ACT_LMODS_TAP = 0b0010, 201 ACT_LMODS_TAP = 0b0010,
@@ -144,74 +214,11 @@ enum action_id {
144 ACT_FUNCTION = 0b1111 214 ACT_FUNCTION = 0b1111
145}; 215};
146 216
147// TODO: not portable across compiler/endianness? 217enum acion_param {
148/* 218 ONE_SHOT = 0x00,
149In avr-gcc bit fields seems to be assigned from LSB(bit0) to MSB(bit15).
150AVR looks like a little endian in avr-gcc.
151
152Byte order and bit order of 0x1234:
153Big endian: 15 ... 8 7 ... 210
154 | 0x12 | 0x34 |
155 0001 0010 0011 0100
156Little endian: 012 ... 7 8 ... 15
157 | 0x34 | 0x12 |
158 0010 1100 0100 1000
159*/
160typedef union {
161 uint16_t code;
162 struct action_kind {
163 uint16_t param :12;
164 uint16_t id :4;
165 } kind;
166 struct action_key {
167 uint16_t code :8;
168 uint16_t mods :4;
169 uint16_t kind :4;
170 } key;
171 struct action_layer {
172 uint16_t code :8;
173 uint16_t opt :4;
174 uint16_t kind :4;
175 } layer;
176 struct action_usage {
177 uint16_t code :10;
178 uint16_t page :2;
179 uint16_t kind :4;
180 } usage;
181 struct action_command {
182 uint16_t id :8;
183 uint16_t option :4;
184 uint16_t kind :4;
185 } command;
186 struct action_function {
187 uint8_t id :8;
188 uint8_t opt :4;
189 uint8_t kind :4;
190 } func;
191} action_t;
192
193
194enum stroke_cmd {
195 STROKE_DOWN,
196 STROKE_UP,
197 STROKE_ALLUP, /* release all keys in reverse order */
198}; 219};
199 220
200typedef struct {
201 keyevent_t event;
202 uint8_t tap_count;
203} keyrecord_t;
204
205/* action function */
206typedef void (*action_func_t)(keyevent_t event, uint8_t opt);
207 221
208
209// TODO: legacy keymap support
210void action_exec(keyevent_t event);
211void action_call_function(keyevent_t event, uint8_t id);
212
213
214// TODO: proper names
215/* action_t utility */ 222/* action_t utility */
216#define ACTION_NO 0 223#define ACTION_NO 0
217#define ACTION(kind, param) ((kind)<<12 | (param)) 224#define ACTION(kind, param) ((kind)<<12 | (param))
@@ -221,16 +228,12 @@ void action_call_function(keyevent_t event, uint8_t id);
221#define ACTION_KEY(key) ACTION(ACT_LMODS, key) 228#define ACTION_KEY(key) ACTION(ACT_LMODS, key)
222#define ACTION_LMODS(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x00) 229#define ACTION_LMODS(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x00)
223#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, (mods)<<8 | (key)) 230#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, (mods)<<8 | (key))
224#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x01)
225#define ACTION_LMODS_SWITCH(mods, tap) ACTION(ACT_LMODS, (mods)<<8 | 0xF0 | (tap))
226#define ACTION_LMODS_TOGGLE(mods, tap) ACTION(ACT_LMODS, (mods)<<8 | 0xF1 | (tap))
227#define ACTION_RMODS(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x00) 231#define ACTION_RMODS(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x00)
228#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, (mods)<<8 | (key)) 232#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, (mods)<<8 | (key))
229#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x01) 233
230#define ACTION_RMODS_SWITCH(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF0 | (tap))
231#define ACTION_RMODS_TOGGLE(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF1 | (tap))
232/* Mods + Tap key */ 234/* Mods + Tap key */
233#define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | (key)) 235#define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | (key))
236#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | ONE_SHOT)
234#define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP, MOD_BITS(mods)<<8 | (key)) 237#define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP, MOD_BITS(mods)<<8 | (key))
235 238
236/* Layer Switch */ 239/* Layer Switch */
@@ -268,15 +271,4 @@ void action_call_function(keyevent_t event, uint8_t id);
268/* Function */ 271/* Function */
269#define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id) 272#define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id)
270 273
271
272/* helpers for readability */
273#define LAYER(layer) (layer)
274#define TAP(tap) (tap)
275#define DOUBLE_TAP 2
276#define TRIPLE_TAP 3
277#define QUADRUPLE_TAP 4
278#define QUINTUPLE_TAP 5
279#define DOWN(key) (key)
280#define UP(key) STROKE_UP, (key)
281
282#endif /* ACTION_H */ 274#endif /* ACTION_H */