diff options
author | tmk <nobody@nowhere> | 2013-03-11 07:35:55 +0100 |
---|---|---|
committer | tmk <nobody@nowhere> | 2013-03-11 07:35:55 +0100 |
commit | 48433a5e9988647a737234c11dd9db4080fd4a4e (patch) | |
tree | 4af03a20658cb7e6cd43f9c65dfa002f1b544332 /common | |
parent | 5d6b848a157a2e94859949961297d40da6a77527 (diff) | |
parent | ef8439bddb2d7fe5fd95faf2b6bebd8235acf160 (diff) | |
download | qmk_firmware-48433a5e9988647a737234c11dd9db4080fd4a4e.tar.gz qmk_firmware-48433a5e9988647a737234c11dd9db4080fd4a4e.tar.xz |
Merge branch 'eeprom_config'
Diffstat (limited to 'common')
-rw-r--r-- | common/bootloader.c | 116 | ||||
-rw-r--r-- | common/bootmagic.c | 67 | ||||
-rw-r--r-- | common/bootmagic.h | 75 | ||||
-rw-r--r-- | common/command.c | 43 | ||||
-rw-r--r-- | common/eeconfig.c | 38 | ||||
-rw-r--r-- | common/eeconfig.h | 85 | ||||
-rw-r--r-- | common/keyboard.c | 39 | ||||
-rw-r--r-- | common/keymap.c | 86 | ||||
-rw-r--r-- | common/keymap.h | 21 | ||||
-rw-r--r-- | common/report.h | 2 |
10 files changed, 471 insertions, 101 deletions
diff --git a/common/bootloader.c b/common/bootloader.c index 6e04efbbd..43a7e47ce 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -1,45 +1,106 @@ +#include <stdint.h> +#include <stdbool.h> #include <avr/io.h> #include <avr/interrupt.h> +#include <avr/wdt.h> #include <util/delay.h> #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 <LUFA/Drivers/USB/USB.h> +#endif + + +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 */ +#ifndef BOOTLOADER_SIZE +#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#define BOOTLOADER_SIZE 4096 +#endif -// TODO: support usbasp -/* Boot Section Size in bytes - * Teensy halfKay 512 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 +#define FLASH_SIZE (FLASHEND + 1L) +#define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) + + +/* + * Entering the Bootloader via Software + * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html */ -#ifndef BOOT_SIZE -#define BOOT_SIZE 512 +#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 + +#ifdef PROTOCOL_PJRC + cli(); + UDCON = 1; + USBCON = (1<<FRZCLK); + UCSR1B = 0; + _delay_ms(5); #endif -#define FLASH_SIZE (FLASHEND + 1) -#define BOOTLOADER_START (FLASHEND - BOOT_SIZE) + // watchdog reset + reset_key = BOOTLOADER_RESET_KEY; + wdt_enable(WDTO_250MS); + for (;;); +} + +/* this runs before main() */ +void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); +void bootloader_jump_after_watchdog_reset(void) +{ + if ((MCUSR & (1<<WDRF)) && reset_key == BOOTLOADER_RESET_KEY) { + reset_key = 0; + + // My custom USBasploader requires this to come up. + MCUSR = 0; + + // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog. + MCUSR &= ~(1<<WDRF); + wdt_disable(); + + ((void (*)(void))BOOTLOADER_START)(); + } +} + + +#if 0 +/* Jumping To The Bootloader + * http://www.pjrc.com/teensy/jump_to_bootloader.html + * + * This method doen't work when using LUFA. idk why. + * - needs to initialize more regisers or interrupt setting? + */ 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<<FRZCLK); // disable USB + USBCON = (1<<FRZCLK); UCSR1B = 0; _delay_ms(5); -#else - // This makes custom USBasploader come up. - MCUSR = 0; #endif + /* + * Initialize + */ #if defined(__AVR_AT90USB162__) EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0; @@ -62,10 +123,9 @@ void bootloader_jump(void) { PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; #endif - - // - //USBasp - // + /* + * USBaspLoader + */ #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) // This makes custom USBasploader come up. MCUSR = 0; @@ -81,7 +141,7 @@ void bootloader_jump(void) { ADCSRA = 0; TWCR = 0; UCSR0B = 0; #endif - // start Bootloader ((void (*)(void))BOOTLOADER_START)(); } +#endif diff --git a/common/bootmagic.c b/common/bootmagic.c new file mode 100644 index 000000000..388099e2e --- /dev/null +++ b/common/bootmagic.c @@ -0,0 +1,67 @@ +#include <stdint.h> +#include <stdbool.h> +#include <util/delay.h> +#include "matrix.h" +#include "keymap.h" +#include "eeconfig.h" +#include "bootloader.h" +#include "bootmagic.h" + + +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_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(); + } + + 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) +{ + 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<<c)) { + if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) { + return true; + } + } + } + } + return false; +} diff --git a/common/bootmagic.h b/common/bootmagic.h new file mode 100644 index 000000000..5791b221f --- /dev/null +++ b/common/bootmagic.h @@ -0,0 +1,75 @@ +#ifndef BOOTMAGIC_H +#define BOOTMAGIC_H + + +#ifndef BOOTMAGIC_IS_ENABLED +#define BOOTMAGIC_IS_ENABLED() true +#endif + +/* kick up bootloader */ +#ifndef BOOTMAGIC_BOOTLOADER_KEY +#define BOOTMAGIC_BOOTLOADER_KEY KC_B +#endif +/* debug enable */ +#ifndef BOOTMAGIC_DEBUG_ENABLE_KEY +#define BOOTMAGIC_DEBUG_ENABLE_KEY KC_D +#endif +/* eeprom clear */ +#ifndef BOOTMAGIC_EEPROM_CLEAR_KEY +#define BOOTMAGIC_EEPROM_CLEAR_KEY KC_BSPACE +#endif + +/* + * 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 +#ifndef BOOTMAGIC_DEFAULT_LAYER_1_KEY +#define BOOTMAGIC_DEFAULT_LAYER_1_KEY KC_1 +#endif +#ifndef BOOTMAGIC_DEFAULT_LAYER_2_KEY +#define BOOTMAGIC_DEFAULT_LAYER_2_KEY KC_2 +#endif +#ifndef BOOTMAGIC_DEFAULT_LAYER_3_KEY +#define BOOTMAGIC_DEFAULT_LAYER_3_KEY KC_3 +#endif + + +void bootmagic(void); +bool bootmagic_scan_keycode(uint8_t keycode); + +#endif diff --git a/common/command.c b/common/command.c index 202d531fd..372ca291e 100644 --- a/common/command.c +++ b/common/command.c @@ -27,20 +27,21 @@ 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 #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 @@ -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 boot config\n"); #ifdef NKRO_ENABLE print("n: toggle NKRO\n"); #endif @@ -121,10 +123,41 @@ static void command_common_help(void) print("Paus: jump to bootloader\n"); } +#ifdef BOOTMAGIC_ENABLE +static void print_eeprom_config(void) +{ + uint8_t eebyte; + + 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_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"); +} +#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(); @@ -218,7 +251,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); @@ -228,7 +261,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 @@ -247,7 +280,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/eeconfig.c b/common/eeconfig.c new file mode 100644 index 000000000..cea3810ee --- /dev/null +++ b/common/eeconfig.c @@ -0,0 +1,38 @@ +#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_KEYCONF, 0); + eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); +} + +void eeconfig_enable(void) +{ + 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); } +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_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 new file mode 100644 index 000000000..3e195478b --- /dev/null +++ b/common/eeconfig.h @@ -0,0 +1,85 @@ +/* +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> + +#ifndef EECONFIG_IS_ENABLED +#define EECONFIG_IS_ENABLED() true +#endif + +#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_KEYCONF (uint8_t *)4 +#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 + + +/* 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) + +/* 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) + + +/* 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_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); + +uint8_t eeconfig_read_defalt_layer(void); +void eeconfig_write_defalt_layer(uint8_t val); + +uint8_t eeconfig_read_keyconf(void); +void eeconfig_write_keyconf(uint8_t val); + +#endif diff --git a/common/keyboard.c b/common/keyboard.c index 91f321d9c..401fdb4e1 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -28,10 +28,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "command.h" #include "util.h" #include "sendchar.h" -#include "bootloader.h" -#ifdef MOUSEKEY_ENABLE +#include "bootmagic.h" +#include "eeconfig.h" #include "mousekey.h" -#endif #ifdef MATRIX_HAS_GHOST @@ -59,27 +58,25 @@ void keyboard_init(void) timer_init(); matrix_init(); - - /* 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()) debug_enable = true; -#endif - #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif + +#ifdef BOOTMAGIC_ENABLE + bootmagic(); + + if (eeconfig_is_enabled()) { + uint8_t config; + config = eeconfig_read_debug(); + // 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(); + } +#endif } /* diff --git a/common/keymap.c b/common/keymap.c index aa8d944a7..ace3f49b6 100644 --- a/common/keymap.c +++ b/common/keymap.c @@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. 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 0c483483f..7efd91f70 100644 --- a/common/keymap.h +++ b/common/keymap.h @@ -23,24 +23,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #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/common/report.h b/common/report.h index 0995189b3..480102768 100644 --- a/common/report.h +++ b/common/report.h @@ -71,7 +71,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* 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 |