71381457fa
d5c5ac6 Merge branch 'develop' 5957682 Merge branch 'hotfix-mediakey' a478c62 Merge branch 'hotfix-vusb' cccebfe Merge branch 'njbair-docfix' 0aaab57 Clean up wording in keymap example dc8bbc3 Clarify layer precedence 9e0b4c1 clarify layer documentation 915eb48 core: Fix media/consumer keys 88f90f3 Fix for VUSB configuration 3e290cd Fix including board.mk in chibios.mk 32c69e0 Merge branch 'newapi' into develop c9a56f9 Merge remote-tracking branch 'flabbergast/chibios' into develop 01e33ea Fix chibios and mbed common.mk for hook.c bea79d9 hook: Change func name of usb events 3e97536 hook: Change file and func names(*_hook -> hook_*) c286d8c Merge pull request #10 from fredizzimo/chibios-contrib2 062d74e Update ChibiOS instructions d47150f Add support for new version of ChibiOS and Contrib 62b5401 Chibios: disable LTO (link-time optimisation). c64e9aa hooks: Fix for LUFA 54e68b0 hooks: Remove led_restore_hook 325c09d Chibios: make the default bootloader_jump redefinable (weak). 078c722 Chibios: fix STM32_BOOTLOADER_ADDRESS name. e73cfe5 hooks: Fix for keyboard LED update e6120c5 Implement basic hooks. 7c370e9 Chibios: Update the main chibios README. 7f0198d Chibios: implement sleep LED for STM32. afef9b4 Fix hard-coded path of CHIBIOS 95c5b19 Merge pull request #7 from fredizzimo/sysvsize 27128a8 Sysv format for ChibiOS arm-none-eabi-size d4b8e68 core: Fix chibios user compile options b85d462 Merge branch 'chibios' of https://github.com/flabbergast/tmk_keyboard into flabbergast_chibios de41aa1 core: Fix ps2_mouse.c debug print d79d925 Removed duplicate debug message code and surrounded it with IFDEF as needed 8f28589 Chibios: Revert common.mk change (fix AVR linking problem). ec9eff2 Chibios: cleanup usb_main code. 28c4665 Chibios: Fix a HardFault bug (wait after start). git-subtree-dir: tmk_core git-subtree-split: d5c5ac63e60dfc6da6661a21bd968b4d577a27d5
202 lines
5.8 KiB
C
202 lines
5.8 KiB
C
/*
|
|
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/>.
|
|
*/
|
|
#include "keymap.h"
|
|
#include "report.h"
|
|
#include "keycode.h"
|
|
#include "action_layer.h"
|
|
#include "action.h"
|
|
#include "action_macro.h"
|
|
#include "wait.h"
|
|
#include "debug.h"
|
|
#include "bootloader.h"
|
|
|
|
#ifdef BOOTMAGIC_ENABLE
|
|
extern keymap_config_t keymap_config;
|
|
#endif
|
|
|
|
static action_t keycode_to_action(uint8_t keycode);
|
|
|
|
|
|
/* converts key to action */
|
|
action_t action_for_key(uint8_t layer, keypos_t key)
|
|
{
|
|
uint8_t keycode = keymap_key_to_keycode(layer, key);
|
|
switch (keycode) {
|
|
case KC_FN0 ... KC_FN31:
|
|
return keymap_fn_to_action(keycode);
|
|
#ifdef BOOTMAGIC_ENABLE
|
|
case KC_CAPSLOCK:
|
|
case KC_LOCKING_CAPS:
|
|
if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
|
|
return keycode_to_action(KC_LCTL);
|
|
}
|
|
return keycode_to_action(keycode);
|
|
case KC_LCTL:
|
|
if (keymap_config.swap_control_capslock) {
|
|
return keycode_to_action(KC_CAPSLOCK);
|
|
}
|
|
return keycode_to_action(KC_LCTL);
|
|
case KC_LALT:
|
|
if (keymap_config.swap_lalt_lgui) {
|
|
if (keymap_config.no_gui) {
|
|
return keycode_to_action(ACTION_NO);
|
|
}
|
|
return keycode_to_action(KC_LGUI);
|
|
}
|
|
return keycode_to_action(KC_LALT);
|
|
case KC_LGUI:
|
|
if (keymap_config.swap_lalt_lgui) {
|
|
return keycode_to_action(KC_LALT);
|
|
}
|
|
if (keymap_config.no_gui) {
|
|
return keycode_to_action(ACTION_NO);
|
|
}
|
|
return keycode_to_action(KC_LGUI);
|
|
case KC_RALT:
|
|
if (keymap_config.swap_ralt_rgui) {
|
|
if (keymap_config.no_gui) {
|
|
return keycode_to_action(ACTION_NO);
|
|
}
|
|
return keycode_to_action(KC_RGUI);
|
|
}
|
|
return keycode_to_action(KC_RALT);
|
|
case KC_RGUI:
|
|
if (keymap_config.swap_ralt_rgui) {
|
|
return keycode_to_action(KC_RALT);
|
|
}
|
|
if (keymap_config.no_gui) {
|
|
return keycode_to_action(ACTION_NO);
|
|
}
|
|
return keycode_to_action(KC_RGUI);
|
|
case KC_GRAVE:
|
|
if (keymap_config.swap_grave_esc) {
|
|
return keycode_to_action(KC_ESC);
|
|
}
|
|
return keycode_to_action(KC_GRAVE);
|
|
case KC_ESC:
|
|
if (keymap_config.swap_grave_esc) {
|
|
return keycode_to_action(KC_GRAVE);
|
|
}
|
|
return keycode_to_action(KC_ESC);
|
|
case KC_BSLASH:
|
|
if (keymap_config.swap_backslash_backspace) {
|
|
return keycode_to_action(KC_BSPACE);
|
|
}
|
|
return keycode_to_action(KC_BSLASH);
|
|
case KC_BSPACE:
|
|
if (keymap_config.swap_backslash_backspace) {
|
|
return keycode_to_action(KC_BSLASH);
|
|
}
|
|
return keycode_to_action(KC_BSPACE);
|
|
#endif
|
|
default:
|
|
return keycode_to_action(keycode);
|
|
}
|
|
}
|
|
|
|
|
|
/* Macro */
|
|
__attribute__ ((weak))
|
|
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
|
{
|
|
(void)record;
|
|
(void)id;
|
|
(void)opt;
|
|
return MACRO_NONE;
|
|
}
|
|
|
|
/* Function */
|
|
__attribute__ ((weak))
|
|
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
|
|
{
|
|
(void)record;
|
|
(void)id;
|
|
(void)opt;
|
|
}
|
|
|
|
|
|
|
|
/* translates keycode to action */
|
|
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_SYSTEM_POWER ... KC_SYSTEM_WAKE:
|
|
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
|
|
break;
|
|
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
|
|
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
|
|
break;
|
|
case KC_MS_UP ... KC_MS_ACCEL2:
|
|
action.code = ACTION_MOUSEKEY(keycode);
|
|
break;
|
|
case KC_TRNS:
|
|
action.code = ACTION_TRANSPARENT;
|
|
break;
|
|
case KC_BOOTLOADER:
|
|
clear_keyboard();
|
|
wait_ms(50);
|
|
bootloader_jump(); // not return
|
|
break;
|
|
default:
|
|
action.code = ACTION_NO;
|
|
break;
|
|
}
|
|
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, keypos_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_LAYER_TAP_KEY(layer, key);
|
|
} else {
|
|
action.code = ACTION_LAYER_MOMENTARY(layer);
|
|
}
|
|
}
|
|
return action;
|
|
default:
|
|
return action;
|
|
}
|
|
}
|
|
#endif
|