keymap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. #pragma message "You may need to add LAYOUT_planck_grid to your keymap layers - see default for an example"
  2. #include "planck.h"
  3. #ifdef BACKLIGHT_ENABLE
  4. #include "backlight.h"
  5. #endif
  6. #include "config.h"
  7. #include "quantum.h"
  8. #include "version.h"
  9. /* Each layer is given a name to aid in readability, which is then
  10. used in the keymap matrix below. The underscores do not denote
  11. anything - you can have a layer called STUFF or any other name.
  12. Layer names don't all need to be of the same length, obviously, and
  13. you could also skip them entirely and just use numbers, though that
  14. means needing to manage the numbers.
  15. It is preferable to keep the symbols short so that a line worth of
  16. key mappings fits compactly onto a line of code. */
  17. /* This was originally based on planck/keymaps/default/default.c, and
  18. then cbbrowne has revised things */
  19. /* Things I did not like about the default mapping
  20. - I found control too hard to get to. I use it more than Tab, so
  21. switched it there.
  22. - Having dash on [lower-j] is a bit nonintuitive, but may be OK
  23. - I'll bet I should switch ESC/TAB
  24. - I'm suspicious that I want to shift M(0) from [4][1] to [4][2],
  25. and shift ESC off the first column so KC_LCTL and KC_LALT can
  26. be on the first column.
  27. - I needed to swap ' and ENTER
  28. - All of the above are done :-)
  29. - Dropped out support for Dvorak and friends. They aren't
  30. improvements to me
  31. */
  32. /* Some interesting things implemented
  33. - There is a macro that writes out "cbbrowne" just to show that I
  34. could
  35. - There is a (somewhat cruddy) linear congruential random number
  36. generator.
  37. - I seed it somewhat with clock info to make it look more random
  38. - There are two macros that use the random number generators
  39. - one, M_RANDDIGIT, generates a random digit based on state
  40. of the random number generator
  41. - the other, M_RANDLETTER, generates a random letter based on state
  42. of the random number generator
  43. - in both, note the use of register_code()/unregister_code()
  44. to indicate the desired key
  45. - I do indeed want a sweet number pad!
  46. */
  47. /* Other things to do...
  48. - Need to think about what zsh and readline actions I use lots
  49. - Ought to ensure that Control-Alt-Delete is convenient enough
  50. - How about Alt-F1 thru Alt-F8? Not yet...
  51. - What's the keystroke to get from X to console these days?
  52. - A layer for doing console switching would not be a bad idea
  53. - I'm messing with jeremy-dev's keymap that shifts everything
  54. outwards. Gotta figure out how to make it sensible...
  55. */
  56. enum layers {
  57. _QWERTY = 0, /* Qwerty mapping */
  58. _LOWER, /* Lower layer, where top line has symbols !@#$%^&*() */
  59. _RAISE, /* Raised layer, where top line has digits 1234567890 */
  60. _KEYPAD, /* Key pad */
  61. _ADJUST, /* Special Adjust layer coming via tri-placement */
  62. };
  63. enum my_keycodes {
  64. MY_ABVE = SAFE_RANGE,
  65. MY_BELW,
  66. MY_TERM,
  67. MY_DEQL, // /=
  68. MY_MEQL, // *=
  69. MY_SEQL, // -=
  70. MY_PEQL, // +=
  71. MY_NEQL, // !=
  72. MY_LTGT, // <>
  73. MY_DPIP, // ||
  74. MY_DAMP, // &&
  75. };
  76. enum macro_id {
  77. M_LED = 0,
  78. M_USERNAME,
  79. M_RANDDIGIT,
  80. M_RANDLETTER,
  81. M_VERSION,
  82. MACRO_UPPER,
  83. MACRO_LOWER,
  84. };
  85. #define M_LOWER M(MACRO_LOWER)
  86. #define M_UPPER M(MACRO_UPPER)
  87. #define ROT_LED M(M_LED) /* Rotate LED */
  88. #define QWERTY DF(_QWERTY) /* Switch to QWERTY layout */
  89. #define KEYPAD DF(_KEYPAD) /* Switch to keypad */
  90. #define USERNAME M(M_USERNAME) /* shortcut for username */
  91. #define RANDDIG M(M_RANDDIGIT)
  92. #define RANDALP M(M_RANDLETTER)
  93. #define CTLENTER MT(MOD_RCTL, KC_ENT)
  94. #define SHIFTQUOTE MT(MOD_RSFT, KC_QUOT)
  95. #define ALTRIGHT MT(MOD_LALT, KC_RGHT)
  96. #define MVERSION M(M_VERSION)
  97. #define ALTSLASH LALT(KC_SLSH)
  98. /* Note that Planck has dimensions 4 rows x 12 columns */
  99. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  100. [_QWERTY] = { /* Qwerty */
  101. {KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  102. {KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, CTLENTER},
  103. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SHIFTQUOTE },
  104. {KC_TAB, KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC, KC_SPC, M_UPPER, KC_LEFT, KC_DOWN, KC_UP, ALTRIGHT}
  105. /* Note that KC_SPC is recorded TWICE, so that either matrix position can activate it */
  106. },
  107. [_RAISE] = { /* RAISE */
  108. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  109. {_______, KC_4, KC_5, KC_6, _______, _______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
  110. {_______, KC_7, KC_8, KC_9, _______, _______, _______, QWERTY, KEYPAD, KEYPAD, ALTSLASH,_______},
  111. {_______, KC_0, _______, _______, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_END, KC_PGUP}
  112. },
  113. [_LOWER] = { /* LOWER */
  114. {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
  115. {_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
  116. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, QWERTY, KEYPAD, KEYPAD, ALTSLASH, _______},
  117. {_______, KEYPAD, _______, _______, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_END, KC_PGUP}
  118. },
  119. [_KEYPAD] = { /* Key Pad */
  120. {KC_ESC, USERNAME, MVERSION, KC_F10, KC_F11, KC_F12, KC_PGUP, KC_KP_ENTER, KC_7, KC_8, KC_9, KC_BSPC},
  121. {KC_LCTL, RANDDIG, KC_F5, KC_F6, KC_F7, KC_F8, KC_PGDN, KC_KP_MINUS, KC_4, KC_5, KC_6, KC_PIPE},
  122. {KC_LSFT, RANDALP, KC_F1, KC_F2, KC_F3, KC_F4, KC_DEL, KC_KP_PLUS, KC_1, KC_2, KC_3, KC_ENTER},
  123. {KC_TAB, KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC, KC_SPC, QWERTY, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT}
  124. },
  125. [_ADJUST] = { /* Adjustments - gonna shift the wild tools in here */
  126. {ROT_LED,USERNAME,MVERSION, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  127. {_______, RANDDIG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  128. {_______, RANDALP, _______, _______, _______, RESET, RESET, _______, _______, _______, _______, _______ },
  129. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ }
  130. }
  131. };
  132. /* What is fn_actions actually used for??? */
  133. const uint16_t PROGMEM fn_actions[] = {
  134. };
  135. /* This bit of logic seeds a wee linear congruential random number generator */
  136. /* lots of prime numbers everywhere... */
  137. static uint16_t random_value = 157;
  138. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  139. {
  140. uint8_t clockbyte=0;
  141. clockbyte = TCNT1 % 256;
  142. uint8_t rval;
  143. // MACRODOWN only works in this function
  144. switch(id) {
  145. case M_LED:
  146. if (record->event.pressed) {
  147. register_code(KC_RSFT);
  148. #ifdef BACKLIGHT_ENABLE
  149. backlight_step();
  150. #endif
  151. } else {
  152. unregister_code(KC_RSFT);
  153. }
  154. break;
  155. case M_USERNAME:
  156. if (record->event.pressed) {
  157. SEND_STRING("cbbrowne");
  158. }
  159. break;
  160. case M_VERSION:
  161. if (record->event.pressed) {
  162. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP "@" QMK_VERSION "@" QMK_BUILDDATE);
  163. }
  164. break;
  165. case M_RANDDIGIT:
  166. /* Generate, based on random number generator, a keystroke for
  167. a numeric digit chosen at random */
  168. random_value = ((random_value + randadd) * randmul) % randmod;
  169. if (record->event.pressed) {
  170. /* Here, we mix the LCRNG with low bits from one of the system
  171. clocks via XOR in the theory that this may be more random
  172. than either separately */
  173. rval = (random_value ^ clockbyte) % 10;
  174. /* Note that KC_1 thru KC_0 are a contiguous range */
  175. register_code (KC_1 + rval);
  176. unregister_code (KC_1 + rval);
  177. }
  178. break;
  179. case M_RANDLETTER:
  180. /* Generate, based on random number generator, a keystroke for
  181. a letter chosen at random */
  182. /* Here, we mix the LCRNG with low bits from one of the system
  183. clocks via XOR in the theory that this may be more random
  184. than either separately */
  185. random_value = ((random_value + randadd) * randmul) % randmod;
  186. if (record->event.pressed) {
  187. rval = (random_value ^ clockbyte) % 26;
  188. register_code (KC_A + rval);
  189. unregister_code (KC_A + rval);
  190. }
  191. break;
  192. case MACRO_UPPER:
  193. if (record->event.pressed)
  194. {
  195. layer_on(_RAISE);
  196. #ifdef BACKLIGHT_BREATHING
  197. breathing_period_set(2);
  198. breathing_pulse();
  199. #endif
  200. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  201. }
  202. else
  203. {
  204. layer_off(_RAISE);
  205. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  206. }
  207. break;
  208. case MACRO_LOWER:
  209. if (record->event.pressed)
  210. {
  211. layer_on(_LOWER);
  212. #ifdef BACKLIGHT_BREATHING
  213. breathing_period_set(2);
  214. breathing_pulse();
  215. #endif
  216. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  217. }
  218. else
  219. {
  220. layer_off(_LOWER);
  221. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  222. }
  223. break;
  224. }
  225. return MACRO_NONE;
  226. };
  227. void press_key(uint16_t key) {
  228. register_code(key);
  229. unregister_code(key);
  230. }
  231. void press_two_keys(uint16_t key1, uint16_t key2) {
  232. register_code(key1);
  233. register_code(key2);
  234. unregister_code(key2);
  235. unregister_code(key1);
  236. }
  237. void press_three_keys(uint16_t key1, uint16_t key2, uint16_t key3) {
  238. register_code(key1);
  239. register_code(key2);
  240. register_code(key3);
  241. unregister_code(key3);
  242. unregister_code(key2);
  243. unregister_code(key1);
  244. }
  245. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  246. switch (keycode) {
  247. case MY_BELW:
  248. if (record->event.pressed) {
  249. press_two_keys(KC_LGUI, KC_RGHT);
  250. press_key(KC_ENT);
  251. }
  252. return false;
  253. case MY_ABVE:
  254. if (record->event.pressed) {
  255. press_two_keys(KC_LGUI, KC_LEFT);
  256. press_key(KC_ENT);
  257. press_key(KC_UP);
  258. }
  259. return false;
  260. case MY_TERM:
  261. if (record->event.pressed) {
  262. press_three_keys(KC_LGUI, KC_LSFT, KC_ENT);
  263. }
  264. return false;
  265. case MY_DEQL: // /=
  266. if (record->event.pressed) {
  267. press_key(KC_SLSH);
  268. press_key(KC_EQL);
  269. }
  270. return false;
  271. case MY_MEQL: // *=
  272. if (record->event.pressed) {
  273. press_two_keys(KC_LSFT, KC_ASTR);
  274. press_key(KC_EQL);
  275. }
  276. return false;
  277. case MY_SEQL: // -=
  278. if (record->event.pressed) {
  279. press_key(KC_MINS);
  280. press_key(KC_EQL);
  281. }
  282. return false;
  283. case MY_PEQL: // +=
  284. if (record->event.pressed) {
  285. press_two_keys(KC_LSFT, KC_PLUS);
  286. press_key(KC_EQL);
  287. }
  288. return false;
  289. case MY_NEQL: // !=
  290. if (record->event.pressed) {
  291. press_two_keys(KC_LSFT, KC_EXLM);
  292. press_key(KC_EQL);
  293. }
  294. return false;
  295. case MY_LTGT: // <>
  296. if (record->event.pressed) {
  297. press_two_keys(KC_LSFT, KC_LABK);
  298. press_two_keys(KC_LSFT, KC_RABK);
  299. }
  300. return false;
  301. case MY_DPIP: // ||
  302. if (record->event.pressed) {
  303. press_two_keys(KC_LSFT, KC_PIPE);
  304. press_two_keys(KC_LSFT, KC_PIPE);
  305. }
  306. return false;
  307. case MY_DAMP: // &&
  308. if (record->event.pressed) {
  309. press_two_keys(KC_LSFT, KC_AMPR);
  310. press_two_keys(KC_LSFT, KC_AMPR);
  311. }
  312. return false;
  313. }
  314. return true;
  315. }