summaryrefslogtreecommitdiff
path: root/quantum
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 /quantum
parentd311fd8d1a0af3b767d26b520d399bf0db22f058 (diff)
almost there - keymap_key_to_keycode returning 16bits, maybeunicode
Diffstat (limited to 'quantum')
-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
5 files changed, 107 insertions, 59 deletions
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},