|
|
@ -2,53 +2,78 @@
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
#include "matrix.h"
|
|
|
|
#include "matrix.h"
|
|
|
|
|
|
|
|
#include "bootloader.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include "keymap.h"
|
|
|
|
#include "keymap.h"
|
|
|
|
#include "eeconfig.h"
|
|
|
|
#include "eeconfig.h"
|
|
|
|
#include "bootloader.h"
|
|
|
|
|
|
|
|
#include "bootmagic.h"
|
|
|
|
#include "bootmagic.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void bootmagic(void)
|
|
|
|
void bootmagic(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!BOOTMAGIC_IS_ENABLED()) { return; }
|
|
|
|
/* check signature */
|
|
|
|
|
|
|
|
if (!eeconfig_is_enabled()) {
|
|
|
|
|
|
|
|
eeconfig_init();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do scans in case of bounce */
|
|
|
|
/* do scans in case of bounce */
|
|
|
|
uint8_t scan = 100;
|
|
|
|
uint8_t scan = 100;
|
|
|
|
while (scan--) { matrix_scan(); _delay_ms(1); }
|
|
|
|
while (scan--) { matrix_scan(); _delay_ms(10); }
|
|
|
|
|
|
|
|
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) {
|
|
|
|
/* bootmagic skip */
|
|
|
|
bootloader_jump();
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) {
|
|
|
|
/* eeconfig clear */
|
|
|
|
eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE);
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
|
|
|
|
|
|
|
|
eeconfig_init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) {
|
|
|
|
/* bootloader */
|
|
|
|
eeconfig_init();
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eeconfig_write_debug(debug_config.raw);
|
|
|
|
|
|
|
|
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_CONTROL_CPASLOCK)) {
|
|
|
|
/* keymap config */
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK);
|
|
|
|
keymap_config.raw = eeconfig_read_keymap();
|
|
|
|
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CPASLOCK)) {
|
|
|
|
|
|
|
|
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_CAPSLOCK_TO_CONTROL)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL);
|
|
|
|
keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_LALT_LGUI)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_LALT_LGUI);
|
|
|
|
keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_RALT_RGUI)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_RALT_RGUI);
|
|
|
|
keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_NO_GUI)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_NO_GUI);
|
|
|
|
keymap_config.no_gui = !keymap_config.no_gui;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_GRAVE_ESC)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_GRAVE_ESC);
|
|
|
|
keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE)) {
|
|
|
|
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
|
|
|
|
eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE);
|
|
|
|
keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eeconfig_write_keymap(keymap_config.raw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool bootmagic_scan_keycode(uint8_t keycode)
|
|
|
|
bool bootmagic_scan_keycode(uint8_t keycode)
|
|
|
|