Skip to content

Commit

Permalink
Use keyboard config for nkro (qmk#7)
Browse files Browse the repository at this point in the history
* removing nkro references - wip

* changed NKRO to be defined by keymap_config
  • Loading branch information
IBNobody authored Sep 7, 2016
1 parent f0388a5 commit 558f3ec
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 101 deletions.
4 changes: 2 additions & 2 deletions keyboards/planck/keymaps/pvc/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

# Build Options
# change to "no" to disable the options, or define them in the Makefile in
# change to "no" to disable the options, or define them in the Makefile in
# the appropriate keymap folder that will get included automatically
#
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
Expand Down
5 changes: 3 additions & 2 deletions keyboards/planck/keymaps/pvc/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum keyboard_macros {
#define SC_ACLS LALT(KC_F4)
#define SC_CCLS LCTL(KC_F4)

#define TG_NKRO MAGIC_TOGGLE_NKRO
#define OS_SHFT KC_FN0

#define _______ KC_TRNS
Expand Down Expand Up @@ -206,7 +207,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[LAYER_ADJUST] = {
{ XXXXXXX, M_BRTOG, M_BSPDU, M_BSPDD, M_BDFLT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, MU_TOG , AU_TOG },
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
{ XXXXXXX, M_QWRTY, XXXXXXX, XXXXXXX, M_BACKL, RESET , XXXXXXX, M_MOUSE, XXXXXXX, XXXXXXX, MUV_IN , XXXXXXX },
{ XXXXXXX, M_QWRTY, XXXXXXX, XXXXXXX, M_BACKL, RESET , TG_NKRO, M_MOUSE, XXXXXXX, XXXXXXX, MUV_IN , XXXXXXX },
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_UPPER, XXXXXXX, XXXXXXX, M_LOWER, XXXXXXX, TMPO_DN, MUV_DE , TMPO_UP }
},

Expand Down Expand Up @@ -236,7 +237,7 @@ void persistant_default_layer_set(uint16_t default_layer)
}

const uint16_t PROGMEM fn_actions[] = {
[0] = ACTION_MODS_ONESHOT(MOD_LSFT),
[0] = ACTION_MODS_ONESHOT(MOD_RSFT),
};

const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
Expand Down
5 changes: 5 additions & 0 deletions quantum/keycode_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "eeconfig.h"
#include "keycode.h"

#ifndef KEYCODE_CONFIG_H
#define KEYCODE_CONFIG_H

uint16_t keycode_config(uint16_t keycode);

/* NOTE: Not portable. Bit field order depends on implementation */
Expand All @@ -19,3 +22,5 @@ typedef union {
} keymap_config_t;

extern keymap_config_t keymap_config;

#endif /* KEYCODE_CONFIG_H */
1 change: 1 addition & 0 deletions quantum/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ enum quantum_keycodes {
MAGIC_UNSWAP_BACKSLASH_BACKSPACE,
MAGIC_UNHOST_NKRO,
MAGIC_UNSWAP_ALT_GUI,
MAGIC_TOGGLE_NKRO,

// Leader key
#ifndef DISABLE_LEADER
Expand Down
124 changes: 68 additions & 56 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
f(KC_RGUI);
}

#ifdef NKRO_ENABLE
extern bool keyboard_nkro;
#endif

