diff options
author | tmk <nobody@nowhere> | 2013-03-07 03:30:08 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2013-03-07 03:30:08 +0900 |
commit | 359b68d35f0763ab0cafa2fb800e0a3497291f95 (patch) | |
tree | 8b048e024f1af5b9394d8883c208ee923c936b64 /common | |
parent | 5d6b848a157a2e94859949961297d40da6a77527 (diff) |
Add eeconfig.c - eeprom stored paramerters
Diffstat (limited to 'common')
-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 |
4 files changed, 131 insertions, 4 deletions
diff --git a/common/command.c b/common/command.c index 202d531fd8..40932e0501 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/>. #include "keyboard.h" #include "bootloader.h" #include "layer_switch.h" +#include "eeconfig.h" #include "command.h" #ifdef MOUSEKEY_ENABLE @@ -108,6 +109,7 @@ static void command_common_help(void) print("v: print device version & info\n"); print("t: print timer count\n"); print("s: print status\n"); + print("e: print eeprom config\n"); #ifdef NKRO_ENABLE print("n: toggle NKRO\n"); #endif @@ -121,10 +123,30 @@ static void command_common_help(void) print("Paus: jump to bootloader\n"); } +static void print_eeprom_config(void) +{ + uint8_t eebyte; + + print("magic: "); print_hex16(eeprom_read_word((uint16_t)0)); print("\n"); + + eebyte = eeconfig_read_debug(); + print("debug: "); print_hex8(eebyte); print("\n"); + + eebyte = eeconfig_read_defalt_layer(); + print("defalt_layer: "); print_hex8(eebyte); print("\n"); + + eebyte = eeconfig_read_modifier(); + print("modifiers: "); print_hex8(eebyte); print("\n"); +} + static bool command_common(uint8_t code) { static host_driver_t *host_driver = 0; switch (code) { + case KC_E: + print("eeprom config\n"); + print_eeprom_config(); + break; case KC_CAPSLOCK: if (host_get_driver()) { host_driver = host_get_driver(); diff --git a/common/eeconfig.c b/common/eeconfig.c new file mode 100644 index 0000000000..a5834aa2c7 --- /dev/null +++ b/common/eeconfig.c @@ -0,0 +1,29 @@ +#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_MODIFIER, 0); + eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); +} + +bool eeconfig_initialized(void) +{ + return (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_modifier(void) { return eeprom_read_byte(EECONFIG_MODIFIER); } +void eeconfig_write_modifier(uint8_t val) { eeprom_write_byte(EECONFIG_MODIFIER, val); } + diff --git a/common/eeconfig.h b/common/eeconfig.h new file mode 100644 index 0000000000..088171f575 --- /dev/null +++ b/common/eeconfig.h @@ -0,0 +1,59 @@ +/* +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> + +#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_MODIFIER (uint8_t *)4 +#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 + + +/* config 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) + +#define EECONFIG_MODIFIER_CONTROL_CAPSLOCK (1<<0) +#define EECONFIG_MODIFIER_ALT_GUI (1<<1) +#define EECONFIG_MODIFIER_ESC_GRAVE (1<<2) +#define EECONFIG_MODIFIER_BACKSPACE_BACKSLASH (1<<3) +#define EECONFIG_MODIFIER_NO_GUI (1<<4) + + +bool eeconfig_initialized(void); + +void eeconfig_init(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_modifier(void); +void eeconfig_write_modifier(uint8_t val); + +#endif diff --git a/common/keyboard.c b/common/keyboard.c index 91f321d9ca..2206f16759 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/>. #ifdef MOUSEKEY_ENABLE #include "mousekey.h" #endif +#include "eeconfig.h" #ifdef MATRIX_HAS_GHOST @@ -59,6 +60,9 @@ void keyboard_init(void) timer_init(); matrix_init(); +#ifdef PS2_MOUSE_ENABLE + ps2_mouse_init(); +#endif /* matrix scan for boot magic keys */ #ifdef DEBOUNCE @@ -74,12 +78,25 @@ void keyboard_init(void) if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); #endif #ifdef IS_BOOTMAGIC_DEBUG - if (IS_BOOTMAGIC_DEBUG()) debug_enable = true; + if (IS_BOOTMAGIC_DEBUG()) { + eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE); + } #endif - -#ifdef PS2_MOUSE_ENABLE - ps2_mouse_init(); +#ifdef IS_BOOTMAGIC_EEPROM_CLEAR + if (IS_BOOTMAGIC_EEPROM_CLEAR()) eeconfig_init(); #endif + + if (eeconfig_initialized()) { + uint8_t config; + config = eeconfig_read_debug(); + debug_enable = (config & EECONFIG_DEBUG_ENABLE); + debug_matrix = (config & EECONFIG_DEBUG_MATRIX); + debug_keyboard = (config & EECONFIG_DEBUG_KEYBOARD); + debug_mouse = (config & EECONFIG_DEBUG_MOUSE); + } else { + eeconfig_init(); + } + } /* |