Keyboard firmwares for Atmel AVR and Cortex-M
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

keymap.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. Copyright 2013 Jun Wako <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "keymap.h"
  15. #include "report.h"
  16. #include "keycode.h"
  17. #include "action_layer.h"
  18. #include "action.h"
  19. #include "action_macro.h"
  20. #include "debug.h"
  21. static action_t keycode_to_action(uint8_t keycode);
  22. /* converts key to action */
  23. __attribute__((__weak__))
  24. action_t action_for_key(uint8_t layer, keypos_t key)
  25. {
  26. return action_for_key_default(layer, key);
  27. }
  28. action_t action_for_key_default(uint8_t layer, keypos_t key)
  29. uint8_t keycode = keymap_key_to_keycode(layer, key);
  30. switch (keycode) {
  31. case KC_FN0 ... KC_FN31:
  32. return keymap_fn_to_action(keycode);
  33. #ifdef BOOTMAGIC_ENABLE
  34. case KC_CAPSLOCK:
  35. case KC_LOCKING_CAPS:
  36. if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
  37. return keycode_to_action(KC_LCTL);
  38. }
  39. return keycode_to_action(keycode);
  40. case KC_LCTL:
  41. if (keymap_config.swap_control_capslock) {
  42. return keycode_to_action(KC_CAPSLOCK);
  43. }
  44. return keycode_to_action(KC_LCTL);
  45. case KC_LALT:
  46. if (keymap_config.swap_lalt_lgui) {
  47. if (keymap_config.no_gui) {
  48. return keycode_to_action(ACTION_NO);
  49. }
  50. return keycode_to_action(KC_LGUI);
  51. }
  52. return keycode_to_action(KC_LALT);
  53. case KC_LGUI:
  54. if (keymap_config.swap_lalt_lgui) {
  55. return keycode_to_action(KC_LALT);
  56. }
  57. if (keymap_config.no_gui) {
  58. return keycode_to_action(ACTION_NO);
  59. }
  60. return keycode_to_action(KC_LGUI);
  61. case KC_RALT:
  62. if (keymap_config.swap_ralt_rgui) {
  63. if (keymap_config.no_gui) {
  64. return keycode_to_action(ACTION_NO);
  65. }
  66. return keycode_to_action(KC_RGUI);
  67. }
  68. return keycode_to_action(KC_RALT);
  69. case KC_RGUI:
  70. if (keymap_config.swap_ralt_rgui) {
  71. return keycode_to_action(KC_RALT);
  72. }
  73. if (keymap_config.no_gui) {
  74. return keycode_to_action(ACTION_NO);
  75. }
  76. return keycode_to_action(KC_RGUI);
  77. case KC_GRAVE:
  78. if (keymap_config.swap_grave_esc) {
  79. return keycode_to_action(KC_ESC);
  80. }
  81. return keycode_to_action(KC_GRAVE);
  82. case KC_ESC:
  83. if (keymap_config.swap_grave_esc) {
  84. return keycode_to_action(KC_GRAVE);
  85. }
  86. return keycode_to_action(KC_ESC);
  87. case KC_BSLASH:
  88. if (keymap_config.swap_backslash_backspace) {
  89. return keycode_to_action(KC_BSPACE);
  90. }
  91. return keycode_to_action(KC_BSLASH);
  92. case KC_BSPACE:
  93. if (keymap_config.swap_backslash_backspace) {
  94. return keycode_to_action(KC_BSLASH);
  95. }
  96. return keycode_to_action(KC_BSPACE);
  97. #endif
  98. default:
  99. return keycode_to_action(keycode);
  100. }
  101. }
  102. /* Macro */
  103. __attribute__ ((weak))
  104. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  105. {
  106. return MACRO_NONE;
  107. }
  108. /* Function */
  109. __attribute__ ((weak))
  110. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  111. {
  112. }
  113. /* translates keycode to action */
  114. static action_t keycode_to_action(uint8_t keycode)
  115. {
  116. action_t action;
  117. switch (keycode) {
  118. case KC_A ... KC_EXSEL:
  119. case KC_LCTRL ... KC_RGUI:
  120. action.code = ACTION_KEY(keycode);
  121. break;
  122. case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
  123. action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
  124. break;
  125. case KC_AUDIO_MUTE ... KC_MEDIA_REWIND:
  126. action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
  127. break;
  128. case KC_MS_UP ... KC_MS_ACCEL2:
  129. action.code = ACTION_MOUSEKEY(keycode);
  130. break;
  131. case KC_TRNS:
  132. action.code = ACTION_TRANSPARENT;
  133. break;
  134. default:
  135. action.code = ACTION_NO;
  136. break;
  137. }
  138. return action;
  139. }
  140. #ifdef USE_LEGACY_KEYMAP
  141. /*
  142. * Legacy keymap support
  143. * Consider using new keymap API instead.
  144. */
  145. __attribute__ ((weak))
  146. uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
  147. {
  148. return keymap_get_keycode(layer, key.row, key.col);
  149. }
  150. /* Legacy keymap support */
  151. __attribute__ ((weak))
  152. action_t keymap_fn_to_action(uint8_t keycode)
  153. {
  154. action_t action = { .code = ACTION_NO };
  155. switch (keycode) {
  156. case KC_FN0 ... KC_FN31:
  157. {
  158. uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
  159. uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
  160. if (key) {
  161. action.code = ACTION_LAYER_TAP_KEY(layer, key);
  162. } else {
  163. action.code = ACTION_LAYER_MOMENTARY(layer);
  164. }
  165. }
  166. return action;
  167. default:
  168. return action;
  169. }
  170. }
  171. #endif