keymap.c 11 KB

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