$(COMMON_DIR)/print.c \ | $(COMMON_DIR)/print.c \ | ||||
$(COMMON_DIR)/debug.c \ | $(COMMON_DIR)/debug.c \ | ||||
$(COMMON_DIR)/bootloader.c \ | $(COMMON_DIR)/bootloader.c \ | ||||
$(COMMON_DIR)/eeconfig.c \ | |||||
$(COMMON_DIR)/util.c | $(COMMON_DIR)/util.c | ||||
#include "keyboard.h" | #include "keyboard.h" | ||||
#include "bootloader.h" | #include "bootloader.h" | ||||
#include "layer_switch.h" | #include "layer_switch.h" | ||||
#include "eeconfig.h" | |||||
#include "command.h" | #include "command.h" | ||||
#ifdef MOUSEKEY_ENABLE | #ifdef MOUSEKEY_ENABLE | ||||
print("v: print device version & info\n"); | print("v: print device version & info\n"); | ||||
print("t: print timer count\n"); | print("t: print timer count\n"); | ||||
print("s: print status\n"); | print("s: print status\n"); | ||||
print("e: print eeprom config\n"); | |||||
#ifdef NKRO_ENABLE | #ifdef NKRO_ENABLE | ||||
print("n: toggle NKRO\n"); | print("n: toggle NKRO\n"); | ||||
#endif | #endif | ||||
print("Paus: jump to bootloader\n"); | 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 bool command_common(uint8_t code) | ||||
{ | { | ||||
static host_driver_t *host_driver = 0; | static host_driver_t *host_driver = 0; | ||||
switch (code) { | switch (code) { | ||||
case KC_E: | |||||
print("eeprom config\n"); | |||||
print_eeprom_config(); | |||||
break; | |||||
case KC_CAPSLOCK: | case KC_CAPSLOCK: | ||||
if (host_get_driver()) { | if (host_get_driver()) { | ||||
host_driver = host_get_driver(); | host_driver = host_get_driver(); |
#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); } | |||||
/* | |||||
Copyright 2013 Jun Wako <[email protected]> | |||||
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 |
#ifdef MOUSEKEY_ENABLE | #ifdef MOUSEKEY_ENABLE | ||||
#include "mousekey.h" | #include "mousekey.h" | ||||
#endif | #endif | ||||
#include "eeconfig.h" | |||||
#ifdef MATRIX_HAS_GHOST | #ifdef MATRIX_HAS_GHOST | ||||
timer_init(); | timer_init(); | ||||
matrix_init(); | matrix_init(); | ||||
#ifdef PS2_MOUSE_ENABLE | |||||
ps2_mouse_init(); | |||||
#endif | |||||
/* matrix scan for boot magic keys */ | /* matrix scan for boot magic keys */ | ||||
#ifdef DEBOUNCE | #ifdef DEBOUNCE | ||||
if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); | if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); | ||||
#endif | #endif | ||||
#ifdef IS_BOOTMAGIC_DEBUG | #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 | #endif | ||||
#ifdef PS2_MOUSE_ENABLE | |||||
ps2_mouse_init(); | |||||
#ifdef IS_BOOTMAGIC_EEPROM_CLEAR | |||||
if (IS_BOOTMAGIC_EEPROM_CLEAR()) eeconfig_init(); | |||||
#endif | #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(); | |||||
} | |||||
} | } | ||||
/* | /* |
/* key position on matrix(ROW:COL) */ | /* key position on matrix(ROW:COL) */ | ||||
#define KEY_FN 0x4A | #define KEY_FN 0x4A | ||||
#define KEY_D 0x23 | #define KEY_D 0x23 | ||||
#define KEY_ESC 0x00 | |||||
#define KEY_IS_ON(key) matrix_is_on((key)>>4, (key)&0xF) | #define KEY_IS_ON(key) matrix_is_on((key)>>4, (key)&0xF) | ||||
/* kick up bootloader */ | /* kick up bootloader */ | ||||
#define IS_BOOTMAGIC_BOOTLOADER() KEY_IS_ON(KEY_FN) | #define IS_BOOTMAGIC_BOOTLOADER() KEY_IS_ON(KEY_FN) | ||||
/* debug on */ | /* debug on */ | ||||
#define IS_BOOTMAGIC_DEBUG() KEY_IS_ON(KEY_D) | #define IS_BOOTMAGIC_DEBUG() KEY_IS_ON(KEY_D) | ||||
/* eeprom clear */ | |||||
#define IS_BOOTMAGIC_EEPROM_CLEAR() KEY_IS_ON(KEY_ESC) | |||||
#endif | #endif |