-
-
Notifications
You must be signed in to change notification settings - Fork 40.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bootmagic.c and fix bootloader_jump
- Loading branch information
Showing
9 changed files
with
178 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef BOOTMAGIC_H | ||
#define BOOTMAGIC_H | ||
|
||
|
||
#ifndef BOOTMAGIC_IS_ENABLE | ||
#define BOOTMAGIC_IS_ENABLE() true | ||
#endif | ||
|
||
/* bootloader */ | ||
#ifndef BOOTMAGIC_BOOTLOADER_KEY | ||
#define BOOTMAGIC_BOOTLOADER_KEY KC_B | ||
#endif | ||
/* debug enable */ | ||
#ifndef BOOTMAGIC_DEBUG_ENABLE_KEY | ||
#define BOOTMAGIC_DEBUG_ENABLE_KEY KC_D | ||
#endif | ||
/* eeprom clear */ | ||
#ifndef BOOTMAGIC_EEPROM_CLEAR_KEY | ||
#define BOOTMAGIC_EEPROM_CLEAR_KEY KC_BSPACE | ||
#endif | ||
|
||
/* change default layer */ | ||
#ifndef BOOTMAGIC_DEFAULT_LAYER_0_KEY | ||
#define BOOTMAGIC_DEFAULT_LAYER_0_KEY KC_0 | ||
#endif | ||
#ifndef BOOTMAGIC_DEFAULT_LAYER_1_KEY | ||
#define BOOTMAGIC_DEFAULT_LAYER_1_KEY KC_1 | ||
#endif | ||
#ifndef BOOTMAGIC_DEFAULT_LAYER_2_KEY | ||
#define BOOTMAGIC_DEFAULT_LAYER_2_KEY KC_2 | ||
#endif | ||
#ifndef BOOTMAGIC_DEFAULT_LAYER_3_KEY | ||
#define BOOTMAGIC_DEFAULT_LAYER_3_KEY KC_3 | ||
#endif | ||
|
||
void bootmagic(void); | ||
bool bootmagic_scan_keycode(uint8_t keycode); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters