Skip to content

Commit 912326c

Browse files
committed
core: Add unimap support
1 parent 00f4011 commit 912326c

File tree

6 files changed

+333
-8
lines changed

6 files changed

+333
-8
lines changed

common.mk

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ SRC += $(COMMON_DIR)/host.c \
1717

1818

1919
# Option modules
20-
ifdef ACTIONMAP_ENABLE
21-
SRC += $(COMMON_DIR)/actionmap.c
22-
OPT_DEFS += -DACTIONMAP_ENABLE
20+
ifdef UNIMAP_ENABLE
21+
SRC += $(COMMON_DIR)/unimap.c
22+
OPT_DEFS += -DUNIMAP_ENABLE
2323
else
24-
SRC += $(COMMON_DIR)/keymap.c
24+
ifdef ACTIONMAP_ENABLE
25+
SRC += $(COMMON_DIR)/actionmap.c
26+
OPT_DEFS += -DACTIONMAP_ENABLE
27+
else
28+
SRC += $(COMMON_DIR)/keymap.c
29+
endif
2530
endif
2631

2732
ifdef BOOTMAGIC_ENABLE

common/actionmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#include "action_code.h"
1919
#include "actionmap.h"
2020

21+
22+
/* Keymapping with 16bit action codes */
23+
extern const action_t actionmaps[][MATRIX_ROWS][MATRIX_COLS];
24+
25+
2126
/* Converts key to action */
2227
__attribute__ ((weak))
2328
action_t action_for_key(uint8_t layer, keypos_t key)

common/actionmap.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
#include "action.h"
2525

2626

27-
/* Keymapping with 16bit action codes */
28-
extern const action_t actionmaps[][MATRIX_ROWS][MATRIX_COLS];
29-
30-
3127
/* Modified key */
3228
#define AC_c(kc) ACTION_MODS_KEY(MOD_LCTL, KC_##kc)
3329
#define AC_s(kc) ACTION_MODS_KEY(MOD_LSFT, KC_##kc)

common/unimap.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "keyboard.h"
2+
#include "action.h"
3+
#include "unimap.h"
4+
#include "print.h"
5+
#if defined(__AVR__)
6+
# include <avr/pgmspace.h>
7+
#endif
8+
9+
10+
/* Keymapping with 16bit action codes */
11+
extern const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS];
12+
13+
// table translates matrix to universal keymap
14+
extern const uint8_t unimap_trans[MATRIX_ROWS][MATRIX_COLS];
15+
16+
17+
18+
// translates raw matrix to universal map
19+
keypos_t unimap_translate(keypos_t key)
20+
{
21+
uint8_t unimap_pos =
22+
#if defined(__AVR__)
23+
pgm_read_byte(&unimap_trans[key.row][key.col]);
24+
#else
25+
unimap_trans[key.row][key.col];
26+
#endif
27+
return (keypos_t) {
28+
.row = ((unimap_pos & 0x70) >> 4),
29+
.col = (unimap_pos & 0x0F)
30+
};
31+
}
32+
33+
/* Converts key to action */
34+
__attribute__ ((weak))
35+
action_t action_for_key(uint8_t layer, keypos_t key)
36+
{
37+
keypos_t uni = unimap_translate(key);
38+
if ((uni.row << 4 | uni.col) == UNIMAP_NO) return (action_t)ACTION_NO;
39+
#if defined(__AVR__)
40+
return (action_t)pgm_read_word(&actionmaps[(layer)][(uni.row)][(uni.col)]);
41+
#else
42+
return actionmaps[(layer)][(uni.row)][(uni.col)];
43+
#endif
44+
}
45+
46+
/* Macro */
47+
__attribute__ ((weak))
48+
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
49+
{
50+
return MACRO_NONE;
51+
}
52+
53+
/* Function */
54+
__attribute__ ((weak))
55+
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
56+
{
57+
}

