Keyboard firmwares for Atmel AVR and Cortex-M
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

keymap.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <avr/pgmspace.h>
  15. #include "keymap.h"
  16. #include "report.h"
  17. #include "keycode.h"
  18. #include "layer_switch.h"
  19. #include "action.h"
  20. #include "action_macro.h"
  21. #include "debug.h"
  22. static action_t keycode_to_action(uint8_t keycode);
  23. #ifdef USE_KEYMAP_V2
  24. /* converts key to action */
  25. action_t action_for_key(uint8_t layer, key_t key)
  26. {
  27. uint8_t keycode = keymap_key_to_keycode(layer, key);
  28. switch (keycode) {
  29. case KC_FN0 ... KC_FN31:
  30. return keymap_fn_to_action(keycode);
  31. default:
  32. return keycode_to_action(keycode);
  33. }
  34. }
  35. __attribute__ ((weak))
  36. const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; }
  37. __attribute__ ((weak))
  38. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {}
  39. #else
  40. /*
  41. * legacy keymap support
  42. */
  43. /* translation for legacy keymap */
  44. action_t action_for_key(uint8_t layer, key_t key)
  45. {
  46. /* convert from legacy keycode to action */
  47. /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */
  48. uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col);
  49. action_t action;
  50. switch (keycode) {
  51. case KC_FN0 ... KC_FN31:
  52. {
  53. uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
  54. uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
  55. if (key) {
  56. action.code = ACTION_KEYMAP_TAP_KEY(layer, key);
  57. } else {
  58. action.code = ACTION_KEYMAP_MOMENTARY(layer);
  59. }
  60. }
  61. return action;
  62. default:
  63. return keycode_to_action(keycode);
  64. }
  65. }
  66. /* not used for legacy keymap */
  67. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  68. {
  69. }
  70. #endif
  71. /* translates keycode to action */
  72. static action_t keycode_to_action(uint8_t keycode)
  73. {
  74. action_t action;
  75. switch (keycode) {
  76. case KC_A ... KC_EXSEL:
  77. action.code = ACTION_KEY(keycode);
  78. break;
  79. case KC_LCTRL ... KC_LGUI:
  80. action.code = ACTION_LMOD(keycode);
  81. break;
  82. case KC_RCTRL ... KC_RGUI:
  83. action.code = ACTION_RMOD(keycode);
  84. break;
  85. case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
  86. action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
  87. break;
  88. case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
  89. action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
  90. break;
  91. case KC_MS_UP ... KC_MS_ACCEL2:
  92. action.code = ACTION_MOUSEKEY(keycode);
  93. break;
  94. case KC_TRNS:
  95. action.code = ACTION_TRANSPARENT;
  96. break;
  97. default:
  98. action.code = ACTION_NO;
  99. break;
  100. }
  101. return action;
  102. }