Peter's keyboard firmware (QMK) https://qmk.fm/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

keymap.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* Copyright 2017 Christopher B Browne
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "xd75.h"
  17. /* Fillers to make layering more clear */
  18. #define ___T___ KC_TRNS
  19. /* Layer shorthand */
  20. enum layers {
  21. _QWERTY = 0, /* Qwerty mapping */
  22. _LOWER, /* Lower layer, where top line has symbols !@#$%^&*() */
  23. _RAISE, /* Raised layer, where top line has digits 1234567890 */
  24. _ADJUST, /* Special Adjust layer coming via tri-placement */
  25. _FUNCTION /* Function key layer */
  26. };
  27. /* Macros need to be uniquely identified; using an enum to do this
  28. automatically
  29. */
  30. enum macro_id {
  31. M_LED = 0,
  32. M_USERNAME,
  33. M_RANDDIGIT,
  34. M_RANDLETTER,
  35. M_VERSION,
  36. MACRO_UPPER,
  37. MACRO_LOWER,
  38. };
  39. /* I want some short forms for keycodes so that they fit into
  40. limited-width cells */
  41. #define M_LOWER M(MACRO_LOWER)
  42. #define M_UPPER M(MACRO_UPPER)
  43. #define ROT_LED M(M_LED) /* Rotate LED */
  44. #define QWERTY DF(_QWERTY) /* Switch to QWERTY layout */
  45. #define QCENT2 DF(_QCENT2) /* Switch to QWERTY-with-centre layout */
  46. #define USERNAME M(M_USERNAME) /* shortcut for username */
  47. #define RANDDIG M(M_RANDDIGIT)
  48. #define RANDALP M(M_RANDLETTER)
  49. #define CTLENTER MT(MOD_RCTL, KC_ENT)
  50. #define SHIFTQUOTE MT(MOD_RSFT, KC_QUOT)
  51. #define ALTRIGHT MT(MOD_LALT, KC_RGHT)
  52. #define MVERSION M(M_VERSION)
  53. #define ALTSLASH LALT(KC_SLSH)
  54. #define FUNCTION MO(_FUNCTION)
  55. #define MRAISE MO(_RAISE)
  56. #define MLOWER MO(_LOWER)
  57. #define ALTPLUS ALT_T(KC_PLUS)
  58. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  59. /* QWERTY - MIT ENHANCED / GRID COMPATIBLE
  60. * .---------------------------------------------------------------------------------------------------------------------- 2u ------------.
  61. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | XXXXXX . BACKSP |
  62. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
  63. * | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \ | DEL |
  64. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------|
  65. * | ESC | A | S | D | F | G | H | J | K | L | ; | ' | XXXXXX . ENTER | PG UP |
  66. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------|
  67. * | LSHIFT | Z | X | C | V | B | N | M | , | . | / | XXXXXX . RSHIFT | UP | PG DN |
  68. * |--------+--------+--------+--------+--------+- 2u ------------+--------+--------+--------+--------+-----------------+--------+--------|
  69. * | BRITE | LCTRL | LALT | LGUI | RAISE | XXXXXX . SPACE | LOWER | RGUI | RALT | RCTRL | FN | LEFT | DOWN | RIGHT |
  70. * '--------------------------------------------------------------------------------------------------------------------------------------'
  71. */
  72. /* layout for centred keypad + qwerty...
  73. |ESC| 1 | 2 | 3 | 4 | 5 | ? | ? | ? | ? | 6 | 7 | 8 | 9 | 0 |
  74. |TAB| q | w | e | r | t | ? | ? | ? | ? | y | u | i | o | p |
  75. |CTL| a | s | d | f | g | ? | ? | ? | ? | h | j | k | l | ; |
  76. |SHF| z | x | c | v | b | ? | ? | ? | ? | n | m | , | . | / |
  77. |ALT|LED| | | | | | | | | | | | | |
  78. keys needing to be assigned:
  79. 51 - KC_TAB - tab
  80. - ROT_LED - rotate LED
  81. 15 - KC_LALT - Left ALT
  82. 53,55 - M_RAISE - switch to RAISE layer
  83. 5b - M_LOWER - switch to LOWER layer
  84. 56,59,5a - KC_SPC - space
  85. 5c - KC_LEFT - famous arrows
  86. 5d - KC_DOWN - famous arrows
  87. 5e - KC_UP - famous arrows
  88. 5f - KC_RIGHT - famous arrows
  89. 3f - KC_ENT - enter
  90. - KC_GRV - leftwards quote
  91. 4f - KC_QUOT - rightwards quote
  92. 1f - KC_BSPC - backspace
  93. 11 - KC_ESC
  94. 19 - KC_GRV - ` - raised
  95. 19 - KC_TILD - ~ - lowered
  96. */
  97. [_QWERTY] = LAYOUT_ortho_5x15( /* QWERTY, with keypad in the centre */
  98. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_EQL, KC_MINS, KC_EQL, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC ,
  99. KC_LALT, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_7, KC_8, KC_EQL, KC_Y, KC_U, KC_I, KC_O, KC_P, ALTPLUS ,
  100. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_LBRC, KC_RBRC,KC_MINS, KC_H, KC_J, KC_K, KC_L, KC_SCLN, CTLENTER ,
  101. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_PGUP, KC_EQL, KC_BSLS, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SHIFTQUOTE ,
  102. KC_TAB, FUNCTION, MRAISE, FUNCTION, MRAISE, KC_SPC,KC_PGDN, KC_MINS, KC_SPC, KC_SPC, MLOWER, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  103. ),
  104. /* LOWER
  105. * .---------------------------------------------------------------------------------------------------------------------- 2u ------------.
  106. * | | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | XXXXXX . |
  107. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
  108. * | | ! | @ | # | $ | % | ^ | & | * | ( | ) | | | | INS |
  109. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------|
  110. * | | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | XXXXXX . | |
  111. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------|
  112. * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | | XXXXXX . | | |
  113. * |--------+--------+--------+--------+--------+- 2u ------------+--------+--------+--------+--------+-----------------+--------+--------|
  114. * | | | | | | XXXXXX . | | | | | | | | |
  115. * '--------------------------------------------------------------------------------------------------------------------------------------'
  116. */
  117. [_LOWER] = LAYOUT_ortho_5x15( /* LOWERED */
  118. ___T___, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, KC_TILD, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11 ,
  119. ___T___, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, _______, _______, _______, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_INS ,
  120. ___T___, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE ,
  121. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______, ___T___, ___T___, _______ ,
  122. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  123. ),
  124. /* RAISED
  125. * .---------------------------------------------------------------------------------------------------------------------- 2u ------------.
  126. * | | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | XXXXXX . |
  127. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
  128. * | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | | | | INS |
  129. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------|
  130. * | | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | XXXXXX . | |
  131. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------|
  132. * | | F7 | F8 | F9 | F10 | F11 | F12 | | | | | XXXXXX . | | |
  133. * |--------+--------+--------+--------+--------+- 2u ------------+--------+--------+--------+--------+-----------------+--------+--------|
  134. * | | | | | | XXXXXX . | | | | | | | | |
  135. * '--------------------------------------------------------------------------------------------------------------------------------------'
  136. */
  137. [_RAISE] = LAYOUT_ortho_5x15 ( /* RAISED */
  138. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, MVERSION, _______, KC_GRV, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, ___T___ ,
  139. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, USERNAME, _______, KC_7, KC_8, KC_LCBR, KC_RCBR, _______, _______, KC_INS ,
  140. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, RANDDIG, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, ___T___, ___T___ ,
  141. KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, RANDALP, _______, _______, _______, _______, ___T___, ___T___, _______, _______ ,
  142. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  143. ),
  144. /* FUNCTION
  145. * .---------------------------------------------------------------------------------------------------------------------- 2u ------------.
  146. * | NUM LK | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | XXXXXX . |
  147. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
  148. * | SCR LK | F13 | F14 | F15 | F16 | F17 | F18 | F19 | F20 | F21 | F22 | F23 | F24 | PAUSE | PR SCR |
  149. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------|
  150. * | CAP LK | MS BT5 | MS BT4 | MS BT3 | MS BT2 | SLOW M | FAST M | NEXT | VOL+ | VOL- | PLAY | | XXXXXX | | WHEEL+ |
  151. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------|
  152. * | RGB TG | RGB MD | RGB HI | RGB HD | RGB SI | RGB SD | RGB VI | RGB VD | BL TOG | BL INC | BL DEC | XXXXXX | | MOUS U | WHEEL- |
  153. * |--------+--------+--------+--------+--------+-- 2u -----------+--------+--------+--------+--------+-----------------+--------+--------|
  154. * | RESET | | QWERTY | COLEMK | DVORAK | XXXXXX . MS BT1 | | | | | | MOUS L | MOUS D | MOUS R |
  155. * '--------------------------------------------------------------------------------------------------------------------------------------'
  156. */
  157. [_FUNCTION] = LAYOUT_ortho_5x15( /* FUNCTION */
  158. KC_NLCK, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, RESET, RESET,
  159. KC_SLCK, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, KC_F21, KC_F22, KC_F23, KC_F24, KC_PAUS, KC_PSCR ,
  160. KC_CAPS, KC_BTN5, KC_BTN4, KC_BTN3, KC_BTN2, KC_ACL0, KC_ACL2, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, ___T___, ___T___, KC_WH_U ,
  161. RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, BL_TOGG, BL_INC, BL_DEC, ___T___, ___T___, KC_MS_U, KC_WH_D ,
  162. RESET , _______, DF(_QWERTY), DF(_QWERTY), DF(_QWERTY), KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R
  163. )
  164. };
  165. /* This bit of logic seeds a wee linear congruential random number generator */
  166. /* lots of prime numbers everywhere... */
  167. static uint16_t random_value = 157;
  168. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  169. {
  170. uint8_t clockbyte=0;
  171. clockbyte = TCNT1 % 256;
  172. uint8_t rval;
  173. /* MACRODOWN only works in this function */
  174. switch(id) {
  175. case 0:
  176. if (record->event.pressed) {
  177. register_code(KC_RSFT);
  178. #ifdef BACKLIGHT_ENABLE
  179. backlight_step();
  180. #endif
  181. } else {
  182. unregister_code(KC_RSFT);
  183. }
  184. break;
  185. case M_USERNAME:
  186. if (record->event.pressed) {
  187. SEND_STRING("cbbrowne");
  188. }
  189. break;
  190. case M_VERSION:
  191. if (record->event.pressed) {
  192. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP);
  193. }
  194. break;
  195. case M_RANDDIGIT:
  196. /* Generate, based on random number generator, a keystroke for
  197. a numeric digit chosen at random */
  198. random_value = ((random_value + randadd) * randmul) % randmod;
  199. if (record->event.pressed) {
  200. /* Here, we mix the LCRNG with low bits from one of the system
  201. clocks via XOR in the theory that this may be more random
  202. than either separately */
  203. rval = (random_value ^ clockbyte) % 10;
  204. /* Note that KC_1 thru KC_0 are a contiguous range */
  205. register_code (KC_1 + rval);
  206. unregister_code (KC_1 + rval);
  207. }
  208. break;
  209. case M_RANDLETTER:
  210. /* Generate, based on random number generator, a keystroke for
  211. a letter chosen at random */
  212. /* Here, we mix the LCRNG with low bits from one of the system
  213. clocks via XOR in the theory that this may be more random
  214. than either separately */
  215. random_value = ((random_value + randadd) * randmul) % randmod;
  216. if (record->event.pressed) {
  217. rval = (random_value ^ clockbyte) % 26;
  218. register_code (KC_A + rval);
  219. unregister_code (KC_A + rval);
  220. }
  221. break;
  222. case MACRO_UPPER:
  223. if (record->event.pressed)
  224. {
  225. layer_on(_RAISE);
  226. #ifdef BACKLIGHT_ENABLE
  227. breathing_period_set(2);
  228. breathing_pulse();
  229. #endif
  230. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  231. }
  232. else
  233. {
  234. layer_off(_RAISE);
  235. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  236. }
  237. break;
  238. case MACRO_LOWER:
  239. if (record->event.pressed)
  240. {
  241. layer_on(_LOWER);
  242. #ifdef BACKLIGHT_ENABLE
  243. breathing_period_set(2);
  244. breathing_pulse();
  245. #endif
  246. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  247. }
  248. else
  249. {
  250. layer_off(_LOWER);
  251. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  252. }
  253. break;
  254. }
  255. return MACRO_NONE;
  256. };
  257. void matrix_init_user(void) {
  258. rgblight_enable();
  259. rgblight_mode(1);
  260. rgblight_sethsv(325,255,255);
  261. }
  262. uint32_t layer_state_set_user(uint32_t state) {
  263. switch(biton32(state)) {
  264. case _QWERTY:
  265. rgblight_sethsv_white();
  266. break;
  267. case _LOWER:
  268. rgblight_sethsv_blue();
  269. break;
  270. case _RAISE:
  271. rgblight_sethsv_green();
  272. break;
  273. case _ADJUST:
  274. rgblight_sethsv_orange();
  275. break;
  276. case _FUNCTION:
  277. rgblight_sethsv_red();
  278. break;
  279. default:
  280. rgblight_sethsv(325,255,255);
  281. break;
  282. }
  283. return state;
  284. }