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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 "layer_switch.h"
  24. #include "report.h"
  25. #include "host.h"
  26. #include "print.h"
  27. #include "debug.h"
  28. #include "keymap.h"
  29. // Convert physical keyboard layout to matrix array.
  30. // This is a macro to define keymap easily in keyboard layout form.
  31. #define KEYMAP( \
  32. KG1, KH7, KJ7, KJ6, KJ1, KO5, KL1, KA6, KA7, KD7, KD5, KD1, KD2, KB5, KB3, KO3, \
  33. KG7, KG5, KH5, KJ5, KI5, KI7, KK7, KK5, KL5, KA5, KC5, KC7, KL7, KD6, KQ7, KN7, KM7, \
  34. KG6, KG3, KH3, KJ3, KI3, KI6, KK6, KK3, KL3, KA3, KC3, KC6, KL6, KD4, KP7, KN5, KM5, \
  35. KH6, KG4, KH4, KJ4, KI4, KI1, KK1, KK4, KL4, KA4, KC4, KC1, KD0, \
  36. KF6, KH1, KG0, KH0, KJ0, KI0, KI2, KK2, KK0, KL0, KA0, KC2, KF4, KN1, \
  37. KO7, KE6, KB1, KP1, KB2, KR4, KA2, KO0, KN2, KP2, KQ2 \
  38. ) { \
  39. /* 0 1 2 3 4 5 6 7 */ \
  40. /* A */ { KC_##KA0, KC_NO , KC_##KA2, KC_##KA3, KC_##KA4, KC_##KA5, KC_##KA6, KC_##KA7 }, \
  41. /* B */ { KC_NO , KC_##KB1, KC_##KB2, KC_##KB3, KC_NO , KC_##KB5, KC_NO , KC_NO }, \
  42. /* C */ { KC_NO , KC_##KC1, KC_##KC2, KC_##KC3, KC_##KC4, KC_##KC5, KC_##KC6, KC_##KC7 }, \
  43. /* D */ { KC_##KD0, KC_##KD1, KC_##KD2, KC_NO , KC_##KD4, KC_##KD5, KC_##KD6, KC_##KD7 }, \
  44. /* E */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KE6, KC_NO }, \
  45. /* F */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KF4, KC_NO , KC_##KF6, KC_NO }, \
  46. /* G */ { KC_##KG0, KC_##KG1, KC_NO , KC_##KG3, KC_##KG4, KC_##KG5, KC_##KG6, KC_##KG7 }, \
  47. /* H */ { KC_##KH0, KC_##KH1, KC_NO , KC_##KH3, KC_##KH4, KC_##KH5, KC_##KH6, KC_##KH7 }, \
  48. /* I */ { KC_##KI0, KC_##KI1, KC_##KI2, KC_##KI3, KC_##KI4, KC_##KI5, KC_##KI6, KC_##KI7 }, \
  49. /* J */ { KC_##KJ0, KC_##KJ1, KC_NO , KC_##KJ3, KC_##KJ4, KC_##KJ5, KC_##KJ6, KC_##KJ7 }, \
  50. /* K */ { KC_##KK0, KC_##KK1, KC_##KK2, KC_##KK3, KC_##KK4, KC_##KK5, KC_##KK6, KC_##KK7 }, \
  51. /* L */ { KC_##KL0, KC_##KL1, KC_NO , KC_##KL3, KC_##KL4, KC_##KL5, KC_##KL6, KC_##KL7 }, \
  52. /* M */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KM5, KC_NO , KC_##KM7 }, \
  53. /* N */ { KC_NO , KC_##KN1, KC_##KN2, KC_NO , KC_NO , KC_##KN5, KC_NO , KC_##KN7 }, \
  54. /* O */ { KC_##KO0, KC_NO , KC_NO , KC_##KO3, KC_NO , KC_##KO5, KC_NO , KC_##KO7 }, \
  55. /* P */ { KC_NO , KC_##KP1, KC_##KP2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KP7 }, \
  56. /* Q */ { KC_NO , KC_NO , KC_##KQ2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KQ7 }, \
  57. /* R */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KR4, KC_NO , KC_NO , KC_NO } \
  58. }
  59. /*
  60. * Add custom layouts. If no custom layout is defined the default layout is used.
  61. */
  62. #if defined(KEYMAP_CUSTOM)
  63. #include "keymap_custom.h"
  64. #else
  65. /*
  66. * Tenkeyless keyboard default layout, ISO & ANSI (ISO is between Left Shift
  67. * and Z, and the ANSI \ key above Return/Enter is used for the additional ISO
  68. * switch in the ASD row next to enter. Use NUBS as keycode for the first and
  69. * NUHS as the keycode for the second.
  70. *
  71. * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
  72. * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
  73. * `---' `---------------' `---------------' `---------------' `-----------'
  74. * ,-----------------------------------------------------------. ,-----------.
  75. * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU|
  76. * |-----------------------------------------------------------| |-----------|
  77. * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD|
  78. * |-----------------------------------------------------------| `-----------'
  79. * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
  80. * |-----------------------------------------------------------| ,---.
  81. * |Shft|ISO| Z| X| C| V| B| N| M| ,| .| /|Shift | |Up |
  82. * |-----------------------------------------------------------| ,-----------.
  83. * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
  84. * `-----------------------------------------------------------' `-----------'
  85. */
  86. static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  87. /* Layer 0: Default Layer
  88. *
  89. * ANSI:
  90. *
  91. * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
  92. * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
  93. * `---' `---------------' `---------------' `---------------' `-----------'
  94. * ,-----------------------------------------------------------. ,-----------.
  95. * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU|
  96. * |-----------------------------------------------------------| |-----------|
  97. * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD|
  98. * |-----------------------------------------------------------| `-----------'
  99. * |FN1 | A| S| D| F| G| H| J| K| L| ;| '|Return |
  100. * |-----------------------------------------------------------| ,---.
  101. * |Shft|iso| Z| X| C| V| B| N| M| ,| .| /|Shift | |Up |
  102. * |-----------------------------------------------------------| ,-----------.
  103. * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
  104. * `-----------------------------------------------------------' `-----------'
  105. */
  106. KEYMAP(\
  107. ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, SLCK, BRK, \
  108. GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, INS, HOME, PGUP, \
  109. TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, BSLS, DEL, END, PGDN, \
  110. FN1, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
  111. LSFT, NUBS, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, \
  112. LCTL, LGUI, LALT, SPC, RALT, RGUI, APP, RCTL, LEFT, DOWN, RGHT),
  113. /* EXAMPLE ISO keymap, see the NUBS and NUHS keycodes
  114. * KEYMAP(\
  115. * ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, SLCK, BRK, \
  116. * GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, INS, HOME, PGUP, \
  117. * TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, NUHS, DEL, END, PGDN, \
  118. * CAPS, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
  119. * LSFT, NUBS, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, \
  120. * LCTL, FN1, LALT, SPC, RALT, RGUI, APP, RCTL, LEFT, DOWN, RGHT),
  121. */
  122. /*
  123. * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
  124. * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Slp|
  125. * `---' `---------------' `---------------' `---------------' `-----------'
  126. * ,-----------------------------------------------------------. ,-----------.
  127. * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9|Mut|V- |V+ |Backsp | |Ins|Hom|PgU|
  128. * |-----------------------------------------------------------| |-----------|
  129. * |Tab | Q| W| E| R| T| Y| U| I|MSt|Ply|Prv|Nxt|Media| |Del|End|PgD|
  130. * |-----------------------------------------------------------| `-----------'
  131. * |FN1 | A| S| D| F| G| H| J| K| L| ;| '|Return |
  132. * |-----------------------------------------------------------| ,---.
  133. * |Shft|iso| Z| X|Clc| V| B| N| M| ,| .| /|Caps | |Up |
  134. * |-----------------------------------------------------------| ,-----------.
  135. * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
  136. * `-----------------------------------------------------------' `-----------'
  137. */
  138. KEYMAP(\
  139. ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, SLCK, SLEP, \
  140. GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9,MUTE, VOLD, VOLU, BSPC, INS, HOME, PGUP, \
  141. TAB, Q, W, E, R, T, Y, U, I,MSTP,MPLY, MPRV, MNXT, MSEL, DEL, END, PGDN, \
  142. FN1, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
  143. LSFT, NUBS, Z, X,CALC, V, B, N, M, COMM, DOT, SLSH, CAPS, UP, \
  144. LCTL, LGUI, LALT, SPC, RALT, RGUI, APP, RCTL, LEFT, DOWN, RGHT),
  145. };
  146. static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
  147. /*
  148. * Fn action definition
  149. */
  150. static const uint16_t PROGMEM fn_actions[] = {
  151. [0] = ACTION_DEFAULT_LAYER_SET(0),
  152. [1] = ACTION_DEFAULT_LAYER_SET(1),
  153. [2] = ACTION_DEFAULT_LAYER_SET(2),
  154. [3] = ACTION_DEFAULT_LAYER_SET(3),
  155. [4] = ACTION_DEFAULT_LAYER_SET(4),
  156. [5] = ACTION_DEFAULT_LAYER_SET(5),
  157. [6] = ACTION_DEFAULT_LAYER_SET(6),
  158. [7] = ACTION_DEFAULT_LAYER_SET(7),
  159. [8] = ACTION_DEFAULT_LAYER_SET(8),
  160. };
  161. #endif
  162. #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
  163. #define OVERLAYS_SIZE (sizeof(overlays) / sizeof(overlays[0]))
  164. #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
  165. /* translates key to keycode */
  166. uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
  167. {
  168. /* Overlay: 16-31(OVERLAY_BIT(0x10) | overlay_layer) */
  169. if (layer & OVERLAY_BIT) {
  170. layer &= OVERLAY_MASK;
  171. if (layer < OVERLAYS_SIZE) {
  172. return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]);
  173. } else {
  174. // XXX: this may cuaes bootlaoder_jump incositent fail.
  175. //debug("key_to_keycode: overlay "); debug_dec(layer); debug(" is invalid.\n");
  176. return KC_TRANSPARENT;
  177. }
  178. }
  179. /* Keymap: 0-15 */
  180. else {
  181. if (layer < KEYMAPS_SIZE) {
  182. return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
  183. } else {
  184. // XXX: this may cuaes bootlaoder_jump incositent fail.
  185. //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
  186. // fall back to layer 0
  187. return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
  188. }
  189. }
  190. }
  191. /* translates Fn keycode to action */
  192. action_t keymap_fn_to_action(uint8_t keycode)
  193. {
  194. action_t action;
  195. if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
  196. action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
  197. } else {
  198. action.code = ACTION_NO;
  199. }
  200. return action;
  201. }