From 359b68d35f0763ab0cafa2fb800e0a3497291f95 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 7 Mar 2013 03:30:08 +0900 Subject: [PATCH 01/13] Add eeconfig.c - eeprom stored paramerters --- common.mk | 1 + common/command.c | 22 ++++++++++++++++ common/eeconfig.c | 29 +++++++++++++++++++++ common/eeconfig.h | 59 ++++++++++++++++++++++++++++++++++++++++++ common/keyboard.c | 25 +++++++++++++++--- keyboard/gh60/config.h | 3 +++ 6 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 common/eeconfig.c create mode 100644 common/eeconfig.h diff --git a/common.mk b/common.mk index 5fb76e739b..a99e335ee1 100644 --- 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 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 . #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 +#include +#include +#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 + +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 . +*/ + +#ifndef EECONFIG_H +#define EECONFIG_H + +#include + +#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 . #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(); + } + } /* diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index ef0c9a1735..3a7a3f97fb 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -56,10 +56,13 @@ along with this program. If not, see . /* 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 From 4d64fd8faa8b1a0ceb9019446ba6915aaf1812ea Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 9 Mar 2013 11:22:27 +0900 Subject: [PATCH 02/13] Add bootmagic.c and fix bootloader_jump --- common.mk | 1 + common/bootloader.c | 100 +++++++++++++++++++++++++++++++---------- common/bootmagic.c | 45 +++++++++++++++++++ common/bootmagic.h | 39 ++++++++++++++++ common/command.c | 4 +- common/keyboard.c | 25 +---------- keyboard/gh60/keymap.c | 6 ++- protocol/lufa.mk | 4 +- protocol/pjrc.mk | 8 +++- 9 files changed, 178 insertions(+), 54 deletions(-) create mode 100644 common/bootmagic.c create mode 100644 common/bootmagic.h diff --git a/common.mk b/common.mk index a99e335ee1..2735f5becf 100644 --- 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)/bootmagic.c \ $(COMMON_DIR)/eeconfig.c \ $(COMMON_DIR)/util.c diff --git a/common/bootloader.c b/common/bootloader.c index 6e04efbbda..77fa1b30a7 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -1,15 +1,16 @@ +#include +#include #include #include +#include #include #include "bootloader.h" -/* Start Bootloader from Application - * See - * http://www.pjrc.com/teensy/jump_to_bootloader.html - * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html - */ +#ifdef PROTOCOL_LUFA +#include +#endif + -// TODO: support usbasp /* Boot Section Size in bytes * Teensy halfKay 512 * Atmel DFU loader 4096 @@ -18,28 +19,82 @@ #ifndef BOOT_SIZE #define BOOT_SIZE 512 #endif - #define FLASH_SIZE (FLASHEND + 1) -#define BOOTLOADER_START (FLASHEND - BOOT_SIZE) +#define BOOTLOADER_START (FLASH_SIZE - BOOT_SIZE) + +/* + * Entering the Bootloader via Software + * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html + */ +#define BOOTLOADER_RESET_KEY 0xB007B007 +uint32_t reset_key __attribute__ ((section (".noinit"))); + +/* initialize MCU status by watchdog reset */ void bootloader_jump(void) { +#ifdef PROTOCOL_LUFA + USB_Disable(); cli(); + _delay_ms(2000); +#endif - // - //Teensy - // -#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) - // disable watchdog, if enabled - // disable all peripherals +#ifdef PROTOCOL_PJRC + cli(); UDCON = 1; - USBCON = (1< +#include +#include +#include "matrix.h" +#include "keymap.h" +#include "eeconfig.h" +#include "bootloader.h" +#include "bootmagic.h" + + +void bootmagic(void) +{ + /* do scans in case of bounce */ + uint8_t scan = 100; + while (scan--) { matrix_scan(); _delay_ms(1); } + + if (!BOOTMAGIC_IS_ENABLE()) { return; } + + if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) { + bootloader_jump(); + } + + if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) { + eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE); + } + + if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) { + eeconfig_init(); + } +} + +bool bootmagic_scan_keycode(uint8_t keycode) +{ + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + matrix_row_t matrix_row = matrix_get_row(r); + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + if (matrix_row & ((matrix_row_t)1<. #include "command.h" #include "util.h" #include "sendchar.h" -#include "bootloader.h" +#include "bootmagic.h" #ifdef MOUSEKEY_ENABLE #include "mousekey.h" #endif @@ -64,27 +64,7 @@ void keyboard_init(void) ps2_mouse_init(); #endif - /* matrix scan for boot magic keys */ -#ifdef DEBOUNCE - uint8_t scan = DEBOUNCE * 2; - while (scan--) { matrix_scan(); _delay_ms(1); } -#else - matrix_scan(); -#endif - - /* boot magic keys */ -#ifdef IS_BOOTMAGIC_BOOTLOADER - /* kick up bootloader */ - if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump(); -#endif -#ifdef IS_BOOTMAGIC_DEBUG - 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 + bootmagic(); if (eeconfig_initialized()) { uint8_t config; @@ -96,7 +76,6 @@ void keyboard_init(void) } else { eeconfig_init(); } - } /* diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c index 1f5344d4c6..d6af16961c 100644 --- a/keyboard/gh60/keymap.c +++ b/keyboard/gh60/keymap.c @@ -231,7 +231,8 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) if (layer < OVERLAYS_SIZE) { return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]); } else { - debug("key_to_keycode: overlay "); debug_dec(layer); debug(" is invalid.\n"); + // XXX: this may cuaes bootlaoder_jump incositent fail. + //debug("key_to_keycode: overlay "); debug_dec(layer); debug(" is invalid.\n"); return KC_TRANSPARENT; } } @@ -240,8 +241,9 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) if (layer < KEYMAPS_SIZE) { return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); } else { + // XXX: this may cuaes bootlaoder_jump incositent fail. + //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n"); // fall back to layer 0 - debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n"); return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); } } diff --git a/protocol/lufa.mk b/protocol/lufa.mk index 443b85344b..8ea071afbe 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk @@ -39,4 +39,6 @@ LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENAB OPT_DEFS += -DF_USB=$(F_USB)UL OPT_DEFS += -DARCH=ARCH_$(ARCH) OPT_DEFS += $(LUFA_OPTS) -OPT_DEFS += -DHOST_LUFA + +# This indicates using LUFA stack +OPT_DEFS += -DPROTOCOL_LUFA diff --git a/protocol/pjrc.mk b/protocol/pjrc.mk index cccdf62042..f5693ba99d 100644 --- a/protocol/pjrc.mk +++ b/protocol/pjrc.mk @@ -1,7 +1,5 @@ PJRC_DIR = protocol/pjrc -OPT_DEFS += -DHOST_PJRC - SRC += $(PJRC_DIR)/main.c \ $(PJRC_DIR)/pjrc.c \ $(PJRC_DIR)/usb_keyboard.c \ @@ -19,3 +17,9 @@ endif # Search Path VPATH += $(TOP_DIR)/$(PJRC_DIR) + +# This indicates using LUFA stack +# TODO: remove HOST_PJRC +OPT_DEFS += -DHOST_PJRC +OPT_DEFS += -DPROTOCOL_PJRC + From 1385058fc21f80347c7afd2b818e38795ce9d55a Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 9 Mar 2013 22:23:32 +0900 Subject: [PATCH 03/13] Fix gh60/matrix.c and Makefile --- keyboard/gh60/Makefile.lufa | 9 ++++++--- keyboard/gh60/Makefile.pjrc | 13 +++++++++---- keyboard/gh60/matrix.c | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa index 7a83032969..65b6240efc 100644 --- a/keyboard/gh60/Makefile.lufa +++ b/keyboard/gh60/Makefile.lufa @@ -93,13 +93,16 @@ ARCH = AVR8 # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. F_USB = $(F_CPU) +# Interrupt driven control endpoint task(+60) +#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + # Build Options # comment out to disable the options. # -MOUSEKEY_ENABLE = yes # Mouse keys -EXTRAKEY_ENABLE = yes # Audio control and System control -CONSOLE_ENABLE = yes # Console for debug +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = yes # Console for debug(+400) #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support diff --git a/keyboard/gh60/Makefile.pjrc b/keyboard/gh60/Makefile.pjrc index af6ef63ec4..2538c0c6bb 100644 --- a/keyboard/gh60/Makefile.pjrc +++ b/keyboard/gh60/Makefile.pjrc @@ -70,15 +70,20 @@ MCU = atmega32u4 # Teensy 2.0 # examples use this variable to calculate timings. Do not add a "UL" here. F_CPU = 16000000 +# Boot Section Size in bytes +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +OPT_DEFS += -DBOOT_SIZE=4096 # Build Options # comment out to disable the options. # -MOUSEKEY_ENABLE = yes # Mouse keys -#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -EXTRAKEY_ENABLE = yes # Audio control and System control -NKRO_ENABLE = yes # USB Nkey Rollover +MOUSEKEY_ENABLE = yes # Mouse keys(+5000) +EXTRAKEY_ENABLE = yes # Audio control and System control(+600) +NKRO_ENABLE = yes # USB Nkey Rollover(+500) CONSOLE_ENABLE = yes # Console for debug +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support # Search Path diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index 85e58fe361..09a051aa66 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c @@ -120,7 +120,7 @@ bool matrix_has_ghost(void) inline bool matrix_is_on(uint8_t row, uint8_t col) { - return (matrix[row] & (1< Date: Sun, 10 Mar 2013 15:05:28 +0900 Subject: [PATCH 04/13] Fix watchdog in bootloader jump - disable watchdog after watchdog reset - clear WDRF after watchdog reset --- common/bootloader.c | 23 +++++++++++++---------- keyboard/hhkb/Makefile.iwrap | 9 +++++++++ keyboard/hhkb/Makefile.lufa | 11 ++++++----- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/common/bootloader.c b/common/bootloader.c index 77fa1b30a7..023220414b 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -11,15 +11,16 @@ #endif -/* Boot Section Size in bytes - * Teensy halfKay 512 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 */ #ifndef BOOT_SIZE #define BOOT_SIZE 512 #endif -#define FLASH_SIZE (FLASHEND + 1) +#define FLASH_SIZE (FLASHEND + 1L) #define BOOTLOADER_START (FLASH_SIZE - BOOT_SIZE) @@ -58,13 +59,15 @@ void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, sec void bootloader_jump_after_watchdog_reset(void) { if ((MCUSR & (1< Date: Sun, 10 Mar 2013 15:36:07 +0900 Subject: [PATCH 05/13] Add BOOTLOADER_SIZE and remove BOOT_SIZE - define BOOTLOADER_SIZE in config.h instead of Makefile --- common/bootloader.c | 16 +++++++++------- keyboard/gh60/Makefile.lufa | 7 ------- keyboard/gh60/config.h | 12 ++++++++++-- keyboard/hhkb/Makefile.iwrap | 9 --------- keyboard/hhkb/Makefile.lufa | 8 -------- keyboard/hhkb/config.h | 10 +++++++++- keyboard/hhkb/config_iwrap.h | 10 ++++++++++ 7 files changed, 38 insertions(+), 34 deletions(-) diff --git a/common/bootloader.c b/common/bootloader.c index 023220414b..f9802d36c5 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -12,16 +12,18 @@ /* Boot Section Size in *BYTEs* - * Teensy halfKay 512 - * Teensy++ halfKay 1024 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 */ -#ifndef BOOT_SIZE -#define BOOT_SIZE 512 +#ifndef BOOTLOADER_SIZE +#warn To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. #endif + #define FLASH_SIZE (FLASHEND + 1L) -#define BOOTLOADER_START (FLASH_SIZE - BOOT_SIZE) +#define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) /* diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa index 65b6240efc..2076c919ca 100644 --- a/keyboard/gh60/Makefile.lufa +++ b/keyboard/gh60/Makefile.lufa @@ -107,13 +107,6 @@ CONSOLE_ENABLE = yes # Console for debug(+400) #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -# Boot Section Size in bytes -# Teensy halfKay 512 -# Atmel DFU loader 4096 -# LUFA bootloader 4096 -OPT_DEFS += -DBOOT_SIZE=4096 - - # Search Path VPATH += $(TARGET_DIR) VPATH += $(TOP_DIR) diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index 3a7a3f97fb..be4d72384e 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -25,12 +25,20 @@ along with this program. If not, see . #define DEVICE_VER 0x0001 #define MANUFACTURER geekhack #define PRODUCT GH60 - - /* message strings */ #define DESCRIPTION t.m.k. keyboard firmware for GH60 +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 + */ +#define BOOTLOADER_SIZE 4096 + + /* matrix size */ #define MATRIX_ROWS 5 #define MATRIX_COLS 14 diff --git a/keyboard/hhkb/Makefile.iwrap b/keyboard/hhkb/Makefile.iwrap index 3ec1a31645..f87df0d2bb 100644 --- a/keyboard/hhkb/Makefile.iwrap +++ b/keyboard/hhkb/Makefile.iwrap @@ -49,15 +49,6 @@ EXTRAKEY_ENABLE = yes # Audio control and System control #NKRO_ENABLE = yes # USB Nkey Rollover -# Boot Section Size in *BYTEs* -# Teensy halfKay 512 -# Teensy++ halfKay 1024 -# Atmel DFU loader 4096 -# LUFA bootloader 4096 -# USBaspLoader 2048 -OPT_DEFS += -DBOOT_SIZE=2048 - - #---------------- Programming Options -------------------------- AVRDUDE = avrdude diff --git a/keyboard/hhkb/Makefile.lufa b/keyboard/hhkb/Makefile.lufa index 75c0310d6e..e8b2414d39 100644 --- a/keyboard/hhkb/Makefile.lufa +++ b/keyboard/hhkb/Makefile.lufa @@ -107,14 +107,6 @@ CONSOLE_ENABLE = yes # Console for debug #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -# Boot Section Size in *BYTEs* -# Teensy halfKay 512 -# Teensy++ halfKay 1024 -# Atmel DFU loader 4096 -# LUFA bootloader 4096 -OPT_DEFS += -DBOOT_SIZE=1024 - - # Search Path VPATH += $(TARGET_DIR) VPATH += $(TOP_DIR) diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h index 72e4d26e92..3bfeb45ed4 100644 --- a/keyboard/hhkb/config.h +++ b/keyboard/hhkb/config.h @@ -27,9 +27,17 @@ along with this program. If not, see . #define DEVICE_VER 0x0103 #define MANUFACTURER t.m.k. #define PRODUCT HHKB mod +#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod -#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 + */ +#define BOOTLOADER_SIZE 1024 /* matrix size */ diff --git a/keyboard/hhkb/config_iwrap.h b/keyboard/hhkb/config_iwrap.h index d50b704d72..2c18cd817a 100644 --- a/keyboard/hhkb/config_iwrap.h +++ b/keyboard/hhkb/config_iwrap.h @@ -27,6 +27,16 @@ along with this program. If not, see . #define DESCRIPTION t.m.k. keyboard firmware for HHKB mod +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 + */ +#define BOOTLOADER_SIZE 2048 + + /* matrix size */ #define MATRIX_ROWS 8 #define MATRIX_COLS 8 From de8ef18a534163b40e307418b3af603142d5d6b0 Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 10 Mar 2013 19:22:54 +0900 Subject: [PATCH 06/13] Add KEYCONF to eeconfig.c --- common/bootmagic.c | 22 ++++++++++++++++++++++ common/bootmagic.h | 40 ++++++++++++++++++++++++++++++++++++++-- common/command.c | 4 ++-- common/eeconfig.c | 19 +++++++++---------- common/eeconfig.h | 21 ++++++++++++--------- 5 files changed, 83 insertions(+), 23 deletions(-) diff --git a/common/bootmagic.c b/common/bootmagic.c index 31b8ae5e62..46fbc180a4 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -27,6 +27,28 @@ void bootmagic(void) if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) { eeconfig_init(); } + + if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_CONTROL_CPASLOCK)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK); + } + if (bootmagic_scan_keycode(BOOTMAGIC_CAPSLOCK_TO_CONTROL)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL); + } + if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_LALT_LGUI)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_LALT_LGUI); + } + if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_RALT_RGUI)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_RALT_RGUI); + } + if (bootmagic_scan_keycode(BOOTMAGIC_NO_GUI)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_NO_GUI); + } + if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_GRAVE_ESC)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_GRAVE_ESC); + } + if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE)) { + eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE); + } } bool bootmagic_scan_keycode(uint8_t keycode) diff --git a/common/bootmagic.h b/common/bootmagic.h index 7aa224def9..d32a5bef88 100644 --- a/common/bootmagic.h +++ b/common/bootmagic.h @@ -6,7 +6,7 @@ #define BOOTMAGIC_IS_ENABLE() true #endif -/* bootloader */ +/* kick up bootloader */ #ifndef BOOTMAGIC_BOOTLOADER_KEY #define BOOTMAGIC_BOOTLOADER_KEY KC_B #endif @@ -19,7 +19,42 @@ #define BOOTMAGIC_EEPROM_CLEAR_KEY KC_BSPACE #endif -/* change default layer */ +/* + * key configure + */ +/* swap control and capslock */ +#ifndef BOOTMAGIC_SWAP_CONTROL_CPASLOCK +#define BOOTMAGIC_SWAP_CONTROL_CPASLOCK KC_LCTRL +#endif +/* capslock to control */ +#ifndef BOOTMAGIC_CAPSLOCK_TO_CONTROL +#define BOOTMAGIC_CAPSLOCK_TO_CONTROL KC_CAPSLOCK +#endif +/* swap alt and gui */ +#ifndef BOOTMAGIC_SWAP_LALT_LGUI +#define BOOTMAGIC_SWAP_LALT_LGUI KC_LALT +#endif +/* swap alt and gui */ +#ifndef BOOTMAGIC_SWAP_RALT_RGUI +#define BOOTMAGIC_SWAP_RALT_RGUI KC_RALT +#endif +/* no gui */ +#ifndef BOOTMAGIC_NO_GUI +#define BOOTMAGIC_NO_GUI KC_LGUI +#endif +/* swap esc and grave */ +#ifndef BOOTMAGIC_SWAP_GRAVE_ESC +#define BOOTMAGIC_SWAP_GRAVE_ESC KC_GRAVE +#endif +/* swap backslash and backspace */ +#ifndef BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE +#define BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE KC_BSLASH +#endif + + +/* + * change default layer + */ #ifndef BOOTMAGIC_DEFAULT_LAYER_0_KEY #define BOOTMAGIC_DEFAULT_LAYER_0_KEY KC_0 #endif @@ -33,6 +68,7 @@ #define BOOTMAGIC_DEFAULT_LAYER_3_KEY KC_3 #endif + void bootmagic(void); bool bootmagic_scan_keycode(uint8_t keycode); diff --git a/common/command.c b/common/command.c index b82d1884ce..cf8d969f81 100644 --- a/common/command.c +++ b/common/command.c @@ -133,8 +133,8 @@ static void print_eeprom_config(void) eebyte = eeconfig_read_defalt_layer(); print("defalt_layer: "); print_hex8(eebyte); print("\n"); - eebyte = eeconfig_read_modifier(); - print("modifiers: "); print_hex8(eebyte); print("\n"); + eebyte = eeconfig_read_keyconf(); + print("keyconf: "); print_hex8(eebyte); print("\n"); } static bool command_common(uint8_t code) diff --git a/common/eeconfig.c b/common/eeconfig.c index a5834aa2c7..f536dc06c9 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -6,11 +6,11 @@ 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); + 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_KEYCONF, 0); + eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); } bool eeconfig_initialized(void) @@ -18,12 +18,11 @@ 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); } +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); } +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); } - +uint8_t eeconfig_read_keyconf(void) { return eeprom_read_byte(EECONFIG_KEYCONF); } +void eeconfig_write_keyconf(uint8_t val) { eeprom_write_byte(EECONFIG_KEYCONF, val); } diff --git a/common/eeconfig.h b/common/eeconfig.h index 088171f575..9cf2ff6802 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h @@ -26,21 +26,24 @@ along with this program. If not, see . #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_KEYCONF (uint8_t *)4 #define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 -/* config bit */ +/* debug 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) +/* keyconf bit */ +#define EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK (1<<0) +#define EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL (1<<1) +#define EECONFIG_KEYCONF_SWAP_LALT_LGUI (1<<2) +#define EECONFIG_KEYCONF_SWAP_RALT_RGUI (1<<3) +#define EECONFIG_KEYCONF_NO_GUI (1<<4) +#define EECONFIG_KEYCONF_SWAP_GRAVE_ESC (1<<5) +#define EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE (1<<6) bool eeconfig_initialized(void); @@ -53,7 +56,7 @@ 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); +uint8_t eeconfig_read_keyconf(void); +void eeconfig_write_keyconf(uint8_t val); #endif From db024b6b1803eb752070422e7240b1ffe52d39f6 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 00:05:35 +0900 Subject: [PATCH 07/13] Add --relax for size optimization to gh60 --- keyboard/gh60/Makefile.lufa | 3 +++ 1 file changed, 3 insertions(+) diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa index 2076c919ca..b885b7dfa1 100644 --- a/keyboard/gh60/Makefile.lufa +++ b/keyboard/gh60/Makefile.lufa @@ -107,6 +107,9 @@ CONSOLE_ENABLE = yes # Console for debug(+400) #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +# Optimize size but this may cause error "relocation truncated to fit" +EXTRALDFLAGS = -Wl,--relax + # Search Path VPATH += $(TARGET_DIR) VPATH += $(TOP_DIR) From 09bd1aef12e42b44f90b8275ae95b578294957c0 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 00:14:58 +0900 Subject: [PATCH 08/13] Rename HOST_* to PROTOCOL_* in protocol/*.mk --- common/command.c | 10 +++++----- common/report.h | 2 +- protocol/iwrap.mk | 2 +- protocol/iwrap/main.c | 14 +++++++------- protocol/pjrc.mk | 3 --- protocol/vusb.mk | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/common/command.c b/common/command.c index cf8d969f81..a18eb78006 100644 --- a/common/command.c +++ b/common/command.c @@ -34,14 +34,14 @@ along with this program. If not, see . #include "mousekey.h" #endif -#ifdef HOST_PJRC +#ifdef PROTOCOL_PJRC # include "usb_keyboard.h" # ifdef EXTRAKEY_ENABLE # include "usb_extra.h" # endif #endif -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB # include "usbdrv.h" #endif @@ -238,7 +238,7 @@ static bool command_common(uint8_t code) case KC_S: print("\n\n----- Status -----\n"); print_val_hex8(host_keyboard_leds()); -#ifdef HOST_PJRC +#ifdef PROTOCOL_PJRC print_val_hex8(UDCON); print_val_hex8(UDIEN); print_val_hex8(UDINT); @@ -248,7 +248,7 @@ static bool command_common(uint8_t code) print_val_hex8(usb_keyboard_idle_count); #endif -#ifdef HOST_VUSB +#ifdef PROTOCOL_PJRC # if USB_COUNT_SOF print_val_hex8(usbSofCount); # endif @@ -267,7 +267,7 @@ static bool command_common(uint8_t code) #ifdef EXTRAKEY_ENABLE case KC_PSCREEN: // TODO: Power key should take this feature? otherwise any key during suspend. -#ifdef HOST_PJRC +#ifdef PROTOCOL_PJRC if (suspend && remote_wakeup) { usb_remote_wakeup(); } else { diff --git a/common/report.h b/common/report.h index 0995189b39..4801027687 100644 --- a/common/report.h +++ b/common/report.h @@ -71,7 +71,7 @@ along with this program. If not, see . /* key report size(NKRO or boot mode) */ -#if defined(HOST_PJRC) +#if defined(PROTOCOL_PJRC) # include "usb.h" # if defined(KBD2_REPORT_KEYS) && KBD2_REPORT_KEYS > KBD_REPORT_KEYS # define REPORT_KEYS KBD2_REPORT_KEYS diff --git a/protocol/iwrap.mk b/protocol/iwrap.mk index 9c83075a4a..96aa4140ca 100644 --- a/protocol/iwrap.mk +++ b/protocol/iwrap.mk @@ -1,6 +1,6 @@ IWRAP_DIR = protocol/iwrap -OPT_DEFS += -DHOST_IWRAP +OPT_DEFS += -DPROTOCOL_IWRAP SRC += $(IWRAP_DIR)/iwrap.c \ $(IWRAP_DIR)/suart.S \ diff --git a/protocol/iwrap/main.c b/protocol/iwrap/main.c index 05a67337fd..ac83280f13 100644 --- a/protocol/iwrap/main.c +++ b/protocol/iwrap/main.c @@ -26,7 +26,7 @@ along with this program. If not, see . #include "matrix.h" #include "host.h" #include "iwrap.h" -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB # include "vusb.h" # include "usbdrv.h" #endif @@ -78,7 +78,7 @@ static void pullup_pins(void) */ -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB static void disable_vusb(void) { // disable interrupt & disconnect to prevent host from enumerating @@ -131,7 +131,7 @@ int main(void) //pullup_pins(); //set_prr(); -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB disable_vusb(); #endif uart_init(115200); @@ -159,12 +159,12 @@ int main(void) last_timer = timer_read(); while (true) { -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB if (host_get_driver() == vusb_driver()) usbPoll(); #endif keyboard_task(); -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB if (host_get_driver() == vusb_driver()) vusb_transfer_keyboard(); #endif @@ -258,7 +258,7 @@ static uint8_t console_command(uint8_t c) print("r: reset. software reset by watchdog\n"); print("i: insomniac. prevent KB from sleeping\n"); print("c: iwrap_call. CALL for BT connection.\n"); -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB print("u: USB mode. switch to USB.\n"); print("w: BT mode. switch to Bluetooth.\n"); #endif @@ -281,7 +281,7 @@ static uint8_t console_command(uint8_t c) print("iwrap_call()\n"); iwrap_call(); return 1; -#ifdef HOST_VUSB +#ifdef PROTOCOL_VUSB case 'u': print("USB mode\n"); init_vusb(); diff --git a/protocol/pjrc.mk b/protocol/pjrc.mk index f5693ba99d..27f908b1c2 100644 --- a/protocol/pjrc.mk +++ b/protocol/pjrc.mk @@ -19,7 +19,4 @@ endif VPATH += $(TOP_DIR)/$(PJRC_DIR) # This indicates using LUFA stack -# TODO: remove HOST_PJRC -OPT_DEFS += -DHOST_PJRC OPT_DEFS += -DPROTOCOL_PJRC - diff --git a/protocol/vusb.mk b/protocol/vusb.mk index 4c5058115b..77b1c6337b 100644 --- a/protocol/vusb.mk +++ b/protocol/vusb.mk @@ -1,6 +1,6 @@ VUSB_DIR = protocol/vusb -OPT_DEFS += -DHOST_VUSB +OPT_DEFS += -DPROTOCOL_VUSB SRC += $(VUSB_DIR)/main.c \ $(VUSB_DIR)/vusb.c \ From e4fbaf30be00d73a3fab2aee24c7a522a0ecdd31 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 01:55:41 +0900 Subject: [PATCH 09/13] Add keyconf in eeconfig.c --- common/command.c | 9 +++++++++ common/eeconfig.h | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/common/command.c b/common/command.c index a18eb78006..d7ba3f232a 100644 --- a/common/command.c +++ b/common/command.c @@ -135,6 +135,15 @@ static void print_eeprom_config(void) eebyte = eeconfig_read_keyconf(); print("keyconf: "); print_hex8(eebyte); print("\n"); + + keyconf kc = (keyconf){ .raw = eebyte }; + print("keyconf.swap_control_capslock: "); print_hex8(kc.swap_control_capslock); print("\n"); + print("keyconf.capslock_to_control: "); print_hex8(kc.capslock_to_control); print("\n"); + print("keyconf.swap_lalt_lgui: "); print_hex8(kc.swap_lalt_lgui); print("\n"); + print("keyconf.swap_ralt_rgui: "); print_hex8(kc.swap_ralt_rgui); print("\n"); + print("keyconf.no_gui: "); print_hex8(kc.no_gui); print("\n"); + print("keyconf.swap_grave_esc: "); print_hex8(kc.swap_grave_esc); print("\n"); + print("keyconf.swap_backslash_backspace: "); print_hex8(kc.swap_backslash_backspace); print("\n"); } static bool command_common(uint8_t code) diff --git a/common/eeconfig.h b/common/eeconfig.h index 9cf2ff6802..2786995a29 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h @@ -46,6 +46,21 @@ along with this program. If not, see . #define EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE (1<<6) +/* XXX: Not portable. Bit field order depends on implementation */ +typedef union { + uint8_t raw; + struct { + bool swap_control_capslock:1; + bool capslock_to_control:1; + bool swap_lalt_lgui:1; + bool swap_ralt_rgui:1; + bool no_gui:1; + bool swap_grave_esc:1; + bool swap_backslash_backspace:1; + bool reserved:1; + }; +} keyconf; + bool eeconfig_initialized(void); void eeconfig_init(void); From fe2230cf60efdc5dafb85356e54b8b87cd52c3a3 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 13:32:46 +0900 Subject: [PATCH 10/13] Add default value to BOOTLOADER_SIZE --- common/bootloader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/bootloader.c b/common/bootloader.c index f9802d36c5..43a7e47ce2 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -19,7 +19,8 @@ * USBaspLoader 2048 */ #ifndef BOOTLOADER_SIZE -#warn To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#define BOOTLOADER_SIZE 4096 #endif #define FLASH_SIZE (FLASHEND + 1L) From 1d5bbb55f28eb2e9eff0543753b8cb85f3b94282 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 14:39:06 +0900 Subject: [PATCH 11/13] Fix legacy keymap support - need to define USE_LEGACY_KEYMAP to use legacy keymap --- common/keymap.c | 86 ++++++++++++++++++++---------------- common/keymap.h | 21 +++++---- converter/pc98_usb/config.h | 3 -- converter/sun_usb/config.h | 14 +++++- keyboard/gh60/config.h | 24 ++++------ keyboard/hhkb/config.h | 3 -- keyboard/hhkb/config_iwrap.h | 3 -- 7 files changed, 82 insertions(+), 72 deletions(-) diff --git a/common/keymap.c b/common/keymap.c index aa8d944a79..ace3f49b69 100644 --- a/common/keymap.c +++ b/common/keymap.c @@ -26,7 +26,7 @@ along with this program. If not, see . static action_t keycode_to_action(uint8_t keycode); -#ifdef USE_KEYMAP_V2 + /* converts key to action */ action_t action_for_key(uint8_t layer, key_t key) { @@ -38,42 +38,20 @@ action_t action_for_key(uint8_t layer, key_t key) return keycode_to_action(keycode); } } -#else -/* - * legacy keymap support - */ -/* translation for legacy keymap */ -action_t action_for_key(uint8_t layer, key_t key) -{ - /* convert from legacy keycode to action */ - /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */ - uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col); - action_t action; - switch (keycode) { - case KC_FN0 ... KC_FN31: - { - uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); - uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); - if (key) { - action.code = ACTION_KEYMAP_TAP_KEY(layer, key); - } else { - action.code = ACTION_KEYMAP_MOMENTARY(layer); - } - } - return action; - default: - return keycode_to_action(keycode); - } -} -#endif +/* Macro */ __attribute__ ((weak)) -const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; } +const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) +{ + return MACRO_NONE; +} +/* Function */ __attribute__ ((weak)) -void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {} - +void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) +{ +} @@ -83,14 +61,9 @@ static action_t keycode_to_action(uint8_t keycode) action_t action; switch (keycode) { case KC_A ... KC_EXSEL: + case KC_LCTRL ... KC_RGUI: action.code = ACTION_KEY(keycode); break; - case KC_LCTRL ... KC_LGUI: - action.code = ACTION_LMOD(keycode); - break; - case KC_RCTRL ... KC_RGUI: - action.code = ACTION_RMOD(keycode); - break; case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode)); break; @@ -109,3 +82,40 @@ static action_t keycode_to_action(uint8_t keycode) } return action; } + + + +#ifdef USE_LEGACY_KEYMAP +/* + * Legacy keymap support + * Consider using new keymap API instead. + */ +__attribute__ ((weak)) +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + return keymap_get_keycode(layer, key.row, key.col); +} + + +/* Legacy keymap support */ +__attribute__ ((weak)) +action_t keymap_fn_to_action(uint8_t keycode) +{ + action_t action = { .code = ACTION_NO }; + switch (keycode) { + case KC_FN0 ... KC_FN31: + { + uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); + uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); + if (key) { + action.code = ACTION_KEYMAP_TAP_KEY(layer, key); + } else { + action.code = ACTION_KEYMAP_MOMENTARY(layer); + } + } + return action; + default: + return action; + } +} +#endif diff --git a/common/keymap.h b/common/keymap.h index 0c483483fb..7efd91f704 100644 --- a/common/keymap.h +++ b/common/keymap.h @@ -23,24 +23,29 @@ along with this program. If not, see . #include "action.h" -#ifdef USE_KEYMAP_V2 -/* translates key to keycode - * layer: 0-15 for base layers - * 16-31 for overlays - */ +/* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); + /* translates Fn keycode to action */ action_t keymap_fn_to_action(uint8_t keycode); -#else -#warning "You are using LEGACY KEYAMP. Consider using NEW KEYMAP." + + + +#ifdef USE_LEGACY_KEYMAP /* - * legacy keymap support + * Legacy keymap + * Consider using new keymap API above instead. */ /* keycode of key */ +__attribute__ ((deprecated)) uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); + /* layer to move during press Fn key */ +__attribute__ ((deprecated)) uint8_t keymap_fn_layer(uint8_t fn_bits); + /* keycode to send when release Fn key without using */ +__attribute__ ((deprecated)) uint8_t keymap_fn_keycode(uint8_t fn_bits); #endif diff --git a/converter/pc98_usb/config.h b/converter/pc98_usb/config.h index 4f91c07ce4..b8d676e4cf 100644 --- a/converter/pc98_usb/config.h +++ b/converter/pc98_usb/config.h @@ -30,9 +30,6 @@ along with this program. If not, see . #define MATRIX_ROWS 16 #define MATRIX_COLS 8 -/* To use new keymap framework */ -#define USE_KEYMAP_V2 - /* key combination for command */ #define IS_COMMAND() ( \ host_get_first_key() == KC_CANCEL \ diff --git a/converter/sun_usb/config.h b/converter/sun_usb/config.h index 65ce9daf61..32303cd32b 100644 --- a/converter/sun_usb/config.h +++ b/converter/sun_usb/config.h @@ -25,12 +25,10 @@ along with this program. If not, see . #define PRODUCT Sun keyboard converter #define DESCRIPTION converts Sun keyboard protocol into USB - /* matrix size */ #define MATRIX_ROWS 16 #define MATRIX_COLS 8 - /* key combination for command */ #define IS_COMMAND() ( \ keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) || \ @@ -38,6 +36,18 @@ along with this program. If not, see . keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ ) +/* legacy keymap support */ +#define USE_LEGACY_KEYMAP + +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 + */ +#define BOOTLOADER_SIZE 4096 + /* Serial(USART) configuration * asynchronous, negative logic, 1200baud, no flow control diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h index be4d72384e..cd98395eb5 100644 --- a/keyboard/gh60/config.h +++ b/keyboard/gh60/config.h @@ -25,20 +25,8 @@ along with this program. If not, see . #define DEVICE_VER 0x0001 #define MANUFACTURER geekhack #define PRODUCT GH60 -/* message strings */ #define DESCRIPTION t.m.k. keyboard firmware for GH60 - -/* Boot Section Size in *BYTEs* - * Teensy halfKay 512 - * Teensy++ halfKay 1024 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 - * USBaspLoader 2048 - */ -#define BOOTLOADER_SIZE 4096 - - /* matrix size */ #define MATRIX_ROWS 5 #define MATRIX_COLS 14 @@ -49,14 +37,20 @@ along with this program. If not, see . /* Set 0 if need no debouncing */ #define DEBOUNCE 5 -/* To use new keymap framework */ -#define USE_KEYMAP_V2 - /* key combination for command */ #define IS_COMMAND() ( \ keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ ) +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 + */ +#define BOOTLOADER_SIZE 4096 + /* * Boot magic keys * call some function by pressing key when pluging cable or powering on. diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h index 3bfeb45ed4..ef2958981c 100644 --- a/keyboard/hhkb/config.h +++ b/keyboard/hhkb/config.h @@ -44,9 +44,6 @@ along with this program. If not, see . #define MATRIX_ROWS 8 #define MATRIX_COLS 8 -/* To use new keymap framework */ -#define USE_KEYMAP_V2 - /* * Boot magic keys * call some function by pressing key when pluging cable or powering on. diff --git a/keyboard/hhkb/config_iwrap.h b/keyboard/hhkb/config_iwrap.h index 2c18cd817a..7a4ec37118 100644 --- a/keyboard/hhkb/config_iwrap.h +++ b/keyboard/hhkb/config_iwrap.h @@ -41,9 +41,6 @@ along with this program. If not, see . #define MATRIX_ROWS 8 #define MATRIX_COLS 8 -/* To use new keymap framework */ -#define USE_KEYMAP_V2 - /* key combination for command */ #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) From d055e0633e36e97802d60554f6002e47021ba5fd Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 15:10:56 +0900 Subject: [PATCH 12/13] Fix debug parameter setting in eeconfig --- common/bootmagic.c | 4 ++-- common/bootmagic.h | 4 ++-- common/eeconfig.c | 14 ++++++++++++-- common/eeconfig.h | 10 +++++++++- common/keyboard.c | 11 ++++++----- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/common/bootmagic.c b/common/bootmagic.c index 46fbc180a4..388099e2e6 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -10,12 +10,12 @@ void bootmagic(void) { + if (!BOOTMAGIC_IS_ENABLED()) { return; } + /* do scans in case of bounce */ uint8_t scan = 100; while (scan--) { matrix_scan(); _delay_ms(1); } - if (!BOOTMAGIC_IS_ENABLE()) { return; } - if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) { bootloader_jump(); } diff --git a/common/bootmagic.h b/common/bootmagic.h index d32a5bef88..5791b221f4 100644 --- a/common/bootmagic.h +++ b/common/bootmagic.h @@ -2,8 +2,8 @@ #define BOOTMAGIC_H -#ifndef BOOTMAGIC_IS_ENABLE -#define BOOTMAGIC_IS_ENABLE() true +#ifndef BOOTMAGIC_IS_ENABLED +#define BOOTMAGIC_IS_ENABLED() true #endif /* kick up bootloader */ diff --git a/common/eeconfig.c b/common/eeconfig.c index f536dc06c9..cea3810ee3 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -13,9 +13,19 @@ void eeconfig_init(void) eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); } -bool eeconfig_initialized(void) +void eeconfig_enable(void) { - return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); + eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); +} + +void eeconfig_disable(void) +{ + eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); +} + +bool eeconfig_is_enabled(void) +{ + return EECONFIG_IS_ENABLED() && (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); } uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } diff --git a/common/eeconfig.h b/common/eeconfig.h index 2786995a29..3e195478b5 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h @@ -20,6 +20,10 @@ along with this program. If not, see . #include +#ifndef EECONFIG_IS_ENABLED +#define EECONFIG_IS_ENABLED() true +#endif + #define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED /* eeprom parameteter address */ @@ -61,10 +65,14 @@ typedef union { }; } keyconf; -bool eeconfig_initialized(void); +bool eeconfig_is_enabled(void); void eeconfig_init(void); +void eeconfig_enable(void); + +void eeconfig_disable(void); + uint8_t eeconfig_read_debug(void); void eeconfig_write_debug(uint8_t val); diff --git a/common/keyboard.c b/common/keyboard.c index 0a0bacd433..1acb79861d 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -66,13 +66,14 @@ void keyboard_init(void) bootmagic(); - if (eeconfig_initialized()) { + if (eeconfig_is_enabled()) { 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); + // ignored if debug is enabled by program before. + if (!debug_enable) debug_enable = (config & EECONFIG_DEBUG_ENABLE); + if (!debug_matrix) debug_matrix = (config & EECONFIG_DEBUG_MATRIX); + if (!debug_keyboard) debug_keyboard = (config & EECONFIG_DEBUG_KEYBOARD); + if (!debug_mouse) debug_mouse = (config & EECONFIG_DEBUG_MOUSE); } else { eeconfig_init(); } From ef8439bddb2d7fe5fd95faf2b6bebd8235acf160 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 15:28:14 +0900 Subject: [PATCH 13/13] Add build option BOOTMAGIC_ENABLE --- common.mk | 8 ++++++-- common/command.c | 4 ++++ common/keyboard.c | 6 +++--- keyboard/gh60/Makefile.lufa | 4 ++-- keyboard/gh60/Makefile.pjrc | 9 ++++----- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/common.mk b/common.mk index 2735f5becf..f9faf2f95b 100644 --- a/common.mk +++ b/common.mk @@ -10,12 +10,16 @@ SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/print.c \ $(COMMON_DIR)/debug.c \ $(COMMON_DIR)/bootloader.c \ - $(COMMON_DIR)/bootmagic.c \ - $(COMMON_DIR)/eeconfig.c \ $(COMMON_DIR)/util.c # Option modules +ifdef BOOTMAGIC_ENABLE + SRC += $(COMMON_DIR)/bootmagic.c + SRC += $(COMMON_DIR)/eeconfig.c + OPT_DEFS += -DBOOTMAGIC_ENABLE +endif + ifdef MOUSEKEY_ENABLE SRC += $(COMMON_DIR)/mousekey.c OPT_DEFS += -DMOUSEKEY_ENABLE diff --git a/common/command.c b/common/command.c index d7ba3f232a..372ca291e2 100644 --- a/common/command.c +++ b/common/command.c @@ -123,6 +123,7 @@ static void command_common_help(void) print("Paus: jump to bootloader\n"); } +#ifdef BOOTMAGIC_ENABLE static void print_eeprom_config(void) { uint8_t eebyte; @@ -145,15 +146,18 @@ static void print_eeprom_config(void) print("keyconf.swap_grave_esc: "); print_hex8(kc.swap_grave_esc); print("\n"); print("keyconf.swap_backslash_backspace: "); print_hex8(kc.swap_backslash_backspace); print("\n"); } +#endif static bool command_common(uint8_t code) { static host_driver_t *host_driver = 0; switch (code) { +#ifdef BOOTMAGIC_ENABLE case KC_E: print("eeprom config\n"); print_eeprom_config(); break; +#endif case KC_CAPSLOCK: if (host_get_driver()) { host_driver = host_get_driver(); diff --git a/common/keyboard.c b/common/keyboard.c index 1acb79861d..401fdb4e17 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -29,10 +29,8 @@ along with this program. If not, see . #include "util.h" #include "sendchar.h" #include "bootmagic.h" -#ifdef MOUSEKEY_ENABLE -#include "mousekey.h" -#endif #include "eeconfig.h" +#include "mousekey.h" #ifdef MATRIX_HAS_GHOST @@ -64,6 +62,7 @@ void keyboard_init(void) ps2_mouse_init(); #endif +#ifdef BOOTMAGIC_ENABLE bootmagic(); if (eeconfig_is_enabled()) { @@ -77,6 +76,7 @@ void keyboard_init(void) } else { eeconfig_init(); } +#endif } /* diff --git a/keyboard/gh60/Makefile.lufa b/keyboard/gh60/Makefile.lufa index b885b7dfa1..a5ff609a77 100644 --- a/keyboard/gh60/Makefile.lufa +++ b/keyboard/gh60/Makefile.lufa @@ -47,8 +47,7 @@ TOP_DIR = ../.. # Directory keyboard dependent files exist TARGET_DIR = . - -# List C source files here. (C dependencies are automatically generated.) +# project specific files SRC += keymap.c \ matrix.c \ led.c @@ -100,6 +99,7 @@ F_USB = $(F_CPU) # Build Options # comment out to disable the options. # +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = yes # Mouse keys(+4700) EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = yes # Console for debug(+400) diff --git a/keyboard/gh60/Makefile.pjrc b/keyboard/gh60/Makefile.pjrc index 2538c0c6bb..f03ca9416d 100644 --- a/keyboard/gh60/Makefile.pjrc +++ b/keyboard/gh60/Makefile.pjrc @@ -47,7 +47,7 @@ TOP_DIR = ../.. # Directory keyboard dependent files exist TARGET_DIR = . -# keyboard dependent files +# project specific files SRC = keymap.c \ matrix.c \ led.c @@ -57,10 +57,8 @@ CONFIG_H = config.h # MCU name, you MUST set this to match the board you are using # type "make clean" after changing this, so all files will be rebuilt -#MCU = at90usb162 # Teensy 1.0 -MCU = atmega32u4 # Teensy 2.0 -#MCU = at90usb646 # Teensy++ 1.0 -#MCU = at90usb1286 # Teensy++ 2.0 +MCU = atmega32u4 +#MCU = at90usb1286 # Processor frequency. @@ -79,6 +77,7 @@ OPT_DEFS += -DBOOT_SIZE=4096 # Build Options # comment out to disable the options. # +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = yes # Mouse keys(+5000) EXTRAKEY_ENABLE = yes # Audio control and System control(+600) NKRO_ENABLE = yes # USB Nkey Rollover(+500)