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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. Copyright 2011 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. /*
  15. * Keymap for HID Liberator controller
  16. */
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include <avr/pgmspace.h>
  20. #include "keycode.h"
  21. #include "action.h"
  22. #include "action_macro.h"
  23. #include "report.h"
  24. #include "host.h"
  25. #include "print.h"
  26. #include "debug.h"
  27. #include "keymap.h"
  28. // Convert physical keyboard layout to matrix array.
  29. // This is a macro to define keymap easily in keyboard layout form.
  30. #define KEYMAP( \
  31. KG1, KH7, KJ7, KJ6, KJ1, KO5, KL1, KA6, KA7, KD7, KD5, KD1, KD2, KB5, KB3, KO3, \
  32. KG7, KG5, KH5, KJ5, KI5, KI7, KK7, KK5, KL5, KA5, KC5, KC7, KL7, KD6, KQ7, KN7, KM7, \
  33. KG6, KG3, KH3, KJ3, KI3, KI6, KK6, KK3, KL3, KA3, KC3, KC6, KL6, KD4, KP7, KN5, KM5, \
  34. KH6, KG4, KH4, KJ4, KI4, KI1, KK1, KK4, KL4, KA4, KC4, KC1, KD0, \
  35. KF6, KH1, KG0, KH0, KJ0, KI0, KI2, KK2, KK0, KL0, KA0, KC2, KF4, KN1, \
  36. KO7, KE6, KB1, KP1, KB2, KR4, KA2, KO0, KN2, KP2, KQ2 \
  37. ) { \
  38. /* 0 1 2 3 4 5 6 7 */ \
  39. /* A */ { KC_##KA0, KC_NO , KC_##KA2, KC_##KA3, KC_##KA4, KC_##KA5, KC_##KA6, KC_##KA7 }, \
  40. /* B */ { KC_NO , KC_##KB1, KC_##KB2, KC_##KB3, KC_NO , KC_##KB5, KC_NO , KC_NO }, \
  41. /* C */ { KC_NO , KC_##KC1, KC_##KC2, KC_##KC3, KC_##KC4, KC_##KC5, KC_##KC6, KC_##KC7 }, \
  42. /* D */ { KC_##KD0, KC_##KD1, KC_##KD2, KC_NO , KC_##KD4, KC_##KD5, KC_##KD6, KC_##KD7 }, \
  43. /* E */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KE6, KC_NO }, \
  44. /* F */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KF4, KC_NO , KC_##KF6, KC_NO }, \
  45. /* G */ { KC_##KG0, KC_##KG1, KC_NO , KC_##KG3, KC_##KG4, KC_##KG5, KC_##KG6, KC_##KG7 }, \
  46. /* H */ { KC_##KH0, KC_##KH1, KC_NO , KC_##KH3, KC_##KH4, KC_##KH5, KC_##KH6, KC_##KH7 }, \
  47. /* I */ { KC_##KI0, KC_##KI1, KC_##KI2, KC_##KI3, KC_##KI4, KC_##KI5, KC_##KI6, KC_##KI7 }, \
  48. /* J */ { KC_##KJ0, KC_##KJ1, KC_NO , KC_##KJ3, KC_##KJ4, KC_##KJ5, KC_##KJ6, KC_##KJ7 }, \
  49. /* K */ { KC_##KK0, KC_##KK1, KC_##KK2, KC_##KK3, KC_##KK4, KC_##KK5, KC_##KK6, KC_##KK7 }, \
  50. /* L */ { KC_##KL0, KC_##KL1, KC_NO , KC_##KL3, KC_##KL4, KC_##KL5, KC_##KL6, KC_##KL7 }, \
  51. /* M */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KM5, KC_NO , KC_##KM7 }, \
  52. /* N */ { KC_NO , KC_##KN1, KC_##KN2, KC_NO , KC_NO , KC_##KN5, KC_NO , KC_##KN7 }, \
  53. /* O */ { KC_##KO0, KC_NO , KC_NO , KC_##KO3, KC_NO , KC_##KO5, KC_NO , KC_##KO7 }, \
  54. /* P */ { KC_NO , KC_##KP1, KC_##KP2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KP7 }, \
  55. /* Q */ { KC_NO , KC_NO , KC_##KQ2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KQ7 }, \
  56. /* R */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KR4, KC_NO , KC_NO , KC_NO } \
  57. }
  58. /*
  59. * Tenkeyless keyboard default layout, ISO & ANSI (ISO is between Left Shift
  60. * and Z, and the ANSI \ key above Return/Enter is used for the additional ISO
  61. * switch in the ASD row next to enter. Use NUBS as keycode for the first and
  62. * NUHS as the keycode for the second.
  63. *
  64. * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
  65. * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
  66. * `---' `---------------' `---------------' `---------------' `-----------'
  67. * ,-----------------------------------------------------------. ,-----------.
  68. * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU|
  69. * |-----------------------------------------------------------| |-----------|
  70. * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD|
  71. * |-----------------------------------------------------------| `-----------'
  72. * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
  73. * |-----------------------------------------------------------| ,---.
  74. * |Shft|ISO| Z| X| C| V| B| N| M| ,| .| /|Shift | |Up |
  75. * |-----------------------------------------------------------| ,-----------.
  76. * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
  77. * `-----------------------------------------------------------' `-----------'
  78. */
  79. /*
  80. * Add different layouts. If no layout is defined the default layout will be set to ANSI.
  81. */
  82. #if defined(LAYOUT_CUSTOM)
  83. #include "keymap_custom.h"
  84. #elif defined(LAYOUT_ALARICLJS)
  85. #include "keymap_alaricljs.h"
  86. #elif defined(LAYOUT_ISO)
  87. #include "keymap_iso.h"
  88. #elif defined(LAYOUT_ANSI)
  89. #include "keymap_ansi.h"
  90. #else
  91. #include "keymap_ansi.h"
  92. #endif
  93. #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
  94. #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
  95. /* translates key to keycode */
  96. uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
  97. {
  98. if (layer < KEYMAPS_SIZE) {
  99. return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
  100. } else {
  101. return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
  102. }
  103. }
  104. /* translates Fn keycode to action */
  105. action_t keymap_fn_to_action(uint8_t keycode)
  106. {
  107. action_t action;
  108. if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
  109. action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
  110. } else {
  111. action.code = ACTION_NO;
  112. }
  113. return action;
  114. }