summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2015-10-27 19:10:36 -0400
committerJack Humbert <jack.humb@gmail.com>2015-10-27 19:10:36 -0400
commite98c501a614385132a2e2a61a1242f12bab89969 (patch)
treef1f302d4ea2b6661f503b76782323545691ee87a
parentd311fd8d1a0af3b767d26b520d399bf0db22f058 (diff)
almost there - keymap_key_to_keycode returning 16bits, maybeunicode
-rw-r--r--keyboard/planck/Makefile6
-rw-r--r--keyboard/planck/keymaps/keymap_default.c8
-rw-r--r--quantum/keymap_common.c69
-rw-r--r--quantum/keymap_common.h10
-rw-r--r--quantum/keymap_unicode.c78
-rw-r--r--quantum/quantum.mk7
-rw-r--r--quantum/template/keymaps/keymap_default.c2
-rw-r--r--tmk_core/common.mk9
-rw-r--r--tmk_core/common/action.c4
-rw-r--r--tmk_core/common/action.h3
-rw-r--r--tmk_core/common/action_layer.c8
-rw-r--r--tmk_core/common/action_layer.h2
-rw-r--r--tmk_core/common/action_tapping.c2
-rw-r--r--tmk_core/common/keymap.c2
14 files changed, 126 insertions, 84 deletions
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile
index 77e38ce366..983d8eed26 100644
--- a/keyboard/planck/Makefile
+++ b/keyboard/planck/Makefile
@@ -123,9 +123,9 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
# NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
-MIDI_ENABLE = YES # MIDI controls
-# UNICODE_ENABLE = YES # Unicode
-BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
+# MIDI_ENABLE = YES # MIDI controls
+UNICODE_ENABLE = YES # Unicode support via UC()
+# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
# Optimize size but this may cause error "relocation truncated to fit"
diff --git a/keyboard/planck/keymaps/keymap_default.c b/keyboard/planck/keymaps/keymap_default.c
index 49670dafd3..d9812e6d4c 100644
--- a/keyboard/planck/keymaps/keymap_default.c
+++ b/keyboard/planck/keymaps/keymap_default.c
@@ -14,9 +14,9 @@
#define _LW 3
#define _RS 4
-const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+const KEYCODE_TYPE PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QW] = { /* Qwerty */
- {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
+ {KC_TAB, 0x89999999, 0x8009999, 0x809999, 0x89999, 0x9999, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
{KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
{KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
{M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
@@ -58,7 +58,9 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
case 0:
if (record->event.pressed) {
register_code(KC_RSFT);
- backlight_step();
+ #ifdef BACKLIGHT_ENABLE
+ backlight_step();
+ #endif
} else {
unregister_code(KC_RSFT);
}
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 5c00c0afa2..22e0948626 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -27,11 +27,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static action_t keycode_to_action(uint16_t keycode);
+#ifdef UNICODE_ENABLE
+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);
+ }
+}
+#endif
+
/* converts key to action */
-action_t action_for_key(uint8_t layer, keypos_t key)
+action_t action_for_key(keyrecord_t *record, uint8_t layer, keypos_t key)
{
- // 16bit keycodes - important
- uint16_t keycode = keymap_key_to_keycode(layer, key);
+ KEYCODE_TYPE keycode = keymap_key_to_keycode(layer, key);
if (keycode >= 0x0100 && keycode < 0x2000) {
// Has a modifier
@@ -49,7 +60,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
action.code = ACTION_MACRO(keycode & 0xFF);
return action;
#ifdef BACKLIGHT_ENABLE
- } else if (keycode >= BL_0 & keycode <= BL_15) {
+ } else if (keycode >= BL_0 && keycode <= BL_15) {
action_t action;
action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
return action;
@@ -71,13 +82,14 @@ action_t action_for_key(uint8_t layer, keypos_t key)
return action;
#endif
} else if (keycode == RESET) { // RESET is 0x5000, which is why this is here
+ clear_keyboard();
bootloader_jump();
- return;
+ return keycode_to_action(ACTION_NO);
} else if (keycode == DEBUG) { // DEBUG is 0x5001
// TODO: Does this actually work?
print("\nDEBUG: enabled.\n");
debug_enable = true;
- return;
+ return keycode_to_action(ACTION_NO);
} else if (keycode >= 0x5000 && keycode < 0x6000) {
// Layer movement shortcuts
// See .h to see constraints/usage
@@ -109,11 +121,40 @@ action_t action_for_key(uint8_t layer, keypos_t key)
return action;
#endif
#ifdef UNICODE_ENABLE
- } else if (keycode >= 0x8000) {
- action_t action;
- uint16_t unicode = keycode & ~(0x8000);
- action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
- return action;
+ } else if (keycode >= 0x8000 && record != NULL) {
+ if (record->event.pressed) {
+ uint32_t unicode = (keycode & 0xFFFFFFF);
+ // register_code(KC_LALT);
+
+ register_code(hextokeycode((unicode & 0xF000000) >> 24));
+ unregister_code(hextokeycode((unicode & 0xF000000) >> 24));
+ register_code(hextokeycode((unicode & 0xF00000) >> 20));
+ unregister_code(hextokeycode((unicode & 0xF00000) >> 20));
+ register_code(hextokeycode((unicode & 0xF0000) >> 16));
+ unregister_code(hextokeycode((unicode & 0xF0000) >> 16));
+ register_code(hextokeycode((unicode & 0xF000) >> 12));
+ unregister_code(hextokeycode((unicode & 0xF000) >> 12));
+ register_code(hextokeycode((unicode & 0xF00) >> 8));
+ unregister_code(hextokeycode((unicode & 0xF00) >> 8));
+ register_code(hextokeycode((unicode & 0xF0) >> 4));
+ unregister_code(hextokeycode((unicode & 0xF0) >> 4));
+ register_code(hextokeycode((unicode & 0xF)));
+ unregister_code(hextokeycode((unicode & 0xF)));
+
+ /* 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);
+ // send_keyboard_report();
+ }
+ return keycode_to_action(ACTION_NO);
#endif
} else {
@@ -236,10 +277,10 @@ static action_t keycode_to_action(uint16_t keycode)
/* translates key to keycode */
-uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
+KEYCODE_TYPE keymap_key_to_keycode(uint8_t layer, keypos_t key)
{
- // Read entire word (16bits)
- return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
+ // Read entire word (16bits? hopefully 32)
+ return (pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]) | (pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]-1) << 16));
}
/* translates Fn keycode to action */
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index b1df4eb0f6..bf4d147119 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -48,9 +48,11 @@ typedef union {
keymap_config_t keymap_config;
#endif
+// 32 bit keycodes!!
+typedef uint32_t KEYCODE_TYPE;
/* translates key to keycode */
-uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
+KEYCODE_TYPE keymap_key_to_keycode(uint8_t layer, keypos_t key);
/* translates Fn keycode to action */
action_t keymap_fn_to_action(uint16_t keycode);
@@ -58,7 +60,7 @@ action_t keymap_fn_to_action(uint16_t keycode);
/* translates Fn keycode to action */
action_t keymap_func_to_action(uint16_t keycode);
-extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
+extern const KEYCODE_TYPE keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint16_t fn_actions[];
// Ability to use mods in layouts
@@ -175,9 +177,7 @@ extern const uint16_t fn_actions[];
#define MIDI(n) (n | 0x6000)
// 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 UNICODE(n) (n | 0x80000000)
#define UC(n) UNICODE(n)
diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c
index a9357edec7..7b0bd70416 100644
--- a/quantum/keymap_unicode.c
+++ b/quantum/keymap_unicode.c
@@ -17,43 +17,43 @@ 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)
-{
-
- 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)));
+// 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)
+// {
+
+// 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
+// /* 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.mk b/quantum/quantum.mk
index c82e478725..691e17efde 100644
--- a/quantum/quantum.mk
+++ b/quantum/quantum.mk
@@ -11,10 +11,17 @@ endif
ifdef MIDI_ENABLE
SRC += $(QUANTUM_DIR)/keymap_midi.c \
$(QUANTUM_DIR)/beeps.c
+
+ OPT_DEFS += -DMIDI_ENABLE
endif
ifdef UNICODE_ENABLE
SRC += $(QUANTUM_DIR)/keymap_unicode.c
+ OPT_DEFS += -DUNICODE_ENABLE
+endif
+
+ifdef BLUETOOTH_ENABLE
+ OPT_DEFS += -DBLUETOOTH_ENABLE
endif
# Optimize size but this may cause error "relocation truncated to fit"
diff --git a/quantum/template/keymaps/keymap_default.c b/quantum/template/keymaps/keymap_default.c
index 1e6684da7b..8ebaac8c48 100644
--- a/quantum/template/keymaps/keymap_default.c
+++ b/quantum/template/keymaps/keymap_default.c
@@ -13,7 +13,7 @@
#define _LW 3
#define _RS 4
-const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+const KEYCODE_TYPE PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QW] = { /* Qwerty */
{KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
{KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index edbcc282a5..cb030b3313 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -49,11 +49,6 @@ ifdef NKRO_ENABLE
OPT_DEFS += -DNKRO_ENABLE
endif
-ifdef MIDI_ENABLE
- OPT_DEFS += -DMIDI_ENABLE
-endif
-
-
ifdef USB_6KRO_ENABLE
OPT_DEFS += -DUSB_6KRO_ENABLE
endif
@@ -69,10 +64,6 @@ ifdef BACKLIGHT_ENABLE
OPT_DEFS += -DBACKLIGHT_ENABLE
endif
-ifdef BLUETOOTH_ENABLE
- OPT_DEFS += -DBLUETOOTH_ENABLE
-endif
-
ifdef KEYMAP_SECTION_ENABLE
OPT_DEFS += -DKEYMAP_SECTION_ENABLE
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 1f15bd0918..01692981ea 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -62,7 +62,7 @@ void process_action(keyrecord_t *record)
if (IS_NOEVENT(event)) { return; }
- action_t action = layer_switch_get_action(event.key);
+ action_t action = layer_switch_get_action(record, event.key);
dprint("ACTION: "); debug_action(action);
#ifndef NO_ACTION_LAYER
dprint(" layer_state: "); layer_debug();
@@ -511,7 +511,7 @@ void clear_keyboard_but_mods(void)
bool is_tap_key(keypos_t key)
{
- action_t action = layer_switch_get_action(key);
+ action_t action = layer_switch_get_action(NULL, key);
switch (action.kind.id) {
case ACT_LMODS_TAP:
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index 8a4736d7bc..16a1ed4b3f 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
+#include <stddef.h>
#include "keyboard.h"
#include "keycode.h"
#include "action_code.h"
@@ -50,7 +51,7 @@ typedef struct {
void action_exec(keyevent_t event);
/* action for key */
-action_t action_for_key(uint8_t layer, keypos_t key);
+action_t action_for_key(keyrecord_t *record, uint8_t layer, keypos_t key);
/* macro */
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c
index c535615f44..8dfb35b626 100644
--- a/tmk_core/common/action_layer.c
+++ b/tmk_core/common/action_layer.c
@@ -112,7 +112,7 @@ void layer_debug(void)
-action_t layer_switch_get_action(keypos_t key)
+action_t layer_switch_get_action(keyrecord_t *record, keypos_t key)
{
action_t action;
action.code = ACTION_TRANSPARENT;
@@ -122,17 +122,17 @@ action_t layer_switch_get_action(keypos_t key)
/* check top layer first */
for (int8_t i = 31; i >= 0; i--) {
if (layers & (1UL<<i)) {
- action = action_for_key(i, key);
+ action = action_for_key(record, i, key);
if (action.code != ACTION_TRANSPARENT) {
return action;
}
}
}
/* fall back to layer 0 */
- action = action_for_key(0, key);
+ action = action_for_key(record, 0, key);
return action;
#else
- action = action_for_key(biton32(default_layer_state), key);
+ action = action_for_key(record, biton32(default_layer_state), key);
return action;
#endif
}
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index b6da353cfd..e91d9dca79 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -72,6 +72,6 @@ void layer_xor(uint32_t state);
/* return action depending on current layer status */
-action_t layer_switch_get_action(keypos_t key);
+action_t layer_switch_get_action(keyrecord_t *record, keypos_t key);
#endif
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c
index 826c233096..62b1874d42 100644
--- a/tmk_core/common/action_tapping.c
+++ b/tmk_core/common/action_tapping.c
@@ -116,7 +116,7 @@ bool process_tapping(keyrecord_t *keyp)
*/
else if (IS_RELEASED(event) && !waiting_buffer_typed(event)) {
// Modifier should be retained till end of this tapping.
- action_t action = layer_switch_get_action(event.key);
+ action_t action = layer_switch_get_action(0, event.key);
switch (action.kind.id) {
case ACT_LMODS:
case ACT_RMODS:
diff --git a/tmk_core/common/keymap.c b/tmk_core/common/keymap.c
index 11f4aa8aaa..0631b15ff8 100644
--- a/tmk_core/common/keymap.c
+++ b/tmk_core/common/keymap.c
@@ -29,7 +29,7 @@ static action_t keycode_to_action(uint8_t keycode);
/* converts key to action */
__attribute__ ((weak))
-action_t action_for_key(uint8_t layer, keypos_t key)
+action_t action_for_key(keyrecord_t *record, uint8_t layer, keypos_t key)
{
uint8_t keycode = keymap_key_to_keycode(layer, key);
switch (keycode) {