keymap.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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" to show that I could
  33. - There is a (somewhat cruddy) linear congruential random number
  34. generator.
  35. - I would like to be seeding it with clock info to make it look
  36. 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?
  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 haven't got page-up/page-down, let's have that...
  53. */
  54. enum layers {
  55. _QWERTY = 0, /* Qwerty mapping */
  56. _LOWER, /* Lower layer, where top line has symbols !@#$%^&*() */
  57. _RAISE, /* Raised layer, where top line has digits 1234567890 */
  58. _KEYPAD, /* Key pad */
  59. _ADJUST, /* Special Adjust layer coming via tri-placement */
  60. };
  61. enum macro_id {
  62. M_LED = 0,
  63. M_USERNAME,
  64. M_RANDDIGIT,
  65. M_RANDLETTER,
  66. M_VERSION,
  67. MACRO_UPPER,
  68. MACRO_LOWER,
  69. };
  70. #define M_LOWER M(MACRO_LOWER)
  71. #define M_UPPER M(MACRO_UPPER)
  72. #define ROT_LED M(M_LED) /* Rotate LED */
  73. #define QWERTY DF(_QWERTY) /* Switch to QWERTY layout */
  74. #define KEYPAD DF(_KEYPAD) /* Switch to keypad */
  75. #define USERNAME M(M_USERNAME) /* shortcut for username */
  76. #define RANDDIG M(M_RANDDIGIT)
  77. #define RANDALP M(M_RANDLETTER)
  78. #define CTLENTER MT(MOD_RCTL, KC_ENT)
  79. #define SHIFTQUOTE MT(MOD_RSFT, KC_QUOT)
  80. #define ALTRIGHT MT(MOD_LALT, KC_RGHT)
  81. #define MVERSION M(M_VERSION)
  82. #define ALTSLASH LALT(KC_SLSH)
  83. /* Note that Planck has dimensions 4 rows x 12 columns */
  84. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  85. [_QWERTY] = { /* Qwerty */
  86. {KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  87. {KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, CTLENTER},
  88. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SHIFTQUOTE },
  89. {KC_TAB, KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC, KC_SPC, M_UPPER, KC_LEFT, KC_DOWN, KC_UP, ALTRIGHT}
  90. /* Note that KC_SPC is recorded TWICE, so that either matrix position can activate it */
  91. },
  92. [_RAISE] = { /* RAISE */
  93. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  94. {_______, KC_4, KC_5, KC_6, _______, _______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
  95. {_______, KC_7, KC_8, KC_9, _______, _______, _______, QWERTY, KEYPAD, KEYPAD, ALTSLASH,_______},
  96. {_______, KC_0, _______, _______, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_END, KC_PGUP}
  97. },
  98. [_LOWER] = { /* LOWER */
  99. {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
  100. {_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
  101. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, QWERTY, KEYPAD, KEYPAD, ALTSLASH, _______},
  102. {_______, KEYPAD, _______, _______, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_END, KC_PGUP}
  103. },
  104. [_KEYPAD] = { /* Key Pad */
  105. {KC_ESC, USERNAME, MVERSION, KC_F10, KC_F11, KC_F12, KC_PGUP, KC_KP_ENTER, KC_7, KC_8, KC_9, KC_BSPC},
  106. {KC_LCTL, RANDDIG, KC_F5, KC_F6, KC_F7, KC_F8, KC_PGDN, KC_KP_MINUS, KC_4, KC_5, KC_6, KC_PIPE},
  107. {KC_LSFT, RANDALP, KC_F1, KC_F2, KC_F3, KC_F4, KC_DEL, KC_KP_PLUS, KC_1, KC_2, KC_3, KC_ENTER},
  108. {KC_TAB, KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC, KC_SPC, QWERTY, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT}
  109. },
  110. [_ADJUST] = { /* Adjustments - gonna shift the wild tools in here */
  111. {ROT_LED,USERNAME,MVERSION, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  112. {_______, RANDDIG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  113. {_______, RANDALP, _______, _______, _______, RESET, RESET, _______, _______, _______, _______, _______ },
  114. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ }
  115. }
  116. };
  117. /* What is fn_actions actually used for??? */
  118. const uint16_t PROGMEM fn_actions[] = {
  119. };
  120. /* This bit of logic seeds a wee linear congruential random number generator */
  121. /* lots of prime numbers everywhere... */
  122. static uint16_t random_value = 157;
  123. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  124. {
  125. uint8_t clockbyte=0;
  126. clockbyte = TCNT1 % 256;
  127. uint8_t rval;
  128. // MACRODOWN only works in this function
  129. switch(id) {
  130. case M_LED:
  131. if (record->event.pressed) {
  132. register_code(KC_RSFT);
  133. #ifdef BACKLIGHT_ENABLE
  134. backlight_step();
  135. #endif
  136. } else {
  137. unregister_code(KC_RSFT);
  138. }
  139. break;
  140. case M_USERNAME:
  141. if (record->event.pressed) {
  142. SEND_STRING("cbbrowne");
  143. }
  144. break;
  145. case M_VERSION:
  146. if (record->event.pressed) {
  147. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP "@" QMK_VERSION "@" QMK_BUILDDATE);
  148. }
  149. break;
  150. case M_RANDDIGIT:
  151. /* Generate, based on random number generator, a keystroke for
  152. a numeric digit chosen at random */
  153. random_value = ((random_value + randadd) * randmul) % randmod;
  154. if (record->event.pressed) {
  155. /* Here, we mix the LCRNG with low bits from one of the system
  156. clocks via XOR in the theory that this may be more random
  157. than either separately */
  158. rval = (random_value ^ clockbyte) % 10;
  159. /* Note that KC_1 thru KC_0 are a contiguous range */
  160. register_code (KC_1 + rval);
  161. unregister_code (KC_1 + rval);
  162. }
  163. break;
  164. case M_RANDLETTER:
  165. /* Generate, based on random number generator, a keystroke for
  166. a letter chosen at random */
  167. /* Here, we mix the LCRNG with low bits from one of the system
  168. clocks via XOR in the theory that this may be more random
  169. than either separately */
  170. random_value = ((random_value + randadd) * randmul) % randmod;
  171. if (record->event.pressed) {
  172. rval = (random_value ^ clockbyte) % 26;
  173. register_code (KC_A + rval);
  174. unregister_code (KC_A + rval);
  175. }
  176. break;
  177. case MACRO_UPPER:
  178. if (record->event.pressed)
  179. {
  180. layer_on(_RAISE);
  181. #ifdef BACKLIGHT_ENABLE
  182. breathing_speed_set(2);
  183. breathing_pulse();
  184. #endif
  185. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  186. }
  187. else
  188. {
  189. layer_off(_RAISE);
  190. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  191. }
  192. break;
  193. case MACRO_LOWER:
  194. if (record->event.pressed)
  195. {
  196. layer_on(_LOWER);
  197. #ifdef BACKLIGHT_ENABLE
  198. breathing_speed_set(2);
  199. breathing_pulse();
  200. #endif
  201. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  202. }
  203. else
  204. {
  205. layer_off(_LOWER);
  206. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  207. }
  208. break;
  209. }
  210. return MACRO_NONE;
  211. };