summaryrefslogtreecommitdiff
path: root/common/bootmagic.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-03-09 11:22:27 +0900
committertmk <nobody@nowhere>2013-03-09 11:22:27 +0900
commit4d64fd8faa8b1a0ceb9019446ba6915aaf1812ea (patch)
tree25410ede4bbf7d5a8994bb385e6c7ee4ad2f4c0c /common/bootmagic.c
parent359b68d35f0763ab0cafa2fb800e0a3497291f95 (diff)
Add bootmagic.c and fix bootloader_jump
Diffstat (limited to 'common/bootmagic.c')
-rw-r--r--common/bootmagic.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/common/bootmagic.c b/common/bootmagic.c
new file mode 100644
index 0000000000..31b8ae5e62
--- /dev/null
+++ b/common/bootmagic.c
@@ -0,0 +1,45 @@
+#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)
+{
+ /* do scans in case of bounce */
+ uint8_t scan = 100;
+ while (scan--) { matrix_scan(); _delay_ms(1); }
+
+ if (!BOOTMAGIC_IS_ENABLE()) { return; }
+
+ 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();
+ }
+}
+
+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;
+}