mirror of
https://github.com/openstenoproject/qmk
synced 2024-11-10 18:49:08 +00:00
Add eeconfig.c - eeprom stored paramerters
This commit is contained in:
parent
5d6b848a15
commit
359b68d35f
6 changed files with 135 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
29
common/eeconfig.c
Normal file
29
common/eeconfig.c
Normal file
|
@ -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); }
|
||||
|
59
common/eeconfig.h
Normal file
59
common/eeconfig.h
Normal file
|
@ -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
|
|
@ -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 IS_BOOTMAGIC_EEPROM_CLEAR
|
||||
if (IS_BOOTMAGIC_EEPROM_CLEAR()) eeconfig_init();
|
||||
#endif
|
||||
|
||||
#ifdef PS2_MOUSE_ENABLE
|
||||
ps2_mouse_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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue