Keyboard firmwares for Atmel AVR and Cortex-M
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

keymap.c 3.2KB

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