summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-05-19 05:47:16 +0200
committerJack Humbert <jack.humb@gmail.com>2016-05-19 05:47:16 +0200
commitb732b79b49b098dba8e14493c745075f336747d8 (patch)
tree069f529df73ba8bfbcf7003f5ddd3987ecaadc57 /quantum
parentbf545061f2a71b054ccdca6f6261bb7c2ffa4957 (diff)
downloadqmk_firmware-b732b79b49b098dba8e14493c745075f336747d8.tar.gz
qmk_firmware-b732b79b49b098dba8e14493c745075f336747d8.tar.xz
adapts unicode to quantum.c (#333)
* Unicode to have unicode input you need to: - set your OS input method to UNICODE if needed - enable unicode in your makefile - copy the action_function from keyboard/planck/keymaps/unicode/unicode.c to your keymap.c set the target OS method in your keymap.c: void matrix_init_user() { set_unicode_mode(UC_OSX); } you can then switch when you want with: set_unicode_mode(UC_OSX); set_unicode_mode(UC_LNX); set_unicode_mode(UC_WIN); put some unicode codes in your keymap like so: UC(0x0061) I did change the bit mask in quantum/keymap_common.c and .h I’m afraid we will need uint32 to get a total support for all unicode tables or relocate the handler as @mbarkhau did. * rearranges keycode values, hooks-up unicode * removes extra lalt ref * adds unicode shortcuts and example
Diffstat (limited to 'quantum')
-rw-r--r--quantum/keymap_common.c26
-rw-r--r--quantum/keymap_common.h76
-rw-r--r--quantum/keymap_unicode.c61
-rw-r--r--quantum/quantum.c79
-rw-r--r--quantum/quantum.h44
-rw-r--r--quantum/quantum.mk4
-rw-r--r--quantum/unicode.h128
7 files changed, 278 insertions, 140 deletions
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 2aae13e67..1d9ab2e05 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -31,7 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "keymap_midi.h"
#endif
-
extern keymap_config_t keymap_config;
#include <stdio.h>
@@ -154,20 +153,22 @@ static action_t keycode_to_action(uint16_t keycode)
case KC_TRNS:
action.code = ACTION_TRANSPARENT;
break;
- case 0x0100 ... 0x1FFF: ;
+ case LCTL(0) ... 0x1FFF: ;
// Has a modifier
// Split it up
action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
break;
- case 0x2000 ... 0x2FFF:
+ case FUNC(0) ... FUNC(0xFFF): ;
// Is a shortcut for function layer, pull last 12bits
// This means we have 4,096 FN macros at our disposal
return keymap_func_to_action(keycode & 0xFFF);
break;
- case 0x3000 ... 0x3FFF: ;
- // When the code starts with 3, it's an action macro.
+ case M(0) ... M(0xFF):
action.code = ACTION_MACRO(keycode & 0xFF);
break;
+ case LT(0, 0) ... LT(0xFF, 0xF):
+ action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
+ break;
#ifdef BACKLIGHT_ENABLE
case BL_0 ... BL_15:
action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
@@ -201,7 +202,7 @@ static action_t keycode_to_action(uint16_t keycode)
print("\nDEBUG: enabled.\n");
debug_enable = true;
break;
- case 0x5002 ... 0x50FF:
+ case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
// MAGIC actions (BOOTMAGIC without the boot)
if (!eeconfig_is_enabled()) {
eeconfig_init();
@@ -251,7 +252,7 @@ static action_t keycode_to_action(uint16_t keycode)
}
eeconfig_update_keymap(keymap_config.raw);
break;
- case 0x5100 ... 0x56FF: ;
+ case TO(0, 1) ... OSM(0xFF): ;
// Layer movement shortcuts
// See .h to see constraints/usage
int type = (keycode >> 0x8) & 0xF;
@@ -282,18 +283,9 @@ static action_t keycode_to_action(uint16_t keycode)
action.code = ACTION_MODS_ONESHOT(mod);
}
break;
- case 0x7000 ... 0x7FFF:
+ case MT(0, 0) ... MT(0xF, 0xFF):
action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
break;
- case 0x8000 ... 0x8FFF:
- action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
- break;
- #ifdef UNICODE_ENABLE
- case 0x8000000 ... 0x8FFFFFF:
- uint16_t unicode = keycode & ~(0x8000);
- action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
- break;
- #endif
default:
action.code = ACTION_NO;
break;
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 1cbe8c61c..91d5c09c1 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -163,38 +163,13 @@ extern const uint16_t fn_actions[];
#define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
-// These affect the backlight (if your keyboard has one).
-// We don't need to comment them out if your keyboard doesn't have a backlight,
-// since they don't take up any space.
-#define BL_ON 0x4009
-#define BL_OFF 0x4000
-#define BL_0 0x4000
-#define BL_1 0x4001
-#define BL_2 0x4002
-#define BL_3 0x4003
-#define BL_4 0x4004
-#define BL_5 0x4005
-#define BL_6 0x4006
-#define BL_7 0x4007
-#define BL_8 0x4008
-#define BL_9 0x4009
-#define BL_10 0x400A
-#define BL_11 0x400B
-#define BL_12 0x400C
-#define BL_13 0x400D
-#define BL_14 0x400E
-#define BL_15 0x400F
-#define BL_DEC 0x4010
-#define BL_INC 0x4011
-#define BL_TOGG 0x4012
-#define BL_STEP 0x4013
+// 0x3100+ is free
+
+// L-ayer, T-ap - 256 keycode max, 16 layer max
+#define LT(layer, kc) (kc | 0x4000 | ((layer & 0xF) << 8))
#define RESET 0x5000
#define DEBUG 0x5001
-#define KC_LEAD 0x5014
-
-
-
// MAGIC keycodes
#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
@@ -239,6 +214,32 @@ extern const uint16_t fn_actions[];
#define MI_ON 0x5028
#define MI_OFF 0x5029
+// These affect the backlight (if your keyboard has one).
+// We don't need to comment them out if your keyboard doesn't have a backlight,
+// since they don't take up any space.
+#define BL_ON 0x5079
+#define BL_OFF 0x5070
+#define BL_0 0x5070
+#define BL_1 0x5071
+#define BL_2 0x5072
+#define BL_3 0x5073
+#define BL_4 0x5074
+#define BL_5 0x5075
+#define BL_6 0x5076
+#define BL_7 0x5077
+#define BL_8 0x5078
+#define BL_9 0x5079
+#define BL_10 0x507A
+#define BL_11 0x507B
+#define BL_12 0x507C
+#define BL_13 0x507D
+#define BL_14 0x507E
+#define BL_15 0x507F
+#define BL_DEC 0x5080
+#define BL_INC 0x5081
+#define BL_TOGG 0x5082
+#define BL_STEP 0x5083
+
// GOTO layer - 16 layers max
// when:
// ON_PRESS = 1
@@ -261,6 +262,8 @@ extern const uint16_t fn_actions[];
// One-shot mod
#define OSM(layer) (layer | 0x5600)
+// chording is currently at 0x57xx
+
// M-od, T-ap - 256 keycode max
#define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
#define CTL_T(kc) MT(0x1, kc)
@@ -276,14 +279,13 @@ extern const uint16_t fn_actions[];
#define KC_HYPR HYPR(KC_NO)
#define KC_MEH MEH(KC_NO)
-// L-ayer, T-ap - 256 keycode max, 16 layer max
-#define LT(layer, kc) (kc | 0x8000 | ((layer & 0xF) << 8))
-
-// For sending unicode codes.
-// You may not send codes over 1FFF -- this supports most of UTF8.
-// To have a key that sends out Œ, go UC(0x0152)
-#define UNICODE(n) (n | 0x8000)
-#define UC(n) UNICODE(n)
+#ifdef UNICODE_ENABLE
+ // For sending unicode codes.
+ // You may not send codes over 7FFF -- this supports most of UTF8.
+ // To have a key that sends out Œ, go UC(0x0152)
+ #define UNICODE(n) (n | 0x8000)
+ #define UC(n) UNICODE(n)
+#endif
// For tri-layer
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c
deleted file mode 100644
index a44965e61..000000000
--- a/quantum/keymap_unicode.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-Copyright 2015 Jack Humbert <jack.humb@gmail.com>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "keymap_common.h"
-
-uint16_t hextokeycode(int hex) {
- if (hex == 0x0) {
- return KC_0;
- } else if (hex < 0xA) {
- return KC_1 + (hex - 0x1);
- } else {
- return KC_A + (hex - 0xA);
- }
-}
-
-void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-
- // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input
-
- if (record->event.pressed) {
- uint16_t unicode = (opt << 8) | id;
- register_code(KC_LALT);
-
- register_code(hextokeycode((unicode & 0xF000) >> 12));
- unregister_code(hextokeycode((unicode & 0xF000) >> 12));
- register_code(hextokeycode((unicode & 0x0F00) >> 8));
- unregister_code(hextokeycode((unicode & 0x0F00) >> 8));
- register_code(hextokeycode((unicode & 0x00F0) >> 4));
- unregister_code(hextokeycode((unicode & 0x00F0) >> 4));
- register_code(hextokeycode((unicode & 0x000F)));
- unregister_code(hextokeycode((unicode & 0x000F)));
-
- /* Test 'a' */
- // register_code(hextokeycode(0x0));
- // unregister_code(hextokeycode(0x0));
- // register_code(hextokeycode(0x0));
- // unregister_code(hextokeycode(0x0));
- // register_code(hextokeycode(0x6));
- // unregister_code(hextokeycode(0x6));
- // register_code(hextokeycode(0x1));
- // unregister_code(hextokeycode(0x1));
-
- unregister_code(KC_LALT);
- }
- return;
-} \ No newline at end of file
diff --git a/quantum/quantum.c b/quantum/quantum.c
index e4d7b9185..1e91ac04a 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -23,6 +23,18 @@ int offset = 7;
#ifdef AUDIO_ENABLE
bool music_activated = false;
+ float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
+
+ // music sequencer
+ static bool music_sequence_recording = false;
+ static bool music_sequence_playing = false;
+ static float music_sequence[16] = {0};
+ static uint8_t music_sequence_count = 0;
+ static uint8_t music_sequence_position = 0;
+
+ static uint16_t music_sequence_timer = 0;
+ static uint16_t music_sequence_interval = 100;
+
#endif
#ifdef MIDI_ENABLE
@@ -44,6 +56,10 @@ uint8_t chord_keys[CHORDING_MAX] = {0};
uint8_t chord_key_count = 0;
uint8_t chord_key_down = 0;
+#ifdef UNICODE_ENABLE
+ static uint8_t input_mode;
+#endif
+
bool keys_chord(uint8_t keys[]) {
uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
bool pass = true;
@@ -66,14 +82,25 @@ bool keys_chord(uint8_t keys[]) {
return (pass && (in == keys_size));
}
-static bool music_sequence_recording = false;
-static bool music_sequence_playing = false;
-static float music_sequence[16] = {0};
-static uint8_t music_sequence_count = 0;
-static uint8_t music_sequence_position = 0;
+#ifdef UNICODE_ENABLE
+
+uint16_t hex_to_keycode(uint8_t hex)
+{
+ if (hex == 0x0) {
+ return KC_0;
+ } else if (hex < 0xA) {
+ return KC_1 + (hex - 0x1);
+ } else {
+ return KC_A + (hex - 0xA);
+ }
+}
+
+void set_unicode_mode(uint8_t os_target)
+{
+ input_mode = os_target;
+}
-static uint16_t music_sequence_timer = 0;
-static uint16_t music_sequence_interval = 100;
+#endif
bool process_record_quantum(keyrecord_t *record) {
@@ -347,6 +374,44 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
+#ifdef UNICODE_ENABLE
+
+ if (keycode > UNICODE(0) && record->event.pressed) {
+ uint16_t unicode = keycode & 0x7FFF;
+ switch(input_mode) {
+ case UC_OSX:
+ register_code(KC_LALT);
+ break;
+ case UC_LNX:
+ register_code(KC_LCTL);
+ register_code(KC_LSFT);
+ register_code(KC_U);
+ unregister_code(KC_U);
+ break;
+ case UC_WIN:
+ register_code(KC_LALT);
+ register_code(KC_PPLS);
+ unregister_code(KC_PPLS);
+ break;
+ }
+ for(int i = 3; i >= 0; i--) {
+ uint8_t digit = ((unicode >> (i*4)) & 0xF);
+ register_code(hex_to_keycode(digit));
+ unregister_code(hex_to_keycode(digit));
+ }
+ switch(input_mode) {
+ case UC_OSX:
+ case UC_WIN:
+ unregister_code(KC_LALT);
+ break;
+ case UC_LNX:
+ unregister_code(KC_LCTL);
+ unregister_code(KC_LSFT);
+ break;
+ }
+ }
+
+#endif
return process_action_kb(record);
}
diff --git a/quantum/quantum.h b/quantum/quantum.h
index f4d8f09d4..d4da77289 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -13,9 +13,12 @@
#include "audio.h"
#endif
#ifdef MIDI_ENABLE
- // #include <keymap_midi.h>
#include <lufa.h>
#endif
+#ifdef UNICODE_ENABLE
+ #include "unicode.h"
+#endif
+
#include "action_layer.h"
#include "eeconfig.h"
#include <stddef.h>
@@ -27,24 +30,37 @@ extern uint32_t default_layer_state;
extern uint32_t layer_state;
#endif
-bool music_activated;
+#ifdef AUDIO_ENABLE
+ bool music_activated;
+#endif
-void matrix_init_kb(void);
-void matrix_scan_kb(void);
-bool process_action_kb(keyrecord_t *record);
+#ifdef UNICODE_ENABLE
+ #define UC_OSX 0
+ #define UC_LNX 1
+ #define UC_WIN 2
+ #define UC_BSD 3
-void leader_start(void);
-void leader_end(void);
+ void set_unicode_input_mode(uint8_t os_target);
+#endif
+
+#ifndef DISABLE_LEADER
+ void leader_start(void);
+ void leader_end(void);
+
+ #ifndef LEADER_TIMEOUT
+ #define LEADER_TIMEOUT 200
+ #endif
+ #define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0)
+ #define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0)
+ #define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3))
-#ifndef LEADER_TIMEOUT
- #define LEADER_TIMEOUT 200
+ #define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size
+ #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
#endif
-#define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0)
-#define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0)
-#define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3))
-#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size
-#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
+void matrix_init_kb(void);
+void matrix_scan_kb(void);
+bool process_action_kb(keyrecord_t *record);
bool is_music_on(void);
void music_toggle(void);
diff --git a/quantum/quantum.mk b/quantum/quantum.mk
index e7ccfd659..c099d6793 100644
--- a/quantum/quantum.mk
+++ b/quantum/quantum.mk
@@ -34,10 +34,6 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/audio/luts.c
endif
-ifeq ($(strip $(UNICODE_ENABLE)), yes)
- SRC += $(QUANTUM_DIR)/keymap_unicode.c
-endif
-
ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/light_ws2812.c
SRC += $(QUANTUM_DIR)/rgblight.c
diff --git a/quantum/unicode.h b/quantum/unicode.h
new file mode 100644
index 000000000..756ec8bc3
--- /dev/null
+++ b/quantum/unicode.h
@@ -0,0 +1,128 @@
+/*
+Copyright 2016 Jack Humbert <jack.humb@gmail.com>
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef UNICODE_H
+#define UNICODE_H
+
+#include "quantum.h"
+#include <math.h>
+
+#define UC_BSPC UC(0x0008)
+
+#define UC_SPC UC(0x0020)
+
+#define UC_EXLM UC(0x0021)
+#define UC_DQUT UC(0x0022)
+#define UC_HASH UC(0x0023)
+#define UC_DLR UC(0x0024)
+#define UC_PERC UC(0x0025)
+#define UC_AMPR UC(0x0026)
+#define UC_QUOT UC(0x0027)
+#define UC_LPRN UC(0x0028)
+#define UC_RPRN UC(0x0029)
+#define UC_ASTR UC(0x002A)
+#define UC_PLUS UC(0x002B)
+#define UC_COMM UC(0x002C)
+#define UC_DASH UC(0x002D)
+#define UC_DOT UC(0x002E)
+#define UC_SLSH UC(0x002F)
+
+#define UC_0 UC(0x0030)
+#define UC_1 UC(0x0031)
+#define UC_2 UC(0x0032)
+#define UC_3 UC(0x0033)
+#define UC_4 UC(0x0034)
+#define UC_5 UC(0x0035)
+#define UC_6 UC(0x0036)
+#define UC_7 UC(0x0037)
+#define UC_8 UC(0x0038)
+#define UC_9 UC(0x0039)
+
+#define UC_COLN UC(0x003A)
+#define UC_SCLN UC(0x003B)
+#define UC_LT UC(0x003C)
+#define UC_EQL UC(0x003D)
+#define UC_GT UC(0x003E)
+#define UC_QUES UC(0x003F)
+#define UC_AT UC(0x0040)
+
+#define UC_A UC(0x0041)
+#define UC_B UC(0x0042)
+#define UC_C UC(0x0043)
+#define UC_D UC(0x0044)
+#define UC_E UC(0x0045)
+#define UC_F UC(0x0046)
+#define UC_G UC(0x0047)
+#define UC_H UC(0x0048)
+#define UC_I UC(0x0049)
+#define UC_J UC(0x004A)
+#define UC_K UC(0x004B)
+#define UC_L UC(0x004C)
+#define UC_M UC(0x004D)
+#define UC_N UC(0x004E)
+#define UC_O UC(0x004F)
+#define UC_P UC(0x0050)
+#define UC_Q UC(0x0051)
+#define UC_R UC(0x0052)
+#define UC_S UC(0x0053)
+#define UC_T UC(0x0054)
+#define UC_U UC(0x0055)
+#define UC_V UC(0x0056)
+#define UC_W UC(0x0057)
+#define UC_X UC(0x0058)
+#define UC_Y UC(0x0059)
+#define UC_Z UC(0x005A)
+
+#define UC_LBRC UC(0x005B)
+#define UC_BSLS UC(0x005C)
+#define UC_RBRC UC(0x005D)
+#define UC_CIRM UC(0x005E)
+#define UC_UNDR UC(0x005F)
+
+#define UC_GRV UC(0x0060)
+
+#define UC_a UC(0x0061)
+#define UC_b UC(0x0062)
+#define UC_c UC(0x0063)
+#define UC_d UC(0x0064)
+#define UC_e UC(0x0065)
+#define UC_f UC(0x0066)
+#define UC_g UC(0x0067)
+#define UC_h UC(0x0068)
+#define UC_i UC(0x0069)
+#define UC_j UC(0x006A)
+#define UC_k UC(0x006B)
+#define UC_l UC(0x006C)
+#define UC_m UC(0x006D)
+#define UC_n UC(0x006E)
+#define UC_o UC(0x006F)
+#define UC_p UC(0x0070)
+#define UC_q UC(0x0071)
+#define UC_r UC(0x0072)
+#define UC_s UC(0x0073)
+#define UC_t UC(0x0074)
+#define UC_u UC(0x0075)
+#define UC_v UC(0x0076)
+#define UC_w UC(0x0077)
+#define UC_x UC(0x0078)
+#define UC_y UC(0x0079)
+#define UC_z UC(0x007A)
+
+#define UC_LCBR UC(0x007B)
+#define UC_PIPE UC(0x007C)
+#define UC_RCBR UC(0x007D)
+#define UC_TILD UC(0x007E)
+#define UC_DEL UC(0x007F)
+
+#endif \ No newline at end of file