diff options
| author | tmk <nobody@nowhere> | 2013-03-09 11:22:27 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-03-09 11:22:27 +0900 |
| commit | 4d64fd8faa8b1a0ceb9019446ba6915aaf1812ea (patch) | |
| tree | 25410ede4bbf7d5a8994bb385e6c7ee4ad2f4c0c /common/bootmagic.c | |
| parent | 359b68d35f0763ab0cafa2fb800e0a3497291f95 (diff) | |
| download | qmk_firmware-4d64fd8faa8b1a0ceb9019446ba6915aaf1812ea.tar.gz qmk_firmware-4d64fd8faa8b1a0ceb9019446ba6915aaf1812ea.zip | |
Add bootmagic.c and fix bootloader_jump
Diffstat (limited to 'common/bootmagic.c')
| -rw-r--r-- | common/bootmagic.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/common/bootmagic.c b/common/bootmagic.c new file mode 100644 index 000000000..31b8ae5e6 --- /dev/null +++ b/common/bootmagic.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include <stdbool.h> | ||
| 3 | #include <util/delay.h> | ||
| 4 | #include "matrix.h" | ||
| 5 | #include "keymap.h" | ||
| 6 | #include "eeconfig.h" | ||
| 7 | #include "bootloader.h" | ||
| 8 | #include "bootmagic.h" | ||
| 9 | |||
| 10 | |||
| 11 | void bootmagic(void) | ||
| 12 | { | ||
| 13 | /* do scans in case of bounce */ | ||
| 14 | uint8_t scan = 100; | ||
| 15 | while (scan--) { matrix_scan(); _delay_ms(1); } | ||
| 16 | |||
| 17 | if (!BOOTMAGIC_IS_ENABLE()) { return; } | ||
| 18 | |||
| 19 | if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) { | ||
| 20 | bootloader_jump(); | ||
| 21 | } | ||
| 22 | |||
| 23 | if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) { | ||
| 24 | eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE); | ||
| 25 | } | ||
| 26 | |||
| 27 | if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) { | ||
| 28 | eeconfig_init(); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | bool bootmagic_scan_keycode(uint8_t keycode) | ||
| 33 | { | ||
| 34 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | ||
| 35 | matrix_row_t matrix_row = matrix_get_row(r); | ||
| 36 | for (uint8_t c = 0; c < MATRIX_COLS; c++) { | ||
| 37 | if (matrix_row & ((matrix_row_t)1<<c)) { | ||
| 38 | if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) { | ||
| 39 | return true; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | return false; | ||
| 45 | } | ||
