aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md368
-rw-r--r--common.mk1
-rw-r--r--common/action.c443
-rw-r--r--common/action.h251
-rw-r--r--common/action_macro.c1
-rw-r--r--common/action_macro.h4
-rw-r--r--common/command.c29
-rw-r--r--common/keymap.c91
-rw-r--r--common/keymap.h17
-rw-r--r--common/layer_switch.c201
-rw-r--r--common/layer_switch.h80
-rw-r--r--common/util.c11
-rw-r--r--common/util.h1
-rw-r--r--converter/m0110_usb/Makefile.lufa91
-rw-r--r--converter/m0110_usb/README.md7
-rw-r--r--converter/m0110_usb/config.h1
-rw-r--r--converter/m0110_usb/keymap.c9
-rw-r--r--converter/pc98_usb/Makefile83
-rw-r--r--converter/pc98_usb/README70
-rw-r--r--converter/pc98_usb/config.h126
-rw-r--r--converter/pc98_usb/keymap.c222
-rw-r--r--converter/pc98_usb/led.c33
-rw-r--r--converter/pc98_usb/matrix.c215
-rw-r--r--converter/sun_usb/config.h68
-rw-r--r--doc/keymap.md514
-rw-r--r--keyboard/IIgs/Makefile (renamed from keyboard/IIgs_Standard/Makefile)0
-rw-r--r--keyboard/IIgs/README (renamed from keyboard/IIgs_Standard/README)0
-rw-r--r--keyboard/IIgs/config.h (renamed from keyboard/IIgs_Standard/config.h)0
-rw-r--r--keyboard/IIgs/doc/PIN_BYPASS.jpg (renamed from keyboard/IIgs_Standard/doc/PIN_BYPASS.jpg)bin329437 -> 329437 bytes
-rw-r--r--keyboard/IIgs/doc/Teensy++_Mod.jpg (renamed from keyboard/IIgs_Standard/doc/Teensy++_Mod.jpg)bin74137 -> 74137 bytes
-rwxr-xr-xkeyboard/IIgs/hid_listen.mac (renamed from keyboard/IIgs_Standard/hid_listen.mac)bin13524 -> 13524 bytes
-rw-r--r--keyboard/IIgs/keymap.c (renamed from keyboard/IIgs_Standard/keymap.c)0
-rw-r--r--keyboard/IIgs/led.c (renamed from keyboard/IIgs_Standard/led.c)0
-rw-r--r--keyboard/IIgs/matrix.c (renamed from keyboard/IIgs_Standard/matrix.c)0
-rw-r--r--keyboard/gh60/Makefile.lufa6
-rw-r--r--keyboard/gh60/Makefile.pjrc6
-rw-r--r--keyboard/gh60/README.md7
-rw-r--r--keyboard/gh60/config.h2
-rw-r--r--keyboard/gh60/keymap.c153
-rw-r--r--keyboard/gh60/keymap_plain.h20
-rw-r--r--keyboard/gh60/keymap_poker.h142
-rw-r--r--keyboard/gh60/keymap_poker_bit.h50
-rw-r--r--keyboard/gh60/keymap_poker_set.h81
-rw-r--r--keyboard/hhkb/config.h2
-rw-r--r--keyboard/hhkb/config_iwrap.h2
-rw-r--r--keyboard/hhkb/keymap.c195
-rw-r--r--protocol/serial.h1
-rw-r--r--protocol/serial_soft.c119
-rw-r--r--protocol/serial_uart.c93
-rw-r--r--protocol/vusb/vusb.c4
-rw-r--r--rules.mk3
51 files changed, 2868 insertions, 955 deletions
diff --git a/README.md b/README.md
index b9238922b..e9dad457d 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Source code is available here: <http://github.com/tmk/tmk_keyboard>
7 7
8Features 8Features
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
@@ -22,24 +22,27 @@ Features
22 22
23Projects 23Projects
24-------- 24--------
25You can find some keyboard specific projects under `converter` and `keyboard` directory.
26
25### converter 27### converter
26* ps2_usb - [PS/2 keyboard to USB][GH_ps2] 28* [ps2_usb](converter/ps2_usb/) - [PS/2 keyboard to USB][GH_ps2]
27* adb_usb - [ADB keyboard to USB][GH_adb] 29* [adb_usb](converter/adb_usb/) - [ADB keyboard to USB][GH_adb]
28* m0110_usb - [Machintosh 128K/512K/Plus keyboard to USB][GH_m0110] 30* [m0110_usb](converter/m0110_usb) - [Machintosh 128K/512K/Plus keyboard to USB][GH_m0110]
29* terminal_usb - [IBM Model M terminal keyboard(PS/2 scancode set3) to USB][GH_terminal] 31* [terminal_usb](converter/terminal_usb/) - [IBM Model M terminal keyboard(PS/2 scancode set3) to USB][GH_terminal]
30* news_usb - [Sony NEWS keyboard to USB][GH_news] 32* [news_usb](converter/news_usb/) - [Sony NEWS keyboard to USB][GH_news]
31* x68k_usb - [Sharp X68000 keyboard to USB][GH_x68k] 33* [x68k_usb](converter/x68k_usb/) - [Sharp X68000 keyboard to USB][GH_x68k]
32* sun_usb - Sun to USB(type4, 5 and 3?) 34* [sun_usb](converter/sun_usb/) - [Sun] to USB(type4, 5 and 3?)
33* usb_usb - USB to USB(experimental) 35* [pc98_usb](converter/pc98_usb/) - [PC98] to USB
36* [usb_usb](converter/usb_usb/) - USB to USB(experimental)
34 37
35### keyboard 38### keyboard
36* hhkb - [Happy Hacking Keyboard professional][GH_hhkb] 39* [hhkb](keyboard/hhkb/) - [Happy Hacking Keyboard professional][GH_hhkb]
37* macway - [Compact keyboard mod][GH_macway] 40* [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway]
38* hbkb - [Happy Buckling sprint keyboard(IBM Model M mod)][GH_hbkb] 41* [hbkb](keyboard/hbkb/) - [Happy Buckling sprint keyboard(IBM Model M mod)][GH_hbkb]
39* IIgs_Standard - Apple IIGS keyboard mod(by JeffreySung) 42* [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung)
40* hid_liber - [HID liberation controller][HID_liber](by alaricljs) 43* [hid_liber](keyboard/hid_liber/) - [HID liberation controller][HID_liber](by alaricljs)
41* phantom - [Phantom keyboard][PHANTOM] (by Tranquilite) 44* [phantom](keyboard/phantom/) - [Phantom keyboard][PHANTOM] (by Tranquilite)
42* gh60 - [GH60 keyboard][GH60] 45* [gh60](keyboard/gh60/) - [GH60 keyboard][GH60]
43 46
44[GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 47[GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930
45[GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 48[GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047
@@ -54,6 +57,9 @@ Projects
54[HID_liber]: http://deskthority.net/wiki/HID_Liberation_Device_-_DIY_Instructions 57[HID_liber]: http://deskthority.net/wiki/HID_Liberation_Device_-_DIY_Instructions
55[PHANTOM]: http://geekhack.org/index.php?topic=26742 58[PHANTOM]: http://geekhack.org/index.php?topic=26742
56[GH60]: http://geekhack.org/index.php?topic=34959 59[GH60]: http://geekhack.org/index.php?topic=34959
60[PC98]: http://en.wikipedia.org/wiki/NEC_PC-9801
61[Sun]: http://en.wikipedia.org/wiki/Sun-3
62[IIGS]: http://en.wikipedia.org/wiki/Apple_IIGS
57 63
58 64
59 65
@@ -203,334 +209,10 @@ Config.h Options
203 #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) 209 #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
204 210
205 211
206Keymap 212Change your keymap
207------ 213------------------
208Many of existent projects offer keymap framework to define your own keymap easily. The following will explain how you can define keymap using this framework. 214[keymap.md](doc/keymap.md)
209 Instead, you can also implement your own `keymap_get_action()` to return action code for each key if you want.
210
211This is keymap example for [HHKB](http://en.wikipedia.org/wiki/Happy_Hacking_Keyboard) keyboard. Keymap is defined in `keymaps[]` array.
212
213 static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
214 /* Layer 0: Default Layer
215 * ,-----------------------------------------------------------.
216 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
217 * |-----------------------------------------------------------|
218 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
219 * |-----------------------------------------------------------|
220 * |Contro| A| S| D| F| G| H| J| K| L| ;| '|Enter |
221 * |-----------------------------------------------------------|
222 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1|
223 * `-----------------------------------------------------------'
224 * |Gui|Alt |Space |Alt |Fn2|
225 * `-------------------------------------------'
226 */
227 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
228 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
229 LCTL,A, S, D, F, G, H, J, K, L, FN2, QUOT,ENT, \
230 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT,FN1, \
231 LGUI,LALT, SPC, RALT,FN3),
232
233 /* Layer 1: HHKB mode (HHKB Fn)
234 * ,-----------------------------------------------------------.
235 * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
236 * |-----------------------------------------------------------|
237 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
238 * |-----------------------------------------------------------|
239 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
240 * |-----------------------------------------------------------|
241 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |Fn1|
242 * `-----------------------------------------------------------'
243 * |Gui |Alt |Space |Alt |Gui|
244 * `--------------------------------------------'
245 */
246 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
247 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS,UP, NO, BSPC, \
248 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
249 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN0, \
250 LGUI,LALT, SPC, RALT,RGUI),
251 /* Layer 2: Mouse mode (Semicolon)
252 * ,-----------------------------------------------------------.
253 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
254 * |-----------------------------------------------------------|
255 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | |Backs|
256 * |-----------------------------------------------------------|
257 * |Contro| | | | | |McL|McD|McU|McR|Fn0| |Return |
258 * |-----------------------------------------------------------|
259 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
260 * `-----------------------------------------------------------'
261 * |Gui |Alt |Mb1 |Alt |Fn0|
262 * `--------------------------------------------'
263 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
264 */
265 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
266 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
267 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,FN0, QUOT,ENT, \
268 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,SLSH,RSFT,NO, \
269 LGUI,LALT, BTN1, RALT,FN0),
270 };
271
272 static const uint16_t PROGMEM fn_actions[] = {
273 ACTION_LAYER_DEFAULT, // FN0
274 ACTION_LAYER_SET(1), // FN1
275 ACTION_LAYER_SET_TAP_KEY(2, KC_SCLN), // FN2
276 ACTION_LAYER_BIT_TOGGLE(2), // FN3
277 };
278
279
280
281### 1. Keycode
282See `common/keycode.h`. Keycode is 8bit internal code to inidicate action performed on key in keymap. Keycode has `KC_` prefixed symbol respectively. Most of keycodes like `KC_A` have simple action register key on press and unregister on release, on the other some of keycodes has some special actions like Fn keys, Media contorl keys, System control keys and Mouse keys.
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`.
285
286#### 1.0 Other key
287- `KC_NO` for no aciton
288- `KC_TRNS` for transparent layer
289
290#### 1.1 Normal key
291- `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key
292- `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT`
293- `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS`
294- `KC_UP`, `KC_DOWN`, `KC_RGHT`, `KC_LEFT`, `KC_PGUP`, `KC_PGDN`, `KC_HOME`, `KC_END`
295- `KC_CAPS`, `KC_NLCK`, `KC_SLCK`, `KC_PSCR`, `KC_PAUS`, `KC_APP`, `KC_F1` to `KC_F24`
296- `KC_P1` to `KC_P0`, `KC_PDOT`, `KC_PCMM`, `KC_PSLS`, `KC_PAST`, `KC_PMNS`, `KC_PPLS`, `KC_PEQL`, `KC_PENT` for keypad.
297
298#### 1.2 Modifier
299There are 8 modifiers which has discrimination between left and right.
300
301- `KC_LCTL` and `KC_RCTL` for Control
302- `KC_LSFT` and `KC_RSFT` for Shift
303- `KC_LALT` and `KC_RALT` for Alt
304- `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac
305
306#### 1.3 Fn key
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.***
308
309#### 1.4 Mousekey
310- `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor
311- `KC_WH_U`, `KC_WH_D`, `KC_WH_L`, `KC_WH_R` for mouse wheel
312- `KC_BTN1`, `KC_BTN2`, `KC_BTN3`, `KC_BTN4`, `KC_BTN5` for mouse buttons
313
314#### 1.5 System & Media key
315- `KC_PWR`, `KC_SLEP`, `KC_WAKE` for Power, Sleep, Wake
316- `KC_MUTE`, `KC_VOLU`, `KC_VOLD` for audio volume control
317- `KC_MNXT`, `KC_MPRV`, `KC_MSTP`, `KC_MPLY`, `KC_MSEL` for media control
318- `KC_MAIL`, `KC_CALC`, `KC_MYCM` for application launch
319- `KC_WSCH`, `KC_WHOM`, `KC_WBAK`, `KC_WFWD`, `KC_WSTP`, `KC_WREF`, `KC_WFAV` for web browser operation
320
321#### Keycode Table
322 See [keycode table](doc/keycode.txt) in `doc/keycode.txt` or `common/keycode.h` for the detail or other keycodes.
323
324 In regard to implementation side most of keycodes are identical with [HID usage] sent to host for real and some virtual keycodes are defined to support special actions.
325[HID usage]: http://www.usb.org/developers/devclass_docs/Hut1_11.pdf
326
327
328
329### 2. Action
330See `common/action.h`. Action is a 16bit code and defines function to perform on events of a key like press, release, hold and tap. You can define various actions to use various action codes.
331
332Most of keys just register 8bit keycode as HID usage(or scan code) to host, but to support other complex features needs 16bit extended action codes internally. But using 16bit action codes in keymap results in double size in memory against keycodes. To avoid this waste 8bit keycodes are used in `KEYMAP` to define instead of action codes. ***Keycodes can be considered as subset of action codes.*** Like `KC_A`(0x04) is equal to a `Key` action(0x0004) that transmit keycode of *'A'*.
333
334#### 2.1 Key action
335Key is simple action that registers keycode on press of key and unregister on release.
336You can define `Key` action on *'A'* key with:
337
338 ACTION_KEY(KC_A)
339
340But you don't need to use this expression directly because you can just put symbol `A` in `KEYMAP` definition.
341
342 Say you want to assign a key to `Shift + 1` to get charactor *'!'* or `Alt + Tab` to switch windows.
343
344 ACTION_MOD_KEY(KC_LSHIFT, KC_1)
345 ACTION_MOD_KEY(KC_LALT, KC_TAB)
346
347Or `Alt,Shift + Tab` can be defined.
348
349 ACTION_MODS_KEY((MOD_BIT(KC_LALT) | MOD_BIT(KC_LSHIFT)), KC_TAB)
350
351These actions are comprised of strokes of modifiers and a key. `Macro` action is needed if you want more complex key strokes.
352
353#### 2.2 Layer Actions
354This sets `default layer` into `current layer`. With this action you can return to `default layer`.
355
356 ACTION_LAYER_DEFAULT
357
358`Layer Set` action sets given layer argument to `current layer`. `Layer Set` action can take 0 to 15 as argument.
359
360 ACTION_LAYER_SET(layer)
361 ACTION_LAYER_SET_TOGGLE(layer)
362 ACTION_LAYER_SET_TAP_KEY(layer, key)
363 ACTION_LAYER_SET_TAP_TOGGLE(layer)
364
365`Layer Bit` action XOR given bits with `current layer`. `Layer Bit` action can take 0 to 15 as argument.
366
367 ACTION_LAYER_BIT(bits)
368 ACTION_LAYER_BIT_TOGGLE(bits)
369 ACTION_LAYER_BIT_TAP_KEY(bits, key)
370 ACTION_LAYER_BIT_TAP_TOGGLE(bits)
371
372These acitons change `default layer`.
373 ACTION_LAYER_SET_DEFAULT(layer)
374 ACTION_LAYER_BIT_DEFAULT(bits)
375
376
377#### 2.3 Macro action
378***NOT FIXED***
379`Macro` action indicates complex key strokes.
380
381 MACRO( MD(LSHIFT), D(D), END )
382 MACRO( U(D), MU(LSHIFT), END )
383 MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END )
384
385##### 2.3.1 Normal mode
386- **I()** change interavl of stroke.
387- **D()** press key
388- **U()** release key
389- **T()** type key(press and release)
390- **W()** wait
391- **MD()** modifier down
392- **MU()** modifier up
393- **END** end mark
394
395##### 2.3.2 Extended mode
396
397***TODO: sample impl***
398See `keyboard/hhkb/keymap.c` for sample.
399
400
401#### 2.4 Function action
402***NOT FIXED***
403There are two type of action, normal `Function` and tappable `Function`.
404These actions call user defined function with `id`, `opt`, and key event information as arguments.
405
406##### 2.4.1 Function
407To define normal `Function` action in keymap use this.
408
409 ACTION_FUNCTION(id, opt)
410
411##### 2.4.2 Function with tap
412To define tappable `Function` action in keymap use this.
413
414 ACTION_FUNCTION_TAP(id, opt)
415
416##### 2.4.3 Implement user function
417`Function` actions can be defined freely with C by user in callback function:
418
419 void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt)
420
421This C function is called every time key is operated, argument `id` selects action to be performed and `opt` can be used for option. Functon `id` can be 0-255 and `opt` can be 0-15.
422
423 `keyrecord_t` is comprised of key event and tap count. `keyevent_t` indicates which and when key is pressed or released. From `tap_count` you can know tap state, 0 means no tap. These information will be used in user function to decide how action of key is performed.
424
425 typedef struct {
426 keyevent_t event;
427 uint8_t tap_count;
428 } keyrecord_t;
429
430 typedef struct {
431 key_t key;
432 bool pressed;
433 uint16_t time;
434 } keyevent_t;
435
436 typedef struct {
437 uint8_t col;
438 uint8_t row;
439 } key_t;
440
441***TODO: sample impl***
442See `keyboard/hhkb/keymap.c` for sample.
443
444
445
446
447
448### 3. Layer
449 Layer is key-action map to assign action to every physical key. You can define multiple layers in keymap and select a layer out of keymap during operation at will.
450
451 First layer is indexed by `Layer 0` which usually become **`default layer`** and active in initial state. **`current layer`** is active layer at that time and can be changed with user interaction. You can define **16 layers** at most in default keymap framework.
452
453 you can define a layer with placing keycode symbols separated with `comma` in `KEYMAP`, which is formed with resemblance to physical keyboard layout so as you can easily put keycode on place you want to map. ***You can define most of keys with just using keycodes*** except for `Fn` key serving special actions.
454
455
456
457### 4. Layer switching
458You can have some ways to switch layer with these actions.
459There are two kind of layer switch action `Layer Set` and `Layer Bit` and two type of switching behaviour **Momentary** and **Toggle**.
460
461#### 4.1 Momentary switching
462Momentary switching changes layer only while holding Fn key.
463
464##### 4.1.1 Momentary Set
465This `Layer Set` action sets new layer `Layer 1` to `current layer` on key press event.
466
467 ACTION_LAYER_SET(1)
468
469It switches to destination layer immediately when key is pressed, after that actions on keymap of destination layer is perfomed. ***Thus you shall need to place action to come back on destination layer***, or you will be stuck in destination layer without way to get back. To get back to `default layer` you can use this action.
470
471 ACTION_LAYER_DEFAULT
472
473##### 4.1.2 Momentary Bit
474This `Layer Bit` action performs XOR `1` with `current layer` on both press and release event. If you are on `Layer 0` now next layer to switch will be `Layer 1`. To come back to previous layer you need to place same action on destination layer.
475
476 ACTION_LAYER_BIT(1)
477
478#### 4.2 Toggle switching
479Toggle switching changes layer after press then release. You keep being on the layer until you press key to return.
480
481##### 4.2.1 Toggle Set
482This `Layer Set Toggle` action is to set `Layer 1` to `current layer` on release and do none on press.
483
484 ACTION_LAYER_SET_TOGGLE(1)
485
486To get back to `default layer` you can use this action.
487
488 ACTION_LAYER_DEFAULT
489
490##### 4.2.2 Toggle Bit
491This `Layer Bit Toggle` action is to XOR `1` with `current layer` on release and do none on press. If you are on `Layer 2` you'll switch to `Layer 3` on press. To come back to previous layer you need to place same action on destination layer.
492
493 ACTION_LAYER_BIT_TOGGLE(1)
494
495
496#### 4.3 Momentary switching with Tap key
497These actions switch to layer only while holding `Fn` key and register key on tap. **Tap** means to press and release key quickly.
498
499 ACTION_LAYER_SET_TAP_KEY(2, KC_SCLN)
500 ACTION_LAYER_SET_BIT_KEY(2, KC_SCLN)
501
502With these you can place layer switching function on normal alphabet key like `;` without losing its original register function.
503
504#### 4.4 Momentary switching with Tap Toggle
505This changes layer only while holding `Fn` key and toggle layer after several taps. **Tap** means to press and release key quickly.
506
507 ACTION_LAYER_SET_TAP_TOGGLE(layer)
508 ACTION_LAYER_BIT_TAP_TOGGLE(layer)
509
510Number of taps can be defined with `TAPPING_TOGGLE` in `config.h`, `5` by default.
511
512
513
514
515Legacy Keymap
516-------------
517This was used in prior version and still works due to legacy support code in `common/keymap.c`. Legacy keymap doesn't support many of features that new keymap offers.
518
519In comparison with new keymap how to define Fn key is different. It uses two arrays `fn_layer[]` and `fn_keycode[]`. The index of arrays corresponds with postfix number of `Fn` key. Array `fn_layer[]` indicates destination layer to switch and `fn_keycode[]` has keycodes to send when tapping `Fn` key.
520
521In following setting example, `Fn0`, `Fn1` and `Fn2` switch layer to 1, 2 and 2 respectively. `Fn2` registers `Space` key when tap while `Fn0` and `Fn1` doesn't send any key.
522
523 static const uint8_t PROGMEM fn_layer[] = {
524 1, // Fn0
525 2, // Fn1
526 2, // Fn2
527 };
528 215
529 static const uint8_t PROGMEM fn_keycode[] = {
530 KC_NO, // Fn0
531 KC_NO, // Fn1
532 KC_SPC, // Fn2
533 };
534 216
535 217
536 218
diff --git a/common.mk b/common.mk
index 86518f03f..5fb76e739 100644
--- a/common.mk
+++ b/common.mk
@@ -3,6 +3,7 @@ SRC += $(COMMON_DIR)/host.c \
3 $(COMMON_DIR)/keyboard.c \ 3 $(COMMON_DIR)/keyboard.c \
4 $(COMMON_DIR)/action.c \ 4 $(COMMON_DIR)/action.c \
5 $(COMMON_DIR)/action_macro.c \ 5 $(COMMON_DIR)/action_macro.c \
6 $(COMMON_DIR)/layer_switch.c \
6 $(COMMON_DIR)/keymap.c \ 7 $(COMMON_DIR)/keymap.c \
7 $(COMMON_DIR)/command.c \ 8 $(COMMON_DIR)/command.c \
8 $(COMMON_DIR)/timer.c \ 9 $(COMMON_DIR)/timer.c \
diff --git a/common/action.c b/common/action.c
index 6528cd46c..15e125a3e 100644
--- a/common/action.c
+++ b/common/action.c
@@ -23,15 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23#include "command.h" 23#include "command.h"
24#include "util.h" 24#include "util.h"
25#include "debug.h" 25#include "debug.h"
26#include "layer_switch.h"
27#include "action_macro.h"
26#include "action.h" 28#include "action.h"
27 29
28 30
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
35static void process_action(keyrecord_t *record); 31static void process_action(keyrecord_t *record);
36static bool process_tapping(keyrecord_t *record); 32static bool process_tapping(keyrecord_t *record);
37static void waiting_buffer_scan_tap(void); 33static void waiting_buffer_scan_tap(void);
@@ -207,28 +203,18 @@ void action_exec(keyevent_t event)
207 } 203 }
208} 204}
209 205
210static action_t get_action(key_t key)
211{
212 action_t action = action_for_key(current_layer, key);
213
214 /* Transparently use default layer */
215 if (action.code == ACTION_TRANSPARENT) {
216 // TODO: layer stacking
217 action = action_for_key(default_layer, key);
218 debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n");
219 }
220 return action;
221}
222
223static void process_action(keyrecord_t *record) 206static void process_action(keyrecord_t *record)
224{ 207{
225 keyevent_t event = record->event; 208 keyevent_t event = record->event;
226 uint8_t tap_count = record->tap_count; 209 uint8_t tap_count = record->tap.count;
227 210
228 if (IS_NOEVENT(event)) { return; } 211 if (IS_NOEVENT(event)) { return; }
229 212
230 action_t action = get_action(event.key); 213 action_t action = layer_switch_get_action(event.key);
231 debug("ACTION: "); debug_action(action); debug("\n"); 214 debug("ACTION: "); debug_action(action);
215 debug(" overlays: "); overlay_debug();
216 debug(" keymaps: "); keymap_debug();
217 debug(" default_layer: "); debug_dec(default_layer); debug("\n");
232 218
233 switch (action.kind.id) { 219 switch (action.kind.id) {
234 /* Key and Mods */ 220 /* Key and Mods */
@@ -287,7 +273,7 @@ static void process_action(keyrecord_t *record)
287 } else { 273 } else {
288 if (tap_count == 0) { 274 if (tap_count == 0) {
289 debug("MODS_TAP: Oneshot: cancel/del_mods\n"); 275 debug("MODS_TAP: Oneshot: cancel/del_mods\n");
290 // cancel oneshot by holding. 276 // cancel oneshot on hold
291 oneshot_cancel(); 277 oneshot_cancel();
292 del_mods(mods); 278 del_mods(mods);
293 } 279 }
@@ -309,7 +295,7 @@ static void process_action(keyrecord_t *record)
309 if (waiting_buffer_has_anykey_pressed()) { 295 if (waiting_buffer_has_anykey_pressed()) {
310 debug("MODS_TAP: Tap: Cancel: add_mods\n"); 296 debug("MODS_TAP: Tap: Cancel: add_mods\n");
311 // ad hoc: set 0 to cancel tap 297 // ad hoc: set 0 to cancel tap
312 record->tap_count = 0; 298 record->tap.count = 0;
313 add_mods(mods); 299 add_mods(mods);
314 } else { 300 } else {
315 debug("MODS_TAP: Tap: register_code\n"); 301 debug("MODS_TAP: Tap: register_code\n");
@@ -368,145 +354,316 @@ static void process_action(keyrecord_t *record)
368#endif 354#endif
369 break; 355 break;
370 356
371 /* Layer key */ 357 case ACT_KEYMAP:
372 case ACT_LAYER:
373 switch (action.layer.code) { 358 switch (action.layer.code) {
374 case LAYER_MOMENTARY: /* momentary */ 359 /* Keymap clear */
375 if (event.pressed) { 360 case OP_RESET:
376 layer_switch(action.layer.val); 361 switch (action.layer.val & 0x03) {
377 } 362 case 0:
378 else { 363 // NOTE: reserved
379 // NOTE: This is needed by legacy keymap support 364 overlay_clear();
380 layer_switch(default_layer); 365 keymap_clear();
381 }
382 break;
383 case LAYER_ON_PRESS:
384 if (event.pressed) {
385 layer_switch(action.layer.val);
386 }
387 break;
388 case LAYER_ON_RELEASE:
389 if (!event.pressed) {
390 layer_switch(action.layer.val);
391 }
392 break;
393 case LAYER_DEFAULT: /* default layer */
394 switch (action.layer.val) {
395 case DEFAULT_ON_BOTH:
396 layer_switch(default_layer);
397 break; 366 break;
398 case DEFAULT_ON_PRESS: 367 case ON_PRESS:
399 if (event.pressed) { 368 if (event.pressed) {
400 layer_switch(default_layer); 369 overlay_clear();
370 keymap_clear();
401 } 371 }
402 break; 372 break;
403 case DEFAULT_ON_RELEASE: 373 case ON_RELEASE:
404 if (!event.pressed) { 374 if (!event.pressed) {
405 layer_switch(default_layer); 375 overlay_clear();
376 keymap_clear();
406 } 377 }
407 break; 378 break;
379 case ON_BOTH:
380 overlay_clear();
381 keymap_clear();
382 break;
383 /* NOTE: 4-7 rserved */
408 } 384 }
409 break; 385 break;
410 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 386 /* Keymap Reset default layer */
387 case (OP_RESET | ON_PRESS):
388 if (event.pressed) {
389 default_layer_set(action.layer.val);
390 }
391 break;
392 case (OP_RESET | ON_RELEASE):
393 if (!event.pressed) {
394 default_layer_set(action.layer.val);
395 }
396 break;
397 case (OP_RESET | ON_BOTH):
398 default_layer_set(action.layer.val);
399 break;
400
401 /* Keymap Bit invert */
402 case OP_INV:
403 /* with tap toggle */
411 if (event.pressed) { 404 if (event.pressed) {
412 if (tap_count < TAPPING_TOGGLE) { 405 if (tap_count < TAPPING_TOGGLE) {
413 layer_switch(action.layer.val); 406 debug("KEYMAP_INV: tap toggle(press).\n");
407 keymap_invert(action.layer.val);
414 } 408 }
415 } else { 409 } else {
416 if (tap_count >= TAPPING_TOGGLE) { 410 if (tap_count <= TAPPING_TOGGLE) {
417 debug("LAYER_PRESSED: tap toggle.\n"); 411 debug("KEYMAP_INV: tap toggle(release).\n");
418 layer_switch(action.layer.val); 412 keymap_invert(action.layer.val);
419 } 413 }
420 } 414 }
421 break; 415 break;
422 case LAYER_CHANGE_DEFAULT: /* change default layer */ 416 case (OP_INV | ON_PRESS):
423 if (event.pressed) { 417 if (event.pressed) {
424 default_layer = action.layer.val; 418 keymap_invert(action.layer.val);
425 layer_switch(default_layer); 419 }
420 break;
421 case (OP_INV | ON_RELEASE):
422 if (!event.pressed) {
423 keymap_invert(action.layer.val);
426 } 424 }
427 break; 425 break;
428 default: /* switch layer on hold and key on tap*/ 426 case (OP_INV | ON_BOTH):
427 keymap_invert(action.layer.val);
428 break;
429
430 /* Keymap Bit on */
431 case OP_ON:
432 if (event.pressed) {
433 keymap_on(action.layer.val);
434 } else {
435 keymap_off(action.layer.val);
436 }
437 break;
438 case (OP_ON | ON_PRESS):
439 if (event.pressed) {
440 keymap_on(action.layer.val);
441 }
442 break;
443 case (OP_ON | ON_RELEASE):
444 if (!event.pressed) {
445 keymap_on(action.layer.val);
446 }
447 break;
448 case (OP_ON | ON_BOTH):
449 keymap_on(action.layer.val);
450 break;
451
452 /* Keymap Bit off */
453 case OP_OFF:
454 if (event.pressed) {
455 keymap_off(action.layer.val);
456 } else {
457 keymap_on(action.layer.val);
458 }
459 break;
460 case (OP_OFF | ON_PRESS):
461 if (event.pressed) {
462 keymap_off(action.layer.val);
463 }
464 break;
465 case (OP_OFF | ON_RELEASE):
466 if (!event.pressed) {
467 keymap_off(action.layer.val);
468 }
469 break;
470 case (OP_OFF | ON_BOTH):
471 keymap_off(action.layer.val);
472 break;
473
474 /* Keymap Bit set */
475 case OP_SET:
476 if (event.pressed) {
477 keymap_set(action.layer.val);
478 } else {
479 keymap_clear();
480 }
481 break;
482 case (OP_SET | ON_PRESS):
483 if (event.pressed) {
484 keymap_set(action.layer.val);
485 }
486 break;
487 case (OP_SET | ON_RELEASE):
488 if (!event.pressed) {
489 keymap_set(action.layer.val);
490 }
491 break;
492 case (OP_SET | ON_BOTH):
493 keymap_set(action.layer.val);
494 break;
495
496 /* Keymap Bit invert with tap key */
497 default:
429 if (event.pressed) { 498 if (event.pressed) {
430 if (tap_count > 0) { 499 if (tap_count > 0) {
431 debug("LAYER_PRESSED: Tap: register_code\n"); 500 debug("KEYMAP_TAP_KEY: Tap: register_code\n");
432 register_code(action.layer.code); 501 register_code(action.layer.code);
433 } else { 502 } else {
434 debug("LAYER_PRESSED: No tap: layer_switch\n"); 503 debug("KEYMAP_TAP_KEY: No tap: On on press\n");
435 layer_switch(action.layer.val); 504 keymap_on(action.layer.val);
436 } 505 }
437 } else { 506 } else {
438 if (tap_count > 0) { 507 if (tap_count > 0) {
439 debug("LAYER_PRESSED: Tap: unregister_code\n"); 508 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
440 unregister_code(action.layer.code); 509 unregister_code(action.layer.code);
441 } else { 510 } else {
442 //debug("LAYER_PRESSED: No tap: NO ACTION\n"); 511 debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
443 // NOTE: This is needed by legacy keymap support 512 keymap_off(action.layer.val);
444 debug("LAYER_PRESSED: No tap: return to default layer\n");
445 layer_switch(default_layer);
446 } 513 }
447 } 514 }
448 break; 515 break;
449 } 516 }
450 break; 517 break;
451 case ACT_LAYER_BIT: 518
519 case ACT_OVERLAY:
452 switch (action.layer.code) { 520 switch (action.layer.code) {
453 case LAYER_MOMENTARY: /* momentary */ 521 // Overlay Invert bit4
454 if (event.pressed) { 522 case OP_INV4 | 0:
455 layer_switch(current_layer ^ action.layer.val); 523 if (action.layer.val == 0) {
524 // NOTE: reserved for future use
525 overlay_clear();
456 } else { 526 } else {
457 layer_switch(current_layer ^ action.layer.val); 527 overlay_set(overlay_stat ^ action.layer.val);
458 } 528 }
459 break; 529 break;
460 case LAYER_ON_PRESS: 530 case OP_INV4 | 1:
461 if (event.pressed) { 531 if (action.layer.val == 0) {
462 layer_switch(current_layer ^ action.layer.val); 532 // on pressed
533 if (event.pressed) overlay_clear();
534 } else {
535 overlay_set(overlay_stat ^ action.layer.val<<4);
463 } 536 }
464 break; 537 break;
465 case LAYER_ON_RELEASE: 538 case OP_INV4 | 2:
466 if (!event.pressed) { 539 if (action.layer.val == 0) {
467 layer_switch(current_layer ^ action.layer.val); 540 // on released
541 if (!event.pressed) overlay_clear();
542 } else {
543 overlay_set(overlay_stat ^ action.layer.val<<8);
544 }
545 break;
546 case OP_INV4 | 3:
547 if (action.layer.val == 0) {
548 // on both
549 overlay_clear();
550 } else {
551 overlay_set(overlay_stat ^ action.layer.val<<12);
468 } 552 }
469 break; 553 break;
470 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 554
555 /* Overlay Bit invert */
556 case OP_INV:
557 /* with tap toggle */
471 if (event.pressed) { 558 if (event.pressed) {
472 if (tap_count < TAPPING_TOGGLE) { 559 if (tap_count < TAPPING_TOGGLE) {
473 debug("LAYER_BIT: tap toggle(press).\n"); 560 debug("OVERLAY_INV: tap toggle(press).\n");
474 layer_switch(current_layer ^ action.layer.val); 561 overlay_invert(action.layer.val);
475 } 562 }
476 } else { 563 } else {
477 if (tap_count <= TAPPING_TOGGLE) { 564 if (tap_count <= TAPPING_TOGGLE) {
478 debug("LAYER_BIT: tap toggle(release).\n"); 565 debug("OVERLAY_INV: tap toggle(release).\n");
479 layer_switch(current_layer ^ action.layer.val); 566 overlay_invert(action.layer.val);
480 } 567 }
481 } 568 }
482 break; 569 break;
483 case 0xFF: 570 case (OP_INV | ON_PRESS):
484 // change default layer 571 if (event.pressed) {
572 overlay_invert(action.layer.val);
573 }
574 break;
575 case (OP_INV | ON_RELEASE):
576 if (!event.pressed) {
577 overlay_invert(action.layer.val);
578 }
579 break;
580 case (OP_INV | ON_BOTH):
581 overlay_invert(action.layer.val);
582 break;
583
584 /* Overlay Bit on */
585 case OP_ON:
485 if (event.pressed) { 586 if (event.pressed) {
486 default_layer = current_layer ^ action.layer.val; 587 overlay_on(action.layer.val);
487 layer_switch(default_layer);
488 } else { 588 } else {
489 default_layer = current_layer ^ action.layer.val; 589 overlay_off(action.layer.val);
490 layer_switch(default_layer); 590 }
591 break;
592 case (OP_ON | ON_PRESS):
593 if (event.pressed) {
594 overlay_on(action.layer.val);
491 } 595 }
492 break; 596 break;
597 case (OP_ON | ON_RELEASE):
598 if (!event.pressed) {
599 overlay_on(action.layer.val);
600 }
601 break;
602 case (OP_ON | ON_BOTH):
603 overlay_on(action.layer.val);
604 break;
605
606 /* Overlay Bit off */
607 case OP_OFF:
608 if (event.pressed) {
609 overlay_off(action.layer.val);
610 } else {
611 overlay_on(action.layer.val);
612 }
613 break;
614 case (OP_OFF | ON_PRESS):
615 if (event.pressed) {
616 overlay_off(action.layer.val);
617 }
618 break;
619 case (OP_OFF | ON_RELEASE):
620 if (!event.pressed) {
621 overlay_off(action.layer.val);
622 }
623 break;
624 case (OP_OFF | ON_BOTH):
625 overlay_off(action.layer.val);
626 break;
627
628 /* Overlay Bit set */
629 case OP_SET:
630 if (event.pressed) {
631 overlay_move(action.layer.val);
632 } else {
633 overlay_clear();
634 }
635 break;
636 case (OP_SET | ON_PRESS):
637 if (event.pressed) {
638 overlay_move(action.layer.val);
639 }
640 break;
641 case (OP_SET | ON_RELEASE):
642 if (!event.pressed) {
643 overlay_move(action.layer.val);
644 }
645 break;
646 case (OP_SET | ON_BOTH):
647 overlay_move(action.layer.val);
648 break;
649
650 /* Overlay Bit invert with tap key */
493 default: 651 default:
494 // with tap key
495 if (event.pressed) { 652 if (event.pressed) {
496 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 653 if (tap_count > 0) {
497 debug("LAYER_BIT: Tap: register_code\n"); 654 debug("OVERLAY_TAP_KEY: Tap: register_code\n");
498 register_code(action.layer.code); 655 register_code(action.layer.code);
499 } else { 656 } else {
500 debug("LAYER_BIT: No tap: layer_switch(bit on)\n"); 657 debug("OVERLAY_TAP_KEY: No tap: On on press\n");
501 layer_switch(current_layer ^ action.layer.val); 658 overlay_on(action.layer.val);
502 } 659 }
503 } else { 660 } else {
504 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 661 if (tap_count > 0) {
505 debug("LAYER_BIT: Tap: unregister_code\n"); 662 debug("OVERLAY_TAP_KEY: Tap: unregister_code\n");
506 unregister_code(action.layer.code); 663 unregister_code(action.layer.code);
507 } else { 664 } else {
508 debug("LAYER_BIT: No tap: layer_switch(bit off)\n"); 665 debug("OVERLAY_TAP_KEY: No tap: Off on release\n");
509 layer_switch(current_layer ^ action.layer.val); 666 overlay_off(action.layer.val);
510 } 667 }
511 } 668 }
512 break; 669 break;
@@ -515,7 +672,7 @@ static void process_action(keyrecord_t *record)
515 672
516 /* Extentions */ 673 /* Extentions */
517 case ACT_MACRO: 674 case ACT_MACRO:
518 // TODO 675 action_macro_play(action_get_macro(record, action.func.id, action.func.opt));
519 break; 676 break;
520 case ACT_COMMAND: 677 case ACT_COMMAND:
521 break; 678 break;
@@ -540,16 +697,17 @@ static bool process_tapping(keyrecord_t *keyp)
540 // if tapping 697 // if tapping
541 if (IS_TAPPING_PRESSED()) { 698 if (IS_TAPPING_PRESSED()) {
542 if (WITHIN_TAPPING_TERM(event)) { 699 if (WITHIN_TAPPING_TERM(event)) {
543 if (tapping_key.tap_count == 0) { 700 if (tapping_key.tap.count == 0) {
544 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 701 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
545 // first tap! 702 // first tap!
546 debug("Tapping: First tap(0->1).\n"); 703 debug("Tapping: First tap(0->1).\n");
547 tapping_key.tap_count = 1; 704 tapping_key.tap.count = 1;
705 tapping_key.tap.interrupted = (waiting_buffer_has_anykey_pressed() ? true : false);
548 debug_tapping_key(); 706 debug_tapping_key();
549 process_action(&tapping_key); 707 process_action(&tapping_key);
550 708
551 // enqueue 709 // enqueue
552 keyp->tap_count = tapping_key.tap_count; 710 keyp->tap = tapping_key.tap;
553 return false; 711 return false;
554 } 712 }
555#if TAPPING_TERM >= 500 713#if TAPPING_TERM >= 500
@@ -573,19 +731,19 @@ static bool process_tapping(keyrecord_t *keyp)
573 // tap_count > 0 731 // tap_count > 0
574 else { 732 else {
575 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 733 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
576 debug("Tapping: Tap release("); debug_dec(tapping_key.tap_count); debug(")\n"); 734 debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n");
577 keyp->tap_count = tapping_key.tap_count; 735 keyp->tap = tapping_key.tap;
578 process_action(keyp); 736 process_action(keyp);
579 tapping_key = *keyp; 737 tapping_key = *keyp;
580 debug_tapping_key(); 738 debug_tapping_key();
581 return true; 739 return true;
582 } 740 }
583 else if (is_tap_key(keyp->event.key) && event.pressed) { 741 else if (is_tap_key(keyp->event.key) && event.pressed) {
584 if (tapping_key.tap_count > 1) { 742 if (tapping_key.tap.count > 1) {
585 debug("Tapping: Start new tap with releasing last tap(>1).\n"); 743 debug("Tapping: Start new tap with releasing last tap(>1).\n");
586 // unregister key 744 // unregister key
587 process_action(&(keyrecord_t){ 745 process_action(&(keyrecord_t){
588 .tap_count = tapping_key.tap_count, 746 .tap = tapping_key.tap,
589 .event.key = tapping_key.event.key, 747 .event.key = tapping_key.event.key,
590 .event.time = event.time, 748 .event.time = event.time,
591 .event.pressed = false 749 .event.pressed = false
@@ -609,7 +767,7 @@ static bool process_tapping(keyrecord_t *keyp)
609 } 767 }
610 // after TAPPING_TERM 768 // after TAPPING_TERM
611 else { 769 else {
612 if (tapping_key.tap_count == 0) { 770 if (tapping_key.tap.count == 0) {
613 debug("Tapping: End. Timeout. Not tap(0): "); 771 debug("Tapping: End. Timeout. Not tap(0): ");
614 debug_event(event); debug("\n"); 772 debug_event(event); debug("\n");
615 process_action(&tapping_key); 773 process_action(&tapping_key);
@@ -619,17 +777,17 @@ static bool process_tapping(keyrecord_t *keyp)
619 } else { 777 } else {
620 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 778 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
621 debug("Tapping: End. last timeout tap release(>0)."); 779 debug("Tapping: End. last timeout tap release(>0).");
622 keyp->tap_count = tapping_key.tap_count; 780 keyp->tap = tapping_key.tap;
623 process_action(keyp); 781 process_action(keyp);
624 tapping_key = (keyrecord_t){}; 782 tapping_key = (keyrecord_t){};
625 return true; 783 return true;
626 } 784 }
627 else if (is_tap_key(keyp->event.key) && event.pressed) { 785 else if (is_tap_key(keyp->event.key) && event.pressed) {
628 if (tapping_key.tap_count > 1) { 786 if (tapping_key.tap.count > 1) {
629 debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); 787 debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
630 // unregister key 788 // unregister key
631 process_action(&(keyrecord_t){ 789 process_action(&(keyrecord_t){
632 .tap_count = tapping_key.tap_count, 790 .tap = tapping_key.tap,
633 .event.key = tapping_key.event.key, 791 .event.key = tapping_key.event.key,
634 .event.time = event.time, 792 .event.time = event.time,
635 .event.pressed = false 793 .event.pressed = false
@@ -653,10 +811,11 @@ static bool process_tapping(keyrecord_t *keyp)
653 } 811 }
654 } else if (IS_TAPPING_RELEASED()) { 812 } else if (IS_TAPPING_RELEASED()) {
655 if (WITHIN_TAPPING_TERM(event)) { 813 if (WITHIN_TAPPING_TERM(event)) {
656 if (tapping_key.tap_count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { 814 if (tapping_key.tap.count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) {
657 // sequential tap. 815 // sequential tap.
658 keyp->tap_count = tapping_key.tap_count + 1; 816 keyp->tap = tapping_key.tap;
659 debug("Tapping: Tap press("); debug_dec(keyp->tap_count); debug(")\n"); 817 keyp->tap.count += 1;
818 debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n");
660 process_action(keyp); 819 process_action(keyp);
661 tapping_key = *keyp; 820 tapping_key = *keyp;
662 debug_tapping_key(); 821 debug_tapping_key();
@@ -701,16 +860,16 @@ static bool process_tapping(keyrecord_t *keyp)
701static void waiting_buffer_scan_tap(void) 860static void waiting_buffer_scan_tap(void)
702{ 861{
703 // tapping already is settled 862 // tapping already is settled
704 if (tapping_key.tap_count > 0) return; 863 if (tapping_key.tap.count > 0) return;
705 // invalid state: tapping_key released && tap_count == 0 864 // invalid state: tapping_key released && tap.count == 0
706 if (!tapping_key.event.pressed) return; 865 if (!tapping_key.event.pressed) return;
707 866
708 for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { 867 for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
709 if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && 868 if (IS_TAPPING_KEY(waiting_buffer[i].event.key) &&
710 !waiting_buffer[i].event.pressed && 869 !waiting_buffer[i].event.pressed &&
711 WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { 870 WITHIN_TAPPING_TERM(waiting_buffer[i].event)) {
712 tapping_key.tap_count = 1; 871 tapping_key.tap.count = 1;
713 waiting_buffer[i].tap_count = 1; 872 waiting_buffer[i].tap.count = 1;
714 process_action(&tapping_key); 873 process_action(&tapping_key);
715 874
716 debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); 875 debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n");
@@ -813,39 +972,24 @@ bool sending_anykey(void)
813 host_last_sysytem_report() || host_last_consumer_report()); 972 host_last_sysytem_report() || host_last_consumer_report());
814} 973}
815 974
816void layer_switch(uint8_t new_layer)
817{
818 if (current_layer != new_layer) {
819 debug("Layer Switch: "); debug_hex(current_layer);
820 debug(" -> "); debug_hex(new_layer); debug("\n");
821
822 current_layer = new_layer;
823 clear_keyboard_but_mods(); // To avoid stuck keys
824 // NOTE: update mods with full scan of matrix? if modifier changes between layers
825 }
826}
827
828bool is_tap_key(key_t key) 975bool is_tap_key(key_t key)
829{ 976{
830 action_t action = get_action(key); 977 action_t action = layer_switch_get_action(key);
831 978
832 switch (action.kind.id) { 979 switch (action.kind.id) {
833 case ACT_LMODS_TAP: 980 case ACT_LMODS_TAP:
834 case ACT_RMODS_TAP: 981 case ACT_RMODS_TAP:
835 return true; 982 return true;
836 case ACT_LAYER: 983 case ACT_KEYMAP:
837 case ACT_LAYER_BIT: 984 case ACT_OVERLAY:
838 switch (action.layer.code) { 985 switch (action.layer.code) {
839 case LAYER_MOMENTARY: 986 case 0x04 ... 0xEF: /* tap key */
840 case LAYER_ON_PRESS: 987 case OP_INV:
841 case LAYER_ON_RELEASE:
842 case LAYER_DEFAULT:
843 return false;
844 case LAYER_TAP_TOGGLE:
845 default: /* tap key */
846 return true; 988 return true;
989 default:
990 return false;
847 } 991 }
848 return false; 992 case ACT_MACRO:
849 case ACT_FUNCTION: 993 case ACT_FUNCTION:
850 if (action.func.opt & FUNC_TAP) { return true; } 994 if (action.func.opt & FUNC_TAP) { return true; }
851 return false; 995 return false;
@@ -865,7 +1009,8 @@ static void debug_event(keyevent_t event)
865} 1009}
866static void debug_record(keyrecord_t record) 1010static void debug_record(keyrecord_t record)
867{ 1011{
868 debug_event(record.event); debug(":"); debug_dec(record.tap_count); 1012 debug_event(record.event); debug(":"); debug_dec(record.tap.count);
1013 if (record.tap.interrupted) debug("-");
869} 1014}
870static void debug_action(action_t action) 1015static void debug_action(action_t action)
871{ 1016{
@@ -876,8 +1021,8 @@ static void debug_action(action_t action)
876 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 1021 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
877 case ACT_USAGE: debug("ACT_USAGE"); break; 1022 case ACT_USAGE: debug("ACT_USAGE"); break;
878 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 1023 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
879 case ACT_LAYER: debug("ACT_LAYER"); break; 1024 case ACT_KEYMAP: debug("ACT_KEYMAP"); break;
880 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; 1025 case ACT_OVERLAY: debug("ACT_OVERLAY"); break;
881 case ACT_MACRO: debug("ACT_MACRO"); break; 1026 case ACT_MACRO: debug("ACT_MACRO"); break;
882 case ACT_COMMAND: debug("ACT_COMMAND"); break; 1027 case ACT_COMMAND: debug("ACT_COMMAND"); break;
883 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 1028 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
diff --git a/common/action.h b/common/action.h
index b9a6cb5b4..ead917983 100644
--- a/common/action.h
+++ b/common/action.h
@@ -19,12 +19,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20#include "keyboard.h" 20#include "keyboard.h"
21#include "keycode.h" 21#include "keycode.h"
22#include "action_macro.h"
22 23
23 24
24/* Struct to record event and tap count */ 25/* Struct to record event and tap count */
26typedef union {
27 struct {
28 bool interrupted :1;
29 bool reserved2 :1;
30 bool reserved1 :1;
31 bool reserved0 :1;
32 uint8_t count :4;
33 };
34} tap_t;
35
25typedef struct { 36typedef struct {
26 keyevent_t event; 37 keyevent_t event;
27 uint8_t tap_count; 38 tap_t tap;
28} keyrecord_t; 39} keyrecord_t;
29 40
30/* Action struct. 41/* Action struct.
@@ -76,17 +87,15 @@ typedef union {
76 87
77 88
78 89
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 */ 90/* Execute action per keyevent */
85void action_exec(keyevent_t event); 91void action_exec(keyevent_t event);
86 92
87/* action for key */ 93/* action for key */
88action_t action_for_key(uint8_t layer, key_t key); 94action_t action_for_key(uint8_t layer, key_t key);
89 95
96/* macro */
97const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
98
90/* user defined special function */ 99/* user defined special function */
91void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); 100void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
92 101
@@ -112,8 +121,8 @@ bool waiting_buffer_has_anykey_pressed(void);
112 * ============ 121 * ============
113 * 16bit code: action_kind(4bit) + action_parameter(12bit) 122 * 16bit code: action_kind(4bit) + action_parameter(12bit)
114 * 123 *
115 * Keyboard Keys 124 * Keyboard Keys(00XX)
116 * ------------- 125 * -------------------
117 * ACT_LMODS(0000): 126 * ACT_LMODS(0000):
118 * 0000|0000|000000|00 No action 127 * 0000|0000|000000|00 No action
119 * 0000|0000|000000|01 Transparent 128 * 0000|0000|000000|01 Transparent
@@ -143,8 +152,8 @@ bool waiting_buffer_has_anykey_pressed(void);
143 * 0011|mods| keycode Right mods + tap Key 152 * 0011|mods| keycode Right mods + tap Key
144 * 153 *
145 * 154 *
146 * Other HID Usage 155 * Other keys(01XX)
147 * --------------- 156 * --------------------
148 * This action handles other usages than keyboard. 157 * This action handles other usages than keyboard.
149 * ACT_USAGE(0100): 158 * ACT_USAGE(0100):
150 * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01) 159 * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01)
@@ -152,41 +161,45 @@ bool waiting_buffer_has_anykey_pressed(void);
152 * 0100|10| usage(10) (reserved) 161 * 0100|10| usage(10) (reserved)
153 * 0100|11| usage(10) (reserved) 162 * 0100|11| usage(10) (reserved)
154 * 163 *
155 *
156 * Mouse Keys
157 * ----------
158 * TODO: can be combined with 'Other HID Usage'? to save action kind id.
159 * ACT_MOUSEKEY(0110): 164 * ACT_MOUSEKEY(0110):
160 * 0101|XXXX| keycode Mouse key 165 * 0101|XXXX| keycode Mouse key
161 * 166 *
162 * 167 *
163 * Layer Actions 168 * Layer Actions(10XX)
164 * ------------- 169 * -------------------
165 * ACT_LAYER(1000): Set layer 170 * ACT_KEYMAP:
166 * ACT_LAYER_BIT(1001): Bit-op layer 171 * 1000|--xx|0000 0000 Clear keyamp and overlay
167 * 172 * 1000|LLLL|0000 00xx Reset default layer and clear keymap and overlay
168 * 1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary) 173 * 1000|LLLL| keycode Invert with tap key
169 * 1000|LLLL|0000 0001 set L to layer on press 174 * 1000|LLLL|1111 0000 Invert with tap toggle
170 * 1000|LLLL|0000 0010 set L to layer on release 175 * 1000|LLLL|1111 00xx Invert[^= 1<<L]
171 * 1000|----|0000 0011 set default to layer on both(return to default layer) 176 * 1000|LLLL|1111 0100 On/Off
172 * 1000|LLLL| keycode set L to layer while hold and send key on tap 177 * 1000|LLLL|1111 01xx On[|= 1<<L]
173 * 1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps 178 * 1000|LLLL|1111 1000 Off/On
174 * 1000|LLLL|1111 1111 set L to default and layer(on press) 179 * 1000|LLLL|1111 10xx Off[&= ~(1<<L)]
175 * 180 * 1000|LLLL|1111 1100 Set/Clear
176 * 1001|BBBB|0000 0000 (not used) 181 * 1000|LLLL|1111 11xx Set[= 1<<L]
177 * 1001|BBBB|0000 0001 bit-xor layer with B on press 182 * default layer: 0-15(4bit)
178 * 1001|BBBB|0000 0010 bit-xor layer with B on release 183 * xx: On {00:for special use, 01:press, 10:release, 11:both}
179 * 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary)
180 * 1001|BBBB| keycode bit-xor layer with B while hold and send key on tap
181 * 1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps
182 * 1001|BBBB|1111 1111 bit-xor default with B and set layer(on press)
183 * 184 *
185 * ACT_OVERLAY:
186 * 1011|0000|0000 0000 Clear overlay
187 * 1011|LLLL|0000 00ss Invert 4-bit chunk [^= L<<(4*ss)]
188 * 1011|LLLL| keycode Invert with tap key
189 * 1011|LLLL|1111 0000 Invert with tap toggle
190 * 1011|LLLL|1111 00xx Invert[^= 1<<L]
191 * 1011|LLLL|1111 0100 On/Off(momentary)
192 * 1011|LLLL|1111 01xx On[|= 1<<L]
193 * 1011|LLLL|1111 1000 Off/On
194 * 1011|LLLL|1111 10xx Off[&= ~(1<<L)]
195 * 1011|LLLL|1111 1100 Set/Clear
196 * 1011|LLLL|1111 11xx Set[= 1<<L]
197 * overlays: 16-layer on/off status(16bit)
198 * xx: On {00:for special use, 01:press, 10:release, 11:both}
184 * 199 *
185 * 200 *
186 * Extensions(11XX) 201 * Extensions(11XX)
187 * ---------------- 202 * ----------------
188 * NOTE: NOT FIXED
189 *
190 * ACT_MACRO(1100): 203 * ACT_MACRO(1100):
191 * 1100|opt | id(8) Macro play? 204 * 1100|opt | id(8) Macro play?
192 * 1100|1111| id(8) Macro record? 205 * 1100|1111| id(8) Macro record?
@@ -208,8 +221,8 @@ enum action_kind_id {
208 ACT_USAGE = 0b0100, 221 ACT_USAGE = 0b0100,
209 ACT_MOUSEKEY = 0b0101, 222 ACT_MOUSEKEY = 0b0101,
210 223
211 ACT_LAYER = 0b1000, 224 ACT_KEYMAP = 0b1000,
212 ACT_LAYER_BIT = 0b1001, 225 ACT_OVERLAY = 0b1001,
213 226
214 ACT_MACRO = 0b1100, 227 ACT_MACRO = 0b1100,
215 ACT_COMMAND = 0b1110, 228 ACT_COMMAND = 0b1110,
@@ -223,20 +236,20 @@ enum action_kind_id {
223#define ACTION(kind, param) ((kind)<<12 | (param)) 236#define ACTION(kind, param) ((kind)<<12 | (param))
224#define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) 237#define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F)
225 238
226/* Key */ 239/*
240 * Key
241 */
227#define ACTION_KEY(key) ACTION(ACT_LMODS, key) 242#define ACTION_KEY(key) ACTION(ACT_LMODS, key)
228/* Mods & key */ 243/* Mods & key */
229#define ACTION_LMODS(mods) ACTION(ACT_LMODS, MODS4(mods)<<8 | 0x00) 244#define ACTION_LMODS(mods) ACTION(ACT_LMODS, MODS4(mods)<<8 | 0x00)
230#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, MODS4(mods)<<8 | (key)) 245#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, MODS4(mods)<<8 | (key))
231#define ACTION_RMODS(mods) ACTION(ACT_RMODS, MODS4(mods)<<8 | 0x00) 246#define ACTION_RMODS(mods) ACTION(ACT_RMODS, MODS4(mods)<<8 | 0x00)
232#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, MODS4(mods)<<8 | (key)) 247#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, MODS4(mods)<<8 | (key))
233/* Mod & key */
234#define ACTION_LMOD(mod) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | 0x00) 248#define ACTION_LMOD(mod) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | 0x00)
235#define ACTION_LMOD_KEY(mod, key) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | (key)) 249#define ACTION_LMOD_KEY(mod, key) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | (key))
236#define ACTION_RMOD(mod) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | 0x00) 250#define ACTION_RMOD(mod) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | 0x00)
237#define ACTION_RMOD_KEY(mod, key) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | (key)) 251#define ACTION_RMOD_KEY(mod, key) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | (key))
238 252/* Tap key */
239/* Mods + Tap key */
240enum mods_codes { 253enum mods_codes {
241 MODS_ONESHOT = 0x00, 254 MODS_ONESHOT = 0x00,
242}; 255};
@@ -244,102 +257,112 @@ enum mods_codes {
244#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT) 257#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
245#define ACTION_RMODS_TAP_KEY(mods, key) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | (key)) 258#define ACTION_RMODS_TAP_KEY(mods, key) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | (key))
246#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT) 259#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
247/* Mod + Tap key */
248#define ACTION_LMOD_TAP_KEY(mod, key) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key)) 260#define ACTION_LMOD_TAP_KEY(mod, key) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
249#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) 261#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
250#define ACTION_RMOD_TAP_KEY(mod, key) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key)) 262#define ACTION_RMOD_TAP_KEY(mod, key) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
251#define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) 263#define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
252 264
265/* HID Usage */
266enum usage_pages {
267 PAGE_SYSTEM,
268 PAGE_CONSUMER
269};
270#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
271#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
253 272
254/* 273/* Mousekey */
255 * Switch layer 274#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
275
276
277
278/* Layer Actions:
279 * Invert layer ^= (1<<layer)
280 * On layer |= (1<<layer)
281 * Off layer &= ~(1<<layer)
282 * Set layer = (1<<layer)
283 * Clear layer = 0
256 */ 284 */
257enum layer_codes { 285enum layer_params {
258 LAYER_MOMENTARY = 0, 286 ON_PRESS = 1,
259 LAYER_ON_PRESS = 1, 287 ON_RELEASE = 2,
260 LAYER_ON_RELEASE = 2, 288 ON_BOTH = 3,
261 LAYER_DEFAULT =3, 289
262 LAYER_TAP_TOGGLE = 0xF0, 290 OP_RESET = 0x00,
263 LAYER_CHANGE_DEFAULT = 0xFF 291 OP_INV4 = 0x00,
264}; 292 OP_INV = 0xF0,
265enum layer_vals_default { 293 OP_ON = 0xF4,
266 DEFAULT_ON_PRESS = 1, 294 OP_OFF = 0xF8,
267 DEFAULT_ON_RELEASE = 2, 295 OP_SET = 0xFC,
268 DEFAULT_ON_BOTH = 3,
269}; 296};
270 297
271/* 298/*
272 * return to default layer 299 * Default Layer
273 */ 300 */
274#define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R 301#define ACTION_DEFAULT_LAYER ACTION(ACT_KEYMAP, ON_RELEASE<<8 | OP_RESET | 0)
275/* set default layer on press */ 302#define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_TO(layer, ON_RELEASE)
276#define ACTION_LAYER_DEFAULT_P ACTION(ACT_LAYER, DEFAULT_ON_PRESS<<8 | LAYER_DEFAULT) 303#define ACTION_DEFAULT_LAYER_TO(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_RESET | (on))
277/* set default layer on release */
278#define ACTION_LAYER_DEFAULT_R ACTION(ACT_LAYER, DEFAULT_ON_RELEASE<<8 | LAYER_DEFAULT)
279/* change default layer and set layer */
280
281/* 304/*
282 * Set layer 305 * Keymap Layer
283 */ 306 */
284/* set layer on press and none on release */ 307#define ACTION_KEYMAP_MOMENTARY(layer) ACTION_KEYMAP_ON_OFF(layer)
285#define ACTION_LAYER_SET(layer) ACTION_LAYER_SET_P(layer) 308#define ACTION_KEYMAP_TOGGLE(layer) ACTION_KEYMAP_INV(layer, ON_RELEASE)
286/* set layer on press and set default on release (This is needed by legacy keymap support.) */ 309/* Keymap Invert */
287#define ACTION_LAYER_SET_MOMENTARY(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_MOMENTARY) 310#define ACTION_KEYMAP_INV(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_INV | (on))
288/* set layer on press and none on release */ 311#define ACTION_KEYMAP_TAP_TOGGLE(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_INV | 0)
289#define ACTION_LAYER_SET_TOGGLE(layer) ACTION_LAYER_SET_R(layer) 312/* Keymap On */
290/* set layer while hold and send key on tap */ 313#define ACTION_KEYMAP_ON(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_ON | (on))
291#define ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key)) 314#define ACTION_KEYMAP_ON_OFF(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_ON | 0)
292/* set layer on press */ 315/* Keymap Off */
293#define ACTION_LAYER_SET_P(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_PRESS) 316#define ACTION_KEYMAP_OFF(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_OFF | (on))
294/* set layer on release */ 317#define ACTION_KEYMAP_OFF_ON(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_OFF | 0)
295#define ACTION_LAYER_SET_R(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_RELEASE) 318/* Keymap Set */
296/* set layer on hold and toggle on several taps */ 319#define ACTION_KEYMAP_SET(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_SET | (on))
297#define ACTION_LAYER_SET_TAP_TOGGLE(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_TAP_TOGGLE) 320#define ACTION_KEYMAP_SET_CLEAR(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_SET | 0)
298/* set default layer on both press and release */ 321/* Keymap Invert with tap key */
299#define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT) 322#define ACTION_KEYMAP_TAP_KEY(layer, key) ACTION(ACT_KEYMAP, (layer)<<8 | (key))
300 323
301/* 324/*
302 * Bit-op layer 325 * Overlay Layer
303 */ 326 */
304/* bit-xor on both press and release */ 327#define ACTION_OVERLAY_MOMENTARY(layer) ACTION_OVERLAY_ON_OFF(layer)
305#define ACTION_LAYER_BIT(bits) ACTION_LAYER_BIT_MOMENTARY(bits) 328#define ACTION_OVERLAY_TOGGLE(layer) ACTION_OVERLAY_INV(layer, ON_RELEASE)
306#define ACTION_LAYER_BIT_MOMENTARY(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_MOMENTARY) 329/* Overlay Clear */
307/* bit-xor on press */ 330#define ACTION_OVERLAY_CLEAR(on) ACTION(ACT_OVERLAY, 0<<8 | OP_INV4 | (on))
308#define ACTION_LAYER_BIT_TOGGLE(bits) ACTION_LAYER_BIT_R(bits) 331/* Overlay Invert 4-bit chunk */
309/* bit-xor while hold and send key on tap */ 332#define ACTION_OVERLAY_INV4(bits, shift) ACTION(ACT_OVERLAY, (bits)<<8 | OP_INV4 | shift)
310#define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key)) 333/* Overlay Invert */
311/* bit-xor on press */ 334#define ACTION_OVERLAY_INV(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_INV | (on))
312#define ACTION_LAYER_BIT_P(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_PRESS) 335#define ACTION_OVERLAY_TAP_TOGGLE(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_INV | 0)
313/* bit-xor on release */ 336/* Overlay On */
314#define ACTION_LAYER_BIT_R(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_RELEASE) 337#define ACTION_OVERLAY_ON(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_ON | (on))
315/* bit-xor while hold and toggle on several taps */ 338#define ACTION_OVERLAY_ON_OFF(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_ON | 0)
316#define ACTION_LAYER_BIT_TAP_TOGGLE(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_TAP_TOGGLE) 339/* Overlay Off */
317/* bit-xor default layer and set layer */ 340#define ACTION_OVERLAY_OFF(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_OFF | (on))
318#define ACTION_LAYER_BIT_DEFAULT(bits) ACTION(ACT_LAYER, (bits)<<8 | LAYER_CHANGE_DEFAULT) 341#define ACTION_OVERLAY_OFF_ON(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_OFF | 0)
319 342/* Overlay Set */
320 343#define ACTION_OVERLAY_SET(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_SET | (on))
321/* HID Usage */ 344#define ACTION_OVERLAY_SET_CLEAR(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_SET | 0)
322enum usage_pages { 345/* Overlay Invert with tap key */
323 PAGE_SYSTEM, 346#define ACTION_OVERLAY_TAP_KEY(layer, key) ACTION(ACT_OVERLAY, (layer)<<8 | (key))
324 PAGE_CONSUMER
325};
326#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
327#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
328 347
329/* Mousekey */
330#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
331 348
349/*
350 * Extensions
351 */
332/* Macro */ 352/* Macro */
333#define ACTION_MACRO(opt, id) ACTION(ACT_FUNCTION, (opt)<<8 | (addr)) 353#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
354#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
355#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id))
334 356
335/* Command */ 357/* Command */
336#define ACTION_COMMAND(opt, id) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) 358#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
337 359
338/* Function */ 360/* Function */
339enum function_opts { 361enum function_opts {
340 FUNC_TAP = 0x8, /* indciates function is tappable */ 362 FUNC_TAP = 0x8, /* indciates function is tappable */
341}; 363};
342#define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id) 364#define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id))
343#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | id) 365#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
366#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id))
344 367
345#endif /* ACTION_H */ 368#endif /* ACTION_H */
diff --git a/common/action_macro.c b/common/action_macro.c
index 72859c0dd..ca7ffa822 100644
--- a/common/action_macro.c
+++ b/common/action_macro.c
@@ -41,7 +41,6 @@ void action_macro_play(const prog_macro_t *macro_p)
41 case MODS_DOWN: 41 case MODS_DOWN:
42 MACRO_READ(); 42 MACRO_READ();
43 debug("MODS_DOWN("); debug_hex(macro); debug(")\n"); 43 debug("MODS_DOWN("); debug_hex(macro); debug(")\n");
44 debug("MODS_UP("); debug_hex(macro); debug(")\n");
45 add_mods(macro); 44 add_mods(macro);
46 break; 45 break;
47 case MODS_UP: 46 case MODS_UP:
diff --git a/common/action_macro.h b/common/action_macro.h
index 3833c7c8a..db6577959 100644
--- a/common/action_macro.h
+++ b/common/action_macro.h
@@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include <avr/pgmspace.h> 20#include <avr/pgmspace.h>
21 21
22 22
23#define MACRO_NONE 0
24#define MACRO(...) ({ static prog_macro_t _m[] PROGMEM = { __VA_ARGS__ }; _m; })
25
26
23typedef uint8_t macro_t; 27typedef uint8_t macro_t;
24typedef macro_t prog_macro_t PROGMEM; 28typedef macro_t prog_macro_t PROGMEM;
25 29
diff --git a/common/command.c b/common/command.c
index 7bb2a23f1..202d531fd 100644
--- a/common/command.c
+++ b/common/command.c
@@ -26,7 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26#include "timer.h" 26#include "timer.h"
27#include "keyboard.h" 27#include "keyboard.h"
28#include "bootloader.h" 28#include "bootloader.h"
29#include "layer_switch.h"
29#include "command.h" 30#include "command.h"
31
30#ifdef MOUSEKEY_ENABLE 32#ifdef MOUSEKEY_ENABLE
31#include "mousekey.h" 33#include "mousekey.h"
32#endif 34#endif
@@ -53,7 +55,7 @@ static void mousekey_console_help(void);
53#endif 55#endif
54 56
55static uint8_t numkey2num(uint8_t code); 57static uint8_t numkey2num(uint8_t code);
56static void switch_layer(uint8_t layer); 58static void switch_default_layer(uint8_t layer);
57 59
58 60
59typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; 61typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
@@ -261,18 +263,16 @@ static bool command_common(uint8_t code)
261#endif 263#endif
262 break; 264 break;
263#endif 265#endif
266 case KC_ESC:
267 case KC_GRV:
264 case KC_0: 268 case KC_0:
265 case KC_F10: 269 switch_default_layer(0);
266 clear_keyboard();
267 switch_layer(0);
268 break; 270 break;
269 case KC_1 ... KC_9: 271 case KC_1 ... KC_9:
270 clear_keyboard(); 272 switch_default_layer((code - KC_1) + 1);
271 switch_layer((code - KC_1) + 1);
272 break; 273 break;
273 case KC_F1 ... KC_F9: 274 case KC_F1 ... KC_F12:
274 clear_keyboard(); 275 switch_default_layer((code - KC_F1) + 1);
275 switch_layer((code - KC_F1) + 1);
276 break; 276 break;
277 default: 277 default:
278 print("?"); 278 print("?");
@@ -541,11 +541,10 @@ static uint8_t numkey2num(uint8_t code)
541 return 0; 541 return 0;
542} 542}
543 543
544static void switch_layer(uint8_t layer) 544static void switch_default_layer(uint8_t layer)
545{ 545{
546 print_val_hex8(current_layer); 546 print("switch_default_layer: "); print_dec(default_layer); print(" to "); print_dec(layer); print("\n");
547 print_val_hex8(default_layer); 547 default_layer_set(layer);
548 current_layer = layer; 548 overlay_clear();
549 default_layer = layer; 549 clear_keyboard();
550 print("switch to "); print_val_hex8(layer);
551} 550}
diff --git a/common/keymap.c b/common/keymap.c
index 078615814..aa8d944a7 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -14,13 +14,71 @@ GNU General Public License for more details.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <avr/pgmspace.h>
17#include "keymap.h" 18#include "keymap.h"
18#include "report.h" 19#include "report.h"
19#include "keycode.h" 20#include "keycode.h"
21#include "layer_switch.h"
20#include "action.h" 22#include "action.h"
23#include "action_macro.h"
24#include "debug.h"
21 25
22 26
23action_t keymap_keycode_to_action(uint8_t keycode) 27static action_t keycode_to_action(uint8_t keycode);
28
29#ifdef USE_KEYMAP_V2
30/* converts key to action */
31action_t action_for_key(uint8_t layer, key_t key)
32{
33 uint8_t keycode = keymap_key_to_keycode(layer, key);
34 switch (keycode) {
35 case KC_FN0 ... KC_FN31:
36 return keymap_fn_to_action(keycode);
37 default:
38 return keycode_to_action(keycode);
39 }
40}
41#else
42/*
43 * legacy keymap support
44 */
45/* translation for legacy keymap */
46action_t action_for_key(uint8_t layer, key_t key)
47{
48 /* convert from legacy keycode to action */
49 /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */
50 uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col);
51 action_t action;
52 switch (keycode) {
53 case KC_FN0 ... KC_FN31:
54 {
55 uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
56 uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
57 if (key) {
58 action.code = ACTION_KEYMAP_TAP_KEY(layer, key);
59 } else {
60 action.code = ACTION_KEYMAP_MOMENTARY(layer);
61 }
62 }
63 return action;
64 default:
65 return keycode_to_action(keycode);
66 }
67}
68#endif
69
70
71__attribute__ ((weak))
72const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; }
73
74__attribute__ ((weak))
75void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {}
76
77
78
79
80/* translates keycode to action */
81static action_t keycode_to_action(uint8_t keycode)
24{ 82{
25 action_t action; 83 action_t action;
26 switch (keycode) { 84 switch (keycode) {
@@ -51,34 +109,3 @@ action_t keymap_keycode_to_action(uint8_t keycode)
51 } 109 }
52 return action; 110 return action;
53} 111}
54
55#ifndef NO_LEGACY_KEYMAP_SUPPORT
56/* legacy support with weak reference */
57__attribute__ ((weak))
58action_t action_for_key(uint8_t layer, key_t key)
59{
60 /* convert from legacy keycode to action */
61 uint8_t keycode = keymap_get_keycode(layer, key.row, key.col);
62 action_t action;
63 switch (keycode) {
64 case KC_FN0 ... KC_FN31:
65 {
66 uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
67 uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
68 if (key) {
69 action.code = ACTION_LAYER_SET_TAP_KEY(layer, key);
70 } else {
71 action.code = ACTION_LAYER_SET_MOMENTARY(layer);
72 }
73 }
74 return action;
75 default:
76 return keymap_keycode_to_action(keycode);
77 }
78}
79#endif
80
81__attribute__ ((weak))
82void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
83{
84}
diff --git a/common/keymap.h b/common/keymap.h
index 63bf14482..0c483483f 100644
--- a/common/keymap.h
+++ b/common/keymap.h
@@ -23,16 +23,19 @@ 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/* translates key_t to keycode */ 26#ifdef USE_KEYMAP_V2
27/* translates key to keycode
28 * layer: 0-15 for base layers
29 * 16-31 for overlays
30 */
27uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); 31uint8_t keymap_key_to_keycode(uint8_t layer, key_t key);
28/* translates keycode to action */
29action_t keymap_keycode_to_action(uint8_t keycode);
30/* translates Fn keycode to action */ 32/* translates Fn keycode to action */
31action_t keymap_fn_to_action(uint8_t keycode); 33action_t keymap_fn_to_action(uint8_t keycode);
32 34#else
33 35#warning "You are using LEGACY KEYAMP. Consider using NEW KEYMAP."
34 36/*
35#ifndef NO_LEGACY_KEYMAP_SUPPORT 37 * legacy keymap support
38 */
36/* keycode of key */ 39/* keycode of key */
37uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); 40uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col);
38/* layer to move during press Fn key */ 41/* layer to move during press Fn key */
diff --git a/common/layer_switch.c b/common/layer_switch.c
new file mode 100644
index 000000000..19e286f88
--- /dev/null
+++ b/common/layer_switch.c
@@ -0,0 +1,201 @@
1#include <stdint.h>
2#include "keyboard.h"
3#include "action.h"
4#include "debug.h"
5#include "util.h"
6#include "layer_switch.h"
7
8
9/*
10 * Default Layer (0-15)
11 */
12uint8_t default_layer = 0;
13
14void default_layer_set(uint8_t layer)
15{
16 debug("default_layer_set: ");
17 debug_dec(default_layer); debug(" to ");
18
19 default_layer = layer;
20
21 debug_dec(default_layer); debug("\n");
22
23 clear_keyboard_but_mods(); // To avoid stuck keys
24}
25
26
27/*
28 * Keymap Layer (0-15)
29 */
30uint16_t keymap_stat = 0;
31
32/* return highest layer whose state is on */
33uint8_t keymap_get_layer(void)
34{
35 return biton16(keymap_stat);
36}
37
38static void keymap_stat_set(uint16_t stat)
39{
40 debug("keymap: ");
41 keymap_debug(); debug(" to ");
42
43 keymap_stat = stat;
44
45 keymap_debug(); debug("\n");
46
47 clear_keyboard_but_mods(); // To avoid stuck keys
48}
49
50void keymap_clear(void)
51{
52 keymap_stat_set(0);
53}
54
55
56void keymap_set(uint16_t stat)
57{
58 keymap_stat_set(stat);
59}
60
61void keymap_move(uint8_t layer)
62{
63 keymap_stat_set(1<<layer);
64}
65
66void keymap_on(uint8_t layer)
67{
68 keymap_stat_set(keymap_stat | (1<<layer));
69}
70
71void keymap_off(uint8_t layer)
72{
73 keymap_stat_set(keymap_stat & ~(1<<layer));
74}
75
76void keymap_invert(uint8_t layer)
77{
78 keymap_stat_set(keymap_stat ^ (1<<layer));
79}
80
81void keymap_or(uint16_t stat)
82{
83 keymap_stat_set(keymap_stat | stat);
84}
85void keymap_and(uint16_t stat)
86{
87 keymap_stat_set(keymap_stat & stat);
88}
89void keymap_xor(uint16_t stat)
90{
91 keymap_stat_set(keymap_stat ^ stat);
92}
93
94void keymap_debug(void)
95{
96 debug_hex16(keymap_stat); debug("("); debug_dec(keymap_get_layer()); debug(")");
97}
98
99
100
101/*
102 * Overlay Layer (16-31 = 0-15|0x10)
103 */
104uint16_t overlay_stat = 0;
105
106/* return highest layer whose state is on */
107uint8_t overlay_get_layer(void)
108{
109 return biton16(overlay_stat);
110}
111
112static void overlay_stat_set(uint16_t stat)
113{
114 debug("overlay: ");
115 overlay_debug(); debug(" to ");
116
117 overlay_stat = stat;
118
119 overlay_debug(); debug("\n");
120
121 clear_keyboard_but_mods(); // To avoid stuck keys
122}
123
124void overlay_clear(void)
125{
126 overlay_stat_set(0);
127}
128
129
130void overlay_set(uint16_t stat)
131{
132 overlay_stat_set(stat);
133}
134
135void overlay_move(uint8_t layer)
136{
137 overlay_stat_set(1<<layer);
138}
139
140void overlay_on(uint8_t layer)
141{
142 overlay_stat_set(overlay_stat | (1<<layer));
143}
144
145void overlay_off(uint8_t layer)
146{
147 overlay_stat_set(overlay_stat & ~(1<<layer));
148}
149
150void overlay_invert(uint8_t layer)
151{
152 overlay_stat_set(overlay_stat ^ (1<<layer));
153}
154
155void overlay_or(uint16_t stat)
156{
157 overlay_stat_set(overlay_stat | stat);
158}
159void overlay_and(uint16_t stat)
160{
161 overlay_stat_set(overlay_stat & stat);
162}
163void overlay_xor(uint16_t stat)
164{
165 overlay_stat_set(overlay_stat ^ stat);
166}
167
168void overlay_debug(void)
169{
170 debug_hex16(overlay_stat); debug("("); debug_dec(overlay_get_layer()); debug(")");
171}
172
173action_t layer_switch_get_action(key_t key)
174{
175 action_t action;
176 action.code = ACTION_TRANSPARENT;
177
178 /* overlay: top layer first */
179 for (int8_t i = 15; i >= 0; i--) {
180 if (overlay_stat & (1<<i)) {
181 action = action_for_key(i | OVERLAY_BIT, key);
182 if (action.code != ACTION_TRANSPARENT) {
183 return action;
184 }
185 }
186 }
187
188 /* keymap: top layer first */
189 for (int8_t i = 15; i >= 0; i--) {
190 if (keymap_stat & (1<<i)) {
191 action = action_for_key(i, key);
192 if (action.code != ACTION_TRANSPARENT) {
193 return action;
194 }
195 }
196 }
197
198 /* default layer */
199 action = action_for_key(default_layer, key);
200 return action;
201}
diff --git a/common/layer_switch.h b/common/layer_switch.h
new file mode 100644
index 000000000..a566ab12b
--- /dev/null
+++ b/common/layer_switch.h
@@ -0,0 +1,80 @@
1/*
2Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef LAYER_SWITCH_H
18#define LAYER_SWITCH_H
19
20#include <stdint.h>
21#include "keyboard.h"
22#include "action.h"
23
24
25/* overlays are asigned at layer 16-31 */
26#define OVERLAY_BIT 0x10
27#define OVERLAY_MASK 0x0F
28
29
30/*
31 * Default Layer
32 */
33/* base layer to fall back */
34extern uint8_t default_layer;
35void default_layer_set(uint8_t layer);
36
37
38/*
39 * Keymap Layer
40 */
41extern uint16_t keymap_stat;
42/* return current active layer */
43uint8_t keymap_get_layer(void);
44void keymap_clear(void);
45void keymap_set(uint16_t stat);
46void keymap_move(uint8_t layer);
47void keymap_on(uint8_t layer);
48void keymap_off(uint8_t layer);
49void keymap_invert(uint8_t layer);
50/* bitwise operation */
51void keymap_or(uint16_t stat);
52void keymap_and(uint16_t stat);
53void keymap_xor(uint16_t stat);
54void keymap_debug(void);
55
56
57/*
58 * Overlay Layer
59 */
60extern uint16_t overlay_stat;
61/* return current active layer */
62uint8_t overlay_get_layer(void);
63void overlay_clear(void);
64void overlay_set(uint16_t stat);
65void overlay_move(uint8_t layer);
66void overlay_on(uint8_t layer);
67void overlay_off(uint8_t layer);
68void overlay_invert(uint8_t layer);
69/* bitwise operation */
70void overlay_or(uint16_t stat);
71void overlay_and(uint16_t stat);
72void overlay_xor(uint16_t stat);
73void overlay_debug(void);
74
75
76
77/* return action depending on current layer status */
78action_t layer_switch_get_action(key_t key);
79
80#endif
diff --git a/common/util.c b/common/util.c
index 9d8fb9321..ff1926d7d 100644
--- a/common/util.c
+++ b/common/util.c
@@ -39,6 +39,7 @@ uint8_t bitpop16(uint16_t bits)
39} 39}
40 40
41// most significant on-bit - return highest location of on-bit 41// most significant on-bit - return highest location of on-bit
42// NOTE: return 0 when bit0 is on or all bits are off
42uint8_t biton(uint8_t bits) 43uint8_t biton(uint8_t bits)
43{ 44{
44 uint8_t n = 0; 45 uint8_t n = 0;
@@ -47,3 +48,13 @@ uint8_t biton(uint8_t bits)
47 if (bits >> 1) { bits >>= 1; n += 1;} 48 if (bits >> 1) { bits >>= 1; n += 1;}
48 return n; 49 return n;
49} 50}
51
52uint8_t biton16(uint16_t bits)
53{
54 uint8_t n = 0;
55 if (bits >> 8) { bits >>= 8; n += 8;}
56 if (bits >> 4) { bits >>= 4; n += 4;}
57 if (bits >> 2) { bits >>= 2; n += 2;}
58 if (bits >> 1) { bits >>= 1; n += 1;}
59 return n;
60}
diff --git a/common/util.h b/common/util.h
index c3734487f..58b7fdf14 100644
--- a/common/util.h
+++ b/common/util.h
@@ -31,5 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31uint8_t bitpop(uint8_t bits); 31uint8_t bitpop(uint8_t bits);
32uint8_t bitpop16(uint16_t bits); 32uint8_t bitpop16(uint16_t bits);
33uint8_t biton(uint8_t bits); 33uint8_t biton(uint8_t bits);
34uint8_t biton16(uint16_t bits);
34 35
35#endif 36#endif
diff --git a/converter/m0110_usb/Makefile.lufa b/converter/m0110_usb/Makefile.lufa
new file mode 100644
index 000000000..028bdf933
--- /dev/null
+++ b/converter/m0110_usb/Makefile.lufa
@@ -0,0 +1,91 @@
1# Target file name (without extension).
2TARGET = m0110_lufa
3
4# Directory common source filess exist
5TOP_DIR = ../..
6
7# Directory keyboard dependent files exist
8TARGET_DIR = .
9
10# keyboard dependent files
11SRC = keymap.c \
12 matrix.c \
13 led.c \
14 m0110.c
15
16CONFIG_H = config.h
17
18
19# MCU name, you MUST set this to match the board you are using
20# type "make clean" after changing this, so all files will be rebuilt
21#MCU = at90usb162 # Teensy 1.0
22MCU = atmega32u4 # Teensy 2.0
23#MCU = at90usb646 # Teensy++ 1.0
24#MCU = at90usb1286 # Teensy++ 2.0
25
26
27# Processor frequency.
28# Normally the first thing your program should do is set the clock prescaler,
29# so your program will run at the correct speed. You should also set this
30# variable to same clock speed. The _delay_ms() macro uses this, and many
31# examples use this variable to calculate timings. Do not add a "UL" here.
32F_CPU = 16000000
33
34
35#
36# LUFA specific
37#
38# Target architecture (see library "Board Types" documentation).
39ARCH = AVR8
40
41# Input clock frequency.
42# This will define a symbol, F_USB, in all source code files equal to the
43# input clock frequency (before any prescaling is performed) in Hz. This value may
44# differ from F_CPU if prescaling is used on the latter, and is required as the
45# raw input clock is fed directly to the PLL sections of the AVR for high speed
46# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
47# at the end, this will be done automatically to create a 32-bit value in your
48# source code.
49#
50# If no clock division is performed on the input clock inside the AVR (via the
51# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
52F_USB = $(F_CPU)
53
54# Interrupt driven control endpoint task
55OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
56
57
58# Build Options
59# *Comment out* to disable the options.
60#
61MOUSEKEY_ENABLE = yes # Mouse keys
62#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
63EXTRAKEY_ENABLE = yes # Audio control and System control
64CONSOLE_ENABLE = yes # Console for debug
65#NKRO_ENABLE = yes # USB Nkey Rollover
66
67
68# Boot Section Size in bytes
69# Teensy halfKay 512
70# Atmel DFU loader 4096
71# LUFA bootloader 4096
72OPT_DEFS += -DBOOT_SIZE=4096
73
74
75
76#---------------- Programming Options --------------------------
77PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
78
79
80# Search Path
81VPATH += $(TARGET_DIR)
82VPATH += $(TOP_DIR)
83
84
85include $(TOP_DIR)/protocol/lufa.mk
86include $(TOP_DIR)/protocol.mk
87include $(TOP_DIR)/common.mk
88include $(TOP_DIR)/rules.mk
89
90hasu: EXTRAFLAGS += -DHASU
91hasu: all
diff --git a/converter/m0110_usb/README.md b/converter/m0110_usb/README.md
index 206f43425..80503e875 100644
--- a/converter/m0110_usb/README.md
+++ b/converter/m0110_usb/README.md
@@ -53,7 +53,8 @@ You can edit *Makefile* and *config.h* to change compile options and pin configu
53 53
54 $ git clone git://github.com/tmk/tmk_keyboard.git (or download source) 54 $ git clone git://github.com/tmk/tmk_keyboard.git (or download source)
55 $ cd m0110_usb 55 $ cd m0110_usb
56 $ make 56 $ make -f Makefile.lufa clean
57 $ make -f Makefile.lufa
57 58
58and program your Teensy with [PJRC Teensy loader](http://www.pjrc.com/teensy/loader.html). 59and program your Teensy with [PJRC Teensy loader](http://www.pjrc.com/teensy/loader.html).
59 60
@@ -74,7 +75,7 @@ You can change keymaps by editing *keymap.c*.
74 |---------------------------------------------------------| |---------------| 75 |---------------------------------------------------------| |---------------|
75 |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | | 1| 2| 3| | 76 |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | | 1| 2| 3| |
76 `---------------------------------------------------------' |-----------|Ent| 77 `---------------------------------------------------------' |-----------|Ent|
77 |Alt|Gui | Space |Ctl |Alt| | 0| .| | 78 |Ctl|Alt | Space |Gui |Ctl| | 0| .| |
78 `-----------------------------------------------' `---------------' 79 `-----------------------------------------------' `---------------'
79#### *HHKB/WASD Layer(WASD/IJKL)* 80#### *HHKB/WASD Layer(WASD/IJKL)*
80 ,---------------------------------------------------------. ,---------------. 81 ,---------------------------------------------------------. ,---------------.
@@ -86,7 +87,7 @@ You can change keymaps by editing *keymap.c*.
86 |---------------------------------------------------------| |---------------| 87 |---------------------------------------------------------| |---------------|
87 |Shift |End| |PgD| | | |PgD| |End| |Shift | | 1| 2| 3| | 88 |Shift |End| |PgD| | | |PgD| |End| |Shift | | 1| 2| 3| |
88 `---------------------------------------------------------' |-----------|Ent| 89 `---------------------------------------------------------' |-----------|Ent|
89 |Alt|Gui | Space |Ctl |Alt| | 0| .| | 90 |Ctl|Alt | Space |Gui |Ctl| | 0| .| |
90 `-----------------------------------------------' `---------------' 91 `-----------------------------------------------' `---------------'
91 92
92### M0110A 93### M0110A
diff --git a/converter/m0110_usb/config.h b/converter/m0110_usb/config.h
index be00259e6..d43f28383 100644
--- a/converter/m0110_usb/config.h
+++ b/converter/m0110_usb/config.h
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24 24
25#define VENDOR_ID 0xFEED 25#define VENDOR_ID 0xFEED
26#define PRODUCT_ID 0x0110 26#define PRODUCT_ID 0x0110
27#define DEVICE_VER 0x0100
27#define MANUFACTURER t.m.k. 28#define MANUFACTURER t.m.k.
28#define PRODUCT M0110 keyboard converter 29#define PRODUCT M0110 keyboard converter
29#define DESCRIPTION convert M0110 keyboard to USB 30#define DESCRIPTION convert M0110 keyboard to USB
diff --git a/converter/m0110_usb/keymap.c b/converter/m0110_usb/keymap.c
index 191bf3a15..7a3bc3585 100644
--- a/converter/m0110_usb/keymap.c
+++ b/converter/m0110_usb/keymap.c
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#include <stdint.h> 19#include <stdint.h>
20#include <stdbool.h> 20#include <stdbool.h>
21#include <avr/pgmspace.h> 21#include <avr/pgmspace.h>
22#include "usb_keyboard.h"
23#include "keycode.h" 22#include "keycode.h"
24#include "print.h" 23#include "print.h"
25#include "debug.h" 24#include "debug.h"
@@ -148,7 +147,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
148 * |---------------------------------------------------------| |---------------| 147 * |---------------------------------------------------------| |---------------|
149 * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shft|Up | | 1| 2| 3| | 148 * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shft|Up | | 1| 2| 3| |
150 * |---------------------------------------------------------| |-----------|Ent| 149 * |---------------------------------------------------------| |-----------|Ent|
151 * |Alt |Gui | Space |Ctl| \|Lft|Rgt|Dn | | 0| .| | 150 * |Ctl |Alt | Space |Gui| \|Lft|Rgt|Dn | | 0| .| |
152 * `---------------------------------------------------------' `---------------' 151 * `---------------------------------------------------------' `---------------'
153 */ 152 */
154 KEYMAP( 153 KEYMAP(
@@ -156,7 +155,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
156 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, P7, P8, P9, PMNS, 155 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, P7, P8, P9, PMNS,
157 FN0, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS, 156 FN0, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS,
158 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, UP, P1, P2, P3, PENT, 157 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, UP, P1, P2, P3, PENT,
159 LALT,LGUI, SPC, LCTL,BSLS,LEFT,RGHT,DOWN, P0, PDOT 158 LCTL,LALT, SPC, LGUI,BSLS,LEFT,RGHT,DOWN, P0, PDOT
160 ), 159 ),
161 /* Cursor Layer(WASD, IJKL) 160 /* Cursor Layer(WASD, IJKL)
162 * ,---------------------------------------------------------. ,---------------. 161 * ,---------------------------------------------------------. ,---------------.
@@ -168,7 +167,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
168 * |---------------------------------------------------------| |---------------| 167 * |---------------------------------------------------------| |---------------|
169 * |Shift |End| |PgD| | | |PgD| |End| |Shif|PgU| | 1| 2| 3| | 168 * |Shift |End| |PgD| | | |PgD| |End| |Shif|PgU| | 1| 2| 3| |
170 * |---------------------------------------------------------| |-----------|Ent| 169 * |---------------------------------------------------------| |-----------|Ent|
171 * |Alt |Gui | Space |Gui |Ins|Hom|End|PgD| | 0| .| | 170 * |Ctl |Alt | Space |Gui |Ins|Hom|End|PgD| | 0| .| |
172 * `---------------------------------------------------------' `---------------' 171 * `---------------------------------------------------------' `---------------'
173 */ 172 */
174 KEYMAP( 173 KEYMAP(
@@ -176,7 +175,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
176 CAPS,HOME,UP, PGUP,NO, NO, NO, PGUP,UP, HOME,PSCR,SLCK,PAUS, P7, P8, P9, PMNS, 175 CAPS,HOME,UP, PGUP,NO, NO, NO, PGUP,UP, HOME,PSCR,SLCK,PAUS, P7, P8, P9, PMNS,
177 FN0, LEFT,DOWN,RGHT,NO, NO, NO, LEFT,DOWN,RGHT,NO, NO, ENT, P4, P5, P6, PPLS, 176 FN0, LEFT,DOWN,RGHT,NO, NO, NO, LEFT,DOWN,RGHT,NO, NO, ENT, P4, P5, P6, PPLS,
178 LSFT,END, NO, PGDN,NO, NO, NO, PGDN,NO, END, NO, PGUP, P1, P2, P3, PENT, 177 LSFT,END, NO, PGDN,NO, NO, NO, PGDN,NO, END, NO, PGUP, P1, P2, P3, PENT,
179 LALT,LGUI, SPC, LCTL,INS, HOME,END, PGDN, P0, PDOT 178 LCTL,LALT, SPC, LGUI,INS, HOME,END, PGDN, P0, PDOT
180 ), 179 ),
181}; 180};
182 181
diff --git a/converter/pc98_usb/Makefile b/converter/pc98_usb/Makefile
new file mode 100644
index 000000000..2575d8667
--- /dev/null
+++ b/converter/pc98_usb/Makefile
@@ -0,0 +1,83 @@
1# Target file name (without extension).
2TARGET = pc98_usb
3
4# Directory common source filess exist
5TOP_DIR = ../..
6
7# Directory keyboard dependent files exist
8TARGET_DIR = .
9
10# keyboard dependent files
11SRC = keymap.c \
12 matrix.c \
13 led.c \
14 protocol/serial_uart.c
15# protocol/serial_soft.c
16
17CONFIG_H = config.h
18
19
20# MCU name, you MUST set this to match the board you are using
21# type "make clean" after changing this, so all files will be rebuilt
22#MCU = at90usb162 # Teensy 1.0
23MCU = atmega32u4 # Teensy 2.0
24#MCU = at90usb646 # Teensy++ 1.0
25#MCU = at90usb1286 # Teensy++ 2.0
26
27
28# Processor frequency.
29# Normally the first thing your program should do is set the clock prescaler,
30# so your program will run at the correct speed. You should also set this
31# variable to same clock speed. The _delay_ms() macro uses this, and many
32# examples use this variable to calculate timings. Do not add a "UL" here.
33F_CPU = 16000000
34
35
36#
37# LUFA specific
38#
39# Target architecture (see library "Board Types" documentation).
40ARCH = AVR8
41
42# Input clock frequency.
43# This will define a symbol, F_USB, in all source code files equal to the
44# input clock frequency (before any prescaling is performed) in Hz. This value may
45# differ from F_CPU if prescaling is used on the latter, and is required as the
46# raw input clock is fed directly to the PLL sections of the AVR for high speed
47# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
48# at the end, this will be done automatically to create a 32-bit value in your
49# source code.
50#
51# If no clock division is performed on the input clock inside the AVR (via the
52# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
53F_USB = $(F_CPU)
54
55# Interrupt driven control endpoint task
56OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
57
58
59# Build Options
60# *Comment out* to disable the options.
61#
62MOUSEKEY_ENABLE = yes # Mouse keys
63EXTRAKEY_ENABLE = yes # Audio control and System control
64CONSOLE_ENABLE = yes # Console for debug
65#NKRO_ENABLE = yes # USB Nkey Rollover
66
67
68# Boot Section Size in bytes
69# Teensy halfKay 512
70# Atmel DFU loader 4096
71# LUFA bootloader 4096
72OPT_DEFS += -DBOOT_SIZE=4096
73
74
75# Search Path
76VPATH += $(TARGET_DIR)
77VPATH += $(TOP_DIR)
78
79
80include $(TOP_DIR)/protocol/lufa.mk
81include $(TOP_DIR)/protocol.mk
82include $(TOP_DIR)/common.mk
83include $(TOP_DIR)/rules.mk
diff --git a/converter/pc98_usb/README b/converter/pc98_usb/README
new file mode 100644
index 000000000..23f1b614e
--- /dev/null
+++ b/converter/pc98_usb/README
@@ -0,0 +1,70 @@
1PC98 to USB keyboard protocol converter
2=======================================
3Target MCU is ATMega32u4 but other USB capable AVR will also work.
4
5
6Connector
7---------
8
9 8Pin mini DIN
10 ___ ___
11 / |_| \
12 / 8 7 6 \
13 | 5 4 3 |
14 \_ 2 1 _/
15 \_____/
16 (receptacle)
17
18
19Wiring: You can change this with ediging config.h.
20
21 Pin mini DIN MCU
22 ----------------------------------
23 1 ~RST PD1
24 2 GND GND
25 3 ~RDY PD4
26 4 RXD PD2
27 5 ~RTY PD5
28 6 NC
29 7 NC
30 8 5V VCC
31
32
33
34
35Protocol
36--------
37Singnal: Asynchronous, Positive logic, 19200baud, Least bit first
38Frame format: 1-Start bit(Lo), 8-Data bits, Odd-Parity, 1-Stop bit
39
40This converter uses software method for testing purpose. AVR UART engine will work better.
41
42
43
44
45Build Firmware
46--------------
47Just use 'make'
48
49 $ cd pc98_usb
50 $ make
51
52Then, load the binary to MCU with your favorite programmer.
53
54
55
56Other PC98 converter projects and resource
57------------------------------------------
58PC98 to USB
59http://davy.nyacom.net/kbd98usb/
60
61PC98 to PS/2
62http://www.tsp.ne.jp/~sawada/mago/c_gka98at.htm
63http://www.tsp.ne.jp/~sawada/mago/src/gka98at.asm
64
65PC98 keyboard commands
66http://www.webtech.co.jp/company/doc/undocumented_mem/io_kb.txt
67
68
69Inhibit repeating key:
700x9C, 0x70
diff --git a/converter/pc98_usb/config.h b/converter/pc98_usb/config.h
new file mode 100644
index 000000000..4f91c07ce
--- /dev/null
+++ b/converter/pc98_usb/config.h
@@ -0,0 +1,126 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21#define VENDOR_ID 0xFEED
22#define PRODUCT_ID 0x9898
23#define DEVICE_VER 0x0100
24#define MANUFACTURER t.m.k.
25#define PRODUCT PC98 keyboard converter
26#define DESCRIPTION converts PC98 keyboard protocol into USB
27
28
29/* matrix size */
30#define MATRIX_ROWS 16
31#define MATRIX_COLS 8
32
33/* To use new keymap framework */
34#define USE_KEYMAP_V2
35
36/* key combination for command */
37#define IS_COMMAND() ( \
38 host_get_first_key() == KC_CANCEL \
39)
40
41
42/* PC98 Reset Port shared with TXD */
43#define PC98_RST_DDR DDRD
44#define PC98_RST_PORT PORTD
45#define PC98_RST_BIT 3
46/* PC98 Ready Port */
47#define PC98_RDY_DDR DDRD
48#define PC98_RDY_PORT PORTD
49#define PC98_RDY_BIT 4
50/* PC98 Retry Port */
51#define PC98_RTY_DDR DDRD
52#define PC98_RTY_PORT PORTD
53#define PC98_RTY_BIT 5
54
55/*
56 * PC98 Serial(USART) configuration
57 * asynchronous, positive logic, 19200baud, bit order: LSB first
58 * 1-start bit, 8-data bit, odd parity, 1-stop bit
59 */
60/*
61 * Software Serial
62 */
63#define SERIAL_SOFT_BAUD 19200
64#define SERIAL_SOFT_PARITY_ODD
65#define SERIAL_SOFT_BIT_ORDER_LSB
66#define SERIAL_SOFT_LOGIC_POSITIVE
67/* RXD Port */
68#define SERIAL_SOFT_RXD_DDR DDRD
69#define SERIAL_SOFT_RXD_PORT PORTD
70#define SERIAL_SOFT_RXD_PIN PIND
71#define SERIAL_SOFT_RXD_BIT 2
72#define SERIAL_SOFT_RXD_READ() (SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT))
73/* RXD Interupt */
74#define SERIAL_SOFT_RXD_VECT INT2_vect
75#define SERIAL_SOFT_RXD_INIT() do { \
76 /* pin configuration: input with pull-up */ \
77 SERIAL_SOFT_RXD_DDR &= ~(1<<SERIAL_SOFT_RXD_BIT); \
78 SERIAL_SOFT_RXD_PORT |= (1<<SERIAL_SOFT_RXD_BIT); \
79 /* enable interrupt: INT2(falling edge) */ \
80 EICRA |= ((1<<ISC21)|(0<<ISC20)); \
81 EIMSK |= (1<<INT2); \
82 sei(); \
83} while (0)
84#define SERIAL_SOFT_RXD_INT_ENTER()
85#define SERIAL_SOFT_RXD_INT_EXIT() do { \
86 /* clear interrupt flag */ \
87 EIFR = (1<<INTF2); \
88} while (0)
89/* TXD Port */
90#define SERIAL_SOFT_TXD_DDR DDRD
91#define SERIAL_SOFT_TXD_PORT PORTD
92#define SERIAL_SOFT_TXD_PIN PIND
93#define SERIAL_SOFT_TXD_BIT 3
94#define SERIAL_SOFT_TXD_HI() do { SERIAL_SOFT_TXD_PORT |= (1<<SERIAL_SOFT_TXD_BIT); } while (0)
95#define SERIAL_SOFT_TXD_LO() do { SERIAL_SOFT_TXD_PORT &= ~(1<<SERIAL_SOFT_TXD_BIT); } while (0)
96#define SERIAL_SOFT_TXD_INIT() do { \
97 /* pin configuration: output */ \
98 SERIAL_SOFT_TXD_DDR |= (1<<SERIAL_SOFT_TXD_BIT); \
99 /* idle */ \
100 SERIAL_SOFT_TXD_ON(); \
101} while (0)
102
103
104/*
105 * Hardware Serial(UART)
106 */
107#ifdef __AVR_ATmega32U4__
108 #define SERIAL_UART_BAUD 19200
109 #define SERIAL_UART_DATA UDR1
110 #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
111 #define SERIAL_UART_RXD_VECT USART1_RX_vect
112 #define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
113 #define SERIAL_UART_INIT() do { \
114 UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \
115 UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \
116 UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \
117 UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); /* TX interrupt, TX: enable */ \
118 UCSR1C |= (1<<UPM11) | (1<<UPM10); /* parity: none(00), even(01), odd(11) */ \
119 sei(); \
120 } while(0)
121#else
122 #error "USART configuration is needed."
123#endif
124
125
126#endif
diff --git a/converter/pc98_usb/keymap.c b/converter/pc98_usb/keymap.c
new file mode 100644
index 000000000..279b2b60c
--- /dev/null
+++ b/converter/pc98_usb/keymap.c
@@ -0,0 +1,222 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include <stdbool.h>
20#include <avr/pgmspace.h>
21#include "keycode.h"
22#include "action.h"
23#include "action_macro.h"
24#include "layer_switch.h"
25#include "util.h"
26#include "keymap.h"
27
28
29
30
31/* PC-9801-98-S02 Raku Raku keyboard(Luckyboard) Normal Mode
32 ,---------------------------------------------------------------.
33 | 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 6A| 6B| 36| 37| 3F| 3E|
34 `---------------------------------------------------------------'
35 ,---------------------------------------------------------------.
36 | 00| 01| 02| 03| 04| 05| 58| 71| 06| 07| 08| 09| 0A| 0E|
37 |---------------------------------------------------------------|
38 | 0F| 10| 11| 12| 13| 14| 3A | 15| 16| 17| 18| 19| 1C|
39 |---------------------------------------------------------'. |
40 | 74| 20| 21| 22| 23| 24| 3B | 3C | 25| 26| 27| 28| 29| |
41 |---------------------------------------------------------------|
42 | 70| 2A| 2B| 2C| 2D| 2E| 38| 3D | 39| 2F| 30| 31| 32| 33| 70|
43 `---------------------------------------------------------------'
44 | 73| 51| 5B| 59| 34| 5A| 35| xx|
45 `-----------------------------------------------'
46 xx: 74 35 F4 B5
47*/
48#define KEYMAP( \
49 K60, K61, K62, K63, K64, K65, K66, K67, K68, K69, K6A, K6B, K36, K37, K3F, K3E, \
50 K00, K01, K02, K03, K04, K05, K58, K71, K06, K07, K08, K09, K0A, K0E, \
51 K0F, K10, K11, K12, K13, K14, K3A, K15, K16, K17, K18, K19, K1C, \
52 K74, K20, K21, K22, K23, K24, K3B, K3C, K25, K26, K27, K28, K29, \
53 K70,K2A, K2B, K2C, K2D, K2E, K38, K3D, K39, K2F, K30, K31, K32, K33, \
54 K73, K51, K5B, K59, K34, K5A, K35 \
55) { \
56 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
57 { KC_##K08, KC_##K09, KC_##K0A, KC_NO, KC_NO, KC_NO, KC_##K0E, KC_##K0F }, \
58 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
59 { KC_##K18, KC_##K19, KC_NO, KC_NO, KC_##K1C, KC_NO, KC_NO, KC_NO }, \
60 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
61 { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
62 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
63 { KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F }, \
64 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
65 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
66 { KC_NO, KC_##K51, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
67 { KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_NO, KC_NO, KC_NO, KC_NO }, \
68 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_##K67 }, \
69 { KC_##K68, KC_##K69, KC_##K6A, KC_##K6B, KC_NO, KC_NO, KC_NO, KC_NO }, \
70 { KC_##K70, KC_##K71, KC_NO, KC_##K73, KC_##K74, KC_NO, KC_NO, KC_NO }, \
71 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \
72}
73
74
75
76static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
77 /*
78 ,---------------------------------------------------------------.
79 | 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 6A| 6B| 36| 37| 3F| 3E|
80 `---------------------------------------------------------------'
81 ,---------------------------------------------------------------.
82 | 00| 01| 02| 03| 04| 05| 58| 71| 06| 07| 08| 09| 0A| 0E|
83 |---------------------------------------------------------------|
84 | 0F| 10| 11| 12| 13| 14| 3A | 15| 16| 17| 18| 19| 1C|
85 |---------------------------------------------------------------|
86 | 74| 20| 21| 22| 23| 24| MINS| EQL| 25| 26| 27| 28| 29| |
87 |---------------------------------------------------------------|
88 | 70| 2A| 2B| 2C| 2D| 2E| 38| 3D | 39| 2F| 30| 31| 32| 33| 70|
89 `---------------------------------------------------------------'
90 | 73| 51| 5B| 59| 34| 5A| 35| xx|
91 `-----------------------------------------------'
92 */
93 KEYMAP(
94 CANCEL,COPY, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, FN6,
95 ESC, 1, 2, 3, 4, 5, FN4, FN5, 6, 7, 8, 9, 0, BSPC,
96 TAB, Q, W, E, R, T, UP, Y, U, I, O, P, ENT,
97 LCTL, A, S, D, F, G, MINS, EQL, H, J, K, L, FN2,
98 LSFT, Z, X, C, V, B, GRV, BSLS, QUOT, N, M,COMM, DOT, FN1,
99 LGUI, LALT, LCTL, LSFT, SPC, SPC, RALT
100 ),
101 KEYMAP(
102 PAUS,COPY, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14,
103 GRV, F1, F2, F3, F4, F5, NO, NO, F6, F7, F8, F9, F10, DEL,
104 TAB, Q, W, E, R, T, UP, HOME,PGDN,PGUP, END, P, ENT,
105 LCTL, A, S, D, F, G, MINS, EQL, LEFT,DOWN, UP,RGHT,SCLN,
106 LSFT, Z, X, C, V, B, INS, DOWN, DEL,HOME,PGDN,PGUP, END,TRNS,
107 LGUI, LALT, LCTL, LSFT, SPC, SPC, RALT
108 ),
109 KEYMAP(
110 PAUS,COPY, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14,
111 GRV, F1, F2, F3, F4, F5, NO, NO, F6, F7, F8, F9, F10, DEL,
112 TAB, Q, W, E, R, T, UP, WH_L,WH_D,WH_U,WH_R, P, ENT,
113 LCTL, A, S, D, F, G, MINS, EQL, MS_L,MS_D,MS_U,MS_R,TRNS,
114 LSFT, Z, X, C, V, B, INS, DOWN, BTN3,BTN2,BTN1,BTN4,BTN5,TRNS,
115 LGUI, LALT, LCTL, LSFT, SPC, SPC, RALT
116 ),
117};
118static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
119
120/*
121 * Macro definition
122 */
123enum macro_id {
124 LBRACKET,
125 RBRACKET,
126 DUMMY,
127};
128
129const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
130{
131 keyevent_t event = record->event;
132 //uint8_t tap_count = record->tap_count;
133
134 switch (id) {
135 case LBRACKET:
136 return (event.pressed ?
137 MACRO( T(LBRC), END ) :
138 MACRO( T(LBRC), END ) );
139 case RBRACKET:
140 return (event.pressed ?
141 MACRO( T(RBRC), END ) :
142 MACRO( T(RBRC), END ) );
143 }
144 return MACRO_NONE;
145}
146
147/*
148 * Action function
149 */
150void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
151{
152/*
153 keyevent_t event = record->event;
154 uint8_t tap_count = record->tap_count;
155 switch (id) {
156 case 0xFF:
157 action_macro_play(get_macro(opt, event.pressed));
158 break;
159 }
160*/
161}
162
163
164/*
165 * Fn actions
166 */
167static const uint16_t PROGMEM fn_actions[] = {
168 ACTION_KEYMAP_TAP_TOGGLE(0), // FN0
169 ACTION_KEYMAP_TAP_KEY(1, KC_SLASH), // FN1
170 ACTION_KEYMAP_TAP_KEY(2, KC_SCLN), // FN2
171 ACTION_KEYMAP_MOMENTARY(2), // FN3
172 ACTION_MACRO(LBRACKET), // FN4
173 ACTION_MACRO(RBRACKET), // FN5
174 ACTION_MACRO(DUMMY), // FN6
175};
176
177
178
179
180
181
182/*
183 * No need to edit.
184 */
185#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
186#define OVERLAYS_SIZE (sizeof(overlays) / sizeof(overlays[0]))
187#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
188
189/* translates key to keycode */
190uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
191{
192 /* Overlay: 16-31(OVERLAY_BIT(0x10) | overlay_layer) */
193 if (layer & OVERLAY_BIT) {
194 layer &= OVERLAY_MASK;
195 if (layer < OVERLAYS_SIZE) {
196 return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]);
197 } else {
198 return KC_TRANSPARENT;
199 }
200 }
201 /* Keymap: 0-15 */
202 else {
203 if (layer < KEYMAPS_SIZE) {
204 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
205 } else {
206 // fall back to layer 0
207 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
208 }
209 }
210}
211
212/* translates Fn keycode to action */
213action_t keymap_fn_to_action(uint8_t keycode)
214{
215 action_t action;
216 if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
217 action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
218 } else {
219 action.code = ACTION_NO;
220 }
221 return action;
222}
diff --git a/converter/pc98_usb/led.c b/converter/pc98_usb/led.c
new file mode 100644
index 000000000..48c3f1c2b
--- /dev/null
+++ b/converter/pc98_usb/led.c
@@ -0,0 +1,33 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "stdint.h"
19#include "serial.h"
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25 uint8_t sun_led = 0;
26 if (usb_led & (1<<USB_LED_NUM_LOCK)) sun_led |= (1<<0);
27 if (usb_led & (1<<USB_LED_COMPOSE)) sun_led |= (1<<1);
28 if (usb_led & (1<<USB_LED_SCROLL_LOCK)) sun_led |= (1<<2);
29 if (usb_led & (1<<USB_LED_CAPS_LOCK)) sun_led |= (1<<3);
30
31 serial_send(0x0E);
32 serial_send(sun_led);
33}
diff --git a/converter/pc98_usb/matrix.c b/converter/pc98_usb/matrix.c
new file mode 100644
index 000000000..d03aaf10d
--- /dev/null
+++ b/converter/pc98_usb/matrix.c
@@ -0,0 +1,215 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include <stdbool.h>
20#include <avr/io.h>
21#include <util/delay.h>
22#include "print.h"
23#include "util.h"
24#include "matrix.h"
25#include "debug.h"
26#include "protocol/serial.h"
27
28
29/*
30 * Matrix Array usage:
31 *
32 * ROW: 16(4bits)
33 * COL: 8(3bits)
34 *
35 * 8bit wide
36 * +---------+
37 * 0|00 ... 07|
38 * 1|08 ... 0F|
39 * :| ... |
40 * :| ... |
41 * E|70 ... 77|
42 * F|78 ... 7F|
43 * +---------+
44 */
45static uint8_t matrix[MATRIX_ROWS];
46#define ROW(code) ((code>>3)&0xF)
47#define COL(code) (code&0x07)
48
49static bool is_modified = false;
50
51
52inline
53uint8_t matrix_rows(void)
54{
55 return MATRIX_ROWS;
56}
57
58inline
59uint8_t matrix_cols(void)
60{
61 return MATRIX_COLS;
62}
63
64static void pc98_inhibit_repeat(void)
65{
66 uint8_t code;
67
68 while (serial_recv()) ;
69RETRY:
70 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
71 _delay_ms(500);
72 serial_send(0x9C);
73
74 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
75 _delay_ms(100);
76 while (!(code = serial_recv())) ;
77 print("PC98: send 9C: "); print_hex8(code); print("\n");
78 if (code != 0xFA) goto RETRY;
79
80
81
82 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
83 _delay_ms(100);
84 serial_send(0x70);
85
86 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
87 _delay_ms(100);
88 //code = serial_recv();
89 while (!(code = serial_recv())) ;
90 print("PC98: send 70: "); print_hex8(code); print("\n");
91 if (code != 0xFA) goto RETRY;
92}
93
94void matrix_init(void)
95{
96 print_enable = true;
97// debug_enable = true;
98// debug_matrix = true;
99
100 PC98_RST_DDR |= (1<<PC98_RST_BIT);
101 PC98_RDY_DDR |= (1<<PC98_RDY_BIT);
102 PC98_RTY_DDR |= (1<<PC98_RTY_BIT);
103 PC98_RST_PORT |= (1<<PC98_RST_BIT);
104 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
105 PC98_RTY_PORT |= (1<<PC98_RTY_BIT);
106
107
108 serial_init();
109
110 // PC98 reset
111/*
112 PC98_RST_PORT &= ~(1<<PC98_RST_BIT);
113 _delay_us(15);
114 PC98_RST_PORT |= (1<<PC98_RST_BIT);
115 _delay_us(13);
116 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
117*/
118
119 _delay_ms(500);
120 pc98_inhibit_repeat();
121
122
123 // PC98 ready
124 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
125
126 // initialize matrix state: all keys off
127 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
128
129 debug("init\n");
130 return;
131}
132
133uint8_t matrix_scan(void)
134{
135 is_modified = false;
136
137 uint16_t code;
138 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
139 _delay_us(30);
140 code = serial_recv2();
141 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
142 if (code == -1) return 0;
143
144if (code == 0x60) {
145 pc98_inhibit_repeat();
146
147/*
148 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
149 _delay_ms(100);
150 serial_send(0x96);
151 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
152*/
153
154 return 0;
155}
156
157 print_hex8(code); print(" ");
158
159 if (code&0x80) {
160 // break code
161 if (matrix_is_on(ROW(code), COL(code))) {
162 matrix[ROW(code)] &= ~(1<<COL(code));
163 is_modified = true;
164 }
165 } else {
166 // make code
167 if (!matrix_is_on(ROW(code), COL(code))) {
168 matrix[ROW(code)] |= (1<<COL(code));
169 is_modified = true;
170 }
171 }
172 return code;
173}
174
175bool matrix_is_modified(void)
176{
177 return is_modified;
178}
179
180inline
181bool matrix_has_ghost(void)
182{
183 return false;
184}
185
186inline
187bool matrix_is_on(uint8_t row, uint8_t col)
188{
189 return (matrix[row] & (1<<col));
190}
191
192inline
193uint8_t matrix_get_row(uint8_t row)
194{
195 return matrix[row];
196}
197
198void matrix_print(void)
199{
200 print("\nr/c 01234567\n");
201 for (uint8_t row = 0; row < matrix_rows(); row++) {
202 phex(row); print(": ");
203 pbin_reverse(matrix_get_row(row));
204 print("\n");
205 }
206}
207
208uint8_t matrix_key_count(void)
209{
210 uint8_t count = 0;
211 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
212 count += bitpop(matrix[i]);
213 }
214 return count;
215}
diff --git a/converter/sun_usb/config.h b/converter/sun_usb/config.h
index b4f0ff977..65ce9daf6 100644
--- a/converter/sun_usb/config.h
+++ b/converter/sun_usb/config.h
@@ -43,40 +43,46 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
43 * asynchronous, negative logic, 1200baud, no flow control 43 * asynchronous, negative logic, 1200baud, no flow control
44 * 1-start bit, 8-data bit, non parity, 1-stop bit 44 * 1-start bit, 8-data bit, non parity, 1-stop bit
45 */ 45 */
46#define SERIAL_BAUD 1200 46#define SERIAL_SOFT_BAUD 1200
47 47#define SERIAL_SOFT_PARITY_NONE
48#define SERIAL_RXD_DDR DDRD 48#define SERIAL_SOFT_BIT_ORDER_LSB
49#define SERIAL_RXD_PORT PORTD 49#define SERIAL_SOFT_LOGIC_NEGATIVE
50#define SERIAL_RXD_PIN PIND 50/* RXD Port */
51#define SERIAL_RXD_BIT 2 51#define SERIAL_SOFT_RXD_ENABLE
52#define SERIAL_RXD_VECT INT2_vect 52#define SERIAL_SOFT_RXD_DDR DDRD
53#define SERIAL_RXD_INIT() do { \ 53#define SERIAL_SOFT_RXD_PORT PORTD
54#define SERIAL_SOFT_RXD_PIN PIND
55#define SERIAL_SOFT_RXD_BIT 2
56#define SERIAL_SOFT_RXD_VECT INT2_vect
57/* RXD Interupt */
58#define SERIAL_SOFT_RXD_INIT() do { \
54 /* pin configuration: input with pull-up */ \ 59 /* pin configuration: input with pull-up */ \
55 SERIAL_RXD_DDR &= ~(1<<SERIAL_RXD_BIT); \ 60 SERIAL_SOFT_RXD_DDR &= ~(1<<SERIAL_SOFT_RXD_BIT); \
56 SERIAL_RXD_PORT |= (1<<SERIAL_RXD_BIT); \ 61 SERIAL_SOFT_RXD_PORT |= (1<<SERIAL_SOFT_RXD_BIT); \
57 /* enable interrupt: INT2(rising edge) */ \ 62 /* enable interrupt: INT2(rising edge) */ \
58 EICRA |= ((1<<ISC21)|(1<<ISC20)); \ 63 EICRA |= ((1<<ISC21)|(1<<ISC20)); \
59 EIMSK |= (1<<INT2); \ 64 EIMSK |= (1<<INT2); \
65 sei(); \
60} while (0) 66} while (0)
61#define SERIAL_RXD_INT_ENTER() 67#define SERIAL_SOFT_RXD_INT_ENTER()
62#define SERIAL_RXD_INT_EXIT() do { \ 68#define SERIAL_SOFT_RXD_INT_EXIT() do { \
63 /* clear interrupt flag */ \ 69 /* clear interrupt flag */ \
64 EIFR = (1<<INTF2); \ 70 EIFR = (1<<INTF2); \
65} while (0) 71} while (0)
66#define SERIAL_RXD_READ() (~SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) 72#define SERIAL_SOFT_RXD_READ() (SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT))
67 73/* TXD Port */
68#define SERIAL_TXD_DDR DDRD 74#define SERIAL_SOFT_TXD_ENABLE
69#define SERIAL_TXD_PORT PORTD 75#define SERIAL_SOFT_TXD_DDR DDRD
70#define SERIAL_TXD_PIN PIND 76#define SERIAL_SOFT_TXD_PORT PORTD
71#define SERIAL_TXD_BIT 3 77#define SERIAL_SOFT_TXD_PIN PIND
72/* negative logic */ 78#define SERIAL_SOFT_TXD_BIT 3
73#define SERIAL_TXD_ON() do { SERIAL_TXD_PORT &= ~(1<<SERIAL_TXD_BIT); } while (0) 79#define SERIAL_SOFT_TXD_HI() do { SERIAL_SOFT_TXD_PORT |= (1<<SERIAL_SOFT_TXD_BIT); } while (0)
74#define SERIAL_TXD_OFF() do { SERIAL_TXD_PORT |= (1<<SERIAL_TXD_BIT); } while (0) 80#define SERIAL_SOFT_TXD_LO() do { SERIAL_SOFT_TXD_PORT &= ~(1<<SERIAL_SOFT_TXD_BIT); } while (0)
75#define SERIAL_TXD_INIT() do { \ 81#define SERIAL_SOFT_TXD_INIT() do { \
76 /* pin configuration: output */ \ 82 /* pin configuration: output */ \
77 SERIAL_TXD_DDR |= (1<<SERIAL_TXD_BIT); \ 83 SERIAL_SOFT_TXD_DDR |= (1<<SERIAL_SOFT_TXD_BIT); \
78 /* idle */ \ 84 /* idle */ \
79 SERIAL_TXD_ON(); \ 85 SERIAL_SOFT_TXD_ON(); \
80} while (0) 86} while (0)
81 87
82#endif 88#endif
diff --git a/doc/keymap.md b/doc/keymap.md
new file mode 100644
index 000000000..ca48c6e5a
--- /dev/null
+++ b/doc/keymap.md
@@ -0,0 +1,514 @@
1Keymap framework - how to define your keymap
2============================================
3***NOTE: This is not final version, may be inconsistent with source code and changed occasionally for a while.***
4
5## 0. Keymap and layers
6**Keymap** is comprised of multiple layers of key layout, you can define **16** layers at most.
7**Layer** is an array of **keycodes** to define **actions** on each physical keys.
8respective layers can be validated simultaneously. Layers are indexed with 0 to 15 and higher layer has precedence.
9
10 Keymap with 16 Layers Layer: array of Keycodes
11 --------------------- ------------------------
12 stack of layers content of layer
13 ____________ precedence _______________________
14 / / | high / ESC / F1 / F2 / F3 ....
15 15 /___________// | /-----/-----/-----/-----
16 14 /___________// | / TAB / / / ....
17 13 /___________/_ | /-----/-----/-----/-----
18 : / : : : : : / | /LCtrl/ / / ....
19 3 /___________// | : / : : : :
20 2 /___________// | 2 `--------------------------
21 1 /___________// | 1 `--------------------------
22 0 /___________/ V low 0 `--------------------------
23
24
25
26### 0.1 Keymap status
27Keymap has its state in two parameters:
28**`default_layer`** indicates a base keymap layer(0-15) which is always valid and to be referred, **`keymap_stat`** is 16bit variable which has current on/off status of layers on its each bit.
29
30Keymap layer '0' is usually `default_layer` and which is the only valid layer and other layers is initially off after boot up firmware, though, you can configured them in `config.h`.
31To change `default_layer` will be useful when you want to switch key layout completely, say you use Colmak instead of Qwerty.
32
33 Initial state of Keymap Change base layout
34 ----------------------- ------------------
35
36 15 15
37 14 14
38 13 13
39 : :
40 3 3 ____________
41 2 ____________ 2 / /
42 1 / / ,->1 /___________/
43 ,->0 /___________/ | 0
44 | |
45 `--- default_layer = 0 `--- default_layer = 1
46 keymap_stat = 0x0001 keymap_stat = 0x0002
47
48On the other hand, you shall change `keymap_state` to overlay base layer with some layers for feature such as navigation keys, function key(F1-F12), media keys or special actions.
49
50 Overlay feature layer
51 --------------------- bit|status
52 ____________ ---+------
53 15 / / 15 | 0
54 14 /___________// -----> 14 | 1
55 13 /___________/ -----> 13 | 1
56 : : |
57 3 ____________ 3 | 0
58 2 / / 2 | 0
59 ,->1 /___________/ -----> 1 | 1
60 | 0 0 | 0
61 | |
62 `--- default_layer = 1 |
63 keymap_stat = 0x6002 <-----'
64
65
66
67### 0.2 Layer Precedence and Transparency
68Note that ***higher layer has higher priority on stack of layers***, namely firmware falls down from top layer to bottom to look up keycode. Once it spots keycode other than **`KC_TRNS`**(transparent) on a layer it stops searching and lower layers aren't referred.
69
70You can place `KC_TRNS` on overlay layer changes just part of layout to fall back on lower or base layer.
71Key with `KC_TRANS` doen't has its own keycode and refers to lower valid layers for keycode, instead.
72See example below.
73
74
75### 0.3 Keymap Example
76Keymap is **`keymaps[]`** C array in fact and you can define layers in it with **`KEYMAP()`** C macro and keycodes. To use complex actions you need to define `Fn` keycode in **`fn_actions[]`** array.
77
78This is a keymap example for [HHKB](http://en.wikipedia.org/wiki/Happy_Hacking_Keyboard) keyboard.
79This example has three layers, 'Qwerty' as base layer, 'Cursor' and 'Mousekey'.
80In this example,
81
82 `Fn0` is a **momentary layer switching** key, you can use keys on Cursor layer while holding the key.
83
84 `Fn1` is a momentary layer switching key with tapping feature, you can get semicolon **';'** with taping the key and switch layers while holding the key. The word **'tap'** or **'tapping'** mean to press and release a key quickly.
85
86 `Fn2` is a **toggle layer switch** key, you can stay switched layer after releasing the key unlike momentary switching.
87
88You can find other keymap definitions in file `keymap.c` located on project directories.
89
90 static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
91 /* 0: Qwerty
92 * ,-----------------------------------------------------------.
93 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
94 * |-----------------------------------------------------------|
95 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
96 * |-----------------------------------------------------------|
97 * |Contro| A| S| D| F| G| H| J| K| L|Fn1| '|Enter |
98 * |-----------------------------------------------------------|
99 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0|
100 * `-----------------------------------------------------------'
101 * |Gui|Alt |Space |Alt |Fn2|
102 * `-------------------------------------------'
103 */
104 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
105 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
106 LCTL,A, S, D, F, G, H, J, K, L, FN1, QUOT,ENT, \
107 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT,FN0, \
108 LGUI,LALT, SPC, RALT,FN2),
109 /* 1: Cursor(HHKB mode)
110 * ,-----------------------------------------------------------.
111 * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
112 * |-----------------------------------------------------------|
113 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
114 * |-----------------------------------------------------------|
115 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
116 * |-----------------------------------------------------------|
117 * |Shift | | | | | | +| -|End|PgD|Dow|Shift | |
118 * `-----------------------------------------------------------'
119 * |Gui |Alt |Space |Alt |Gui|
120 * `--------------------------------------------'
121 */
122 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
123 CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP, TRNS,BSPC, \
124 LCTL,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
125 LSFT,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,RSFT,TRNS, \
126 LGUI,LALT, SPC, RALT,RGUI),
127 /* 2: Mousekey
128 * ,-----------------------------------------------------------.
129 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
130 * |-----------------------------------------------------------|
131 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | |Backs|
132 * |-----------------------------------------------------------|
133 * |Contro| | | | | |McL|McD|McU|McR| | |Return |
134 * |-----------------------------------------------------------|
135 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
136 * `-----------------------------------------------------------'
137 * |Gui |Alt |Mb1 |Alt | |
138 * `--------------------------------------------'
139 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
140 */
141 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
142 TAB, TRNS,TRNS,TRNS,TRNS,TRNS,WH_L,WH_D,WH_U,WH_R,TRNS,TRNS,TRNS,BSPC, \
143 LCTL,TRNS,ACL0,ACL1,ACL2,TRNS,MS_L,MS_D,MS_U,MS_R,TRNS,QUOT,ENT, \
144 LSFT,TRNS,TRNS,TRNS,TRNS,BTN3,BTN2,BTN1,BTN4,BTN5,SLSH,RSFT,TRNS, \
145 LGUI,LALT, BTN1, RALT,TRNS),
146 };
147
148 static const uint16_t PROGMEM fn_actions[] = {
149 ACTION_KEYMAP_MOMENTARY(1), // FN0
150 ACTION_KEYMAP_TAP_KEY(2, KC_SCLN), // FN1
151 ACTION_KEYMAP_TOGGLE(2), // FN2
152 };
153
154
155
156
157## 1. Keycode
158See [`common/keycode.h`](../common/keycode.h) or keycode table below for the detail. Keycode is internal **8bit code** to inidicate action performed on key in keymap. Keycode has `KC_` prefixed symbol respectively. Most of keycodes like `KC_A` have simple action registers key to host on press and unregister on release, while some of other keycodes has some special actions like `Fn` keys, Media contorl keys, System control keys and Mousekeys.
159
160 ***In `KEYMAP()` macro you should 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()`.
161
162### 1.0 Other key
163- `KC_NO` for no aciton
164- `KC_TRNS` for layer transparency (See above)
165
166### 1.1 Normal key
167- `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key
168- `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT`
169- `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS`
170- `KC_UP`, `KC_DOWN`, `KC_RGHT`, `KC_LEFT`, `KC_PGUP`, `KC_PGDN`, `KC_HOME`, `KC_END`
171- `KC_CAPS`, `KC_NLCK`, `KC_SLCK`, `KC_PSCR`, `KC_PAUS`, `KC_APP`, `KC_F1` to `KC_F24`
172- `KC_P1` to `KC_P0`, `KC_PDOT`, `KC_PCMM`, `KC_PSLS`, `KC_PAST`, `KC_PMNS`, `KC_PPLS`, `KC_PEQL`, `KC_PENT` for keypad.
173
174### 1.2 Modifier
175There are 8 modifiers which has discrimination between left and right.
176
177- `KC_LCTL` and `KC_RCTL` for Control
178- `KC_LSFT` and `KC_RSFT` for Shift
179- `KC_LALT` and `KC_RALT` for Alt
180- `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac
181
182### 1.3 Mousekey
183- `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor
184- `KC_WH_U`, `KC_WH_D`, `KC_WH_L`, `KC_WH_R` for mouse wheel
185- `KC_BTN1`, `KC_BTN2`, `KC_BTN3`, `KC_BTN4`, `KC_BTN5` for mouse buttons
186
187### 1.4 System & Media key
188- `KC_PWR`, `KC_SLEP`, `KC_WAKE` for Power, Sleep, Wake
189- `KC_MUTE`, `KC_VOLU`, `KC_VOLD` for audio volume control
190- `KC_MNXT`, `KC_MPRV`, `KC_MSTP`, `KC_MPLY`, `KC_MSEL` for media control
191- `KC_MAIL`, `KC_CALC`, `KC_MYCM` for application launch
192- `KC_WSCH`, `KC_WHOM`, `KC_WBAK`, `KC_WFWD`, `KC_WSTP`, `KC_WREF`, `KC_WFAV` for web browser operation
193
194### 1.5 Fn key
195`KC_FNnn` are keycodes for `Fn` key which not given any actions at the beginning unlike most of keycodes has its own inborn action. To use these keycodes in `KEYMAP` you need to assign action you want at first. Action of `Fn` key is defined in `fn_actions[]` and its index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` keyocde indicates the action defined in first element of the array. ***32 `Fn` keys can be defined at most.***
196
197### 1.6 Keycode Table
198 See keycode table in [`doc/keycode.txt`](./keycode.txt) for description of keycodes.
199
200 In regard to implementation side most of keycodes are identical with [HID usage][HID_usage](pdf) sent to host for real and some virtual keycodes are defined to support special actions.
201[HID_usage]: http://www.usb.org/developers/devclass_docs/Hut1_11.pdf
202
203
204
205## 2. Action
206See [`common/action.h`](../common/action.h). Action is a **16bit code** and defines function to perform on events of a key like press, release, holding and tapping.
207
208Most of keys just register 8bit scancode to host, but to support other complex features needs 16bit extended action codes internally. However, using 16bit action codes in keymap results in double size in memory against using jsut keycodes. To avoid this waste 8bit keycodes are used in `KEYMAP` instead of action codes.
209
210***You can just use keycodes of `Normal key`, `Modifier`, `Mousekey` and `System & Media key` in keymap*** to indicate corresponding actions instead of using action codes. While ***to use other special actions you should use keycode of `Fn` key defined in `fn_actions[]`.***
211
212Usually action codes are needed only when you want to use layer switching, or
213
214### 2.1 Key action
215This is a simple action that registers scancodes(HID usage in fact) to host on press event of key and unregister on release.
216
217#### 2.1.1 Normal key and Modifier
218This action usually won't be used expressly because you can use keycodes in `KEYMAP()` instead.
219You can define `Key` action on *'A'* key and *'left shift'* modifier with:
220
221 ACTION_KEY(KC_A)
222 ACTION_KEY(KC_LSHIFT)
223
224#### 2.1.2 Key with modifiers
225This action is comprised of strokes of modifiers and a key. `Macro` action is needed if you want more complex key strokes.
226Say you want to assign a key to `Shift + 1` to get charactor *'!'* or `Alt + Tab` to switch application windows.
227
228 ACTION_LMOD_KEY(KC_LSHIFT, KC_1)
229 ACTION_LMOD_KEY(KC_LALT, KC_TAB)
230
231Or `Alt,Shift + Tab` can be defined. `ACTION_LMODS_KEY()` requires **4-bit modifier state** and a **keycode** as arguments. See `keycode.h` for `MOD_BIT()` macro.
232
233 ACTION_LMODS_KEY((MOD_BIT(KC_LALT) | MOD_BIT(KC_LSHIFT)), KC_TAB)
234
235
236
237### 2.2 Layer Action
238These actions operate layers of keymap.
239
240Parameters:
241- layer: 0-15
242- on: { press | release | both }
243
244
245#### 2.2.0 Default Layer
246`default_layer` is layer which always is valid and referred to when actions is not defined on other layers.
247
248##### Return to Default Layer
249Turns on only `default layer` with clearing other all layers.
250
251 ACTION_DEFAULT_LAYER
252
253##### Set Default Layer
254Sets 'default layer' to layer and turn it on.
255
256 ACTION_DEFAULT_LAYER_SET_TO(layer)
257 ACTION_DEFAULT_LAYER_SET(layer, on)
258
259
260#### 2.2.1 Keymap
261These actions operate layer status of keymap.
262
263##### Momentary Switch
264Turns on layer momentary while holding, in other words turn on when key is pressed and off when released.
265
266 ACTION_KEYMAP_MOMENTARY(layer)
267
268
269##### Toggle Switch
270Turns on layer on first type and turns off on next.
271
272 ACTION_KEYMAP_TOGGLE(layer)
273
274
275##### Momentary Switch with tap key
276Turns on layer momentary while holding but registers key on tap.
277
278 ACTION_KEYMAP_TAP_KEY(layer, key)
279
280
281##### Momentary Switch with tap toggle
282Turns on layer momentary while holding but toggles it with serial taps.
283
284 ACTION_KEYMAP_TAP_TOGGLE(layer)
285
286
287##### Invert layer
288Inverts current layer state. If the layer is on it becomes off with this action.
289
290 ACTION_KEYMAP_INV(layer, on)
291
292
293##### Turn On layer
294Turns on layer state.
295
296 ACTION_KEYMAP_ON(layer, on)
297
298Turns on layer state on press and turn off on release. This is identical to **'Switch to layer'** action.
299
300 ACTION_KEYMAP_ON_OFF(layer)
301
302
303##### Turn Off layer
304Turns off layer state.
305
306 ACTION_KEYMAP_OFF(layer, on)
307
308
309##### Set layer
310Turn on layer only.
311`keymap_stat = (1<<layer) [layer: 0-15]`
312
313 ACTION_KEYMAP_SET(layer, on)
314
315Turns on layer only and clear all layer on release..
316
317 ACTION_KEYMAP_SET_CLEAR(layer)
318
319
320#### 2.2.2 Overlay
321***TBD***
322
323In addition to actions of `Keymap` above these actions are also available.
324
325##### Invert 4bit layer states
326Invert 4bits out of 16bits of overlay status on both press and release.
327`overlay_stat = (overlay_stat ^ bits<<(shift*4)) [bits: 0-15, shift: 0-3]`
328
329 ACTION_OVERLAY_INV4(bits, shift)
330
331
332
333### 2.3 Macro action
334***TBD***
335
336`Macro` action indicates complex key strokes.
337
338 MACRO( MD(LSHIFT), D(D), END )
339 MACRO( U(D), MU(LSHIFT), END )
340 MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END )
341
342#### 2.3.1 Normal mode
343- **I()** change interavl of stroke.
344- **D()** press key
345- **U()** release key
346- **T()** type key(press and release)
347- **W()** wait
348- **MD()** modifier down
349- **MU()** modifier up
350- **END** end mark
351
352#### 2.3.2 Extended mode
353
354***TODO: sample impl***
355See `keyboard/hhkb/keymap.c` for sample.
356
357
358### 2.4 Function action
359***TBD***
360
361There are two type of action, normal `Function` and tappable `Function`.
362These actions call user defined function with `id`, `opt`, and key event information as arguments.
363
364#### 2.4.1 Function
365To define normal `Function` action in keymap use this.
366
367 ACTION_FUNCTION(id, opt)
368
369#### 2.4.2 Function with tap
370To define tappable `Function` action in keymap use this.
371
372 ACTION_FUNCTION_TAP(id, opt)
373
374#### 2.4.3 Implement user function
375`Function` actions can be defined freely with C by user in callback function:
376
377 void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt)
378
379This C function is called every time key is operated, argument `id` selects action to be performed and `opt` can be used for option. Functon `id` can be 0-255 and `opt` can be 0-15.
380
381 `keyrecord_t` is comprised of key event and tap count. `keyevent_t` indicates which and when key is pressed or released. From `tap_count` you can know tap state, 0 means no tap. These information will be used in user function to decide how action of key is performed.
382
383 typedef struct {
384 keyevent_t event;
385 uint8_t tap_count;
386 } keyrecord_t;
387
388 typedef struct {
389 key_t key;
390 bool pressed;
391 uint16_t time;
392 } keyevent_t;
393
394 typedef struct {
395 uint8_t col;
396 uint8_t row;
397 } key_t;
398
399***TODO: sample impl***
400See `keyboard/hhkb/keymap.c` for sample.
401
402
403
404
405
406## 4. Layer switching Example
407There are some ways to switch layer with 'Layer' actions.
408
409### 4.1 Momentary switching
410Momentary switching changes layer only while holding Fn key.
411
412This action makes 'Layer 1' active(valid) on key press event and inactive on release event. Namely you can overlay a layer on base layer temporarily with this.
413
414 ACTION_KEYMAP_MOMENTARY(1)
415
416
417After switch actions of destination layer are perfomed.
418***Thus you shall need to place action to come back on destination layer***, or you will be stuck in destination layer without way to get back. Usually you need to palce same action or 'KC_TRNS` on destination layer to get back.
419
420
421### 4.2 Toggle switching
422Toggle switching changes layer after press then release. With this you can keep staying on the layer until you press the key again to return.
423
424This is toggle action of 'Layer 2'.
425
426 ACTION_KEYMAP_TOGGLE(2)
427
428
429
430### 4.3 Momentary switching with Tap key
431These actions switch layer only while holding `Fn` key and register key on tap. **Tap** means to press and release key quickly.
432
433 ACTION_KEYMAP_TAP_KEY(2, KC_SCLN)
434
435With this you can place layer switching function on normal key like ';' without losing its original key register function.
436
437
438
439### 4.4 Momentary switching with Tap Toggle
440This switches layer only while holding `Fn` key and toggle layer after several taps. **Tap** means to press and release key quickly.
441
442 ACTION_KEYMAP_TAP_TOGGLE(1)
443
444Number of taps can be defined with `TAPPING_TOGGLE` in `config.h`, `5` by default.
445
446
447
448## Tapping
449Tapping is to press and release key quickly. Tapping speed is determined with setting of `TAPPING_TERM`, which can be defined in `config.h`, 200ms by default.
450
451### Tap Key
452This is feature to assign normal key action and modifier including `Fn` to just one physical key. This is a kind of [Dual role modifier][dual_role]. It works as modifier or `Fn` when holding a key but registers normal key when tapping.
453
454Action for modifier with tap key.
455
456 ACTION_LMODS_TAP_KEY(mods, key)
457
458Action for `Fn` with tap key.
459
460 ACTION_KEYMAP_TAP_KEY(layer, key)
461
462[dual_role]: http://en.wikipedia.org/wiki/Modifier_key#Dual-role_modifier_keys
463
464
465### Tap Toggle
466This is feature to assign both toggle layer and momentary switch layer action to just one physical key. It works as mementary switch when holding a key but toggle switch when tapping.
467
468 ACTION_KEYMAP_TAP_TOGGLE(layer)
469
470
471### One Shot Modifier
472This adds oneshot feature to modifier key. 'One Shot Modifier' is one time modifier which has effect only on following one alpha key.
473It works as normal modifier key when holding but oneshot modifier when tapping.
474
475 ACTION_LMODS_ONESHOT(mods)
476
477Say you want to type 'The', you have to push and hold Shift before type 't' then release Shift before type 'h' and 'e' or you'll get 'THe'. With One Shot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here.
478
479
480
481
482## Legacy Keymap
483This was used in prior version and still works due to legacy support code in `common/keymap.c`. Legacy keymap doesn't support many of features that new keymap offers.
484
485In comparison with new keymap how to define Fn key is different. It uses two arrays `fn_layer[]` and `fn_keycode[]`. The index of arrays corresponds with postfix number of `Fn` key. Array `fn_layer[]` indicates destination layer to switch and `fn_keycode[]` has keycodes to send when tapping `Fn` key.
486
487In following setting example, `Fn0`, `Fn1` and `Fn2` switch layer to 1, 2 and 2 respectively. `Fn2` registers `Space` key when tap while `Fn0` and `Fn1` doesn't send any key.
488
489 static const uint8_t PROGMEM fn_layer[] = {
490 1, // Fn0
491 2, // Fn1
492 2, // Fn2
493 };
494
495 static const uint8_t PROGMEM fn_keycode[] = {
496 KC_NO, // Fn0
497 KC_NO, // Fn1
498 KC_SPC, // Fn2
499 };
500
501
502## Terminology
503- keymap
504- layer
505- layout
506- key
507- keycode
508- scancode
509- action
510- layer transparency
511- layer precedence
512- register
513- tap
514- Fn key
diff --git a/keyboard/IIgs_Standard/Makefile b/keyboard/IIgs/Makefile
index c18e9720c..c18e9720c 100644
--- a/keyboard/IIgs_Standard/Makefile
+++ b/keyboard/IIgs/Makefile
diff --git a/keyboard/IIgs_Standard/README b/keyboard/IIgs/README
index 4f9cad1ca..4f9cad1ca 100644
--- a/keyboard/IIgs_Standard/README
+++ b/keyboard/IIgs/README
diff --git a/keyboard/IIgs_Standard/config.h b/keyboard/IIgs/config.h
index 11acf87c0..11acf87c0 100644
--- a/keyboard/IIgs_Standard/config.h
+++ b/keyboard/IIgs/config.h
diff --git a/keyboard/IIgs_Standard/doc/PIN_BYPASS.jpg b/keyboard/IIgs/doc/PIN_BYPASS.jpg
index 2998f0c3f..2998f0c3f 100644
--- a/keyboard/IIgs_Standard/doc/PIN_BYPASS.jpg
+++ b/keyboard/IIgs/doc/PIN_BYPASS.jpg
Binary files differ
diff --git a/keyboard/IIgs_Standard/doc/Teensy++_Mod.jpg b/keyboard/IIgs/doc/Teensy++_Mod.jpg
index 146c1ab93..146c1ab93 100644
--- a/keyboard/IIgs_Standard/doc/Teensy++_Mod.jpg
+++ b/keyboard/IIgs/doc/Teensy++_Mod.jpg
Binary files differ
diff --git a/keyboard/IIgs_Standard/hid_listen.mac b/keyboard/IIgs/hid_listen.mac
index 8758fdf88..8758fdf88 100755
--- a/keyboard/IIgs_Standard/hid_listen.mac
+++ b/keyboard/IIgs/hid_listen.mac
Binary files differ
diff --git a/keyboard/IIgs_Standard/keymap.c b/keyboard/IIgs/keymap.c
index cd33e223a..cd33e223a 100644
--- a/keyboard/IIgs_Standard/keymap.c
+++ b/keyboard/IIgs/keymap.c
diff --git a/keyboard/IIgs_Standard/led.c b/keyboard/IIgs/led.c
index f76545f0b..f76545f0b 100644
--- a/keyboard/IIgs_Standard/led.c
+++ b/keyboard/IIgs/led.c
diff --git a/keyboard/IIgs_Standard/matrix.c b/keyboard/IIgs/matrix.c
index 6ca55b7ea..6ca55b7ea 100644
--- a/keyboard/IIgs_Standard/matrix.c
+++ b/keyboard/IIgs/matrix.c
diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa
index c8d3fa494..7a8303296 100644
--- a/keyboard/gh60/Makefile.lufa
+++ b/keyboard/gh60/Makefile.lufa
@@ -124,3 +124,9 @@ plain: all
124 124
125poker: OPT_DEFS += -DKEYMAP_POKER 125poker: OPT_DEFS += -DKEYMAP_POKER
126poker: all 126poker: all
127
128poker_set: OPT_DEFS += -DKEYMAP_POKER_SET
129poker_set: all
130
131poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT
132poker_bit: all
diff --git a/keyboard/gh60/Makefile.pjrc b/keyboard/gh60/Makefile.pjrc
index f253704fa..af6ef63ec 100644
--- a/keyboard/gh60/Makefile.pjrc
+++ b/keyboard/gh60/Makefile.pjrc
@@ -94,3 +94,9 @@ plain: all
94 94
95poker: OPT_DEFS += -DKEYMAP_POKER 95poker: OPT_DEFS += -DKEYMAP_POKER
96poker: all 96poker: all
97
98poker_set: OPT_DEFS += -DKEYMAP_POKER_SET
99poker_set: all
100
101poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT
102poker_bit: all
diff --git a/keyboard/gh60/README.md b/keyboard/gh60/README.md
index 405ab3dff..4dc4e5ee2 100644
--- a/keyboard/gh60/README.md
+++ b/keyboard/gh60/README.md
@@ -47,9 +47,10 @@ See [keymap_plain.h](keymap_plain.h) for detail.
47 `-----------------------------------------------------------' 47 `-----------------------------------------------------------'
48 48
49### 2 Poker keymap 49### 2 Poker keymap
50Poker layer emulation without Esc/grave bug :)
51 50
52See [keymap_poker.h](keymap_poker.h) for detail. 51See [keymap_poker.h](keymap_poker.h) for Poker layer emulation, [keymap_poker_bit.h](keymap_poker_bit.h) and [keymap_poker_set.h](keymap_poker_set.h) for better support of Esc and arrow.
52
53 These keymap supports Colemak, Dvorak and Workmans, use `Magic` + {`1`, `2`, `3`} to switch and `Magic` + `0` to return to Qwerty.
53 54
54#### 2.0 Poker Default Layer 55#### 2.0 Poker Default Layer
55 ,-----------------------------------------------------------. 56 ,-----------------------------------------------------------.
@@ -108,7 +109,7 @@ See [keymap_poker.h](keymap_poker.h) for detail.
108### 3. Funky keymap 109### 3. Funky keymap
109This is my keymap(default) with HHKB, Vi cursor and Mousekey layer. 110This is my keymap(default) with HHKB, Vi cursor and Mousekey layer.
110 111
111See [keymap.h](keymap.h) for detail. 112See [keymap.c](keymap.c) for detail.
112 113
113#### 3.0 Funky Default Layer 114#### 3.0 Funky Default Layer
114 ,-----------------------------------------------------------. 115 ,-----------------------------------------------------------.
diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h
index a760d5dfb..ef0c9a173 100644
--- a/keyboard/gh60/config.h
+++ b/keyboard/gh60/config.h
@@ -41,6 +41,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
41/* Set 0 if need no debouncing */ 41/* Set 0 if need no debouncing */
42#define DEBOUNCE 5 42#define DEBOUNCE 5
43 43
44/* To use new keymap framework */
45#define USE_KEYMAP_V2
44 46
45/* key combination for command */ 47/* key combination for command */
46#define IS_COMMAND() ( \ 48#define IS_COMMAND() ( \
diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c
index a17c11fc3..1f5344d4c 100644
--- a/keyboard/gh60/keymap.c
+++ b/keyboard/gh60/keymap.c
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include "keycode.h" 20#include "keycode.h"
21#include "action.h" 21#include "action.h"
22#include "action_macro.h" 22#include "action_macro.h"
23#include "layer_switch.h"
23#include "report.h" 24#include "report.h"
24#include "host.h" 25#include "host.h"
25#include "print.h" 26#include "print.h"
@@ -64,12 +65,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
64 #include "keymap_plain.h" 65 #include "keymap_plain.h"
65#elif defined(KEYMAP_POKER) 66#elif defined(KEYMAP_POKER)
66 #include "keymap_poker.h" 67 #include "keymap_poker.h"
68#elif defined(KEYMAP_POKER_SET)
69 #include "keymap_poker_set.h"
70#elif defined(KEYMAP_POKER_BIT)
71 #include "keymap_poker_bit.h"
67#else 72#else
68static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 73static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
69 /* 74 /*
70 * Funky 75 * Funky
71 */ 76 */
72 /* Layer 0: Default Layer 77 /* Keymap 0: Default Layer
73 * ,-----------------------------------------------------------. 78 * ,-----------------------------------------------------------.
74 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | 79 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
75 * |-----------------------------------------------------------| 80 * |-----------------------------------------------------------|
@@ -85,10 +90,32 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
85 KEYMAP_ANSI( 90 KEYMAP_ANSI(
86 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 91 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
87 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 92 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
88 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT, ENT, \ 93 LCTL,A, S, D, F, G, H, J, K, L, FN2, QUOT, ENT, \
89 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT, \ 94 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, \
90 LCTL,LGUI,LALT, SPC, RALT,FN4, FN4, FN1), 95 LCTL,LGUI,LALT, SPC, RALT,FN3, FN3, FN0),
91 /* Layer 1: HHKB mode 96 /* Keymap 1: colemak */
97 KEYMAP_ANSI(
98 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
99 TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, \
100 BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, \
101 LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, \
102 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, FN0),
103 /* Keymap 2: dvorak */
104 KEYMAP_ANSI(
105 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, \
106 TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, \
107 CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, \
108 LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, \
109 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, FN0),
110 /* Keymap 3: workman */
111 KEYMAP_ANSI(
112 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
113 TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, \
114 BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, \
115 LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, \
116 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, FN0),
117
118 /* Overlay 4: HHKB mode
92 * ,-----------------------------------------------------------. 119 * ,-----------------------------------------------------------.
93 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | 120 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
94 * |-----------------------------------------------------------| 121 * |-----------------------------------------------------------|
@@ -98,16 +125,16 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
98 * |-----------------------------------------------------------| 125 * |-----------------------------------------------------------|
99 * |Shift | | | | | | +| -|End|PgD|Dow|Shift | 126 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |
100 * |-----------------------------------------------------------| 127 * |-----------------------------------------------------------|
101 * |Ctrl|Gui |Alt | Space |Alt |Gui |App |Fn0 | 128 * |Ctrl|Gui |Alt | Space |Alt |Gui |App | |
102 * `-----------------------------------------------------------' 129 * `-----------------------------------------------------------'
103 */ 130 */
104 KEYMAP_ANSI( 131 KEYMAP_ANSI(
105 PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ 132 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \
106 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS,UP, NO, INS, \ 133 CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP, TRNS,INS, \
107 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT, ENT, \ 134 LCTL,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT, ENT, \
108 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN, RSFT, \ 135 LSFT,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN, RSFT, \
109 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, FN0), 136 LCTL,LGUI,LALT, SPC, RALT,RGUI,FN4, TRNS),
110 /* Layer 2: Vi mode (Slash) 137 /* Overlay 5: Vi mode (Slash)
111 * ,-----------------------------------------------------------. 138 * ,-----------------------------------------------------------.
112 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backsp | 139 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backsp |
113 * |-----------------------------------------------------------| 140 * |-----------------------------------------------------------|
@@ -115,79 +142,119 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
115 * |-----------------------------------------------------------| 142 * |-----------------------------------------------------------|
116 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | |Return | 143 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | |Return |
117 * |-----------------------------------------------------------| 144 * |-----------------------------------------------------------|
118 * |Shift | | | | | |Hom|PgD|PgU|End|Fn0|Shift | 145 * |Shift | | | | | |Hom|PgD|PgU|End| |Shift |
119 * |-----------------------------------------------------------| 146 * |-----------------------------------------------------------|
120 * |Ctrl|Gui |Alt | Space |Alt |Gui |App |Ctrl| 147 * |Ctrl|Gui |Alt | Space |Alt |Gui |App |Ctrl|
121 * `-----------------------------------------------------------' 148 * `-----------------------------------------------------------'
122 */ 149 */
123 KEYMAP_ANSI( 150 KEYMAP_ANSI(
124 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BSPC, \ 151 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BSPC, \
125 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, NO, \ 152 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, TRNS,TRNS,TRNS,TRNS, \
126 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \ 153 LCTL,TRNS,LEFT,DOWN,RGHT,TRNS,LEFT,DOWN,UP, RGHT,TRNS,TRNS, ENT, \
127 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN0, RSFT, \ 154 LSFT,TRNS,TRNS,TRNS,TRNS,TRNS,HOME,PGDN,PGUP,END, TRNS, RSFT, \
128 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL), 155 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL),
129 /* Layer 3: Mouse mode (Semicolon/App) 156 /* Overlay 6: Mouse mode (Semicolon/App)
130 * ,-----------------------------------------------------------. 157 * ,-----------------------------------------------------------.
131 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backsp | 158 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backsp |
132 * |-----------------------------------------------------------| 159 * |-----------------------------------------------------------|
133 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | | | 160 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | | |
134 * |-----------------------------------------------------------| 161 * |-----------------------------------------------------------|
135 * |Contro| |Ac0|Ac1|Ac1| |McL|McD|McU|McR|Fn0| |Return | 162 * |Contro| |Ac0|Ac1|Ac1| |McL|McD|McU|McR| | |Return |
136 * |-----------------------------------------------------------| 163 * |-----------------------------------------------------------|
137 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | 164 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift |
138 * |-----------------------------------------------------------| 165 * |-----------------------------------------------------------|
139 * |Ctrl|Gui |Alt | Space | |Fn0 |Fn0 | | 166 * |Ctrl|Gui |Alt | Space | | | | |
140 * `-----------------------------------------------------------' 167 * `-----------------------------------------------------------'
141 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel 168 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
142 */ 169 */
143 KEYMAP_ANSI( 170 KEYMAP_ANSI(
144 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BSPC, \ 171 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BSPC, \
145 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, NO, \ 172 TAB, TRNS,TRNS,TRNS,TRNS,TRNS,WH_L,WH_D,WH_U,WH_R,TRNS,TRNS,TRNS,TRNS, \
146 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, ENT, \ 173 LCTL,TRNS,ACL0,ACL1,ACL2,TRNS,MS_L,MS_D,MS_U,MS_R,TRNS,TRNS, ENT, \
147 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT, \ 174 LSFT,TRNS,TRNS,TRNS,TRNS,BTN3,BTN2,BTN1,BTN4,BTN5,TRNS, RSFT, \
148 LCTL,LGUI,LALT, BTN1, NO, FN0, FN0, NO ), 175 LCTL,LGUI,LALT, BTN1, TRNS,TRNS,TRNS,RCTL),
176 /* Overlay 7: Layout selector
177 * ,-----------------------------------------------------------.
178 * | Lq| Lc| Ld| Lw| | | | | | | | | | |
179 * |-----------------------------------------------------------|
180 * | |Lq |Lw | | | | | | | | | | | |
181 * |-----------------------------------------------------------|
182 * | | | |Ld | | | | | | | | | |
183 * |-----------------------------------------------------------|
184 * | | | |Lc | | | | | | | | |
185 * |-----------------------------------------------------------|
186 * | | | | | | | | |
187 * `-----------------------------------------------------------'
188 * Lq: set Qwerty layout
189 * Lc: set Colemak layout
190 * Ld: set Dvorak layout
191 * Lw: set Workman layout
192 */
193 KEYMAP_ANSI(
194 FN5, FN6, FN7, FN8, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
195 TRNS,FN5, FN8, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
196 TRNS,TRNS,TRNS,FN7, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
197 TRNS,TRNS,TRNS,FN6, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
198 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
149}; 199};
150 200
201static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
202
151/* 203/*
152 * Fn action definition 204 * Fn action definition
153 */ 205 */
154static const uint16_t PROGMEM fn_actions[] = { 206static const uint16_t PROGMEM fn_actions[] = {
155 ACTION_LAYER_DEFAULT, // FN0 207 [0] = ACTION_KEYMAP_MOMENTARY(4),
156 ACTION_LAYER_SET(1), // FN1 208 [1] = ACTION_KEYMAP_TAP_KEY(5, KC_SLASH),
157 ACTION_LAYER_SET_TAP_KEY(2, KC_SLASH), // FN2 Layer with Slash 209 [2] = ACTION_KEYMAP_TAP_KEY(6, KC_SCLN),
158 ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // FN3 Layer with Semicolon 210 [3] = ACTION_KEYMAP_MOMENTARY(6),
159 ACTION_LAYER_SET(3), // FN4 211 [4] = ACTION_KEYMAP_MOMENTARY(7), // to Layout selector
212 [5] = ACTION_DEFAULT_LAYER_SET(0), // set qwerty layout
213 [6] = ACTION_DEFAULT_LAYER_SET(1), // set colemak layout
214 [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout
215 [8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout
160}; 216};
161#endif 217#endif
162 218
163 219
164 220
221#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
222#define OVERLAYS_SIZE (sizeof(overlays) / sizeof(overlays[0]))
223#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
224
165/* translates key to keycode */ 225/* translates key to keycode */
166uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 226uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
167{ 227{
168 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); 228 /* Overlay: 16-31(OVERLAY_BIT(0x10) | overlay_layer) */
229 if (layer & OVERLAY_BIT) {
230 layer &= OVERLAY_MASK;
231 if (layer < OVERLAYS_SIZE) {
232 return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]);
233 } else {
234 debug("key_to_keycode: overlay "); debug_dec(layer); debug(" is invalid.\n");
235 return KC_TRANSPARENT;
236 }
237 }
238 /* Keymap: 0-15 */
239 else {
240 if (layer < KEYMAPS_SIZE) {
241 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
242 } else {
243 // fall back to layer 0
244 debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
245 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
246 }
247 }
169} 248}
170 249
171/* translates Fn index to action */ 250/* translates Fn keycode to action */
172action_t keymap_fn_to_action(uint8_t keycode) 251action_t keymap_fn_to_action(uint8_t keycode)
173{ 252{
174 action_t action; 253 action_t action;
175 if (FN_INDEX(keycode) < sizeof(fn_actions) / sizeof(fn_actions[0])) { 254 if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
176 action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); 255 action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
177 } else { 256 } else {
178 action.code = ACTION_NO; 257 action.code = ACTION_NO;
179 } 258 }
180 return action; 259 return action;
181} 260}
182
183/* convert key to action */
184action_t action_for_key(uint8_t layer, key_t key)
185{
186 uint8_t keycode = keymap_key_to_keycode(layer, key);
187 switch (keycode) {
188 case KC_FN0 ... KC_FN31:
189 return keymap_fn_to_action(keycode);
190 default:
191 return keymap_keycode_to_action(keycode);
192 }
193}
diff --git a/keyboard/gh60/keymap_plain.h b/keyboard/gh60/keymap_plain.h
index ad0bc2f26..85331715d 100644
--- a/keyboard/gh60/keymap_plain.h
+++ b/keyboard/gh60/keymap_plain.h
@@ -1,24 +1,10 @@
1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
2 /* 2 /* Keymap 0: qwerty */
3 * Plain
4 */
5 /* Layer 0: Default Layer
6 * ,-----------------------------------------------------------.
7 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
8 * |-----------------------------------------------------------|
9 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
10 * |-----------------------------------------------------------|
11 * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
12 * |-----------------------------------------------------------|
13 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |
14 * |-----------------------------------------------------------|
15 * |Ctrl|Gui |Alt | Space |Alt |Gui |App |Ctrl|
16 * `-----------------------------------------------------------'
17 */
18 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 3 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
19 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 4 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
20 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, \ 5 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, \
21 LSFT,NO, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, \ 6 LSFT,NO, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, \
22 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL), 7 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL),
23}; 8};
24 9static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
10static const uint16_t PROGMEM fn_actions[] = {};
diff --git a/keyboard/gh60/keymap_poker.h b/keyboard/gh60/keymap_poker.h
index 186020b3b..3e0921ad9 100644
--- a/keyboard/gh60/keymap_poker.h
+++ b/keyboard/gh60/keymap_poker.h
@@ -1,88 +1,104 @@
1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
2 /* 2 /* Keymap 0: qwerty */
3 * Poker Layer
4 */
5 /* Layer x000: Poker Default Layer
6 * ,-----------------------------------------------------------.
7 * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
8 * |-----------------------------------------------------------|
9 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
10 * |-----------------------------------------------------------|
11 * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
12 * |-----------------------------------------------------------|
13 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |
14 * |-----------------------------------------------------------|
15 * |Ctrl|Gui |Alt | Space |Fn |Gui |App |Ctrl|
16 * `-----------------------------------------------------------'
17 */
18 KEYMAP_ANSI( 3 KEYMAP_ANSI(
19 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 4 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
20 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 5 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
21 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ 6 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
22 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ 7 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \
23 LCTL,LGUI,LALT, SPC, FN2, RGUI,APP, RCTL), 8 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
24 /* Layer x001: Poker with Arrow */ 9 /* Keymap 1: colemak */
10 KEYMAP_ANSI(
11 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
12 TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, \
13 BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, \
14 LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, \
15 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
16 /* Keymap 2: dvorak */
17 KEYMAP_ANSI(
18 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, \
19 TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, \
20 CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, \
21 LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, \
22 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
23 /* Keymap: workman */
24 KEYMAP_ANSI(
25 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
26 TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, \
27 BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, \
28 LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, \
29 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
30};
31static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
32 /* Overlay 0: Poker with Arrow */
25 KEYMAP_ANSI( 33 KEYMAP_ANSI(
26 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 34 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
27 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 35 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
28 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 36 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
29 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ 37 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
30 TRNS,TRNS,TRNS, TRNS, FN2, LEFT,DOWN,RGHT), 38 TRNS,TRNS,TRNS, TRNS, TRNS,LEFT,DOWN,RGHT),
31 /* Layer x010: Poker with Esc */ 39 /* Overlay 1: Poker with Esc */
32 KEYMAP_ANSI( 40 KEYMAP_ANSI(
33 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 41 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
34 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 42 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
35 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 43 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
36 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 44 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
37 TRNS,TRNS,TRNS, TRNS, FN2, TRNS,TRNS,TRNS), 45 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
38 /* Layer x011: Poker with Arrow and Esc */ 46 /* Overlay 2: Poker Fn
39 KEYMAP_ANSI( 47 * ,-----------------------------------------------------------.
40 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 48 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| |
41 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 49 * |-----------------------------------------------------------|
42 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 50 * | |FnQ| Up| | | | | | |Cal| |Hom|Ins|FnL |
43 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ 51 * |-----------------------------------------------------------|
44 TRNS,TRNS,TRNS, TRNS, FN2, LEFT,DOWN,RGHT), 52 * | |Lef|Dow|Rig| | |Psc|Slk|Pau| |Tsk|End| |
45 /* 53 * |-----------------------------------------------------------|
46 * Poker Momentary Fn Layer 54 * | |Del| |Web|Mut|VoU|VoD| |PgU|PgD|Del| |
55 * |-----------------------------------------------------------|
56 * | | | | FnS | | | | |
57 * `-----------------------------------------------------------'
58 * Fn: to Fn overlay
59 * FnL: to Layout selector overaly
60 * FnQ: toggle Esc overlay
61 * FnS: toggle Arrow overlay
47 */ 62 */
48 /* Layer x100: Poker Default + Fn'd */
49 KEYMAP_ANSI( 63 KEYMAP_ANSI(
50 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 64 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
51 TRNS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 65 TRNS,FN2, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, FN4, \
52 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ 66 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \
53 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ 67 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
54 TRNS,TRNS,TRNS, FN0, FN2, TRNS,TRNS,TRNS), 68 TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS),
55 /* Layer x101: Poker with Arrow + Fn'd */ 69 /* Overlay 3: Layout selector
56 KEYMAP_ANSI( 70 * ,-----------------------------------------------------------.
57 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 71 * | Lq| Lc| Ld| Lw| | | | | | | | | | |
58 TRNS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 72 * |-----------------------------------------------------------|
59 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ 73 * | |Lq |Lw | | | | | | | | | | | |
60 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, UP, \ 74 * |-----------------------------------------------------------|
61 TRNS,TRNS,TRNS, FN0, FN2, LEFT,DOWN,RGHT), 75 * | | | |Ld | | | | | | | | | |
62 /* Layer x110: Poker with Esc + Fn'd */ 76 * |-----------------------------------------------------------|
63 KEYMAP_ANSI( 77 * | | | |Lc | | | | | | | | |
64 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 78 * |-----------------------------------------------------------|
65 TRNS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 79 * | | | | | | | | |
66 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ 80 * `-----------------------------------------------------------'
67 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ 81 * Lq: set Qwerty layout
68 TRNS,TRNS,TRNS, FN0, FN2, TRNS,TRNS,TRNS), 82 * Lc: set Colemak layout
69 /* Layer x111: Poker with Arrow and Esc + Fn'd */ 83 * Ld: set Dvorak layout
84 * Lw: set Workman layout
85 */
70 KEYMAP_ANSI( 86 KEYMAP_ANSI(
71 GRV, F9, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 87 FN5, FN6, FN7, FN8, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
72 TRNS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 88 TRNS,FN5, FN8, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
73 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ 89 TRNS,TRNS,TRNS,FN7, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
74 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, UP, \ 90 TRNS,TRNS,TRNS,FN6, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
75 TRNS,TRNS,TRNS, FN0, FN2, LEFT,DOWN,RGHT), 91 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
76}; 92};
77
78/*
79 * Fn action definition
80 */
81static const uint16_t PROGMEM fn_actions[] = { 93static const uint16_t PROGMEM fn_actions[] = {
82 /* Poker Layout */ 94 /* Poker Layout */
83 [0] = ACTION_LAYER_BIT_TOGGLE(1), // FN0 Poker Arrow toggle(Space) 95 [0] = ACTION_OVERLAY_MOMENTARY(2), // to Fn overlay
84 [1] = ACTION_LAYER_BIT_TOGGLE(2), // FN1 Poker Esc toggle(Q) 96 [1] = ACTION_OVERLAY_TOGGLE(0), // toggle arrow overlay
85 [2] = ACTION_LAYER_BIT(4), // FN2 Poker Fn 97 [2] = ACTION_OVERLAY_TOGGLE(1), // toggle Esc overlay
86 [3] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN3 Task(RControl,RShift+Esc) 98 [3] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // Task(RControl,RShift+Esc)
99 [4] = ACTION_OVERLAY_MOMENTARY(3), // to Layout selector
100 [5] = ACTION_DEFAULT_LAYER_SET(0), // set qwerty layout
101 [6] = ACTION_DEFAULT_LAYER_SET(1), // set colemak layout
102 [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout
103 [8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout
87}; 104};
88
diff --git a/keyboard/gh60/keymap_poker_bit.h b/keyboard/gh60/keymap_poker_bit.h
new file mode 100644
index 000000000..982632d05
--- /dev/null
+++ b/keyboard/gh60/keymap_poker_bit.h
@@ -0,0 +1,50 @@
1// Poker fix with toggle and bit operation
2// Fn + Esc = `
3// Fn + {left, down, up, right} = {home, pgdown, pgup, end}
4static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
5 /* Keymap 0: qwerty */
6 KEYMAP_ANSI(
7 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
9 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
10 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \
11 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
12};
13static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
14 /* Overlay 0: Poker Default + Fn'd */
15 KEYMAP_ANSI(
16 TRNS,F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
17 CAPS,FN2, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
18 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN4, END, TRNS, \
19 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
20 TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS),
21 /* Overlay 1: Poker with Arrow */
22 KEYMAP_ANSI(
23 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
24 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
25 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
26 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, PGUP, \
27 TRNS,TRNS,TRNS, TRNS, FN3, HOME,PGDN,END),
28 /* Overlay 2: Poker with Esc */
29 KEYMAP_ANSI(
30 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
31 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
32 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
33 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
34 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
35 /* Overlay 3: Poker with Arrow + Fn'd */
36 KEYMAP_ANSI(
37 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
38 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
39 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
40 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
41 TRNS,TRNS,TRNS, TRNS, TRNS,LEFT,DOWN,RGHT),
42};
43static const uint16_t PROGMEM fn_actions[] = {
44 /* Poker Layout */
45 [0] = ACTION_OVERLAY_INV4(0b0101, 0), // Poker Fn(with fix for Esc)
46 [1] = ACTION_OVERLAY_TOGGLE(1), // Poker Arrow toggle
47 [2] = ACTION_OVERLAY_TOGGLE(2), // Poker Esc toggle
48 [3] = ACTION_OVERLAY_INV4(0b1101, 0), // Poker Fn(with fix for Arrow)
49 [4] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN3 Task(RControl,RShift+Esc)
50};
diff --git a/keyboard/gh60/keymap_poker_set.h b/keyboard/gh60/keymap_poker_set.h
new file mode 100644
index 000000000..eaaf3159d
--- /dev/null
+++ b/keyboard/gh60/keymap_poker_set.h
@@ -0,0 +1,81 @@
1// Poker fix with set(state transition)
2// Fn + Esc = `
3// Fn + {left, down, up, right} = {home, pgdown, pgup, end}
4static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
5 /* Keymap 0: qwerty */
6 KEYMAP_ANSI(
7 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
9 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
10 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \
11 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
12};
13static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
14 /* Overlay 0: Poker with Arrow */
15 KEYMAP_ANSI(
16 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
17 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
18 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
19 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
20 TRNS,TRNS,TRNS, TRNS, FN1, LEFT,DOWN,RGHT),
21 /* Overlay 1: Poker with Esc */
22 KEYMAP_ANSI(
23 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
24 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
25 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
26 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
27 TRNS,TRNS,TRNS, TRNS, FN2, TRNS,TRNS,TRNS),
28 /* Overlay 2: Poker with Arrow and Esc */
29 KEYMAP_ANSI(
30 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
31 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
32 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
33 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
34 TRNS,TRNS,TRNS, TRNS, FN3, LEFT,DOWN,RGHT),
35 /* Overlay 3: Poker Fn'd */
36 KEYMAP_ANSI(
37 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
38 TRNS,FN6, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
39 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
40 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
41 TRNS,TRNS,TRNS, FN5, FN4, TRNS,TRNS,TRNS),
42 /* Overlay 4: Poker Fn'd arrow */
43 KEYMAP_ANSI(
44 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
45 TRNS,FN7, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
46 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
47 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \
48 TRNS,TRNS,TRNS, FN4, FN5, HOME,PGDN,END),
49 /* Overlay 5: Poker Fn'd Esc */
50 KEYMAP_ANSI(
51 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
52 TRNS,FN4, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
53 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
54 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
55 TRNS,TRNS,TRNS, FN7, FN6, TRNS,TRNS,TRNS),
56 /* Overlay 6: Poker Fn'd Arrow + Esc */
57 KEYMAP_ANSI(
58 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
59 TRNS,FN5, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
60 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
61 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \
62 TRNS,TRNS,TRNS, FN6, FN7, HOME,PGDN,END),
63};
64
65/*
66 * Fn action definition
67 */
68static const uint16_t PROGMEM fn_actions[] = {
69 /* Poker Layout */
70 [0] = ACTION_OVERLAY_SET(3, ON_PRESS), // FN0 move to Fn'd when press
71 [1] = ACTION_OVERLAY_SET(4, ON_PRESS), // FN1 move to Fn'd arrow when press
72 [2] = ACTION_OVERLAY_SET(5, ON_PRESS), // FN2 move to Fn'd Esc when press
73 [3] = ACTION_OVERLAY_SET(6, ON_PRESS), // FN3 move to Fn'd arrow + Esc when press
74
75 [4] = ACTION_OVERLAY_CLEAR(ON_RELEASE), // FN4 clear overlay when release
76 [5] = ACTION_OVERLAY_SET(0, ON_RELEASE), // FN5 move to arrow when release
77 [6] = ACTION_OVERLAY_SET(1, ON_RELEASE), // FN6 move to Esc when release
78 [7] = ACTION_OVERLAY_SET(2, ON_RELEASE), // FN7 move to arrow + Esc when release
79
80 [8] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN8 Task(RControl,RShift+Esc)
81};
diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h
index 5fcec95eb..72e4d26e9 100644
--- a/keyboard/hhkb/config.h
+++ b/keyboard/hhkb/config.h
@@ -36,6 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
36#define MATRIX_ROWS 8 36#define MATRIX_ROWS 8
37#define MATRIX_COLS 8 37#define MATRIX_COLS 8
38 38
39/* To use new keymap framework */
40#define USE_KEYMAP_V2
39 41
40/* 42/*
41 * Boot magic keys 43 * Boot magic keys
diff --git a/keyboard/hhkb/config_iwrap.h b/keyboard/hhkb/config_iwrap.h
index 734d66977..d50b704d7 100644
--- a/keyboard/hhkb/config_iwrap.h
+++ b/keyboard/hhkb/config_iwrap.h
@@ -31,6 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31#define MATRIX_ROWS 8 31#define MATRIX_ROWS 8
32#define MATRIX_COLS 8 32#define MATRIX_COLS 8
33 33
34/* To use new keymap framework */
35#define USE_KEYMAP_V2
34 36
35/* key combination for command */ 37/* key combination for command */
36#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) 38#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
index ef21282ff..094d33af1 100644
--- a/keyboard/hhkb/keymap.c
+++ b/keyboard/hhkb/keymap.c
@@ -56,18 +56,18 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
56 * |-----------------------------------------------------------| 56 * |-----------------------------------------------------------|
57 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs| 57 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
58 * |-----------------------------------------------------------| 58 * |-----------------------------------------------------------|
59 * |Fn6 | A| S| D| F| G| H| J| K| L|Fn3| '|Return | 59 * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Fn4 |
60 * |-----------------------------------------------------------| 60 * |-----------------------------------------------------------|
61 * |Fn8 | Z| X| C| V| B| N| M| ,| .|Fn2|Fn12 |Fn1| 61 * |Fn5 | Z| X| C| V| B| N| M| ,| .|Fn2|Shift |Fn1|
62 * `-----------------------------------------------------------' 62 * `-----------------------------------------------------------'
63 * |Gui|Alt | Fn5 |Alt |Fn4| 63 * |Gui|Alt | Fn6 |Alt |Fn7|
64 * `-------------------------------------------' 64 * `-------------------------------------------'
65 */ 65 */
66 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \ 66 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
67 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ 67 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
68 FN6, A, S, D, F, G, H, J, K, L, FN3, QUOT,FN7, \ 68 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN4, \
69 FN8, Z, X, C, V, B, N, M, COMM,DOT, FN2, FN12,FN9, \ 69 FN5,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
70 LGUI,LALT, FN5, FN13,FN4), 70 LGUI,LALT, FN6, RALT,FN7),
71 71
72 /* Layer 1: HHKB mode (HHKB Fn) 72 /* Layer 1: HHKB mode (HHKB Fn)
73 * ,-----------------------------------------------------------. 73 * ,-----------------------------------------------------------.
@@ -77,15 +77,15 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
77 * |-----------------------------------------------------------| 77 * |-----------------------------------------------------------|
78 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter | 78 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
79 * |-----------------------------------------------------------| 79 * |-----------------------------------------------------------|
80 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |Fn0| 80 * |Shift | | | | | | +| -|End|PgD|Dow|Shift | |
81 * `-----------------------------------------------------------' 81 * `-----------------------------------------------------------'
82 * |Gui|Alt | Space |Alt |Gui| 82 * |Gui|Alt | Space |Alt |Gui|
83 * `-------------------------------------------' 83 * `-------------------------------------------'
84 */ 84 */
85 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \ 85 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
86 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS, UP, NO, BSPC, \ 86 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS, UP, NO, BSPC, \
87 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ 87 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
88 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN0, \ 88 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,TRNS, \
89 LGUI,LALT, SPC, RALT,RGUI), 89 LGUI,LALT, SPC, RALT,RGUI),
90 90
91 /* Layer 2: Vi mode (Slash) 91 /* Layer 2: Vi mode (Slash)
@@ -101,10 +101,10 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
101 * |Gui|Alt | Space |Alt |Gui| 101 * |Gui|Alt | Space |Alt |Gui|
102 * `-------------------------------------------' 102 * `-------------------------------------------'
103 */ 103 */
104 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \ 104 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
105 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \ 105 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \
106 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \ 106 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \
107 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN0, RSFT,NO, \ 107 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, TRNS,RSFT,NO, \
108 LGUI,LALT, SPC, RALT,RGUI), 108 LGUI,LALT, SPC, RALT,RGUI),
109 109
110 /* Layer 3: Mouse mode (Semicolon) 110 /* Layer 3: Mouse mode (Semicolon)
@@ -121,13 +121,13 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
121 * `--------------------------------------------' 121 * `--------------------------------------------'
122 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel 122 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
123 */ 123 */
124 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \ 124 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
125 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \ 125 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
126 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,FN0, QUOT,ENT, \ 126 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,TRNS,QUOT,ENT, \
127 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,SLSH,RSFT,NO, \ 127 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,SLSH,RSFT,NO, \
128 LGUI,LALT, BTN1, RALT,FN0), 128 LGUI,LALT, BTN1, RALT,TRNS),
129 129
130 /* Layer 4: Matias half keyboard style (Space) 130 /* Layer 4: Matias half-qwerty keyboard style (Space)
131 * ,-----------------------------------------------------------. 131 * ,-----------------------------------------------------------.
132 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc| 132 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc|
133 * |-----------------------------------------------------------| 133 * |-----------------------------------------------------------|
@@ -144,7 +144,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
144 BSPC,P, O, I, U, Y, T, R, E, W, Q, NO, NO, TAB, \ 144 BSPC,P, O, I, U, Y, T, R, E, W, Q, NO, NO, TAB, \
145 LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \ 145 LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \
146 LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \ 146 LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \
147 LGUI,LALT, FN0, RALT,RGUI), 147 LGUI,LALT, TRNS, RALT,RGUI),
148 148
149 /* Layer5: another Mouse mode (Space) 149 /* Layer5: another Mouse mode (Space)
150 * ,-----------------------------------------------------------. 150 * ,-----------------------------------------------------------.
@@ -164,7 +164,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
164 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \ 164 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
165 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,NO, NO, ENT, \ 165 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,NO, NO, ENT, \
166 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \ 166 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
167 LGUI,LALT, FN0, RALT,RGUI), 167 LGUI,LALT, TRNS, RALT,RGUI),
168}; 168};
169 169
170 170
@@ -173,56 +173,72 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
173enum function_id { 173enum function_id {
174 LSHIFT_LPAREN, 174 LSHIFT_LPAREN,
175 RSHIFT_RPAREN, 175 RSHIFT_RPAREN,
176 MACRO = 0xff 176};
177
178enum macro_id {
179 LSHIFT_PAREN,
180 RSHIFT_PAREN,
181 HELLO,
177}; 182};
178 183
179 184
180/* 185/*
181 * Fn action definition 186 * Fn action definition
182 */ 187 */
183// TODO: use [1] = KEYMAP(...) to prevent from changing index of element?
184static const uint16_t PROGMEM fn_actions[] = { 188static const uint16_t PROGMEM fn_actions[] = {
185 ACTION_LAYER_DEFAULT, // FN0 189 [0] = ACTION_DEFAULT_LAYER, // Default layer(not used)
186 ACTION_LAYER_SET(1), // FN1 190// [1] = ACTION_KEYMAP(1), // HHKB layer
187 ACTION_LAYER_SET_TAP_KEY(2, KC_SLASH), // FN2 Layer with Slash 191 [1] = ACTION_KEYMAP_TAP_TOGGLE(1), // HHKB layer(toggle with 5 taps)
188 ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // FN3 Layer with Semicolon 192 [2] = ACTION_KEYMAP_TAP_KEY(2, KC_SLASH), // Cursor layer with Slash*
193 [3] = ACTION_KEYMAP_TAP_KEY(3, KC_SCLN), // Mousekey layer with Semicolon*
194 [4] = ACTION_RMOD_TAP_KEY(KC_RCTL, KC_ENT), // RControl with tap Enter*
195 [5] = ACTION_LMOD_ONESHOT(KC_LSFT), // Oneshot Shift*
196// [6] = ACTION_KEYMAP_TAP_KEY(4, KC_SPC), // Half-qwerty layer with Space
197 [6] = ACTION_KEYMAP_TAP_KEY(5, KC_SPC), // Mousekey layer with Space
198// [7] = ACTION_KEYMAP(3), // Mousekey layer
199 [7] = ACTION_KEYMAP_TOGGLE(3), // Mousekey layer(toggle)
189 200
190 ACTION_LAYER_SET(3), // FN4 201// [8] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace
191// ACTION_LAYER_SET_TOGGLE(3), // FN4 202// [9] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc
192// ACTION_FUNCTION(MACRO, 0), // FN4 203// [11] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '('
193 ACTION_LAYER_SET_TAP_KEY(5, KC_SPC), // FN5 204// [12] = ACTION_FUNCTION_TAP(RSHIFT_RPAREN), // Function: RShift with tap ')'
194// ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // FN6 Control with tap Backspace 205// [13] = ACTION_MACRO_TAP(LSHIFT_PAREN), // Macro: LShift with tap '('
195 ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // FN6 Control with tap Backspace 206// [14] = ACTION_MACRO_TAP(RSHIFT_PAREN), // Macro: RShift with tap ')'
196 ACTION_RMOD_TAP_KEY(KC_RCTL, KC_ENT), // FN7 Control with tap Enter 207// [15] = ACTION_MACRO(HELLO), // Macro: say hello
197 ACTION_LMOD_ONESHOT(KC_LSFT), // FN8 Oneshot Shift
198 ACTION_LAYER_SET_TAP_TOGGLE(1), // FN9
199 ACTION_LAYER_BIT_TAP_KEY(1, KC_GRV), // FN10 Layer with Grave
200 //ACTION_LAYER_BIT(1), // FN10
201 //ACTION_LAYER_BIT_TAP_TOGGLE(1), // FN10
202 ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // FN11 Function: LShift with tap '('
203 ACTION_FUNCTION_TAP(RSHIFT_RPAREN), // FN12 Function: RShift with tap ')'
204 ACTION_FUNCTION(MACRO, 1), // FN13 Macro:
205}; 208};
206 209
207 210
208/* 211/*
209 * Macro definition 212 * Macro definition
210 */ 213 */
211#define MACRO(...) ({ static prog_macro_t _m[] PROGMEM = { __VA_ARGS__ }; _m; }) 214const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
212#define MACRO_NONE 0
213static const prog_macro_t *get_macro(uint8_t id, bool pressed)
214{ 215{
216 keyevent_t event = record->event;
217 tap_t tap = record->tap;
218
215 switch (id) { 219 switch (id) {
216 case 0: 220 case LSHIFT_PAREN:
217 return (pressed ? 221 if (tap.count > 0 && !tap.interrupted) {
218 MACRO( MD(LSHIFT), D(D), END ) : 222 return (event.pressed ?
219 MACRO( U(D), MU(LSHIFT), END ) ); 223 MACRO( MD(LSHIFT), D(9), U(9), MU(LSHIFT), END ) : MACRO_NONE);
220 case 1: 224 } else {
221 return (pressed ? 225 return (event.pressed ?
222 MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ) : 226 MACRO( MD(LSHIFT), END ) : MACRO( MU(LSHIFT), END ) );
227 }
228 case RSHIFT_PAREN:
229 if (tap.count > 0 && !tap.interrupted) {
230 return (event.pressed ?
231 MACRO( MD(RSHIFT), D(0), U(0), MU(RSHIFT), END ) : MACRO_NONE);
232 } else {
233 return (event.pressed ?
234 MACRO( MD(RSHIFT), END ) : MACRO( MU(RSHIFT), END ) );
235 }
236 case HELLO:
237 return (event.pressed ?
238 MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
223 MACRO_NONE ); 239 MACRO_NONE );
224 } 240 }
225 return 0; 241 return MACRO_NONE;
226} 242}
227 243
228 244
@@ -230,82 +246,51 @@ static const prog_macro_t *get_macro(uint8_t id, bool pressed)
230/* 246/*
231 * user defined action function 247 * user defined action function
232 */ 248 */
233void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt) 249void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
234{ 250{
235 keyevent_t event = record->event; 251 keyevent_t event = record->event;
236 uint8_t tap_count = record->tap_count; 252 tap_t tap = record->tap;
237
238 debug("action_call_function: ");
239 if (event.pressed) debug("pressed"); else debug("released");
240 debug(" id: "); debug_hex(id);
241 debug(" tap_count: "); debug_dec(tap_count);
242 debug("\n");
243 253
244 switch (id) { 254 switch (id) {
245 case LSHIFT_LPAREN: 255 case LSHIFT_LPAREN:
246 // LShft + tap '(' 256 // LShft + tap '('
257 // NOTE: cant use register_code to avoid conflicting with magic key bind
247 if (event.pressed) { 258 if (event.pressed) {
248 if (tap_count == 0) { 259 if (tap.count == 0 || tap.interrupted) {
249 add_mods(MOD_BIT(KC_LSHIFT)); 260 add_mods(MOD_BIT(KC_LSHIFT));
250 } else { 261 } else {
251 if (waiting_buffer_has_anykey_pressed()) { 262 host_add_mods(MOD_BIT(KC_LSHIFT));
252 // ad hoc: set 0 to cancel tap 263 host_add_key(KC_9);
253 record->tap_count = 0; 264 host_send_keyboard_report();
254 add_mods(MOD_BIT(KC_LSHIFT));
255 } else {
256 // NOTE to avoid conflicting command key bind(LShift+RShift)
257 //register_code(KC_LSHIFT);
258 //register_code(KC_9);
259 host_add_mods(MOD_BIT(KC_LSHIFT));
260 host_add_key(KC_9);
261 host_send_keyboard_report();
262 }
263 }
264 } else {
265 if (tap_count == 0) {
266 del_mods(MOD_BIT(KC_LSHIFT));
267 } else {
268 //unregister_code(KC_9);
269 //unregister_code(KC_LSHIFT);
270 host_del_mods(MOD_BIT(KC_LSHIFT)); 265 host_del_mods(MOD_BIT(KC_LSHIFT));
271 host_del_key(KC_9); 266 host_del_key(KC_9);
272 host_send_keyboard_report(); 267 host_send_keyboard_report();
273 } 268 }
269 } else {
270 if (tap.count == 0 || tap.interrupted) {
271 del_mods(MOD_BIT(KC_LSHIFT));
272 }
274 } 273 }
275 break; 274 break;
276 case RSHIFT_RPAREN: 275 case RSHIFT_RPAREN:
277 // RShift + tap ')' 276 // RShift + tap ')'
278 if (event.pressed) { 277 if (event.pressed) {
279 if (tap_count == 0) { 278 if (tap.count == 0 || tap.interrupted) {
280 add_mods(MOD_BIT(KC_RSHIFT)); 279 add_mods(MOD_BIT(KC_RSHIFT));
281 } else { 280 } else {
282 if (waiting_buffer_has_anykey_pressed()) { 281 host_add_mods(MOD_BIT(KC_RSHIFT));
283 // ad hoc: set 0 to cancel tap 282 host_add_key(KC_0);
284 record->tap_count = 0; 283 host_send_keyboard_report();
285 add_mods(MOD_BIT(KC_RSHIFT));
286 } else {
287 //register_code(KC_RSHIFT);
288 //register_code(KC_0);
289 host_add_mods(MOD_BIT(KC_RSHIFT));
290 host_add_key(KC_0);
291 host_send_keyboard_report();
292 }
293 }
294 } else {
295 if (tap_count == 0) {
296 del_mods(MOD_BIT(KC_RSHIFT));
297 } else {
298 //unregister_code(KC_0);
299 //unregister_code(KC_RSHIFT);
300 host_del_mods(MOD_BIT(KC_RSHIFT)); 284 host_del_mods(MOD_BIT(KC_RSHIFT));
301 host_del_key(KC_0); 285 host_del_key(KC_0);
302 host_send_keyboard_report(); 286 host_send_keyboard_report();
303 } 287 }
288 } else {
289 if (tap.count == 0 || tap.interrupted) {
290 del_mods(MOD_BIT(KC_RSHIFT));
291 }
304 } 292 }
305 break; 293 break;
306 case MACRO:
307 action_macro_play(get_macro(opt, event.pressed));
308 break;
309 } 294 }
310} 295}
311 296
@@ -328,15 +313,3 @@ action_t keymap_fn_to_action(uint8_t keycode)
328 } 313 }
329 return action; 314 return action;
330} 315}
331
332/* convert key to action */
333action_t action_for_key(uint8_t layer, key_t key)
334{
335 uint8_t keycode = keymap_key_to_keycode(layer, key);
336 switch (keycode) {
337 case KC_FN0 ... KC_FN31:
338 return keymap_fn_to_action(keycode);
339 default:
340 return keymap_keycode_to_action(keycode);
341 }
342}
diff --git a/protocol/serial.h b/protocol/serial.h
index bd071bec9..96913c867 100644
--- a/protocol/serial.h
+++ b/protocol/serial.h
@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
41/* host role */ 41/* host role */
42void serial_init(void); 42void serial_init(void);
43uint8_t serial_recv(void); 43uint8_t serial_recv(void);
44int16_t serial_recv2(void);
44void serial_send(uint8_t data); 45void serial_send(uint8_t data);
45 46
46#endif 47#endif
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c
index beddc353c..e8870bcd7 100644
--- a/protocol/serial_soft.c
+++ b/protocol/serial_soft.c
@@ -43,15 +43,47 @@ POSSIBILITY OF SUCH DAMAGE.
43 43
44/* 44/*
45 * Stupid Inefficient Busy-wait Software Serial 45 * Stupid Inefficient Busy-wait Software Serial
46 * is still useful for negative logic signal like Sun protocol not supported by hardware USART. 46 * which is still useful for negative logic signal like Sun protocol
47 * if it is not supported by hardware UART.
48 *
49 * TODO: delay is not accurate enough. Instruction cycle should be counted and inline assemby is needed.
47 */ 50 */
48 51
49#define WAIT_US (1000000/SERIAL_BAUD) 52#define WAIT_US (1000000L/SERIAL_SOFT_BAUD)
53
54#ifdef SERIAL_SOFT_LOGIC_NEGATIVE
55 #define SERIAL_SOFT_RXD_IN() !(SERIAL_SOFT_RXD_READ())
56 #define SERIAL_SOFT_TXD_ON() SERIAL_SOFT_TXD_LO()
57 #define SERIAL_SOFT_TXD_OFF() SERIAL_SOFT_TXD_HI()
58#else
59 #define SERIAL_SOFT_RXD_IN() !!(SERIAL_SOFT_RXD_READ())
60 #define SERIAL_SOFT_TXD_ON() SERIAL_SOFT_TXD_HI()
61 #define SERIAL_SOFT_TXD_OFF() SERIAL_SOFT_TXD_LO()
62#endif
63
64#ifdef SERIAL_SOFT_PARITY_EVEN
65 #define SERIAL_SOFT_PARITY_VAL 0
66#elif defined(SERIAL_SOFT_PARITY_ODD)
67 #define SERIAL_SOFT_PARITY_VAL 1
68#endif
69
70/* debug for signal timing, see debug pin with oscilloscope */
71#define SERIAL_SOFT_DEBUG
72#ifdef SERIAL_SOFT_DEBUG
73 #define SERIAL_SOFT_DEBUG_INIT() (DDRD |= 1<<7)
74 #define SERIAL_SOFT_DEBUG_TGL() (PORTD ^= 1<<7)
75#else
76 #define SERIAL_SOFT_DEBUG_INIT()
77 #define SERIAL_SOFT_DEBUG_TGL()
78#endif
79
50 80
51void serial_init(void) 81void serial_init(void)
52{ 82{
53 SERIAL_RXD_INIT(); 83 SERIAL_SOFT_DEBUG_INIT();
54 SERIAL_TXD_INIT(); 84
85 SERIAL_SOFT_RXD_INIT();
86 SERIAL_SOFT_TXD_INIT();
55} 87}
56 88
57/* RX ring buffer */ 89/* RX ring buffer */
@@ -60,6 +92,7 @@ static uint8_t rbuf[RBUF_SIZE];
60static uint8_t rbuf_head = 0; 92static uint8_t rbuf_head = 0;
61static uint8_t rbuf_tail = 0; 93static uint8_t rbuf_tail = 0;
62 94
95
63uint8_t serial_recv(void) 96uint8_t serial_recv(void)
64{ 97{
65 uint8_t data = 0; 98 uint8_t data = 0;
@@ -72,68 +105,120 @@ uint8_t serial_recv(void)
72 return data; 105 return data;
73} 106}
74 107
108int16_t serial_recv2(void)
109{
110 uint8_t data = 0;
111 if (rbuf_head == rbuf_tail) {
112 return -1;
113 }
114
115 data = rbuf[rbuf_tail];
116 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
117 return data;
118}
119
75void serial_send(uint8_t data) 120void serial_send(uint8_t data)
76{ 121{
77 /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */ 122 /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
78 /* start bit */
79 SERIAL_TXD_OFF();
80 _delay_us(WAIT_US);
81 123
82#ifdef SERIAL_BIT_ORDER_MSB 124#ifdef SERIAL_SOFT_BIT_ORDER_MSB
83 uint8_t mask = 0x80; 125 uint8_t mask = 0x80;
84#else 126#else
85 uint8_t mask = 0x01; 127 uint8_t mask = 0x01;
86#endif 128#endif
129
130 uint8_t parity = 0;
131
132 /* start bit */
133 SERIAL_SOFT_TXD_OFF();
134 _delay_us(WAIT_US);
135
87 while (mask) { 136 while (mask) {
88 if (data&mask) { SERIAL_TXD_ON(); } else { SERIAL_TXD_OFF(); } 137 if (data&mask) {
138 SERIAL_SOFT_TXD_ON();
139 parity ^= 1;
140 } else {
141 SERIAL_SOFT_TXD_OFF();
142 }
89 _delay_us(WAIT_US); 143 _delay_us(WAIT_US);
90 144
91#ifdef SERIAL_BIT_ORDER_MSB 145#ifdef SERIAL_SOFT_BIT_ORDER_MSB
92 mask >>= 1; 146 mask >>= 1;
93#else 147#else
94 mask <<= 1; 148 mask <<= 1;
95#endif 149#endif
96 } 150 }
97 151
152#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
153 /* to center of parity bit */
154 if (parity != SERIAL_SOFT_PARITY_VAL) {
155 SERIAL_SOFT_TXD_ON();
156 } else {
157 SERIAL_SOFT_TXD_OFF();
158 }
159 _delay_us(WAIT_US);
160#endif
161
98 /* stop bit */ 162 /* stop bit */
99 SERIAL_TXD_ON(); 163 SERIAL_SOFT_TXD_ON();
100 _delay_us(WAIT_US); 164 _delay_us(WAIT_US);
101} 165}
102 166
103/* detect edge of start bit */ 167/* detect edge of start bit */
104ISR(SERIAL_RXD_VECT) 168ISR(SERIAL_SOFT_RXD_VECT)
105{ 169{
106 SERIAL_RXD_INT_ENTER() 170 SERIAL_SOFT_DEBUG_TGL();
171 SERIAL_SOFT_RXD_INT_ENTER()
107 172
108 uint8_t data = 0; 173 uint8_t data = 0;
109#ifdef SERIAL_BIT_ORDER_MSB 174
175#ifdef SERIAL_SOFT_BIT_ORDER_MSB
110 uint8_t mask = 0x80; 176 uint8_t mask = 0x80;
111#else 177#else
112 uint8_t mask = 0x01; 178 uint8_t mask = 0x01;
113#endif 179#endif
180
181 uint8_t parity = 0;
182
114 /* to center of start bit */ 183 /* to center of start bit */
115 _delay_us(WAIT_US/2); 184 _delay_us(WAIT_US/2);
185 SERIAL_SOFT_DEBUG_TGL();
116 do { 186 do {
117 /* to center of next bit */ 187 /* to center of next bit */
118 _delay_us(WAIT_US); 188 _delay_us(WAIT_US);
119 189
120 if (SERIAL_RXD_READ()) { 190 SERIAL_SOFT_DEBUG_TGL();
191 if (SERIAL_SOFT_RXD_IN()) {
121 data |= mask; 192 data |= mask;
193 parity ^= 1;
122 } 194 }
123#ifdef SERIAL_BIT_ORDER_MSB 195#ifdef SERIAL_SOFT_BIT_ORDER_MSB
124 mask >>= 1; 196 mask >>= 1;
125#else 197#else
126 mask <<= 1; 198 mask <<= 1;
127#endif 199#endif
128 } while (mask); 200 } while (mask);
201
202#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
203 /* to center of parity bit */
204 _delay_us(WAIT_US);
205 if (SERIAL_SOFT_RXD_IN()) { parity ^= 1; }
206 SERIAL_SOFT_DEBUG_TGL();
207#endif
208
129 /* to center of stop bit */ 209 /* to center of stop bit */
130 _delay_us(WAIT_US); 210 _delay_us(WAIT_US);
131 211
132 uint8_t next = (rbuf_head + 1) % RBUF_SIZE; 212 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
213#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
214 if ((parity == SERIAL_SOFT_PARITY_VAL) && next != rbuf_tail) {
215#else
133 if (next != rbuf_tail) { 216 if (next != rbuf_tail) {
217#endif
134 rbuf[rbuf_head] = data; 218 rbuf[rbuf_head] = data;
135 rbuf_head = next; 219 rbuf_head = next;
136 } 220 }
137 221
138 SERIAL_RXD_INT_EXIT(); 222 SERIAL_SOFT_RXD_INT_EXIT();
223 SERIAL_SOFT_DEBUG_TGL();
139} 224}
diff --git a/protocol/serial_uart.c b/protocol/serial_uart.c
new file mode 100644
index 000000000..6c0af8817
--- /dev/null
+++ b/protocol/serial_uart.c
@@ -0,0 +1,93 @@
1/*
2Copyright 2013 Jun WAKO <wakojun@gmail.com>
3
4This software is licensed with a Modified BSD License.
5All of this is supposed to be Free Software, Open Source, DFSG-free,
6GPL-compatible, and OK to use in both free and proprietary applications.
7Additions and corrections to this file are welcome.
8
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13* Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16* Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21* Neither the name of the copyright holders nor the names of
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36*/
37
38#include <stdbool.h>
39#include <avr/io.h>
40#include <avr/interrupt.h>
41#include "serial.h"
42
43
44void serial_init(void)
45{
46 SERIAL_UART_INIT();
47}
48
49// RX ring buffer
50#define RBUF_SIZE 8
51static uint8_t rbuf[RBUF_SIZE];
52static uint8_t rbuf_head = 0;
53static uint8_t rbuf_tail = 0;
54
55uint8_t serial_recv(void)
56{
57 uint8_t data = 0;
58 if (rbuf_head == rbuf_tail) {
59 return 0;
60 }
61
62 data = rbuf[rbuf_tail];
63 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
64 return data;
65}
66
67int16_t serial_recv2(void)
68{
69 uint8_t data = 0;
70 if (rbuf_head == rbuf_tail) {
71 return -1;
72 }
73
74 data = rbuf[rbuf_tail];
75 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
76 return data;
77}
78
79void serial_send(uint8_t data)
80{
81 while (!SERIAL_UART_TXD_READY) ;
82 SERIAL_UART_DATA = data;
83}
84
85// USART RX complete interrupt
86ISR(SERIAL_UART_RXD_VECT)
87{
88 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
89 if (next != rbuf_tail) {
90 rbuf[rbuf_head] = SERIAL_UART_DATA;
91 rbuf_head = next;
92 }
93}
diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c
index 1d5f4a852..328885a9b 100644
--- a/protocol/vusb/vusb.c
+++ b/protocol/vusb/vusb.c
@@ -88,6 +88,10 @@ static void send_keyboard(report_keyboard_t *report)
88 } else { 88 } else {
89 debug("kbuf: full\n"); 89 debug("kbuf: full\n");
90 } 90 }
91
92 // NOTE: send key strokes of Macro
93 usbPoll();
94 vusb_transfer_keyboard();
91} 95}
92 96
93 97
diff --git a/rules.mk b/rules.mk
index 2e4fce518..7a40d1de9 100644
--- a/rules.mk
+++ b/rules.mk
@@ -340,7 +340,8 @@ LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst
340 340
341 341
342# Compiler flags to generate dependency files. 342# Compiler flags to generate dependency files.
343GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d 343#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
344GENDEPFLAGS = -MMD -MP -MF .dep/$(subst /,_,$@).d
344 345
345 346
346# Combine all necessary flags and optional flags. 347# Combine all necessary flags and optional flags.