You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keymap.c 3.3KB

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