summaryrefslogtreecommitdiff
path: root/common/bootmagic.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-03-11 15:35:55 +0900
committertmk <nobody@nowhere>2013-03-11 15:35:55 +0900
commit48433a5e9988647a737234c11dd9db4080fd4a4e (patch)
tree4af03a20658cb7e6cd43f9c65dfa002f1b544332 /common/bootmagic.c
parent5d6b848a157a2e94859949961297d40da6a77527 (diff)
parentef8439bddb2d7fe5fd95faf2b6bebd8235acf160 (diff)
downloadqmk_firmware-48433a5e9988647a737234c11dd9db4080fd4a4e.tar.gz
qmk_firmware-48433a5e9988647a737234c11dd9db4080fd4a4e.zip
Merge branch 'eeprom_config'
Diffstat (limited to 'common/bootmagic.c')
-rw-r--r--common/bootmagic.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/common/bootmagic.c b/common/bootmagic.c
new file mode 100644
index 0000000000..388099e2e6
--- /dev/null
+++ b/common/bootmagic.c
@@ -0,0 +1,67 @@
+#include <stdint.h>
+#include <stdbool.h>
+#include <util/delay.h>
+#include "matrix.h"
+#include "keymap.h"
+#include "eeconfig.h"
+#include "bootloader.h"
+#include "bootmagic.h"
+
+
+void bootmagic(void)
+{
+ if (!BOOTMAGIC_IS_ENABLED()) { return; }
+
+ /* do scans in case of bounce */
+ uint8_t scan = 100;
+ while (scan--) { matrix_scan(); _delay_ms(1); }
+
+ if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) {
+ bootloader_jump();
+ }
+
+ if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) {
+ eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE);
+ }
+
+ if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) {
+ eeconfig_init();
+ }
+
+ if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_CONTROL_CPASLOCK)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK);
+ }
+ if (bootmagic_scan_keycode(BOOTMAGIC_CAPSLOCK_TO_CONTROL)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL);
+ }
+ if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_LALT_LGUI)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_LALT_LGUI);
+ }
+ if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_RALT_RGUI)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_RALT_RGUI);
+ }
+ if (bootmagic_scan_keycode(BOOTMAGIC_NO_GUI)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_NO_GUI);
+ }
+ if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_GRAVE_ESC)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_GRAVE_ESC);
+ }
+ if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE)) {
+ eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE);
+ }
+}
+
+bool bootmagic_scan_keycode(uint8_t keycode)
+{
+ 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)) {
+ if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}