2013-03-09 02:22:27 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
#include "matrix.h"
|
2013-04-07 06:36:50 +00:00
|
|
|
#include "bootloader.h"
|
|
|
|
#include "debug.h"
|
2013-03-09 02:22:27 +00:00
|
|
|
#include "keymap.h"
|
2014-04-09 22:54:16 +00:00
|
|
|
#include "host.h"
|
2013-07-23 15:41:28 +00:00
|
|
|
#include "action_layer.h"
|
2013-03-09 02:22:27 +00:00
|
|
|
#include "eeconfig.h"
|
|
|
|
#include "bootmagic.h"
|
|
|
|
|
|
|
|
|
|
|
|
void bootmagic(void)
|
|
|
|
{
|
2013-04-07 06:36:50 +00:00
|
|
|
/* check signature */
|
|
|
|
if (!eeconfig_is_enabled()) {
|
|
|
|
eeconfig_init();
|
|
|
|
}
|
2013-03-11 06:10:56 +00:00
|
|
|
|
2013-03-09 02:22:27 +00:00
|
|
|
/* do scans in case of bounce */
|
2013-09-21 12:21:34 +00:00
|
|
|
print("boogmagic scan: ... ");
|
2013-03-09 02:22:27 +00:00
|
|
|
uint8_t scan = 100;
|
2013-04-07 06:36:50 +00:00
|
|
|
while (scan--) { matrix_scan(); _delay_ms(10); }
|
2013-09-21 12:21:34 +00:00
|
|
|
print("done.\n");
|
2013-03-09 02:22:27 +00:00
|
|
|
|
2013-04-07 06:36:50 +00:00
|
|
|
/* bootmagic skip */
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
|
|
|
|
return;
|
2013-03-09 02:22:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 06:36:50 +00:00
|
|
|
/* eeconfig clear */
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
|
|
|
|
eeconfig_init();
|
2013-03-09 02:22:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 06:36:50 +00:00
|
|
|
/* bootloader */
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
|
|
|
|
bootloader_jump();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* debug enable */
|
|
|
|
debug_config.raw = eeconfig_read_debug();
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
|
|
|
|
debug_config.matrix = !debug_config.matrix;
|
|
|
|
} else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
|
|
|
|
debug_config.keyboard = !debug_config.keyboard;
|
|
|
|
} else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
|
|
|
|
debug_config.mouse = !debug_config.mouse;
|
|
|
|
} else {
|
|
|
|
debug_config.enable = !debug_config.enable;
|
|
|
|
}
|
2013-03-09 02:22:27 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
eeconfig_write_debug(debug_config.raw);
|
2013-03-10 10:22:54 +00:00
|
|
|
|
2013-04-07 06:36:50 +00:00
|
|
|
/* keymap config */
|
|
|
|
keymap_config.raw = eeconfig_read_keymap();
|
2013-09-21 12:21:34 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
|
2013-04-07 06:36:50 +00:00
|
|
|
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
|
|
|
|
keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
|
|
|
|
keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
|
|
|
|
keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
|
|
|
|
keymap_config.no_gui = !keymap_config.no_gui;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
|
|
|
|
keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
|
|
|
|
keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
|
2013-03-10 10:22:54 +00:00
|
|
|
}
|
2014-04-09 22:54:16 +00:00
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
|
|
|
|
keymap_config.nkro = !keymap_config.nkro;
|
|
|
|
}
|
2013-04-07 06:36:50 +00:00
|
|
|
eeconfig_write_keymap(keymap_config.raw);
|
2013-06-22 07:14:56 +00:00
|
|
|
|
2014-04-09 22:54:16 +00:00
|
|
|
#ifdef NKRO_ENABLE
|
|
|
|
keyboard_nkro = keymap_config.nkro;
|
|
|
|
#endif
|
|
|
|
|
2013-06-22 07:14:56 +00:00
|
|
|
/* default layer */
|
|
|
|
uint8_t default_layer = 0;
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
|
|
|
|
if (default_layer) {
|
|
|
|
eeconfig_write_default_layer(default_layer);
|
|
|
|
default_layer_set((uint32_t)default_layer);
|
|
|
|
} else {
|
|
|
|
default_layer = eeconfig_read_default_layer();
|
|
|
|
default_layer_set((uint32_t)default_layer);
|
|
|
|
}
|
2013-03-09 02:22:27 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 15:41:28 +00:00
|
|
|
static bool scan_keycode(uint8_t keycode)
|
2013-03-09 02:22:27 +00:00
|
|
|
{
|
|
|
|
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
|
|
|
|
matrix_row_t matrix_row = matrix_get_row(r);
|
|
|
|
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
|
|
|
|
if (matrix_row & ((matrix_row_t)1<<c)) {
|
2014-06-16 15:57:59 +00:00
|
|
|
if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
|
2013-03-09 02:22:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-23 15:41:28 +00:00
|
|
|
|
|
|
|
bool bootmagic_scan_keycode(uint8_t keycode)
|
|
|
|
{
|
|
|
|
if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
|
|
|
|
|
|
|
|
return scan_keycode(keycode);
|
|
|
|
}
|