Keyboard firmwares for Atmel AVR and Cortex-M
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.

keymap.c 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.h"
  18. /* layer */
  19. uint8_t default_layer = 0;
  20. uint8_t current_layer = 0;
  21. action_t keymap_keycode_to_action(uint8_t keycode)
  22. {
  23. action_t action;
  24. switch (keycode) {
  25. case KC_A ... KC_EXSEL:
  26. action.code = ACTION_KEY(keycode);
  27. break;
  28. case KC_LCTRL ... KC_LGUI:
  29. action.code = ACTION_LMOD(keycode);
  30. break;
  31. case KC_RCTRL ... KC_RGUI:
  32. action.code = ACTION_RMOD(keycode);
  33. break;
  34. case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
  35. action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
  36. break;
  37. case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
  38. action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
  39. break;
  40. case KC_MS_UP ... KC_MS_ACCEL2:
  41. action.code = ACTION_MOUSEKEY(keycode);
  42. break;
  43. case KC_TRNS:
  44. action.code = ACTION_TRANSPARENT;
  45. break;
  46. default:
  47. action.code = ACTION_NO;
  48. break;
  49. }
  50. return action;
  51. }
  52. #ifndef NO_LEGACY_KEYMAP_SUPPORT
  53. /* legacy support with weak reference */
  54. __attribute__ ((weak))
  55. action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
  56. {
  57. /* convert from legacy keycode to action */
  58. uint8_t keycode = keymap_get_keycode(layer, row, col);
  59. action_t action;
  60. switch (keycode) {
  61. case KC_FN0 ... KC_FN31:
  62. {
  63. uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
  64. uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
  65. if (key) {
  66. action.code = ACTION_LAYER_SET_TAP_KEY(layer, key);
  67. } else {
  68. action.code = ACTION_LAYER_SET_MOMENTARY(layer);
  69. }
  70. }
  71. return action;
  72. default:
  73. return keymap_keycode_to_action(keycode);
  74. }
  75. }
  76. #endif
  77. __attribute__ ((weak))
  78. void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt)
  79. {
  80. }