keymap.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. uint8_t rval;
  103. // MACRODOWN only works in this function
  104. switch(id) {
  105. case M_LED:
  106. if (record->event.pressed) {
  107. register_code(KC_RSFT);
  108. #ifdef BACKLIGHT_ENABLE
  109. backlight_step();
  110. #endif
  111. } else {
  112. unregister_code(KC_RSFT);
  113. }
  114. break;
  115. case M_USERNAME:
  116. if (record->event.pressed) {
  117. return MACRO( I(1), T(C), T(B), T(B), T(R), T(O), T(W), T(N), T(E));
  118. } else {
  119. return MACRO_NONE ;
  120. }
  121. break;
  122. case M_RANDDIGIT:
  123. /* Generate, based on random number generator, a keystroke for
  124. a numeric digit chosen at random */
  125. random_value = ((random_value + randadd) * randmul) % randmod;
  126. if (record->event.pressed) {
  127. /* Here, we mix the LCRNG with low bits from one of the system
  128. clocks via XOR in the theory that this may be more random
  129. than either separately */
  130. rval = (random_value ^ clockbyte) % 10;
  131. /* Note that KC_1 thru KC_0 are a contiguous range */
  132. register_code (KC_1 + rval);
  133. unregister_code (KC_1 + rval);
  134. }
  135. break;
  136. case M_RANDLETTER:
  137. /* Generate, based on random number generator, a keystroke for
  138. a letter chosen at random */
  139. /* Here, we mix the LCRNG with low bits from one of the system
  140. clocks via XOR in the theory that this may be more random
  141. than either separately */
  142. random_value = ((random_value + randadd) * randmul) % randmod;
  143. if (record->event.pressed) {
  144. rval = (random_value ^ clockbyte) % 26;
  145. register_code (KC_A + rval);
  146. unregister_code (KC_A + rval);
  147. }
  148. break;
  149. }
  150. return MACRO_NONE;
  151. };