From e696e4c152816e661fb6ea7c1c9a6affe410055f Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 24 Jan 2016 21:05:03 -0500 Subject: unicode working --- keyboard/planck/keymaps/lock/keymap.c | 23 ++++++++-------- quantum/keymap_common.c | 30 ++++++++++++++------- quantum/keymap_common.h | 28 ++++++++++---------- quantum/keymap_unicode.c | 49 +++++++++++++++++++---------------- tmk_core/common.mk | 4 +++ tmk_core/common/action.c | 10 +++---- 6 files changed, 82 insertions(+), 62 deletions(-) diff --git a/keyboard/planck/keymaps/lock/keymap.c b/keyboard/planck/keymaps/lock/keymap.c index cad5fc37e3..93cfe7ad48 100644 --- a/keyboard/planck/keymaps/lock/keymap.c +++ b/keyboard/planck/keymaps/lock/keymap.c @@ -9,6 +9,9 @@ #include "audio.h" #include #include +#ifdef UNICODE_ENABLE + #include "keymap_unicode.h" +#endif const uint32_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = { /* Qwerty */ @@ -19,20 +22,20 @@ const uint32_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // Space is repeated to accommadate for both spacebar wiring positions }, [1] = { /* Colemak */ - {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, - {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT}, - {KC_FN3, KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + {KC_TAB, UC_q, UC_w, UC_f, UC_p, UC_g, UC_j, UC_l, UC_u, UC_y, UC_SCLN, UC_BSPC}, + {KC_ESC, UC_a, UC_r, UC_s, UC_t, UC_d, UC_h, UC_n, UC_e, UC_i, UC_o, UC_QUOT}, + {KC_LSFT, UC_z, UC_x, UC_c, UC_v, UC_b, UC_k, UC_m, UC_COMM, UC_DOT, UC_SLSH, KC_ENT}, + {KC_TRNS, KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} }, [2] = { /* RAISE */ {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_TRNS, FUNC(3), FUNC(4), RESET, UC(0x1028), KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, + {KC_TRNS, FUNC(3), FUNC(4), RESET, UC(0xD83C), UC(0xDF83), KC_TRNS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, {KC_TRNS, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS}, {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(1), KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} }, [3] = { /* LOWER */ {S(KC_GRV), S(KC_1), S(KC_2), S(KC_3), S(KC_4), S(KC_5), S(KC_6), S(KC_7), S(KC_8), S(KC_9), S(KC_0), KC_BSPC}, - {KC_TRNS, FUNC(3), FUNC(4), RESET, UC(0x1028), KC_TRNS, KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)}, + {KC_TRNS, FUNC(3), FUNC(4), RESET, UC(0xD83C), UC(0xDF83), KC_TRNS, S(KC_MINS), S(KC_EQL), S(KC_LBRC), S(KC_RBRC), S(KC_BSLS)}, {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS}, {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FUNC(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} } @@ -82,9 +85,8 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef BACKLIGHT_ENABLE backlight_set(BACKLIGHT_LEVELS); #endif - debug_enable = true; - // default_layer_and(0); - // default_layer_or((1<<1)); + // debug_enable = true; + layer_state |= (1<<1); // uint8_t low = boot_lock_fuse_bits_get(0x0000); // uint8_t high = boot_lock_fuse_bits_get(0x0003); @@ -121,8 +123,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) #ifdef BACKLIGHT_ENABLE backlight_set(0); #endif - // default_layer_and(0); - // default_layer_or(0); + layer_state &= ~(1<<1); } break; } diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 94588ef41c..05e0831f02 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -25,17 +25,28 @@ along with this program. If not, see . #include "debug.h" #include "backlight.h" #include "keymap_midi.h" +#include +#include +#ifdef AUDIO_ENABLE + #include "audio.h" + + float goodbye[][2] = { + {440.0*pow(2.0,(67)/12.0), 400}, + {0, 50}, + {440.0*pow(2.0,(60)/12.0), 400}, + {0, 50}, + {440.0*pow(2.0,(55)/12.0), 600}, + }; +#endif static action_t keycode_to_action(uint32_t keycode); /* converts key to action */ action_t action_for_key(uint8_t layer, keypos_t key) { - // 16bit keycodes - important + // 32bit keycodes - important uint32_t keycode = keymap_key_to_keycode(layer, key); - dprintln(); - dprintf("keycode: %16X", keycode); - dprintln(); + if (keycode >= 0x0100 && keycode < 0x2000) { // Has a modifier action_t action; @@ -49,7 +60,7 @@ action_t action_for_key(uint8_t layer, keypos_t key) } else if (keycode >= 0x3000 && keycode < 0x4000) { // When the code starts with 3, it's an action macro. action_t action; - action.code = ACTION_MACRO(keycode & 0xFF); + action.code = (0xC000 | (keycode & 0xFF)); return action; #ifdef BACKLIGHT_ENABLE } else if (keycode >= BL_0 & keycode <= BL_15) { @@ -73,13 +84,15 @@ action_t action_for_key(uint8_t layer, keypos_t key) action.code = ACTION_BACKLIGHT_STEP(); return action; #endif - } else if (keycode == RESET) { // RESET is 0x5000, which is why this is here + } else if (keycode == RESET) { // RESET is 0x5000 clear_keyboard(); + #ifdef AUDIO_ENABLE + play_notes(&goodbye, 5, false); + #endif _delay_ms(250); bootloader_jump(); return; } else if (keycode == DEBUG) { // DEBUG is 0x5001 - // TODO: Does this actually work? print("\nDEBUG: enabled.\n"); debug_enable = true; return; @@ -128,10 +141,9 @@ action_t action_for_key(uint8_t layer, keypos_t key) action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); return action; #ifdef UNICODE_ENABLE - } else if (keycode >= 0x9000) { + } else if (keycode >= 0x0000FFFF) { action_t action; action.code = keycode; - action.custom.kind = 0x8; return action; #endif } else { diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 396fead332..396230d88b 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -62,18 +62,18 @@ extern const uint32_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; extern const uint16_t fn_actions[]; // Ability to use mods in layouts -#define LCTL(kc) kc | 0x0100 -#define LSFT(kc) kc | 0x0200 -#define LALT(kc) kc | 0x0400 -#define LGUI(kc) kc | 0x0800 -#define HYPR(kc) kc | 0x0F00 -#define MEH(kc) kc | 0x0700 -#define LCAG(kc) kc | 0x0D00 // Modifier Ctrl Alt and GUI - -#define RCTL(kc) kc | 0x1100 -#define RSFT(kc) kc | 0x1200 -#define RALT(kc) kc | 0x1400 -#define RGUI(kc) kc | 0x1800 +#define LCTL(kc) (kc | 0x0100) +#define LSFT(kc) (kc | 0x0200) +#define LALT(kc) (kc | 0x0400) +#define LGUI(kc) (kc | 0x0800) +#define HYPR(kc) (kc | 0x0F00) +#define MEH(kc) (kc | 0x0700) +#define LCAG(kc) (kc | 0x0D00) // Modifier Ctrl Alt and GUI + +#define RCTL(kc) (kc | 0x1100) +#define RSFT(kc) (kc | 0x1200) +#define RALT(kc) (kc | 0x1400) +#define RGUI(kc) (kc | 0x1800) // Aliases for shifted symbols // Each key has a 4-letter code, and some have longer aliases too. @@ -129,13 +129,13 @@ extern const uint16_t fn_actions[]; #define KC_DELT KC_DELETE // Del key (four letter code) // Alias for function layers than expand past FN31 -#define FUNC(kc) kc | 0x2000 +#define FUNC(kc) (kc | 0x2000) // Aliases #define S(kc) LSFT(kc) #define F(kc) FUNC(kc) -#define M(kc) kc | 0x3000 +#define M(kc) (kc | 0x00003000) #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c index 3a480878b7..cda167d2c1 100644 --- a/quantum/keymap_unicode.c +++ b/quantum/keymap_unicode.c @@ -16,6 +16,9 @@ along with this program. If not, see . */ #include "keymap_common.h" +#include + +#define UNICODE_OSX /* Mac with Unicode Hex Input */ uint16_t hextokeycode(int hex) { if (hex == 0x0) { @@ -29,33 +32,33 @@ uint16_t hextokeycode(int hex) { void action_custom(keyrecord_t *record, uint32_t code) { - // 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) { + #ifdef UNICODE_OSX + register_code(KC_LALT); + #endif + uint32_t unicode = code; - // 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); + bool leading_zero = false; + for(int i = 6; i >= 0; i--) { + uint8_t digit = ((unicode >> (int)(i*4)) & 0xF); + if (digit > 0 || leading_zero || (i < 4)) { + leading_zero = true; + register_code(hextokeycode(digit)); + unregister_code(hextokeycode(digit)); + if (i == 4) { + register_code(KC_LSFT); + register_code(KC_EQL); + unregister_code(KC_EQL); + unregister_code(KC_LSFT); + } + } + } + + #ifdef UNICODE_OSX + unregister_code(KC_LALT); + #endif } return; } \ No newline at end of file diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 89c366f554..99e7bbf858 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -57,6 +57,10 @@ ifdef AUDIO_ENABLE OPT_DEFS += -DAUDIO_ENABLE endif +ifdef UNICODE_ENABLE + OPT_DEFS += -DUNICODE_ENABLE +endif + ifdef USB_6KRO_ENABLE OPT_DEFS += -DUSB_6KRO_ENABLE endif diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index 7a47100a54..893e4db9c4 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -70,11 +70,11 @@ void process_action(keyrecord_t *record) #endif dprintln(); - // if (action.code >= 0x80000000) { - // action_custom(record, action.custom.id); - // return; - // } - dprintf("%X", action.custom.kind); + // 28bit custom action + if (action.custom.kind == 0x8) { + action_custom(record, action.custom.id); + return; + } switch (action.kind.id) { /* Key and Mods */ -- cgit v1.2.3