aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-02-15 16:36:31 -0500
committerJack Humbert <jack.humb@gmail.com>2017-02-15 16:36:31 -0500
commitcbabb4d417ef58f5d484dc256b637f61619efaa8 (patch)
tree01ed906acd8ef81a213385697599cee3ac2f68de
parent6788cbd76291e1f3103a350598f7bf5d523a7310 (diff)
downloadqmk_firmware-cbabb4d417ef58f5d484dc256b637f61619efaa8.tar.gz
qmk_firmware-cbabb4d417ef58f5d484dc256b637f61619efaa8.zip
split up unicode systems into different files
-rw-r--r--build_keyboard.mk4
-rw-r--r--quantum/process_keycode/process_ucis.c133
-rw-r--r--quantum/process_keycode/process_ucis.h34
-rw-r--r--quantum/process_keycode/process_unicode.c200
-rw-r--r--quantum/process_keycode/process_unicode.h36
-rw-r--r--quantum/process_keycode/process_unicodemap.c54
-rw-r--r--quantum/process_keycode/process_unicodemap.h8
-rw-r--r--quantum/quantum.c13
-rw-r--r--quantum/quantum.h10
9 files changed, 253 insertions, 239 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index c8e82cf0e..9d2eaec1f 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -168,12 +168,12 @@ endif
168 168
169ifeq ($(strip $(UCIS_ENABLE)), yes) 169ifeq ($(strip $(UCIS_ENABLE)), yes)
170 OPT_DEFS += -DUCIS_ENABLE 170 OPT_DEFS += -DUCIS_ENABLE
171 UNICODE_ENABLE = yes 171 SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
172endif 172endif
173 173
174ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) 174ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
175 OPT_DEFS += -DUNICODEMAP_ENABLE 175 OPT_DEFS += -DUNICODEMAP_ENABLE
176 UNICODE_ENABLE = yes 176 SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
177endif 177endif
178 178
179ifeq ($(strip $(UNICODE_ENABLE)), yes) 179ifeq ($(strip $(UNICODE_ENABLE)), yes)
diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c
new file mode 100644
index 000000000..4ad2533b0
--- /dev/null
+++ b/quantum/process_keycode/process_ucis.c
@@ -0,0 +1,133 @@
1#include "process_ucis.h"
2
3qk_ucis_state_t qk_ucis_state;
4
5void qk_ucis_start(void) {
6 qk_ucis_state.count = 0;
7 qk_ucis_state.in_progress = true;
8
9 qk_ucis_start_user();
10}
11
12__attribute__((weak))
13void qk_ucis_start_user(void) {
14 unicode_input_start();
15 register_hex(0x2328);
16 unicode_input_finish();
17}
18
19static bool is_uni_seq(char *seq) {
20 uint8_t i;
21
22 for (i = 0; seq[i]; i++) {
23 uint16_t code;
24 if (('1' <= seq[i]) && (seq[i] <= '0'))
25 code = seq[i] - '1' + KC_1;
26 else
27 code = seq[i] - 'a' + KC_A;
28
29 if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code)
30 return false;
31 }
32
33 return (qk_ucis_state.codes[i] == KC_ENT ||
34 qk_ucis_state.codes[i] == KC_SPC);
35}
36
37__attribute__((weak))
38void qk_ucis_symbol_fallback (void) {
39 for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
40 uint8_t code = qk_ucis_state.codes[i];
41 register_code(code);
42 unregister_code(code);
43 wait_ms(UNICODE_TYPE_DELAY);
44 }
45}
46
47void register_ucis(const char *hex) {
48 for(int i = 0; hex[i]; i++) {
49 uint8_t kc = 0;
50 char c = hex[i];
51
52 switch (c) {
53 case '0':
54 kc = KC_0;
55 break;
56 case '1' ... '9':
57 kc = c - '1' + KC_1;
58 break;
59 case 'a' ... 'f':
60 kc = c - 'a' + KC_A;
61 break;
62 case 'A' ... 'F':
63 kc = c - 'A' + KC_A;
64 break;
65 }
66
67 if (kc) {
68 register_code (kc);
69 unregister_code (kc);
70 wait_ms (UNICODE_TYPE_DELAY);
71 }
72 }
73}
74
75bool process_ucis (uint16_t keycode, keyrecord_t *record) {
76 uint8_t i;
77
78 if (!qk_ucis_state.in_progress)
79 return true;
80
81 if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH &&
82 !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
83 return false;
84 }
85
86 if (!record->event.pressed)
87 return true;
88
89 qk_ucis_state.codes[qk_ucis_state.count] = keycode;
90 qk_ucis_state.count++;
91
92 if (keycode == KC_BSPC) {
93 if (qk_ucis_state.count >= 2) {
94 qk_ucis_state.count -= 2;
95 return true;
96 } else {
97 qk_ucis_state.count--;
98 return false;
99 }
100 }
101
102 if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
103 bool symbol_found = false;
104
105 for (i = qk_ucis_state.count; i > 0; i--) {
106 register_code (KC_BSPC);
107 unregister_code (KC_BSPC);
108 wait_ms(UNICODE_TYPE_DELAY);
109 }
110
111 if (keycode == KC_ESC) {
112 qk_ucis_state.in_progress = false;
113 return false;
114 }
115
116 unicode_input_start();
117 for (i = 0; ucis_symbol_table[i].symbol; i++) {
118 if (is_uni_seq (ucis_symbol_table[i].symbol)) {
119 symbol_found = true;
120 register_ucis(ucis_symbol_table[i].code + 2);
121 break;
122 }
123 }
124 if (!symbol_found) {
125 qk_ucis_symbol_fallback();
126 }
127 unicode_input_finish();
128
129 qk_ucis_state.in_progress = false;
130 return false;
131 }
132 return true;
133} \ No newline at end of file
diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h
new file mode 100644
index 000000000..520db8042
--- /dev/null
+++ b/quantum/process_keycode/process_ucis.h
@@ -0,0 +1,34 @@
1#ifndef PROCESS_UCIS_H
2#define PROCESS_UCIS_H
3
4#include "quantum.h"
5
6#ifndef UCIS_MAX_SYMBOL_LENGTH
7#define UCIS_MAX_SYMBOL_LENGTH 32
8#endif
9
10typedef struct {
11 char *symbol;
12 char *code;
13} qk_ucis_symbol_t;
14
15typedef struct {
16 uint8_t count;
17 uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
18 bool in_progress:1;
19} qk_ucis_state_t;
20
21extern qk_ucis_state_t qk_ucis_state;
22
23#define UCIS_TABLE(...) {__VA_ARGS__, {NULL, NULL}}
24#define UCIS_SYM(name, code) {name, #code}
25
26extern const qk_ucis_symbol_t ucis_symbol_table[];
27
28void qk_ucis_start(void);
29void qk_ucis_start_user(void);
30void qk_ucis_symbol_fallback (void);
31void register_ucis(const char *hex);
32bool process_ucis (uint16_t keycode, keyrecord_t *record);
33
34#endif
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c
index 9d01a592d..898e168a3 100644
--- a/quantum/process_keycode/process_unicode.c
+++ b/quantum/process_keycode/process_unicode.c
@@ -4,18 +4,6 @@
4static uint8_t input_mode; 4static uint8_t input_mode;
5uint8_t mods; 5uint8_t mods;
6 6
7__attribute__((weak))
8uint16_t hex_to_keycode(uint8_t hex)
9{
10 if (hex == 0x0) {
11 return KC_0;
12 } else if (hex < 0xA) {
13 return KC_1 + (hex - 0x1);
14 } else {
15 return KC_A + (hex - 0xA);
16 }
17}
18
19void set_unicode_input_mode(uint8_t os_target) 7void set_unicode_input_mode(uint8_t os_target)
20{ 8{
21 input_mode = os_target; 9 input_mode = os_target;
@@ -108,191 +96,3 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) {
108 return true; 96 return true;
109} 97}
110 98
111#ifdef UNICODEMAP_ENABLE
112__attribute__((weak))
113const uint32_t PROGMEM unicode_map[] = {
114};
115
116void register_hex32(uint32_t hex) {
117 uint8_t onzerostart = 1;
118 for(int i = 7; i >= 0; i--) {
119 if (i <= 3) {
120 onzerostart = 0;
121 }
122 uint8_t digit = ((hex >> (i*4)) & 0xF);
123 if (digit == 0) {
124 if (onzerostart == 0) {
125 register_code(hex_to_keycode(digit));
126 unregister_code(hex_to_keycode(digit));
127 }
128 } else {
129 register_code(hex_to_keycode(digit));
130 unregister_code(hex_to_keycode(digit));
131 onzerostart = 0;
132 }
133 }
134}
135
136__attribute__((weak))
137void unicode_map_input_error() {}
138
139bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
140 if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
141 const uint32_t* map = unicode_map;
142 uint16_t index = keycode - QK_UNICODE_MAP;
143 uint32_t code = pgm_read_dword_far(&map[index]);
144 if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
145 // Convert to UTF-16 surrogate pair
146 code -= 0x10000;
147 uint32_t lo = code & 0x3ff;
148 uint32_t hi = (code & 0xffc00) >> 10;
149 unicode_input_start();
150 register_hex32(hi + 0xd800);
151 register_hex32(lo + 0xdc00);
152 unicode_input_finish();
153 } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
154 // when character is out of range supported by the OS
155 unicode_map_input_error();
156 } else {
157 unicode_input_start();
158 register_hex32(code);
159 unicode_input_finish();
160 }
161 }
162 return true;
163}
164#endif
165
166#ifdef UCIS_ENABLE
167qk_ucis_state_t qk_ucis_state;
168
169void qk_ucis_start(void) {
170 qk_ucis_state.count = 0;
171 qk_ucis_state.in_progress = true;
172
173 qk_ucis_start_user();
174}
175
176__attribute__((weak))
177void qk_ucis_start_user(void) {
178 unicode_input_start();
179 register_hex(0x2328);
180 unicode_input_finish();
181}
182
183static bool is_uni_seq(char *seq) {
184 uint8_t i;
185
186 for (i = 0; seq[i]; i++) {
187 uint16_t code;
188 if (('1' <= seq[i]) && (seq[i] <= '0'))
189 code = seq[i] - '1' + KC_1;
190 else
191 code = seq[i] - 'a' + KC_A;
192
193 if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code)
194 return false;
195 }
196
197 return (qk_ucis_state.codes[i] == KC_ENT ||
198 qk_ucis_state.codes[i] == KC_SPC);
199}
200
201__attribute__((weak))
202void qk_ucis_symbol_fallback (void) {
203 for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
204 uint8_t code = qk_ucis_state.codes[i];
205 register_code(code);
206 unregister_code(code);
207 wait_ms(UNICODE_TYPE_DELAY);
208 }
209}
210
211void register_ucis(const char *hex) {
212 for(int i = 0; hex[i]; i++) {
213 uint8_t kc = 0;
214 char c = hex[i];
215
216 switch (c) {
217 case '0':
218 kc = KC_0;
219 break;
220 case '1' ... '9':
221 kc = c - '1' + KC_1;
222 break;
223 case 'a' ... 'f':
224 kc = c - 'a' + KC_A;
225 break;
226 case 'A' ... 'F':
227 kc = c - 'A' + KC_A;
228 break;
229 }
230
231 if (kc) {
232 register_code (kc);
233 unregister_code (kc);
234 wait_ms (UNICODE_TYPE_DELAY);
235 }
236 }
237}
238
239bool process_ucis (uint16_t keycode, keyrecord_t *record) {
240 uint8_t i;
241
242 if (!qk_ucis_state.in_progress)
243 return true;
244
245 if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH &&
246 !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
247 return false;
248 }
249
250 if (!record->event.pressed)
251 return true;
252
253 qk_ucis_state.codes[qk_ucis_state.count] = keycode;
254 qk_ucis_state.count++;
255
256 if (keycode == KC_BSPC) {
257 if (qk_ucis_state.count >= 2) {
258 qk_ucis_state.count -= 2;
259 return true;
260 } else {
261 qk_ucis_state.count--;
262 return false;
263 }
264 }
265
266 if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
267 bool symbol_found = false;
268
269 for (i = qk_ucis_state.count; i > 0; i--) {
270 register_code (KC_BSPC);
271 unregister_code (KC_BSPC);
272 wait_ms(UNICODE_TYPE_DELAY);
273 }
274
275 if (keycode == KC_ESC) {
276 qk_ucis_state.in_progress = false;
277 return false;
278 }
279
280 unicode_input_start();
281 for (i = 0; ucis_symbol_table[i].symbol; i++) {
282 if (is_uni_seq (ucis_symbol_table[i].symbol)) {
283 symbol_found = true;
284 register_ucis(ucis_symbol_table[i].code + 2);
285 break;
286 }
287 }
288 if (!symbol_found) {
289 qk_ucis_symbol_fallback();
290 }
291 unicode_input_finish();
292
293 qk_ucis_state.in_progress = false;
294 return false;
295 }
296 return true;
297}
298#endif
diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h
index f17cfa6cf..7ed9e54d5 100644
--- a/quantum/process_keycode/process_unicode.h
+++ b/quantum/process_keycode/process_unicode.h
@@ -21,42 +21,6 @@ void register_hex(uint16_t hex);
21 21
22bool process_unicode(uint16_t keycode, keyrecord_t *record); 22bool process_unicode(uint16_t keycode, keyrecord_t *record);
23 23
24#ifdef UNICODEMAP_ENABLE
25void unicode_map_input_error(void);
26bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
27#endif
28
29#ifdef UCIS_ENABLE
30#ifndef UCIS_MAX_SYMBOL_LENGTH
31#define UCIS_MAX_SYMBOL_LENGTH 32
32#endif
33
34typedef struct {
35 char *symbol;
36 char *code;
37} qk_ucis_symbol_t;
38
39typedef struct {
40 uint8_t count;
41 uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
42 bool in_progress:1;
43} qk_ucis_state_t;
44
45extern qk_ucis_state_t qk_ucis_state;
46
47#define UCIS_TABLE(...) {__VA_ARGS__, {NULL, NULL}}
48#define UCIS_SYM(name, code) {name, #code}
49
50extern const qk_ucis_symbol_t ucis_symbol_table[];
51
52void qk_ucis_start(void);
53void qk_ucis_start_user(void);
54void qk_ucis_symbol_fallback (void);
55void register_ucis(const char *hex);
56bool process_ucis (uint16_t keycode, keyrecord_t *record);
57
58#endif
59
60#define UC_BSPC UC(0x0008) 24#define UC_BSPC UC(0x0008)
61 25
62#define UC_SPC UC(0x0020) 26#define UC_SPC UC(0x0020)
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c
new file mode 100644
index 000000000..b8cdeaa97
--- /dev/null
+++ b/quantum/process_keycode/process_unicodemap.c
@@ -0,0 +1,54 @@
1#include "process_unicode_map.h"
2
3__attribute__((weak))
4const uint32_t PROGMEM unicode_map[] = {
5};
6
7void register_hex32(uint32_t hex) {
8 uint8_t onzerostart = 1;
9 for(int i = 7; i >= 0; i--) {
10 if (i <= 3) {
11 onzerostart = 0;
12 }
13 uint8_t digit = ((hex >> (i*4)) & 0xF);
14 if (digit == 0) {
15 if (onzerostart == 0) {
16 register_code(hex_to_keycode(digit));
17 unregister_code(hex_to_keycode(digit));
18 }
19 } else {
20 register_code(hex_to_keycode(digit));
21 unregister_code(hex_to_keycode(digit));
22 onzerostart = 0;
23 }
24 }
25}
26
27__attribute__((weak))
28void unicode_map_input_error() {}
29
30bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
31 if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
32 const uint32_t* map = unicode_map;
33 uint16_t index = keycode - QK_UNICODE_MAP;
34 uint32_t code = pgm_read_dword_far(&map[index]);
35 if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
36 // Convert to UTF-16 surrogate pair
37 code -= 0x10000;
38 uint32_t lo = code & 0x3ff;
39 uint32_t hi = (code & 0xffc00) >> 10;
40 unicode_input_start();
41 register_hex32(hi + 0xd800);
42 register_hex32(lo + 0xdc00);
43 unicode_input_finish();
44 } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
45 // when character is out of range supported by the OS
46 unicode_map_input_error();
47 } else {
48 unicode_input_start();
49 register_hex32(code);
50 unicode_input_finish();
51 }
52 }
53 return true;
54} \ No newline at end of file
diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h
new file mode 100644
index 000000000..291bd8de0
--- /dev/null
+++ b/quantum/process_keycode/process_unicodemap.h
@@ -0,0 +1,8 @@
1#ifndef PROCESS_UNICODEMAP_H
2#define PROCESS_UNICODEMAP_H
3
4#include "quantum.h"
5
6void unicode_map_input_error(void);
7bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
8#endif \ No newline at end of file
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 2088c10c9..4a6d0355f 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -972,6 +972,19 @@ void send_nibble(uint8_t number) {
972 } 972 }
973} 973}
974 974
975
976__attribute__((weak))
977uint16_t hex_to_keycode(uint8_t hex)
978{
979 if (hex == 0x0) {
980 return KC_0;
981 } else if (hex < 0xA) {
982 return KC_1 + (hex - 0x1);
983 } else {
984 return KC_A + (hex - 0xA);
985 }
986}
987
975void api_send_unicode(uint32_t unicode) { 988void api_send_unicode(uint32_t unicode) {
976#ifdef API_ENABLE 989#ifdef API_ENABLE
977 uint8_t chunk[4]; 990 uint8_t chunk[4];
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 18f072189..580d51202 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -56,6 +56,14 @@ extern uint32_t default_layer_state;
56 #include "process_unicode.h" 56 #include "process_unicode.h"
57#endif 57#endif
58 58
59#ifdef UCIS_ENABLE
60 #include "process_ucis.h"
61#endif
62
63#ifdef UNICODEMAP_ENABLE
64 #include "process_unicodemap.h"
65#endif
66
59#include "process_tap_dance.h" 67#include "process_tap_dance.h"
60 68
61#ifdef PRINTING_ENABLE 69#ifdef PRINTING_ENABLE
@@ -117,7 +125,7 @@ void send_dword(uint32_t number);
117void send_word(uint16_t number); 125void send_word(uint16_t number);
118void send_byte(uint8_t number); 126void send_byte(uint8_t number);
119void send_nibble(uint8_t number); 127void send_nibble(uint8_t number);
120 128uint16_t hex_to_keycode(uint8_t hex);
121 129
122void led_set_user(uint8_t usb_led); 130void led_set_user(uint8_t usb_led);
123void led_set_kb(uint8_t usb_led); 131void led_set_kb(uint8_t usb_led);