upload
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_common.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. Copyright 2012,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. #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. /* NOTE: Not portable. Bit field order depends on implementation */
  28. typedef union {
  29. uint16_t raw;
  30. struct {
  31. bool swap_control_capslock:1;
  32. bool capslock_to_control:1;
  33. bool swap_lalt_lgui:1;
  34. bool swap_ralt_rgui:1;
  35. bool no_gui:1;
  36. bool swap_grave_esc:1;
  37. bool swap_backslash_backspace:1;
  38. bool nkro:1;
  39. };
  40. } keymap_config_t;
  41. /* translates key to keycode */
  42. uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
  43. /* translates Fn keycode to action */
  44. action_t keymap_fn_to_action(uint16_t keycode);
  45. /* translates Fn keycode to action */
  46. action_t keymap_func_to_action(uint16_t keycode);
  47. extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
  48. extern const uint16_t fn_actions[];
  49. // Ability to use mods in layouts
  50. #define LCTL(kc) kc | 0x0100
  51. #define LSFT(kc) kc | 0x0200
  52. #define LALT(kc) kc | 0x0400
  53. #define LGUI(kc) kc | 0x0800
  54. #define HYPR(kc) kc | 0x0F00
  55. #define MEH(kc) kc | 0x0700
  56. #define LCAG(kc) kc | 0x0D00 // Modifier Ctrl Alt and GUI
  57. #define MOD_HYPR 0xf
  58. #define MOD_MEH 0x7
  59. #define RCTL(kc) kc | 0x1100
  60. #define RSFT(kc) kc | 0x1200
  61. #define RALT(kc) kc | 0x1400
  62. #define RGUI(kc) kc | 0x1800
  63. // Aliases for shifted symbols
  64. // Each key has a 4-letter code, and some have longer aliases too.
  65. // While the long aliases are descriptive, the 4-letter codes
  66. // make for nicer grid layouts (everything lines up), and are
  67. // the preferred style for Quantum.
  68. #define KC_TILD LSFT(KC_GRV) // ~
  69. #define KC_TILDE KC_TILD
  70. #define KC_EXLM LSFT(KC_1) // !
  71. #define KC_EXCLAIM KC_EXLM
  72. #define KC_AT LSFT(KC_2) // @
  73. #define KC_HASH LSFT(KC_3) // #
  74. #define KC_DLR LSFT(KC_4) // $
  75. #define KC_DOLLAR KC_DLR
  76. #define KC_PERC LSFT(KC_5) // %
  77. #define KC_PERCENT KC_PERC
  78. #define KC_CIRC LSFT(KC_6) // ^
  79. #define KC_CIRCUMFLEX KC_CIRC
  80. #define KC_AMPR LSFT(KC_7) // &
  81. #define KC_AMPERSAND KC_AMPR
  82. #define KC_ASTR LSFT(KC_8) // *
  83. #define KC_ASTERISK KC_ASTR
  84. #define KC_LPRN LSFT(KC_9) // (
  85. #define KC_LEFT_PAREN KC_LPRN
  86. #define KC_RPRN LSFT(KC_0) // )
  87. #define KC_RIGHT_PAREN KC_RPRN
  88. #define KC_UNDS LSFT(KC_MINS) // _
  89. #define KC_UNDERSCORE KC_UNDS
  90. #define KC_PLUS LSFT(KC_EQL) // +
  91. #define KC_LCBR LSFT(KC_LBRC) // {
  92. #define KC_LEFT_CURLY_BRACE KC_LCBR
  93. #define KC_RCBR LSFT(KC_RBRC) // }
  94. #define KC_RIGHT_CURLY_BRACE KC_RCBR
  95. #define KC_LABK LSFT(KC_COMM) // <
  96. #define KC_LEFT_ANGLE_BRACKET KC_LABK
  97. #define KC_RABK LSFT(KC_DOT) // >
  98. #define KC_RIGHT_ANGLE_BRACKET KC_RABK
  99. #define KC_COLN LSFT(KC_SCLN) // :
  100. #define KC_COLON KC_COLN
  101. #define KC_PIPE LSFT(KC_BSLS) // |
  102. #define KC_LT LSFT(KC_COMM) // <
  103. #define KC_GT LSFT(KC_DOT) // >
  104. #define KC_QUES LSFT(KC_SLSH) // ?
  105. #define KC_QUESTION KC_QUES
  106. #define KC_DQT LSFT(KC_QUOT) // "
  107. #define KC_DOUBLE_QUOTE KC_DQT
  108. #define KC_DQUO KC_DQT
  109. #define KC_DELT KC_DELETE // Del key (four letter code)
  110. // Alias for function layers than expand past FN31
  111. #define FUNC(kc) kc | 0x2000
  112. // Aliases
  113. #define S(kc) LSFT(kc)
  114. #define F(kc) FUNC(kc)
  115. #define M(kc) (kc | 0x3000)
  116. #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
  117. // 0x3100+ is free
  118. // L-ayer, T-ap - 256 keycode max, 16 layer max
  119. #define LT(layer, kc) (kc | 0x4000 | ((layer & 0xF) << 8))
  120. #define RESET 0x5000
  121. #define DEBUG 0x5001
  122. // MAGIC keycodes
  123. #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
  124. #define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003
  125. #define MAGIC_CAPSLOCK_TO_CONTROL 0x5004
  126. #define MAGIC_UNCAPSLOCK_TO_CONTROL 0x5005
  127. #define MAGIC_SWAP_LALT_LGUI 0x5006
  128. #define MAGIC_UNSWAP_LALT_LGUI 0x5007
  129. #define MAGIC_SWAP_RALT_RGUI 0x5008
  130. #define MAGIC_UNSWAP_RALT_RGUI 0x5009
  131. #define MAGIC_NO_GUI 0x500a
  132. #define MAGIC_UNNO_GUI 0x500b
  133. #define MAGIC_SWAP_GRAVE_ESC 0x500c
  134. #define MAGIC_UNSWAP_GRAVE_ESC 0x500d
  135. #define MAGIC_SWAP_BACKSLASH_BACKSPACE 0x500e
  136. #define MAGIC_UNSWAP_BACKSLASH_BACKSPACE 0x500f
  137. #define MAGIC_HOST_NKRO 0x5010
  138. #define MAGIC_UNHOST_NKRO 0x5011
  139. #define MAGIC_SWAP_ALT_GUI 0x5012
  140. #define MAGIC_UNSWAP_ALT_GUI 0x5013
  141. #define AG_SWAP MAGIC_SWAP_ALT_GUI
  142. #define AG_NORM MAGIC_UNSWAP_ALT_GUI
  143. #define KC_LEAD 0x5014
  144. // Audio on/off
  145. #define AU_ON 0x5020
  146. #define AU_OFF 0x5021
  147. #define AU_TOG 0x5022
  148. // Music mode on/off
  149. #define MU_ON 0x5023
  150. #define MU_OFF 0x5024
  151. #define MU_TOG 0x5025
  152. // Music voice iterate
  153. #define MUV_IN 0x5026
  154. #define MUV_DE 0x5027
  155. // Midi mode on/off
  156. #define MI_ON 0x5028
  157. #define MI_OFF 0x5029
  158. // These affect the backlight (if your keyboard has one).
  159. // We don't need to comment them out if your keyboard doesn't have a backlight,
  160. // since they don't take up any space.
  161. #define BL_ON 0x5079
  162. #define BL_OFF 0x5070
  163. #define BL_0 0x5070
  164. #define BL_1 0x5071
  165. #define BL_2 0x5072
  166. #define BL_3 0x5073
  167. #define BL_4 0x5074
  168. #define BL_5 0x5075
  169. #define BL_6 0x5076
  170. #define BL_7 0x5077
  171. #define BL_8 0x5078
  172. #define BL_9 0x5079
  173. #define BL_10 0x507A
  174. #define BL_11 0x507B
  175. #define BL_12 0x507C
  176. #define BL_13 0x507D
  177. #define BL_14 0x507E
  178. #define BL_15 0x507F
  179. #define BL_DEC 0x5080
  180. #define BL_INC 0x5081
  181. #define BL_TOGG 0x5082
  182. #define BL_STEP 0x5083
  183. #define KC_LSPO 0x5084 // Left shift, open parens when tapped
  184. #define KC_RSPC 0x5085 // Right shift, close parens when tapped
  185. // GOTO layer - 16 layers max
  186. // when:
  187. // ON_PRESS = 1
  188. // ON_RELEASE = 2
  189. // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default.
  190. #define TO(layer, when) (layer | 0x5100 | (when << 0x4))
  191. // Momentary switch layer - 256 layer max
  192. #define MO(layer) (layer | 0x5200)
  193. // Set default layer - 256 layer max
  194. #define DF(layer) (layer | 0x5300)
  195. // Toggle to layer - 256 layer max
  196. #define TG(layer) (layer | 0x5400)
  197. // One-shot layer - 256 layer max
  198. #define OSL(layer) (layer | 0x5500)
  199. // One-shot mod
  200. #define OSM(layer) (layer | 0x5600)
  201. // chording is currently at 0x57xx
  202. // M-od, T-ap - 256 keycode max
  203. #define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
  204. #define CTL_T(kc) MT(0x1, kc)
  205. #define SFT_T(kc) MT(0x2, kc)
  206. #define ALT_T(kc) MT(0x4, kc)
  207. #define GUI_T(kc) MT(0x8, kc)
  208. #define C_S_T(kc) MT(0x3, kc) // Control + Shift e.g. for gnome-terminal
  209. #define MEH_T(kc) MT(0x7, kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl
  210. #define LCAG_T(kc) MT(0xD, kc) // Left control alt and gui
  211. #define ALL_T(kc) MT(0xF, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
  212. // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
  213. #define KC_HYPR HYPR(KC_NO)
  214. #define KC_MEH MEH(KC_NO)
  215. #ifdef UNICODE_ENABLE
  216. // For sending unicode codes.
  217. // You may not send codes over 7FFF -- this supports most of UTF8.
  218. // To have a key that sends out Œ, go UC(0x0152)
  219. #define UNICODE(n) (n | 0x8000)
  220. #define UC(n) UNICODE(n)
  221. #endif
  222. // For tri-layer
  223. void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
  224. #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
  225. #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
  226. #endif