Fix keymap to adjust new keyboard.c.
[tmk_keyboard.git] / converter / ps2_usb / keymap_jis.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 PS/2 keyboard
20 */
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <avr/pgmspace.h>
24 #include "keycode.h"
25 #include "print.h"
26 #include "debug.h"
27 #include "util.h"
28 #include "keymap.h"
29
30
31
32
33 // Following macros help you to define a keymap with the form of actual keyboard layout.
34
35 /* US layout plus all other various keys */
36 #define KEYMAP_ALL( \
37 K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \
38 K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \
39 K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \
40 K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \
41 K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \
42 K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \
43 \
44 K61, /* for European ISO */ \
45 K51, K13, K6A, K64, K67, /* for Japanese JIS */ \
46 K08, K10, K18, K20, K28, K30, K38, K40, K48, K50, K57, K5F, /* F13-24 */ \
47 KB7, KBF, KDE, /* System Power, Sleep, Wake */ \
48 KA3, KB2, KA1, /* Mute, Volume Up, Volume Down */ \
49 KCD, K95, KBB, KB4, KD0, /* Next, Previous, Stop, Pause, Media Select */ \
50 KC8, KAB, KC0, /* Mail, Calculator, My Computer */ \
51 K90, KBA, KB8, KB0, /* WWW Search, Home, Back, Forward */ \
52 KA8, KA0, K98 /* WWW Stop, Refresh, Favorites */ \
53 ) { \
54 { KC_NO, KC_##K01, KC_NO, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
55 { KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_NO }, \
56 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_NO }, \
57 { KC_##K18, KC_NO, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_NO }, \
58 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_NO }, \
59 { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_NO }, \
60 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_NO }, \
61 { KC_##K38, KC_NO, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_NO }, \
62 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_NO }, \
63 { KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_NO }, \
64 { KC_##K50, KC_##K51, KC_##K52, KC_NO, KC_##K54, KC_##K55, KC_NO, KC_##K57 }, \
65 { KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_NO, KC_##K5D, KC_NO, KC_##K5F }, \
66 { KC_NO, KC_##K61, KC_NO, KC_NO, KC_##K64, KC_NO, KC_##K66, KC_##K67 }, \
67 { KC_NO, KC_##K69, KC_##K6A, KC_##K6B, KC_##K6C, KC_NO, KC_NO, KC_NO }, \
68 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_##K77 }, \
69 { KC_##K78, KC_##K79, KC_##K7A, KC_##K7B, KC_##K7C, KC_##K7D, KC_##K7E, KC_NO }, \
70 { KC_NO, KC_NO, KC_NO, KC_##K83, KC_NO, KC_NO, KC_NO, KC_NO }, \
71 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
72 { KC_##K90, KC_##K91, KC_NO, KC_NO, KC_##K94, KC_##K95, KC_NO, KC_NO }, \
73 { KC_##K98, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_##K9F }, \
74 { KC_##KA0, KC_##KA1, KC_NO, KC_##KA3, KC_NO, KC_NO, KC_NO, KC_##KA7 }, \
75 { KC_##KA8, KC_NO, KC_NO, KC_##KAB, KC_NO, KC_NO, KC_NO, KC_##KAF }, \
76 { KC_##KB0, KC_NO, KC_##KB2, KC_NO, KC_##KB4, KC_NO, KC_NO, KC_##KB7 }, \
77 { KC_##KB8, KC_NO, KC_##KBA, KC_##KBB, KC_NO, KC_NO, KC_NO, KC_##KBF }, \
78 { KC_##KC0, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
79 { KC_##KC8, KC_NO, KC_##KCA, KC_NO, KC_NO, KC_##KCD, KC_NO, KC_NO }, \
80 { KC_##KD0, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
81 { KC_NO, KC_NO, KC_##KDA, KC_NO, KC_NO, KC_NO, KC_##KDE, KC_NO }, \
82 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
83 { KC_NO, KC_##KE9, KC_NO, KC_##KEB, KC_##KEC, KC_NO, KC_NO, KC_NO }, \
84 { KC_##KF0, KC_##KF1, KC_##KF2, KC_NO, KC_##KF4, KC_##KF5, KC_NO, KC_NO }, \
85 { KC_NO, KC_NO, KC_##KFA, KC_NO, KC_##KFC, KC_##KFD, KC_##KFE, KC_NO }, \
86 }
87
88 /* JIS layout */
89 #define KEYMAP_JIS( \
90 K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \
91 K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K6A,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \
92 K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B, KF1,KE9,KFA, K6C,K75,K7D, \
93 K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52,K5D, K5A, K6B,K73,K74,K79, \
94 K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A,K51, K59, KF5, K69,K72,K7A, \
95 K14,K9F,K11, K67,K29,K64,K13, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \
96 ) \
97 KEYMAP_ALL( \
98 K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \
99 K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \
100 K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \
101 K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \
102 K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \
103 K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \
104 \
105 NUBS, \
106 K51, K13, K6A, K64, K67, \
107 F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, \
108 SYSTEM_POWER, SYSTEM_SLEEP, SYSTEM_WAKE, \
109 AUDIO_MUTE, AUDIO_VOL_UP, AUDIO_VOL_DOWN, \
110 MEDIA_NEXT_TRACK, MEDIA_PREV_TRACK, MEDIA_STOP, MEDIA_PLAY_PAUSE, MEDIA_SELECT, \
111 MAIL, CALCULATOR, MY_COMPUTER, \
112 WWW_SEARCH, WWW_HOME, WWW_BACK, WWW_FORWARD, \
113 WWW_STOP, WWW_REFRESH, WWW_FAVORITES \
114 )
115
116 #define KEYMAP_JIS_COMPACT( \
117 K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K6A,K66, \
118 K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B, \
119 K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52,K5D, K5A, \
120 K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A,K51, K59, \
121 K14,K9F,K11, K67,K29,K64,K13, K91,KA7,KAF,K94 \
122 ) \
123 KEYMAP_ALL( \
124 ESC,F1, F2, F3, F4, F5, F6, F7, F8, F9, F10,F11,F12, PSCR,SLCK,BRK, \
125 K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, \
126 K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, DEL, END, PGDN, P7, P8, P9, \
127 K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, P4, P5, P6, PPLS, \
128 K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, UP, P1, P2, P3, \
129 K14,K9F,K11, K29, K91,KA7,KAF,K94, LEFT,DOWN,RGHT, P0, PDOT,PENT, \
130 \
131 NUBS, \
132 K51, K13, K6A, K64, K67, \
133 F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, \
134 SYSTEM_POWER, SYSTEM_SLEEP, SYSTEM_WAKE, \
135 AUDIO_MUTE, AUDIO_VOL_UP, AUDIO_VOL_DOWN, \
136 MEDIA_NEXT_TRACK, MEDIA_PREV_TRACK, MEDIA_STOP, MEDIA_PLAY_PAUSE, MEDIA_SELECT, \
137 MAIL, CALCULATOR, MY_COMPUTER, \
138 WWW_SEARCH, WWW_HOME, WWW_BACK, WWW_FORWARD, \
139 WWW_STOP, WWW_REFRESH, WWW_FAVORITES \
140 )
141
142
143 // Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
144 static const uint8_t PROGMEM fn_layer[] = {
145 1, // Fn0
146 2, // Fn1
147 1, // Fn2
148 2, // Fn3
149 3, // Fn4
150 4, // Fn5
151 0, // Fn6
152 0 // Fn7
153 };
154
155 // Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer.
156 // See layer.c for details.
157 static const uint8_t PROGMEM fn_keycode[] = {
158 KC_SCLN, // Fn0
159 KC_SLSH, // Fn1
160 KC_BSPC, // Fn2
161 KC_NO, // Fn3
162 KC_NO, // Fn4
163 KC_SPC, // Fn5
164 KC_NO, // Fn6
165 KC_NO // Fn7
166 };
167
168
169 // The keymap is a 32*8 byte array which convert a PS/2 scan code into a USB keycode.
170 // See keycode.h for USB keycodes. You should omit a 'KC_' prefix of USB keycodes in keymap macro.
171 // Use KEYMAP_ISO() or KEYMAP_JIS() instead of KEYMAP() if your keyboard is ISO or JIS.
172 static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
173 /* 0: JIS LAYOUT
174 * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,-----------.
175 * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|Slp|Wak|
176 * `---' `---------------' `---------------' `---------------' `-----------' `-----------'
177 * ,-----------------------------------------------------------. ,-----------. ,---------------.
178 * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| JY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -|
179 * |-----------------------------------------------------------| |-----------| |---------------|
180 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| Ret | |Del|End|PgD| | 7| 8| 9| |
181 * |------------------------------------------------------` | `-----------' |-----------| +|
182 * |CapsLo| A| S| D| F| G| H| J| K| L| ;| :| \| | | 4| 5| 6| |
183 * |-----------------------------------------------------------| ,---. |---------------|
184 * |Shift | Z| X| C| V| B| N| M| ,| ,| /| RO|Shift | |Up | | 1| 2| 3| |
185 * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
186 * |Ctrl |Gui |Alt |MHEN| Space |HENK|KANA|Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| |
187 * `-----------------------------------------------------------' `-----------' `---------------'
188 */
189 /*
190 KEYMAP_JIS(
191 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK,
192 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
193 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, DEL, END, PGDN, P7, P8, P9,
194 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,BSLS, ENT, P4, P5, P6, PPLS,
195 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RO, RSFT, UP, P1, P2, P3,
196 LCTL,LGUI,LALT, MHEN,SPC, HENK,KANA, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
197 ),
198 */
199 /* 0: HHKB-wise
200 * ,-----------------------------------------------------------.
201 * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
202 * |-----------------------------------------------------------|
203 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| Bsp |
204 * |------------------------------------------------------` |
205 * |Ctrl | A| S| D| F| G| H| J| K| L| ;| :|Ret| |
206 * |-----------------------------------------------------------|
207 * |Shift | Z| X| C| V| B| N| M| ,| ,| /| RO|Shift |
208 * |-----------------------------------------------------------|
209 * |Ctrl |Gui |Alt |MHEN| Space |HENK|KANA|Alt |Gui |Menu|Ctrl|
210 * `-----------------------------------------------------------'
211 */
212 KEYMAP_JIS_COMPACT(
213 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,BSPC,
214 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,
215 LCTL,A, S, D, F, G, H, J, K, L, FN0, QUOT,GRV, ENT,
216 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, FN4,
217 LCTL,LGUI,LALT, LALT,FN5, FN2, FN3, RALT,RGUI,APP, LGUI
218 ),
219
220 /* 1: Mouse keys
221 * ,-----------------------------------------------------------.
222 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backspa|
223 * |-----------------------------------------------------------|
224 * |Tab |MwL|MwU|McU|WwU|WwR|MwL|MwD|MwU|MwR| | | | \|
225 * |-----------------------------------------------------------|
226 * |CapsLo| |McL|McD|McR| |McL|McD|McU|McR|Fn0| |Return |
227 * |-----------------------------------------------------------|
228 * |Shift |VoD|VoU|Mut|Mb2|Mb3|Mb2|Mb1|VoD|VoU|Mut|Shift |
229 * |-----------------------------------------------------------|
230 * |Ctrl |Gui |Alt | Mb1 |Alt |Gui |Menu|Ctrl|
231 * `-----------------------------------------------------------'
232 * Mc = mouse cursor, Mw = mouse wheel, Mb = mouse button
233 * Vo = Volume, Mut = Mute
234 */
235 KEYMAP_JIS_COMPACT(
236 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, INS, DEL,
237 TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO,
238 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, NO, ENT,
239 LSFT,NO, NO, BTN1,BTN2,BTN3,BTN2,BTN1,BTN2,BTN3,NO, RSFT, RSFT,
240 LCTL,LGUI,LALT, LALT,BTN1,FN2, RALT, RALT,RGUI,APP, LGUI
241 ),
242
243 /* 2: Cursor keys
244 * ,-----------------------------------------------------------.
245 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backspa|
246 * |-----------------------------------------------------------|
247 * |Tab |Hom|PgU| Up|PgU|End|Hom|PgD|PgU|End| | | | \|
248 * |-----------------------------------------------------------|
249 * |CapsLo| |Lef|Dow|Rig| |Lef|Dow| Up|Rig| | |Return |
250 * |-----------------------------------------------------------|
251 * |Shift | | | | | |Hom|PgD|PgU|End|Fn1|Shift |
252 * |-----------------------------------------------------------|
253 * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl|
254 * `-----------------------------------------------------------'
255 */
256 KEYMAP_JIS_COMPACT(
257 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, INS, DEL,
258 TAB, HOME,PGUP,UP, PGDN,END, HOME,PGDN,PGUP,END, NO, NO, NO,
259 LCTL,HOME,LEFT,DOWN,RGHT,END, LEFT,DOWN,UP, RGHT,NO, NO, NO, ENT,
260 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN1, RSFT, RSFT,
261 LCTL,LGUI,LALT, LALT,BTN1,BSPC,FN3, RALT,RGUI,APP, LGUI
262 ),
263
264 /* 3: HHKB Fn layer */
265 KEYMAP_JIS_COMPACT(
266 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, INS, DEL,
267 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS,UP, NO,
268 LCTL,VOLD,VOLU,MUTE,NO, NO, NO, NO, HOME,PGUP,LEFT,RGHT,NO, ENT,
269 LSFT,NO, NO, NO, NO, NO, NO, NO, END, PGDN,DOWN,RSFT, FN4,
270 LCTL,LGUI,LALT, LALT,SPC, BSPC,NO, RALT,RGUI,APP, LGUI
271 ),
272
273 /* 4: Number */
274 KEYMAP_JIS_COMPACT(
275 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, INS, DEL,
276 TAB, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO,
277 LCTL,1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, ENT,
278 LSFT,NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, RSFT, RSFT,
279 LCTL,LGUI,LALT, LALT,FN5, BSPC,NO, RALT,RGUI,APP, LGUI
280 ),
281 };
282
283
284 uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
285 {
286 return pgm_read_byte(&keymaps[(layer)][(row)][(col)]);
287 }
288
289 uint8_t keymap_fn_layer(uint8_t index)
290 {
291 return pgm_read_byte(&fn_layer[index]);
292 }
293
294 uint8_t keymap_fn_keycode(uint8_t index)
295 {
296 return pgm_read_byte(&fn_keycode[index]);
297 }
Imprint / Impressum