core: Fix bootmagic
- EEPROM_CLEAR wipes out eeprom with 0xFF now(avr) - keymap config is not enabled during bootmagic - wait until all key is released after bootmagic - add eeconfig_debug() to command.c
This commit is contained in:
parent
66da6f4d64
commit
1cc716477b
4 changed files with 52 additions and 13 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
#include "eeconfig.h"
|
#include "eeconfig.h"
|
||||||
#include "keymap.h"
|
#include "keymap.h"
|
||||||
|
#include "print.h"
|
||||||
|
|
||||||
void eeconfig_init(void)
|
void eeconfig_init(void)
|
||||||
{
|
{
|
||||||
|
|
@ -28,6 +29,11 @@ void eeconfig_enable(void)
|
||||||
void eeconfig_disable(void)
|
void eeconfig_disable(void)
|
||||||
{
|
{
|
||||||
eeprom_write_word(EECONFIG_MAGIC, 0xFFFF);
|
eeprom_write_word(EECONFIG_MAGIC, 0xFFFF);
|
||||||
|
eeprom_write_byte(EECONFIG_DEBUG, 0xFF);
|
||||||
|
eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0xFF);
|
||||||
|
eeprom_write_byte(EECONFIG_KEYMAP, 0xFF);
|
||||||
|
eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0xFF);
|
||||||
|
eeprom_write_byte(EECONFIG_BACKLIGHT, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool eeconfig_is_enabled(void)
|
bool eeconfig_is_enabled(void)
|
||||||
|
|
@ -48,3 +54,13 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val
|
||||||
uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
|
uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
|
||||||
void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); }
|
void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void eeconfig_debug(void)
|
||||||
|
{
|
||||||
|
xprintf("eeprom:");
|
||||||
|
for (int i = 0; i < 16 /* E2END + 1 */; i++) {
|
||||||
|
if ((i % 16) == 0) { xprintf("\n%04X: ", i); }
|
||||||
|
xprintf("%02X ", eeprom_read_byte((uint8_t *)i));
|
||||||
|
}
|
||||||
|
xprintf("\n");
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ void bootmagic(void)
|
||||||
|
|
||||||
/* eeconfig clear */
|
/* eeconfig clear */
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
|
||||||
eeconfig_init();
|
eeconfig_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bootloader */
|
/* bootloader */
|
||||||
|
|
@ -45,6 +45,10 @@ void bootmagic(void)
|
||||||
/* user-defined checks */
|
/* user-defined checks */
|
||||||
hook_bootmagic();
|
hook_bootmagic();
|
||||||
|
|
||||||
|
if (!eeconfig_is_enabled()) {
|
||||||
|
goto WAIT;
|
||||||
|
}
|
||||||
|
|
||||||
/* debug enable */
|
/* debug enable */
|
||||||
debug_config.raw = eeconfig_read_debug();
|
debug_config.raw = eeconfig_read_debug();
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
|
||||||
|
|
@ -61,35 +65,36 @@ void bootmagic(void)
|
||||||
eeconfig_write_debug(debug_config.raw);
|
eeconfig_write_debug(debug_config.raw);
|
||||||
|
|
||||||
/* keymap config */
|
/* keymap config */
|
||||||
keymap_config.raw = eeconfig_read_keymap();
|
keymap_config_t kc;
|
||||||
|
kc.raw = eeconfig_read_keymap();
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
|
||||||
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
|
kc.swap_control_capslock = !kc.swap_control_capslock;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
|
||||||
keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
|
kc.capslock_to_control = !kc.capslock_to_control;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
|
||||||
keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
|
kc.swap_lalt_lgui = !kc.swap_lalt_lgui;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
|
||||||
keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
|
kc.swap_ralt_rgui = !kc.swap_ralt_rgui;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_NO_GUI)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_NO_GUI)) {
|
||||||
keymap_config.no_gui = !keymap_config.no_gui;
|
kc.no_gui = !kc.no_gui;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
|
||||||
keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
|
kc.swap_grave_esc = !kc.swap_grave_esc;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
|
if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
|
||||||
keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
|
kc.swap_backslash_backspace = !kc.swap_backslash_backspace;
|
||||||
}
|
}
|
||||||
if (bootmagic_scan_key(BOOTMAGIC_HOST_NKRO)) {
|
if (bootmagic_scan_key(BOOTMAGIC_HOST_NKRO)) {
|
||||||
keymap_config.nkro = !keymap_config.nkro;
|
kc.nkro = !kc.nkro;
|
||||||
}
|
}
|
||||||
eeconfig_write_keymap(keymap_config.raw);
|
eeconfig_write_keymap(kc.raw);
|
||||||
|
|
||||||
#if defined(NKRO_ENABLE) || defined(NKRO_6KRO_ENABLE)
|
#if defined(NKRO_ENABLE) || defined(NKRO_6KRO_ENABLE)
|
||||||
keyboard_nkro = keymap_config.nkro;
|
keyboard_nkro = kc.nkro;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* default layer */
|
/* default layer */
|
||||||
|
|
@ -109,6 +114,18 @@ void bootmagic(void)
|
||||||
default_layer = eeconfig_read_default_layer();
|
default_layer = eeconfig_read_default_layer();
|
||||||
default_layer_set((uint32_t)default_layer);
|
default_layer_set((uint32_t)default_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keymap_config = kc;
|
||||||
|
|
||||||
|
// wait until all key is released
|
||||||
|
WAIT:
|
||||||
|
matrix_scan();
|
||||||
|
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
|
||||||
|
if (matrix_get_row(r)) {
|
||||||
|
goto WAIT;
|
||||||
|
wait_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool scan_key(uint16_t code)
|
static bool scan_key(uint16_t code)
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,8 @@ static void command_common_help(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOTMAGIC_ENABLE
|
#ifdef BOOTMAGIC_ENABLE
|
||||||
|
__attribute__ ((weak)) void eeconfig_debug(void) {}
|
||||||
|
|
||||||
static void print_eeconfig(void)
|
static void print_eeconfig(void)
|
||||||
{
|
{
|
||||||
print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
|
print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
|
||||||
|
|
@ -176,6 +178,8 @@ static void print_eeconfig(void)
|
||||||
print(".enable: "); print_dec(bc.enable); print("\n");
|
print(".enable: "); print_dec(bc.enable); print("\n");
|
||||||
print(".level: "); print_dec(bc.level); print("\n");
|
print(".level: "); print_dec(bc.level); print("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
eeconfig_debug();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,4 +72,6 @@ uint8_t eeconfig_read_backlight(void);
|
||||||
void eeconfig_write_backlight(uint8_t val);
|
void eeconfig_write_backlight(uint8_t val);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void eeconfig_debug(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue