]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
Add eeconfig.c - eeprom stored paramerters
authortmk <nobody@nowhere>
Wed, 6 Mar 2013 18:30:08 +0000 (03:30 +0900)
committertmk <nobody@nowhere>
Wed, 6 Mar 2013 18:30:08 +0000 (03:30 +0900)
common.mk
common/command.c
common/eeconfig.c [new file with mode: 0644]
common/eeconfig.h [new file with mode: 0644]
common/keyboard.c
keyboard/gh60/config.h

index 5fb76e739b03f5e1ebf1c0bf30c19f574523ecbe..a99e335ee19a36e5e1fbf34d08499f5122ba4789 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -10,6 +10,7 @@ SRC +=        $(COMMON_DIR)/host.c \
        $(COMMON_DIR)/print.c \
        $(COMMON_DIR)/debug.c \
        $(COMMON_DIR)/bootloader.c \
+       $(COMMON_DIR)/eeconfig.c \
        $(COMMON_DIR)/util.c
 
 
index 202d531fd83363a0f9e08a6c6e38d55a366a7a31..40932e05010e331fbf77074cdef5c5f45381e710 100644 (file)
@@ -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 (file)
index 0000000..a5834aa
--- /dev/null
@@ -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 (file)
index 0000000..088171f
--- /dev/null
@@ -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
index 91f321d9ca24b02838b38cc89bc6005544c8cebc..2206f16759353743c44fa513f77571843afffb8b 100644 (file)
@@ -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();
+    }
+
 }
 
 /*
index ef0c9a1735dbc8870de50911ad05b004c0cb4b3a..3a7a3f97fbf6e382b04f513e0aaff2ca44800236 100644 (file)
@@ -56,10 +56,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* key position on matrix(ROW:COL) */
 #define KEY_FN          0x4A
 #define KEY_D           0x23
+#define KEY_ESC         0x00
 #define KEY_IS_ON(key)  matrix_is_on((key)>>4, (key)&0xF)
 /* kick up bootloader */
 #define IS_BOOTMAGIC_BOOTLOADER()       KEY_IS_ON(KEY_FN)
 /* debug on */
 #define IS_BOOTMAGIC_DEBUG()            KEY_IS_ON(KEY_D)
+/* eeprom clear */
+#define IS_BOOTMAGIC_EEPROM_CLEAR()     KEY_IS_ON(KEY_ESC)
 
 #endif