void register_code16 (uint16_t code) {
do_code16 (code, register_code);
register_code (code);
Expand Down Expand Up @@ -203,65 +199,81 @@ bool process_record_quantum(keyrecord_t *record) {
return false;
break;
#endif
case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
if (record->event.pressed) {
// MAGIC actions (BOOTMAGIC without the boot)
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
/* keymap config */
keymap_config.raw = eeconfig_read_keymap();
if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
keymap_config.swap_control_capslock = 1;
} else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
keymap_config.capslock_to_control = 1;
} else if (keycode == MAGIC_SWAP_LALT_LGUI) {
keymap_config.swap_lalt_lgui = 1;
} else if (keycode == MAGIC_SWAP_RALT_RGUI) {
keymap_config.swap_ralt_rgui = 1;
} else if (keycode == MAGIC_NO_GUI) {
keymap_config.no_gui = 1;
} else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
keymap_config.swap_grave_esc = 1;
} else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
keymap_config.swap_backslash_backspace = 1;
} else if (keycode == MAGIC_HOST_NKRO) {
keymap_config.nkro = 1;

#ifdef NKRO_ENABLE
clear_keyboard(); // clear to prevent stuck keys
keyboard_nkro = keymap_config.nkro;
#endif
} else if (keycode == MAGIC_SWAP_ALT_GUI) {
keymap_config.swap_lalt_lgui = 1;
keymap_config.swap_ralt_rgui = 1;
}
/* UNs */
else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
keymap_config.swap_control_capslock = 0;
} else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
keymap_config.capslock_to_control = 0;
} else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
keymap_config.swap_lalt_lgui = 0;
} else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
keymap_config.swap_ralt_rgui = 0;
} else if (keycode == MAGIC_UNNO_GUI) {
keymap_config.no_gui = 0;
} else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
keymap_config.swap_grave_esc = 0;
} else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
keymap_config.swap_backslash_backspace = 0;
} else if (keycode == MAGIC_UNHOST_NKRO) {
keymap_config.nkro = 0;
#ifdef NKRO_ENABLE
clear_keyboard(); // clear to prevent stuck keys
keyboard_nkro = keymap_config.nkro;
#endif
} else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
keymap_config.swap_lalt_lgui = 0;
keymap_config.swap_ralt_rgui = 0;
switch (keycode)
{
case MAGIC_SWAP_CONTROL_CAPSLOCK:
keymap_config.swap_control_capslock = true;
break;
case MAGIC_CAPSLOCK_TO_CONTROL:
keymap_config.capslock_to_control = true;
break;
case MAGIC_SWAP_LALT_LGUI:
keymap_config.swap_lalt_lgui = true;
break;
case MAGIC_SWAP_RALT_RGUI:
keymap_config.swap_ralt_rgui = true;
break;
case MAGIC_NO_GUI:
keymap_config.no_gui = true;
break;
case MAGIC_SWAP_GRAVE_ESC:
keymap_config.swap_grave_esc = true;
break;
case MAGIC_SWAP_BACKSLASH_BACKSPACE:
keymap_config.swap_backslash_backspace = true;
break;
case MAGIC_HOST_NKRO:
keymap_config.nkro = true;
break;
case MAGIC_SWAP_ALT_GUI:
keymap_config.swap_lalt_lgui = true;
keymap_config.swap_ralt_rgui = true;
break;
case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
keymap_config.swap_control_capslock = false;
break;
case MAGIC_UNCAPSLOCK_TO_CONTROL:
keymap_config.capslock_to_control = false;
break;
case MAGIC_UNSWAP_LALT_LGUI:
keymap_config.swap_lalt_lgui = false;
break;
case MAGIC_UNSWAP_RALT_RGUI:
keymap_config.swap_ralt_rgui = false;
break;
case MAGIC_UNNO_GUI:
keymap_config.no_gui = false;
break;
case MAGIC_UNSWAP_GRAVE_ESC:
keymap_config.swap_grave_esc = false;
break;
case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
keymap_config.swap_backslash_backspace = false;
break;
case MAGIC_UNHOST_NKRO:
keymap_config.nkro = false;
break;
case MAGIC_UNSWAP_ALT_GUI:
keymap_config.swap_lalt_lgui = false;
keymap_config.swap_ralt_rgui = false;
break;
case MAGIC_TOGGLE_NKRO:
keymap_config.nkro = !keymap_config.nkro;
break;
default:
break;
}
eeconfig_update_keymap(keymap_config.raw);
clear_keyboard(); // clear to prevent stuck keys

return false;
}
break;
Expand All @@ -284,7 +296,7 @@ bool process_record_quantum(keyrecord_t *record) {
unregister_mods(MOD_BIT(KC_LSFT));
}
return false;
break;
// break;
}