common/unimap.h

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/*
2+
Copyright 2016 Jun Wako <[email protected]>
3+
*/
4+
#ifndef _UNIMAP_H_
5+
#define _UNIMAP_H_
6+
7+
#include <stdint.h>
8+
#include <stdbool.h>
9+
#include "action.h"
10+
#include "action_code.h"
11+
#include "actionmap.h"
12+
13+
14+
// Universal map table: 8x16=128key
15+
#define UNIMAP_ROWS 8
16+
#define UNIMAP_COLS 16
17+
18+
/* Universal 128-key keyboard layout(8x16)
19+
,-----------------------------------------------.
20+
|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|
21+
,---. |-----------------------------------------------| ,-----------. ,-----------.
22+
|Esc| |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12| |PrS|ScL|Pau| |VDn|VUp|Mut|
23+
`---' `-----------------------------------------------' `-----------' `-----------'
24+
,-----------------------------------------------------------. ,-----------. ,---------------.
25+
| `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -|
26+
|-----------------------------------------------------------| |-----------| |---------------|
27+
|Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|End|PgD| | 7| 8| 9| +|
28+
|-----------------------------------------------------------| `-----------' |---------------|
29+
|CapsL | A| S| D| F| G| H| J| K| L| ;| '| #|Retn| | 4| 5| 6|KP,|
30+
|-----------------------------------------------------------| ,---. |---------------|
31+
|Shft| <| Z| X| C| V| B| N| M| ,| ,| /| RO|Shift | |Up | | 1| 2| 3|KP=|
32+
|-----------------------------------------------------------| ,-----------. |---------------|
33+
|Ctl|Gui|Alt|MHEN| Space |HENK|KANA|Alt|Gui|App|Ctl| |Lef|Dow|Rig| | 0 | .|Ent|
34+
`-----------------------------------------------------------' `-----------' `---------------'
35+
App: Windows Menu key
36+
Gui: Windows key, Mac ⌘ key or Meta key
37+
VDn Vup Mut: Volume control
38+
< #: ISO keys(in UK legend)
39+
KP=: Keypad = for Mac
40+
KP,: Brazilian Keypad Comma
41+
JPY: Japanese Yen(¥)
42+
RO: Japanese ろ(Ro) or Brazilian /(Slash)
43+
MHEN: Japanese 無変換(Non Conversion) or Korean Hanja
44+
HENK: Japanese 変換(Conversion) or Korean Hangul/English
45+
KANA: Japanese かな(Hiragana/Katakana)
46+
https://en.wikipedia.org/wiki/Keyboard_layout#Japanese
47+
https://en.wikipedia.org/wiki/Keyboard_layout#Hangul_.28for_Korean.29
48+
*/
49+
#define UNIMAP( \
50+
K68,K69,K6A,K6B,K6C,K6D,K6E,K6F,K70,K71,K72,K73, \
51+
K29, K3A,K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,K45, K46,K47,K48, K01,K02,K03, \
52+
K35,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K2D,K2E,K74,K2A, K49,K4A,K4B, K53,K54,K55,K56, \
53+
K2B,K14,K1A,K08,K15,K17,K1C,K18,K0C,K12,K13,K2F,K30, K31, K4C,K4D,K4E, K5F,K60,K61,K57, \
54+
K39,K04,K16,K07,K09,K0A,K0B,K0D,K0E,K0F,K33,K34, K32,K28, K5C,K5D,K5E,K66, \
55+
K79,K64,K1D,K1B,K06,K19,K05,K11,K10,K36,K37,K38, K75,K7D, K52, K59,K5A,K5B,K67, \
56+
K78,K7B,K7A,K77, K2C, K76,K00,K7E,K7F,K65,K7C, K50,K51,K4F, K62, K63,K58 \
57+
) { \
58+
{ AC_##K00, AC_##K01, AC_##K02, AC_##K03, AC_##K04, AC_##K05, AC_##K06, AC_##K07, /* 00-07 */ \
59+
AC_##K08, AC_##K09, AC_##K0A, AC_##K0B, AC_##K0C, AC_##K0D, AC_##K0E, AC_##K0F }, /* 08-0F */ \
60+
{ AC_##K10, AC_##K11, AC_##K12, AC_##K13, AC_##K14, AC_##K15, AC_##K16, AC_##K17, /* 10-17 */ \
61+
AC_##K18, AC_##K19, AC_##K1A, AC_##K1B, AC_##K1C, AC_##K1D, AC_##K1E, AC_##K1F }, /* 18-1F */ \
62+
{ AC_##K20, AC_##K21, AC_##K22, AC_##K23, AC_##K24, AC_##K25, AC_##K26, AC_##K27, /* 20-27 */ \
63+
AC_##K28, AC_##K29, AC_##K2A, AC_##K2B, AC_##K2C, AC_##K2D, AC_##K2E, AC_##K2F }, /* 28-2F */ \
64+
{ AC_##K30, AC_##K31, AC_##K32, AC_##K33, AC_##K34, AC_##K35, AC_##K36, AC_##K37, /* 30-37 */ \
65+
AC_##K38, AC_##K39, AC_##K3A, AC_##K3B, AC_##K3C, AC_##K3D, AC_##K3E, AC_##K3F }, /* 38-3F */ \
66+
{ AC_##K40, AC_##K41, AC_##K42, AC_##K43, AC_##K44, AC_##K45, AC_##K46, AC_##K47, /* 40-47 */ \
67+
AC_##K48, AC_##K49, AC_##K4A, AC_##K4B, AC_##K4C, AC_##K4D, AC_##K4E, AC_##K4F }, /* 48-4F */ \
68+
{ AC_##K50, AC_##K51, AC_##K52, AC_##K53, AC_##K54, AC_##K55, AC_##K56, AC_##K57, /* 50-57 */ \
69+
AC_##K58, AC_##K59, AC_##K5A, AC_##K5B, AC_##K5C, AC_##K5D, AC_##K5E, AC_##K5F }, /* 58-5F */ \
70+
{ AC_##K60, AC_##K61, AC_##K62, AC_##K63, AC_##K64, AC_##K65, AC_##K66, AC_##K67, /* 60-67 */ \
71+
AC_##K68, AC_##K69, AC_##K6A, AC_##K6B, AC_##K6C, AC_##K6D, AC_##K6E, AC_##K6F }, /* 68-6F */ \
72+
{ AC_##K70, AC_##K71, AC_##K72, AC_##K73, AC_##K74, AC_##K75, AC_##K76, AC_##K77, /* 70-77 */ \
73+
AC_##K78, AC_##K79, AC_##K7A, AC_##K7B, AC_##K7C, AC_##K7D, AC_##K7E, AC_##K7F } /* 78-7F */ \
74+
}
75+
76+
// Universal map position codes
77+
enum unimap_position_codes {
78+
// logical name position(row << 4 | col)
79+
// ------------------------------------------------
80+
UNIMAP_KANA, // 0x00
81+
UNIMAP_VOLUME_DOWN, // 0x01
82+
UNIMAP_VOLUME_UP, // 0x02
83+
UNIMAP_VOLUME_MUTE, // 0x03
84+
UNIMAP_A, // 0x04
85+
UNIMAP_B, // 0x05
86+
UNIMAP_C, // 0x06
87+
UNIMAP_D, // 0x07
88+
UNIMAP_E, // 0x08
89+
UNIMAP_F, // 0x09
90+
UNIMAP_G, // 0x0A
91+
UNIMAP_H, // 0x0B
92+
UNIMAP_I, // 0x0C
93+
UNIMAP_J, // 0x0D
94+
UNIMAP_K, // 0x0E
95+
UNIMAP_L, // 0x0F
96+
UNIMAP_M, // 0x10
97+
UNIMAP_N, // 0x11
98+
UNIMAP_O, // 0x12
99+
UNIMAP_P, // 0x13
100+
UNIMAP_Q, // 0x14
101+
UNIMAP_R, // 0x15
102+
UNIMAP_S, // 0x16
103+
UNIMAP_T, // 0x17
104+
UNIMAP_U, // 0x18
105+
UNIMAP_V, // 0x19
106+
UNIMAP_W, // 0x1A
107+
UNIMAP_X, // 0x1B
108+
UNIMAP_Y, // 0x1C
109+
UNIMAP_Z, // 0x1D
110+
UNIMAP_1, // 0x1E
111+
UNIMAP_2, // 0x1F
112+
UNIMAP_3, // 0x20
113+
UNIMAP_4, // 0x21
114+
UNIMAP_5, // 0x22
115+
UNIMAP_6, // 0x23
116+
UNIMAP_7, // 0x24
117+
UNIMAP_8, // 0x25
118+
UNIMAP_9, // 0x26
119+
UNIMAP_0, // 0x27
120+
UNIMAP_ENTER, // 0x28
121+
UNIMAP_ESCAPE, // 0x29
122+
UNIMAP_BSPACE, // 0x2A
123+
UNIMAP_TAB, // 0x2B
124+
UNIMAP_SPACE, // 0x2C
125+
UNIMAP_MINUS, // 0x2D
126+
UNIMAP_EQUAL, // 0x2E
127+
UNIMAP_LBRACKET, // 0x2F
128+
UNIMAP_RBRACKET, // 0x30
129+
UNIMAP_BSLASH, // 0x31
130+
UNIMAP_NONUS_HASH, // 0x32 ISO UK hasu
131+
UNIMAP_SCOLON, // 0x33
132+
UNIMAP_QUOTE, // 0x34
133+
UNIMAP_GRAVE, // 0x35
134+
UNIMAP_COMMA, // 0x36
135+
UNIMAP_DOT, // 0x37
136+
UNIMAP_SLASH, // 0x38
137+
UNIMAP_CAPSLOCK, // 0x39
138+
UNIMAP_F1, // 0x3A
139+
UNIMAP_F2, // 0x3B
140+
UNIMAP_F3, // 0x3C
141+
UNIMAP_F4, // 0x3D
142+
UNIMAP_F5, // 0x3E
143+
UNIMAP_F6, // 0x3F
144+
UNIMAP_F7, // 0x40
145+
UNIMAP_F8, // 0x41
146+
UNIMAP_F9, // 0x42
147+
UNIMAP_F10, // 0x43
148+
UNIMAP_F11, // 0x44
149+
UNIMAP_F12, // 0x45
150+
UNIMAP_PSCREEN, // 0x46
151+
UNIMAP_SCROLLLOCK, // 0x47
152+
UNIMAP_PAUSE, // 0x48
153+
UNIMAP_INSERT, // 0x49
154+
UNIMAP_HOME, // 0x4A
155+
UNIMAP_PGUP, // 0x4B
156+
UNIMAP_DELETE, // 0x4C
157+
UNIMAP_END, // 0x4D
158+
UNIMAP_PGDOWN, // 0x4E
159+
UNIMAP_RIGHT, // 0x4F
160+
UNIMAP_LEFT, // 0x50
161+
UNIMAP_DOWN, // 0x51
162+
UNIMAP_UP, // 0x52
163+
UNIMAP_NUMLOCK, // 0x53
164+
UNIMAP_KP_SLASH, // 0x54
165+
UNIMAP_KP_ASTERISK, // 0x55
166+
UNIMAP_KP_MINUS, // 0x56
167+
UNIMAP_KP_PLUS, // 0x57
168+
UNIMAP_KP_ENTER, // 0x58
169+
UNIMAP_KP_1, // 0x59
170+
UNIMAP_KP_2, // 0x5A
171+
UNIMAP_KP_3, // 0x5B
172+
UNIMAP_KP_4, // 0x5C
173+
UNIMAP_KP_5, // 0x5D
174+
UNIMAP_KP_6, // 0x5E
175+
UNIMAP_KP_7, // 0x5F
176+
UNIMAP_KP_8, // 0x60
177+
UNIMAP_KP_9, // 0x61
178+
UNIMAP_KP_0, // 0x62
179+
UNIMAP_KP_DOT, // 0x63
180+
UNIMAP_NONUS_BSLASH, // 0x64 ISO UK backslash
181+
UNIMAP_APPLICATION, // 0x65
182+
UNIMAP_KP_COMMA, // 0x66
183+
UNIMAP_KP_EQUAL, // 0x67
184+
UNIMAP_F13, // 0x68
185+
UNIMAP_F14, // 0x69
186+
UNIMAP_F15, // 0x6A
187+
UNIMAP_F16, // 0x6B
188+
UNIMAP_F17, // 0x6C
189+
UNIMAP_F18, // 0x6D
190+
UNIMAP_F19, // 0x6E
191+
UNIMAP_F20, // 0x6F
192+
UNIMAP_F21, // 0x70
193+
UNIMAP_F22, // 0x71
194+
UNIMAP_F23, // 0x72
195+
UNIMAP_F24, // 0x73
196+
UNIMAP_JYEN, // 0x74
197+
UNIMAP_RO, // 0x75
198+
UNIMAP_HENK, // 0x76
199+
UNIMAP_MHEN, // 0x77
200+
UNIMAP_LCTRL, // 0x78
201+
UNIMAP_LSHIFT, // 0x79
202+
UNIMAP_LALT, // 0x7A
203+
UNIMAP_LGUI, // 0x7B
204+
UNIMAP_RCTRL, // 0x7C
205+
UNIMAP_RSHIFT, // 0x7D
206+
UNIMAP_RALT, // 0x7E
207+
UNIMAP_RGUI, // 0x7F
208+
UNIMAP_NO, // 0x80
209+
};
210+
211+
#endif

doc/unimap.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Unimap
2+
======
3+
universal keymapping framework
4+
using logical 128-key keyboard layout independent from physical keyboad matrix
5+
6+
unimap is actually an actionmap whose size is row:8xcol:16.
7+
8+
/* Keymapping with 16bit action codes */
9+
extern const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS];
10+
11+
/* Universal 128-key keyboard layout(8x16)
12+
,-----------------------------------------------.
13+
|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|
14+
,---. |-----------------------------------------------| ,-----------. ,-----------.
15+
|Esc| |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12| |PrS|ScL|Pau| |VDn|VUp|Mut|
16+
`---' `-----------------------------------------------' `-----------' `-----------'
17+
,-----------------------------------------------------------. ,-----------. ,---------------.
18+
| `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -|
19+
|-----------------------------------------------------------| |-----------| |---------------|
20+
|Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|End|PgD| | 7| 8| 9| +|
21+
|-----------------------------------------------------------| `-----------' |---------------|
22+
|CapsL | A| S| D| F| G| H| J| K| L| ;| '| #|Retn| | 4| 5| 6|KP,|
23+
|-----------------------------------------------------------| ,---. |---------------|
24+
|Shft| <| Z| X| C| V| B| N| M| ,| ,| /| RO|Shift | |Up | | 1| 2| 3|KP=|
25+
|-----------------------------------------------------------| ,-----------. |---------------|
26+
|Ctl|Gui|Alt|MHEN| Space |HENK|KANA|Alt|Gui|App|Ctl| |Lef|Dow|Rig| | 0 | .|Ent|
27+
`-----------------------------------------------------------' `-----------' `---------------'
28+
App: Windows Menu key
29+
Gui: Windows key, Mac ⌘ key or Meta key
30+
VDn Vup Mut: Volume control
31+
< #: ISO keys(in UK legend)
32+
KP=: Keypad = for Mac
33+
KP,: Brazilian Keypad Comma
34+
JPY: Japanese Yen(¥)
35+
RO: Japanese ろ(Ro) or Brazilian /(Slash)
36+
MHEN: Japanese 無変換(Non Conversion) or Korean Hanja
37+
HENK: Japanese 変換(Conversion) or Korean Hangul/English
38+
KANA: Japanese かな(Hiragana/Katakana)
39+
https://en.wikipedia.org/wiki/Keyboard_layout#Japanese
40+
https://en.wikipedia.org/wiki/Keyboard_layout#Hangul_.28for_Korean.29
41+
*/
42+
43+
44+
when refering to keymapping physical matrix position needed to be translated into logical one on unimap
45+
the translation is defined in unimap array
46+
47+
row and col of unimap positon is encoded as follows
48+
position = (row << 4) | col
49+
50+
// table translates matrix to universal keymap
51+
extern const uint8_t unimap_trans[MATRIX_ROWS][MATRIX_COLS];

0 commit comments

Comments
 (0)