]> git.gir.st - tmk_keyboard.git/blob - orphan/hid_liber/keymap.c
Merge commit '22b6e15a179031afb7c3534cf7b109b0668b602c'
[tmk_keyboard.git] / orphan / hid_liber / keymap.c
1 /*
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 * Keymap for HID Liberator controller
20 */
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <avr/pgmspace.h>
24 #include "keycode.h"
25 #include "action.h"
26 #include "action_macro.h"
27 #include "report.h"
28 #include "host.h"
29 #include "print.h"
30 #include "debug.h"
31 #include "keymap.h"
32
33
34 // Convert physical keyboard layout to matrix array.
35 // This is a macro to define keymap easily in keyboard layout form.
36 #define KEYMAP( \
37 KG1, KH7, KJ7, KJ6, KJ1, KO5, KL1, KA6, KA7, KD7, KD5, KD1, KD2, KB5, KB3, KO3, \
38 KG7, KG5, KH5, KJ5, KI5, KI7, KK7, KK5, KL5, KA5, KC5, KC7, KL7, KD6, KQ7, KN7, KM7, \
39 KG6, KG3, KH3, KJ3, KI3, KI6, KK6, KK3, KL3, KA3, KC3, KC6, KL6, KD4, KP7, KN5, KM5, \
40 KH6, KG4, KH4, KJ4, KI4, KI1, KK1, KK4, KL4, KA4, KC4, KC1, KD0, \
41 KF6, KH1, KG0, KH0, KJ0, KI0, KI2, KK2, KK0, KL0, KA0, KC2, KF4, KN1, \
42 KO7, KE6, KB1, KP1, KB2, KR4, KA2, KO0, KN2, KP2, KQ2 \
43 ) { \
44 /* 0 1 2 3 4 5 6 7 */ \
45 /* A */ { KC_##KA0, KC_NO , KC_##KA2, KC_##KA3, KC_##KA4, KC_##KA5, KC_##KA6, KC_##KA7 }, \
46 /* B */ { KC_NO , KC_##KB1, KC_##KB2, KC_##KB3, KC_NO , KC_##KB5, KC_NO , KC_NO }, \
47 /* C */ { KC_NO , KC_##KC1, KC_##KC2, KC_##KC3, KC_##KC4, KC_##KC5, KC_##KC6, KC_##KC7 }, \
48 /* D */ { KC_##KD0, KC_##KD1, KC_##KD2, KC_NO , KC_##KD4, KC_##KD5, KC_##KD6, KC_##KD7 }, \
49 /* E */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KE6, KC_NO }, \
50 /* F */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KF4, KC_NO , KC_##KF6, KC_NO }, \
51 /* G */ { KC_##KG0, KC_##KG1, KC_NO , KC_##KG3, KC_##KG4, KC_##KG5, KC_##KG6, KC_##KG7 }, \
52 /* H */ { KC_##KH0, KC_##KH1, KC_NO , KC_##KH3, KC_##KH4, KC_##KH5, KC_##KH6, KC_##KH7 }, \
53 /* I */ { KC_##KI0, KC_##KI1, KC_##KI2, KC_##KI3, KC_##KI4, KC_##KI5, KC_##KI6, KC_##KI7 }, \
54 /* J */ { KC_##KJ0, KC_##KJ1, KC_NO , KC_##KJ3, KC_##KJ4, KC_##KJ5, KC_##KJ6, KC_##KJ7 }, \
55 /* K */ { KC_##KK0, KC_##KK1, KC_##KK2, KC_##KK3, KC_##KK4, KC_##KK5, KC_##KK6, KC_##KK7 }, \
56 /* L */ { KC_##KL0, KC_##KL1, KC_NO , KC_##KL3, KC_##KL4, KC_##KL5, KC_##KL6, KC_##KL7 }, \
57 /* M */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KM5, KC_NO , KC_##KM7 }, \
58 /* N */ { KC_NO , KC_##KN1, KC_##KN2, KC_NO , KC_NO , KC_##KN5, KC_NO , KC_##KN7 }, \
59 /* O */ { KC_##KO0, KC_NO , KC_NO , KC_##KO3, KC_NO , KC_##KO5, KC_NO , KC_##KO7 }, \
60 /* P */ { KC_NO , KC_##KP1, KC_##KP2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KP7 }, \
61 /* Q */ { KC_NO , KC_NO , KC_##KQ2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KQ7 }, \
62 /* R */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KR4, KC_NO , KC_NO , KC_NO } \
63 }
64
65 /*
66 * Tenkeyless keyboard default layout, ISO & ANSI (ISO is between Left Shift
67 * and Z, and the ANSI \ key above Return/Enter is used for the additional ISO
68 * switch in the ASD row next to enter. Use NUBS as keycode for the first and
69 * NUHS as the keycode for the second.
70 *
71 * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
72 * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
73 * `---' `---------------' `---------------' `---------------' `-----------'
74 * ,-----------------------------------------------------------. ,-----------.
75 * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU|
76 * |-----------------------------------------------------------| |-----------|
77 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD|
78 * |-----------------------------------------------------------| `-----------'
79 * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
80 * |-----------------------------------------------------------| ,---.
81 * |Shft|ISO| Z| X| C| V| B| N| M| ,| .| /|Shift | |Up |
82 * |-----------------------------------------------------------| ,-----------.
83 * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
84 * `-----------------------------------------------------------' `-----------'
85 */
86
87 /*
88 * Add different layouts. If no layout is defined the default layout will be set to ANSI.
89 */
90 #if defined(LAYOUT_CUSTOM)
91 #include "keymap_custom.h"
92 #elif defined(LAYOUT_ALARICLJS)
93 #include "keymap_alaricljs.h"
94 #elif defined(LAYOUT_ISO)
95 #include "keymap_iso.h"
96 #elif defined(LAYOUT_ANSI)
97 #include "keymap_ansi.h"
98 #else
99 #include "keymap_ansi.h"
100 #endif
101
102 #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
103 #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
104
105 /* translates key to keycode */
106 uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
107 {
108 if (layer < KEYMAPS_SIZE) {
109 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
110 } else {
111 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
112 }
113 }
114
115 /* translates Fn keycode to action */
116 action_t keymap_fn_to_action(uint8_t keycode)
117 {
118 action_t action;
119 if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
120 action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
121 } else {
122 action.code = ACTION_NO;
123 }
124 return action;
125 }
Imprint / Impressum