keymap.c 11 KB

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