diff options
| -rw-r--r-- | common.mk | 1 | ||||
| -rw-r--r-- | common/command.c | 22 | ||||
| -rw-r--r-- | common/eeconfig.c | 29 | ||||
| -rw-r--r-- | common/eeconfig.h | 59 | ||||
| -rw-r--r-- | common/keyboard.c | 25 | ||||
| -rw-r--r-- | keyboard/gh60/config.h | 3 |
6 files changed, 135 insertions, 4 deletions
| @@ -10,6 +10,7 @@ SRC += $(COMMON_DIR)/host.c \ | |||
| 10 | $(COMMON_DIR)/print.c \ | 10 | $(COMMON_DIR)/print.c \ |
| 11 | $(COMMON_DIR)/debug.c \ | 11 | $(COMMON_DIR)/debug.c \ |
| 12 | $(COMMON_DIR)/bootloader.c \ | 12 | $(COMMON_DIR)/bootloader.c \ |
| 13 | $(COMMON_DIR)/eeconfig.c \ | ||
| 13 | $(COMMON_DIR)/util.c | 14 | $(COMMON_DIR)/util.c |
| 14 | 15 | ||
| 15 | 16 | ||
diff --git a/common/command.c b/common/command.c index 202d531fd..40932e050 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | #include "keyboard.h" | 27 | #include "keyboard.h" |
| 28 | #include "bootloader.h" | 28 | #include "bootloader.h" |
| 29 | #include "layer_switch.h" | 29 | #include "layer_switch.h" |
| 30 | #include "eeconfig.h" | ||
| 30 | #include "command.h" | 31 | #include "command.h" |
| 31 | 32 | ||
| 32 | #ifdef MOUSEKEY_ENABLE | 33 | #ifdef MOUSEKEY_ENABLE |
| @@ -108,6 +109,7 @@ static void command_common_help(void) | |||
| 108 | print("v: print device version & info\n"); | 109 | print("v: print device version & info\n"); |
| 109 | print("t: print timer count\n"); | 110 | print("t: print timer count\n"); |
| 110 | print("s: print status\n"); | 111 | print("s: print status\n"); |
| 112 | print("e: print eeprom config\n"); | ||
| 111 | #ifdef NKRO_ENABLE | 113 | #ifdef NKRO_ENABLE |
| 112 | print("n: toggle NKRO\n"); | 114 | print("n: toggle NKRO\n"); |
| 113 | #endif | 115 | #endif |
| @@ -121,10 +123,30 @@ static void command_common_help(void) | |||
| 121 | print("Paus: jump to bootloader\n"); | 123 | print("Paus: jump to bootloader\n"); |
| 122 | } | 124 | } |
| 123 | 125 | ||
| 126 | static void print_eeprom_config(void) | ||
| 127 | { | ||
| 128 | uint8_t eebyte; | ||
| 129 | |||
| 130 | print("magic: "); print_hex16(eeprom_read_word((uint16_t)0)); print("\n"); | ||
| 131 | |||
| 132 | eebyte = eeconfig_read_debug(); | ||
| 133 | print("debug: "); print_hex8(eebyte); print("\n"); | ||
| 134 | |||
| 135 | eebyte = eeconfig_read_defalt_layer(); | ||
| 136 | print("defalt_layer: "); print_hex8(eebyte); print("\n"); | ||
| 137 | |||
| 138 | eebyte = eeconfig_read_modifier(); | ||
| 139 | print("modifiers: "); print_hex8(eebyte); print("\n"); | ||
| 140 | } | ||
| 141 | |||
| 124 | static bool command_common(uint8_t code) | 142 | static bool command_common(uint8_t code) |
| 125 | { | 143 | { |
| 126 | static host_driver_t *host_driver = 0; | 144 | static host_driver_t *host_driver = 0; |
| 127 | switch (code) { | 145 | switch (code) { |
| 146 | case KC_E: | ||
| 147 | print("eeprom config\n"); | ||
| 148 | print_eeprom_config(); | ||
| 149 | break; | ||
| 128 | case KC_CAPSLOCK: | 150 | case KC_CAPSLOCK: |
| 129 | if (host_get_driver()) { | 151 | if (host_get_driver()) { |
| 130 | host_driver = host_get_driver(); | 152 | host_driver = host_get_driver(); |
diff --git a/common/eeconfig.c b/common/eeconfig.c new file mode 100644 index 000000000..a5834aa2c --- /dev/null +++ b/common/eeconfig.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include <stdbool.h> | ||
| 3 | #include <avr/eeprom.h> | ||
| 4 | #include "eeconfig.h" | ||
| 5 | |||
| 6 | |||
| 7 | void eeconfig_init(void) | ||
| 8 | { | ||
| 9 | eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); | ||
| 10 | eeprom_write_byte(EECONFIG_DEBUG, 0); | ||
| 11 | eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); | ||
| 12 | eeprom_write_byte(EECONFIG_MODIFIER, 0); | ||
| 13 | eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); | ||
| 14 | } | ||
| 15 | |||
| 16 | bool eeconfig_initialized(void) | ||
| 17 | { | ||
| 18 | return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); | ||
| 19 | } | ||
| 20 | |||
| 21 | uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } | ||
| 22 | void eeconfig_write_debug(uint8_t val) { eeprom_write_byte(EECONFIG_DEBUG, val); } | ||
| 23 | |||
| 24 | uint8_t eeconfig_read_defalt_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } | ||
| 25 | void eeconfig_write_defalt_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFAULT_LAYER, val); } | ||
| 26 | |||
| 27 | uint8_t eeconfig_read_modifier(void) { return eeprom_read_byte(EECONFIG_MODIFIER); } | ||
| 28 | void eeconfig_write_modifier(uint8_t val) { eeprom_write_byte(EECONFIG_MODIFIER, val); } | ||
| 29 | |||
diff --git a/common/eeconfig.h b/common/eeconfig.h new file mode 100644 index 000000000..088171f57 --- /dev/null +++ b/common/eeconfig.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef EECONFIG_H | ||
| 19 | #define EECONFIG_H | ||
| 20 | |||
| 21 | #include <stdint.h> | ||
| 22 | |||
| 23 | #define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED | ||
| 24 | |||
| 25 | /* eeprom parameteter address */ | ||
| 26 | #define EECONFIG_MAGIC (uint16_t *)0 | ||
| 27 | #define EECONFIG_DEBUG (uint8_t *)2 | ||
| 28 | #define EECONFIG_DEFAULT_LAYER (uint8_t *)3 | ||
| 29 | #define EECONFIG_MODIFIER (uint8_t *)4 | ||
| 30 | #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 | ||
| 31 | |||
| 32 | |||
| 33 | /* config bit */ | ||
| 34 | #define EECONFIG_DEBUG_ENABLE (1<<0) | ||
| 35 | #define EECONFIG_DEBUG_MATRIX (1<<1) | ||
| 36 | #define EECONFIG_DEBUG_KEYBOARD (1<<2) | ||
| 37 | #define EECONFIG_DEBUG_MOUSE (1<<3) | ||
| 38 | |||
| 39 | #define EECONFIG_MODIFIER_CONTROL_CAPSLOCK (1<<0) | ||
| 40 | #define EECONFIG_MODIFIER_ALT_GUI (1<<1) | ||
| 41 | #define EECONFIG_MODIFIER_ESC_GRAVE (1<<2) | ||
| 42 | #define EECONFIG_MODIFIER_BACKSPACE_BACKSLASH (1<<3) | ||
| 43 | #define EECONFIG_MODIFIER_NO_GUI (1<<4) | ||
| 44 | |||
| 45 | |||
| 46 | bool eeconfig_initialized(void); | ||
| 47 | |||
| 48 | void eeconfig_init(void); | ||
| 49 | |||
| 50 | uint8_t eeconfig_read_debug(void); | ||
| 51 | void eeconfig_write_debug(uint8_t val); | ||
| 52 | |||
| 53 | uint8_t eeconfig_read_defalt_layer(void); | ||
| 54 | void eeconfig_write_defalt_layer(uint8_t val); | ||
| 55 | |||
| 56 | uint8_t eeconfig_read_modifier(void); | ||
| 57 | void eeconfig_write_modifier(uint8_t val); | ||
| 58 | |||
| 59 | #endif | ||
diff --git a/common/keyboard.c b/common/keyboard.c index 91f321d9c..2206f1675 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
| @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 32 | #ifdef MOUSEKEY_ENABLE | 32 | #ifdef MOUSEKEY_ENABLE |
| 33 | #include "mousekey.h" | 33 | #include "mousekey.h" |
| 34 | #endif | 34 | #endif |
| 35 | #include "eeconfig.h" | ||
| 35 | 36 | ||
| 36 | 37 | ||
| 37 | #ifdef MATRIX_HAS_GHOST | 38 | #ifdef MATRIX_HAS_GHOST |
| @@ -59,6 +60,9 @@ void keyboard_init(void) | |||
| 59 | 60 | ||
| 60 | timer_init(); | 61 | timer_init(); |
| 61 | matrix_init(); | 62 | matrix_init(); |
| 63 | #ifdef PS2_MOUSE_ENABLE | ||
| 64 | ps2_mouse_init(); | ||
| 65 | #endif | ||
| 62 | 66 | ||
| 63 | /* matrix scan for boot magic keys */ | 67 | /* matrix scan for boot magic keys */ |
| 64 | #ifdef DEBOUNCE | 68 | #ifdef DEBOUNCE |
| @@ -74,12 +78,25 @@ void keyboard_init(void) | |||
| 74 | if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); | 78 | if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); |
| 75 | #endif | 79 | #endif |
| 76 | #ifdef IS_BOOTMAGIC_DEBUG | 80 | #ifdef IS_BOOTMAGIC_DEBUG |
| 77 | if (IS_BOOTMAGIC_DEBUG()) debug_enable = true; | 81 | if (IS_BOOTMAGIC_DEBUG()) { |
| 82 | eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE); | ||
| 83 | } | ||
| 78 | #endif | 84 | #endif |
| 79 | 85 | #ifdef IS_BOOTMAGIC_EEPROM_CLEAR | |
| 80 | #ifdef PS2_MOUSE_ENABLE | 86 | if (IS_BOOTMAGIC_EEPROM_CLEAR()) eeconfig_init(); |
| 81 | ps2_mouse_init(); | ||
| 82 | #endif | 87 | #endif |
| 88 | |||
| 89 | if (eeconfig_initialized()) { | ||
| 90 | uint8_t config; | ||
| 91 | config = eeconfig_read_debug(); | ||
| 92 | debug_enable = (config & EECONFIG_DEBUG_ENABLE); | ||
| 93 | debug_matrix = (config & EECONFIG_DEBUG_MATRIX); | ||
| 94 | debug_keyboard = (config & EECONFIG_DEBUG_KEYBOARD); | ||
| 95 | debug_mouse = (config & EECONFIG_DEBUG_MOUSE); | ||
| 96 | } else { | ||
| 97 | eeconfig_init(); | ||
| 98 | } | ||
| 99 | |||
| 83 | } | 100 | } |
| 84 | 101 | ||
| 85 | /* | 102 | /* |
diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index ef0c9a173..3a7a3f97f 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h | |||
| @@ -56,10 +56,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 56 | /* key position on matrix(ROW:COL) */ | 56 | /* key position on matrix(ROW:COL) */ |
| 57 | #define KEY_FN 0x4A | 57 | #define KEY_FN 0x4A |
| 58 | #define KEY_D 0x23 | 58 | #define KEY_D 0x23 |
| 59 | #define KEY_ESC 0x00 | ||
| 59 | #define KEY_IS_ON(key) matrix_is_on((key)>>4, (key)&0xF) | 60 | #define KEY_IS_ON(key) matrix_is_on((key)>>4, (key)&0xF) |
| 60 | /* kick up bootloader */ | 61 | /* kick up bootloader */ |
| 61 | #define IS_BOOTMAGIC_BOOTLOADER() KEY_IS_ON(KEY_FN) | 62 | #define IS_BOOTMAGIC_BOOTLOADER() KEY_IS_ON(KEY_FN) |
| 62 | /* debug on */ | 63 | /* debug on */ |
| 63 | #define IS_BOOTMAGIC_DEBUG() KEY_IS_ON(KEY_D) | 64 | #define IS_BOOTMAGIC_DEBUG() KEY_IS_ON(KEY_D) |
| 65 | /* eeprom clear */ | ||
| 66 | #define IS_BOOTMAGIC_EEPROM_CLEAR() KEY_IS_ON(KEY_ESC) | ||
| 64 | 67 | ||
| 65 | #endif | 68 | #endif |
