keymap_common.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
  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. #ifndef KEYMAP_H
  15. #define KEYMAP_H
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "action.h"
  19. #include <avr/pgmspace.h>
  20. #include "keycode.h"
  21. #include "keymap.h"
  22. #include "action_macro.h"
  23. #include "report.h"
  24. #include "host.h"
  25. // #include "print.h"
  26. #include "debug.h"
  27. #ifdef BOOTMAGIC_ENABLE
  28. /* NOTE: Not portable. Bit field order depends on implementation */
  29. typedef union {
  30. uint16_t raw;
  31. struct {
  32. bool swap_control_capslock:1;
  33. bool capslock_to_control:1;
  34. bool swap_lalt_lgui:1;
  35. bool swap_ralt_rgui:1;
  36. bool no_gui:1;
  37. bool swap_grave_esc:1;
  38. bool swap_backslash_backspace:1;
  39. bool nkro:1;
  40. };
  41. } keymap_config_t;
  42. keymap_config_t keymap_config;
  43. #endif
  44. /* translates key to keycode */
  45. uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
  46. /* translates Fn keycode to action */
  47. action_t keymap_fn_to_action(uint16_t keycode);
  48. /* translates Fn keycode to action */
  49. action_t keymap_func_to_action(uint16_t keycode);
  50. extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
  51. extern const uint16_t fn_actions[];
  52. // Ability to use mods in layouts
  53. #define LCTL(kc) kc | 0x0100
  54. #define LSFT(kc) kc | 0x0200
  55. #define LALT(kc) kc | 0x0400
  56. #define LGUI(kc) kc | 0x0800
  57. #define RCTL(kc) kc | 0x1100
  58. #define RSFT(kc) kc | 0x1200
  59. #define RALT(kc) kc | 0x1400
  60. #define RGUI(kc) kc | 0x1800
  61. // Aliases for shifted symbols
  62. // Each key has a 4-letter code, and some have longer aliases too.
  63. // While the long aliases are descriptive, the 4-letter codes
  64. // make for nicer grid layouts (everything lines up), and are
  65. // the preferred style for Quantum.
  66. #define KC_TILD LSFT(KC_GRV) // ~
  67. #define KC_TILDE KC_TILD
  68. #define KC_EXLM LSFT(KC_1) // !
  69. #define KC_EXCLAIM KC_EXLM
  70. #define KC_AT LSFT(KC_2) // @
  71. #define KC_HASH LSFT(KC_3) // #
  72. #define KC_DLR LSFT(KC_4) // $
  73. #define KC_DOLLAR KC_DLR
  74. #define KC_PERC LSFT(KC_5) // %
  75. #define KC_PERCENT KC_PERC
  76. #define KC_CIRC LSFT(KC_6) // ^
  77. #define KC_CIRCUMFLEX KC_CIRC
  78. #define KC_AMPR LSFT(KC_7) // &
  79. #define KC_AMPERSAND KC_AMPR
  80. #define KC_ASTR LSFT(KC_8) // *
  81. #define KC_ASTERISK KC_ASTR
  82. #define KC_LPRN LSFT(KC_9) // (
  83. #define KC_LEFT_PAREN KC_LPRN
  84. #define KC_RPRN LSFT(KC_0) // )
  85. #define KC_RIGHT_PAREN KC_RPRN
  86. #define KC_UNDS LSFT(KC_MINS) // _
  87. #define KC_UNDERSCORE KC_UNDS
  88. #define KC_PLUS LSFT(KC_EQL) // +
  89. #define KC_LCBR LSFT(KC_LBRC) // {
  90. #define KC_LEFT_CURLY_BRACE KC_LCBR
  91. #define KC_RCBR LSFT(KC_RBRC) // }
  92. #define KC_RIGHT_CURLY_BRACE KC_RCBR
  93. #define KC_COLN LSFT(KC_SCLN) // :
  94. #define KC_COLON KC_COLN
  95. #define KC_PIPE LSFT(KC_SLSH) // |
  96. #define KC_DELT KC_DELETE // Del key (four letter code)
  97. // Alias for function layers than expand past FN31
  98. #define FUNC(kc) kc | 0x2000
  99. // Aliases
  100. #define S(kc) LSFT(kc)
  101. #define F(kc) FUNC(kc)
  102. #define M(kc) kc | 0x3000
  103. #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
  104. // These affect the backlight (if your keyboard has one).
  105. // We don't need to comment them out if your keyboard doesn't have a backlight,
  106. // since they don't take up any space.
  107. #define BL_ON 0x4009
  108. #define BL_OFF 0x4000
  109. #define BL_0 0x4000
  110. #define BL_1 0x4001
  111. #define BL_2 0x4002
  112. #define BL_3 0x4003
  113. #define BL_4 0x4004
  114. #define BL_5 0x4005
  115. #define BL_6 0x4006
  116. #define BL_7 0x4007
  117. #define BL_8 0x4008
  118. #define BL_9 0x4009
  119. #define BL_10 0x400A
  120. #define BL_11 0x400B
  121. #define BL_12 0x400C
  122. #define BL_13 0x400D
  123. #define BL_14 0x400E
  124. #define BL_15 0x400F
  125. #define BL_DEC 0x4010
  126. #define BL_INC 0x4011
  127. #define BL_TOGG 0x4012
  128. #define BL_STEP 0x4013
  129. #define RESET 0x5000
  130. #define DEBUG 0x5001
  131. // GOTO layer - 16 layers max
  132. // when:
  133. // ON_PRESS = 1
  134. // ON_RELEASE = 2
  135. // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default.
  136. #define TO(layer, when) (layer | 0x5100 | (when << 0x4))
  137. // Momentary switch layer - 256 layer max
  138. #define MO(layer) (layer | 0x5200)
  139. // Set default layer - 256 layer max
  140. #define DF(layer) (layer | 0x5300)
  141. // Toggle to layer - 256 layer max
  142. #define TG(layer) (layer | 0x5400)
  143. #define MIDI(n) (n | 0x6000)
  144. // M-od, T-ap - 256 keycode max
  145. #define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
  146. #define CTL_T(kc) MT(0x1, kc)
  147. #define SFT_T(kc) MT(0x2, kc)
  148. #define ALT_T(kc) MT(0x4, kc)
  149. #define GUI_T(kc) MT(0x8, kc)
  150. #define ALL_T(kc) MT(0xF, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
  151. // L-ayer, T-ap - 256 keycode max, 16 layer max
  152. #define LT(layer, kc) (kc | 0x8000 | ((layer & 0xF) << 8))
  153. // For sending unicode codes.
  154. // You may not send codes over 1FFF -- this supports most of UTF8.
  155. // To have a key that sends out Œ, go UC(0x0152)
  156. #define UNICODE(n) (n | 0x8000)
  157. #define UC(n) UNICODE(n)
  158. #endif