case KC_RSPC: {
Expand All @@ -306,7 +318,7 @@ bool process_record_quantum(keyrecord_t *record) {
unregister_mods(MOD_BIT(KC_RSFT));
}
return false;
break;
// break;
}
default: {
shift_interrupted[0] = true;
Expand Down
10 changes: 7 additions & 3 deletions tmk_core/common/action_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action_util.h"
#include "action_layer.h"
#include "timer.h"
#include "keycode_config.h"

extern keymap_config_t keymap_config;


static inline void add_key_byte(uint8_t code);
static inline void del_key_byte(uint8_t code);
Expand Down Expand Up @@ -139,7 +143,7 @@ void send_keyboard_report(void) {
void add_key(uint8_t key)
{
#ifdef NKRO_ENABLE
if (keyboard_protocol && keyboard_nkro) {
if (keyboard_protocol && keymap_config.nkro) {
add_key_bit(key);
return;
}
Expand All @@ -150,7 +154,7 @@ void add_key(uint8_t key)
void del_key(uint8_t key)
{
#ifdef NKRO_ENABLE
if (keyboard_protocol && keyboard_nkro) {
if (keyboard_protocol && keymap_config.nkro) {
del_key_bit(key);
return;
}
Expand Down Expand Up @@ -231,7 +235,7 @@ uint8_t has_anymod(void)
uint8_t get_first_key(void)
{
#ifdef NKRO_ENABLE
if (keyboard_protocol && keyboard_nkro) {
if (keyboard_protocol && keymap_config.nkro) {
uint8_t i = 0;
for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
;
Expand Down
4 changes: 0 additions & 4 deletions tmk_core/common/bootmagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ void bootmagic(void)
}
eeconfig_update_keymap(keymap_config.raw);

#ifdef NKRO_ENABLE
keyboard_nkro = keymap_config.nkro;
#endif

/* default layer */
uint8_t default_layer = 0;
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
Expand Down
6 changes: 3 additions & 3 deletions tmk_core/common/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static void print_status(void)
print_val_hex8(keyboard_protocol);
print_val_hex8(keyboard_idle);
#ifdef NKRO_ENABLE
print_val_hex8(keyboard_nkro);
print_val_hex8(keymap_config.nkro);
#endif
print_val_hex32(timer_read32());

Expand Down Expand Up @@ -435,8 +435,8 @@ static bool command_common(uint8_t code)
// NKRO toggle
case MAGIC_KC(MAGIC_KEY_NKRO):
clear_keyboard(); // clear to prevent stuck keys
keyboard_nkro = !keyboard_nkro;
if (keyboard_nkro) {
keymap_config.nkro = !keymap_config.nkro;
if (keymap_config.nkro) {
print("NKRO: on\n");
} else {
print("NKRO: off\n");
Expand Down
5 changes: 0 additions & 5 deletions tmk_core/common/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "util.h"
#include "debug.h"


#ifdef NKRO_ENABLE
bool keyboard_nkro = true;
#endif

static host_driver_t *driver;
static uint16_t last_system_report = 0;
static uint16_t last_consumer_report = 0;
Expand Down
4 changes: 0 additions & 4 deletions tmk_core/common/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" {
#endif

#ifdef NKRO_ENABLE
extern bool keyboard_nkro;
#endif

extern uint8_t keyboard_idle;
extern uint8_t keyboard_protocol;

Expand Down
4 changes: 3 additions & 1 deletion tmk_core/common/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "visualizer/visualizer.h"
#endif



#ifdef MATRIX_HAS_GHOST
static bool has_ghost_in_row(uint8_t row)
{
Expand Down Expand Up @@ -106,7 +108,7 @@ void keyboard_init(void) {
rgblight_init();
#endif
#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
keyboard_nkro = true;
keymap_config.nkro = 1;
#endif
}

Expand Down
4 changes: 0 additions & 4 deletions tmk_core/common/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ void magic(void)
/* keymap config */
keymap_config.raw = eeconfig_read_keymap();

#ifdef NKRO_ENABLE
keyboard_nkro = keymap_config.nkro;
#endif

uint8_t default_layer = 0;
default_layer = eeconfig_read_default_layer();
default_layer_set((uint32_t)default_layer);
Expand Down
Loading

0 comments on commit 558f3ec

Please sign in to comment.