commit
48433a5e99
@ -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;
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
#ifndef BOOTMAGIC_H
|
||||||
|
#define BOOTMAGIC_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BOOTMAGIC_IS_ENABLED
|
||||||
|
#define BOOTMAGIC_IS_ENABLED() true
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* kick up 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* key configure
|
||||||
|
*/
|
||||||
|
/* swap control and capslock */
|
||||||
|
#ifndef BOOTMAGIC_SWAP_CONTROL_CPASLOCK
|
||||||
|
#define BOOTMAGIC_SWAP_CONTROL_CPASLOCK KC_LCTRL
|
||||||
|
#endif
|
||||||
|
/* capslock to control */
|
||||||
|
#ifndef BOOTMAGIC_CAPSLOCK_TO_CONTROL
|
||||||
|
#define BOOTMAGIC_CAPSLOCK_TO_CONTROL KC_CAPSLOCK
|
||||||
|
#endif
|
||||||
|
/* swap alt and gui */
|
||||||
|
#ifndef BOOTMAGIC_SWAP_LALT_LGUI
|
||||||
|
#define BOOTMAGIC_SWAP_LALT_LGUI KC_LALT
|
||||||
|
#endif
|
||||||
|
/* swap alt and gui */
|
||||||
|
#ifndef BOOTMAGIC_SWAP_RALT_RGUI
|
||||||
|
#define BOOTMAGIC_SWAP_RALT_RGUI KC_RALT
|
||||||
|
#endif
|
||||||
|
/* no gui */
|
||||||
|
#ifndef BOOTMAGIC_NO_GUI
|
||||||
|
#define BOOTMAGIC_NO_GUI KC_LGUI
|
||||||
|
#endif
|
||||||
|
/* swap esc and grave */
|
||||||
|
#ifndef BOOTMAGIC_SWAP_GRAVE_ESC
|
||||||
|
#define BOOTMAGIC_SWAP_GRAVE_ESC KC_GRAVE
|
||||||
|
#endif
|
||||||
|
/* swap backslash and backspace */
|
||||||
|
#ifndef BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE
|
||||||
|
#define BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE KC_BSLASH
|
||||||
|
#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
|
@ -0,0 +1,38 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
#include "eeconfig.h"
|
||||||
|
|
||||||
|
|
||||||
|
void eeconfig_init(void)
|
||||||
|
{
|
||||||
|
eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
|
||||||
|
eeprom_write_byte(EECONFIG_DEBUG, 0);
|
||||||
|
eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0);
|
||||||
|
eeprom_write_byte(EECONFIG_KEYCONF, 0);
|
||||||
|
eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void eeconfig_enable(void)
|
||||||
|
{
|
||||||
|
eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void eeconfig_disable(void)
|
||||||
|
{
|
||||||
|
eeprom_write_word(EECONFIG_MAGIC, 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool eeconfig_is_enabled(void)
|
||||||
|
{
|
||||||
|
return EECONFIG_IS_ENABLED() && (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
|
||||||
|
void eeconfig_write_debug(uint8_t val) { eeprom_write_byte(EECONFIG_DEBUG, val); }
|
||||||
|
|
||||||
|
uint8_t eeconfig_read_defalt_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
|
||||||
|
void eeconfig_write_defalt_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFAULT_LAYER, val); }
|
||||||
|
|
||||||
|
uint8_t eeconfig_read_keyconf(void) { return eeprom_read_byte(EECONFIG_KEYCONF); }
|
||||||
|
void eeconfig_write_keyconf(uint8_t val) { eeprom_write_byte(EECONFIG_KEYCONF, val); }
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2013 Jun Wako <wakojun@gmail.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EECONFIG_H
|
||||||
|
#define EECONFIG_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifndef EECONFIG_IS_ENABLED
|
||||||
|
#define EECONFIG_IS_ENABLED() true
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED
|
||||||
|
|
||||||
|
/* eeprom parameteter address */
|
||||||
|
#define EECONFIG_MAGIC (uint16_t *)0
|
||||||
|
#define EECONFIG_DEBUG (uint8_t *)2
|
||||||
|
#define EECONFIG_DEFAULT_LAYER (uint8_t *)3
|
||||||
|
#define EECONFIG_KEYCONF (uint8_t *)4
|
||||||
|
#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
|
||||||
|
|
||||||
|
|
||||||
|
/* debug bit */
|
||||||
|
#define EECONFIG_DEBUG_ENABLE (1<<0)
|
||||||
|
#define EECONFIG_DEBUG_MATRIX (1<<1)
|
||||||
|
#define EECONFIG_DEBUG_KEYBOARD (1<<2)
|
||||||
|
#define EECONFIG_DEBUG_MOUSE (1<<3)
|
||||||
|
|
||||||
|
/* keyconf bit */
|
||||||
|
#define EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK (1<<0)
|
||||||
|
#define EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL (1<<1)
|
||||||
|
#define EECONFIG_KEYCONF_SWAP_LALT_LGUI (1<<2)
|
||||||
|
#define EECONFIG_KEYCONF_SWAP_RALT_RGUI (1<<3)
|
||||||
|
#define EECONFIG_KEYCONF_NO_GUI (1<<4)
|
||||||
|
#define EECONFIG_KEYCONF_SWAP_GRAVE_ESC (1<<5)
|
||||||
|
#define EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE (1<<6)
|
||||||
|
|
||||||
|
|
||||||
|
/* XXX: Not portable. Bit field order depends on implementation */
|
||||||
|
typedef union {
|
||||||
|
uint8_t raw;
|
||||||
|
struct {
|
||||||
|
bool swap_control_capslock:1;
|
||||||
|
bool capslock_to_control:1;
|
||||||
|
bool swap_lalt_lgui:1;
|
||||||
|
bool swap_ralt_rgui:1;
|
||||||
|
bool no_gui:1;
|
||||||
|
bool swap_grave_esc:1;
|
||||||
|
bool swap_backslash_backspace:1;
|
||||||
|
bool reserved:1;
|
||||||
|
};
|
||||||
|
} keyconf;
|
||||||
|
|
||||||
|
bool eeconfig_is_enabled(void);
|
||||||
|
|
||||||
|
void eeconfig_init(void);
|
||||||
|
|
||||||
|
void eeconfig_enable(void);
|
||||||
|
|
||||||
|
void eeconfig_disable(void);
|
||||||
|
|
||||||
|
uint8_t eeconfig_read_debug(void);
|
||||||
|
void eeconfig_write_debug(uint8_t val);
|
||||||
|
|
||||||
|
uint8_t eeconfig_read_defalt_layer(void);
|
||||||
|
void eeconfig_write_defalt_layer(uint8_t val);
|
||||||
|
|
||||||
|
uint8_t eeconfig_read_keyconf(void);
|
||||||
|
void eeconfig_write_keyconf(uint8_t val);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in new issue