keymap.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #include "planck.h"
  2. #ifdef BACKLIGHT_ENABLE
  3. #include "backlight.h"
  4. #endif
  5. /* Each layer is given a name to aid in readability, which is then
  6. used in the keymap matrix below. The underscores do not denote
  7. anything - you can have a layer called STUFF or any other name.
  8. Layer names don't all need to be of the same length, obviously, and
  9. you could also skip them entirely and just use numbers, though that
  10. means needing to manage the numbers.
  11. It is preferable to keep the symbols short so that a line worth of
  12. key mappings fits compactly onto a line of code. */
  13. /* This was originally based on planck/keymaps/default/default.c, and
  14. then cbbrowne has revised things */
  15. /* Things I did not like about the default mapping
  16. - I find control too hard to get to. I think I'll want it on a
  17. left finger. Gonna need to lose something to do that...
  18. - Almost certainly, KC_LCTL should be on [2][1]
  19. - having dash on [lower-j] is a bit nonintuitive, but may be OK
  20. - I'll bet I should switch ESC/TAB
  21. - I'm suspicious that I want to shift M(0) from [4][1] to [4][2],
  22. and shift ESC off the first column so KC_LCTL and KC_LALT can
  23. be on the first column.
  24. - I think I wanna swap ' and ENTER
  25. - All of the above are done :-)
  26. - I'm keeping Colemak and Dvorak around for reference, and added
  27. Workman just for fun. They're useless to me, though.
  28. */
  29. /* Some interesting things implemented
  30. - There is a macro that writes out "cbbrowne" just because I could
  31. - There is a (somewhat cruddy) linear congruential random number
  32. generator.
  33. - I would like to be seeding it with clock info to make it look
  34. more random
  35. - There are two macros that use the random number generators
  36. - one, M_RANDDIGIT, generates a random digit based on state
  37. of the random number generator
  38. - the other, M_RANDLETTER, generates a random letter based on state
  39. of the random number generator
  40. - in both, note the use of register_code()/unregister_code()
  41. to indicate the desired key
  42. */
  43. /* Other things to do...
  44. - Need to think about what zsh and readline actions I use lots
  45. - Wanna figure out macros, so I can put in a "cbbrowne" macro
  46. - Ought to ensure that Control-Alt-Delete is convenient enough
  47. - How about Alt-F1 thru Alt-F8?
  48. - What's the keystroke to get from X to console these days?
  49. - I do indeed want a sweet number pad!
  50. - A layer for doing console switching would not be a bad idea
  51. */
  52. enum layers {
  53. _QW = 0, /* Qwerty mapping */
  54. _LW, /* Lower layer, where top line has symbols !@#$%^&*() */
  55. _RS, /* Raised layer, where top line has digits 1234567890 */
  56. _KP, /* Key pad */
  57. };
  58. enum macro_id {
  59. M_LED = 0,
  60. M_USERNAME,
  61. M_RANDDIGIT,
  62. M_RANDLETTER
  63. };
  64. /* Note that Planck has dimensions 4 rows x 12 columns */
  65. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  66. [_QW] = { /* Qwerty */
  67. {KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  68. {KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT},
  69. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_QUOT },
  70. {KC_TAB, M(M_LED), KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  71. },
  72. [_RS] = { /* RAISE */
  73. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  74. {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
  75. {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_KP), DF(_KP), RESET, KC_TRNS},
  76. {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  77. },
  78. [_LW] = { /* LOWER */
  79. {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
  80. {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
  81. {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_KP), DF(_KP), RESET, KC_TRNS},
  82. {KC_TRNS, DF(_KP), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  83. },
  84. [_KP] = { /* Key Pad */
  85. {KC_ESC, M(M_USERNAME), KC_W, KC_E, KC_R, KC_T, KC_Y, KC_KP_ENTER, KC_KP_PLUS, KC_KP_PLUS, KC_KP_ENTER, KC_BSPC},
  86. {KC_LCTL, M(M_RANDDIGIT), KC_S, KC_D, KC_F, KC_G, KC_H, KC_KP_MINUS, KC_7, KC_8, KC_9, KC_ENT},
  87. {KC_LSFT, M(M_RANDLETTER), KC_X, KC_C, KC_V, KC_B, KC_N, KC_KP_PLUS, KC_4, KC_5, KC_6, KC_DOT},
  88. {BL_STEP, M(M_LED), KC_LALT, KC_LGUI, KC_NO, KC_SPC, KC_SPC, DF(_QW), KC_1, KC_2, KC_3, KC_0}
  89. }
  90. };
  91. const uint16_t PROGMEM fn_actions[] = {
  92. };
  93. /* This bit of logic seeds a wee linear congruential random number generator */
  94. static uint16_t random_value = 157;
  95. #define randadd 53
  96. #define randmul 181
  97. #define randmod 167
  98. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  99. {
  100. uint8_t clockbyte=0;
  101. clockbyte = TCNT1 % 256;
  102. // MACRODOWN only works in this function
  103. switch(id) {
  104. case M_LED:
  105. if (record->event.pressed) {
  106. register_code(KC_RSFT);
  107. #ifdef BACKLIGHT_ENABLE
  108. backlight_step();
  109. #endif
  110. } else {
  111. unregister_code(KC_RSFT);
  112. }
  113. break;
  114. case M_USERNAME:
  115. if (record->event.pressed) {
  116. return MACRO( I(1), T(C), T(B), T(B), T(R), T(O), T(W), T(N), T(E));
  117. } else {
  118. return MACRO_NONE ;
  119. }
  120. break;
  121. case M_RANDDIGIT:
  122. /* Generate, based on random number generator, a keystroke for
  123. a numeric digit chosen at random */
  124. random_value = ((random_value + randadd) * randmul) % randmod;
  125. if (record->event.pressed)
  126. /* Here, we mix the LCRNG with low bits from one of the system
  127. clocks via XOR in the theory that this may be more random
  128. than either separately */
  129. switch ((random_value ^ clockbyte) % 10) {
  130. case 0:
  131. register_code (KC_0);
  132. unregister_code (KC_0);
  133. break;
  134. case 1:
  135. register_code (KC_1);
  136. unregister_code (KC_1);
  137. break;
  138. case 2:
  139. register_code (KC_2);
  140. unregister_code (KC_2);
  141. break;
  142. case 3:
  143. register_code (KC_3);
  144. unregister_code (KC_3);
  145. break;
  146. case 4:
  147. register_code (KC_4);
  148. unregister_code (KC_4);
  149. break;
  150. case 5:
  151. register_code (KC_5);
  152. unregister_code (KC_5);
  153. break;
  154. case 6:
  155. register_code (KC_6);
  156. unregister_code (KC_6);
  157. break;
  158. case 7:
  159. register_code (KC_7);
  160. unregister_code (KC_7);
  161. break;
  162. case 8:
  163. register_code (KC_8);
  164. unregister_code (KC_8);
  165. break;
  166. case 9:
  167. register_code (KC_9);
  168. unregister_code (KC_9);
  169. break;
  170. }
  171. break;
  172. case M_RANDLETTER:
  173. /* Generate, based on random number generator, a keystroke for
  174. a letter chosen at random */
  175. /* Here, we mix the LCRNG with low bits from one of the system
  176. clocks via XOR in the theory that this may be more random
  177. than either separately */
  178. random_value = ((random_value + randadd) * randmul) % randmod;
  179. if (record->event.pressed)
  180. switch((random_value ^ clockbyte) % 26) {
  181. case 0:
  182. register_code(KC_A);
  183. unregister_code(KC_A);
  184. break;
  185. case 1:
  186. register_code(KC_B);
  187. unregister_code(KC_B);
  188. break;
  189. case 2:
  190. register_code(KC_C);
  191. unregister_code(KC_C);
  192. break;
  193. case 3:
  194. register_code(KC_D);
  195. unregister_code(KC_D);
  196. break;
  197. case 4:
  198. register_code(KC_E);
  199. unregister_code(KC_E);
  200. break;
  201. case 5:
  202. register_code(KC_F);
  203. unregister_code(KC_F);
  204. break;
  205. case 6:
  206. register_code(KC_G);
  207. unregister_code(KC_G);
  208. break;
  209. case 7:
  210. register_code(KC_H);
  211. unregister_code(KC_H);
  212. break;
  213. case 8:
  214. register_code(KC_I);
  215. unregister_code(KC_I);
  216. break;
  217. case 9:
  218. register_code(KC_J);
  219. unregister_code(KC_J);
  220. break;
  221. case 10:
  222. register_code(KC_K);
  223. unregister_code(KC_K);
  224. break;
  225. case 11:
  226. register_code(KC_L);
  227. unregister_code(KC_L);
  228. break;
  229. case 12:
  230. register_code(KC_M);
  231. unregister_code(KC_M);
  232. break;
  233. case 13:
  234. register_code(KC_N);
  235. unregister_code(KC_N);
  236. break;
  237. case 14:
  238. register_code(KC_O);
  239. unregister_code(KC_O);
  240. break;
  241. case 15:
  242. register_code(KC_P);
  243. unregister_code(KC_P);
  244. break;
  245. case 16:
  246. register_code(KC_Q);
  247. unregister_code(KC_Q);
  248. break;
  249. case 17:
  250. register_code(KC_R);
  251. unregister_code(KC_R);
  252. break;
  253. case 18:
  254. register_code(KC_S);
  255. unregister_code(KC_S);
  256. break;
  257. case 19:
  258. register_code(KC_T);
  259. unregister_code(KC_T);
  260. break;
  261. case 20:
  262. register_code(KC_U);
  263. unregister_code(KC_U);
  264. break;
  265. case 21:
  266. register_code(KC_V);
  267. unregister_code(KC_V);
  268. break;
  269. case 22:
  270. register_code(KC_W);
  271. unregister_code(KC_W);
  272. break;
  273. case 23:
  274. register_code(KC_X);
  275. unregister_code(KC_X);
  276. break;
  277. case 24:
  278. register_code(KC_Y);
  279. unregister_code(KC_Y);
  280. break;
  281. case 25:
  282. register_code(KC_Z);
  283. unregister_code(KC_Z);
  284. break;
  285. }
  286. break;
  287. }
  288. return MACRO_NONE;
  289. };