keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /* Copyright 2022 charlesrocket
  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 QMK_KEYBOARD_H
  17. enum alt_keycodes {
  18. L_BRI = SAFE_RANGE, //LED Brightness Increase //Working
  19. L_BRD, //LED Brightness Decrease //Working
  20. L_EDG_I, //LED Edge Brightness Increase
  21. L_EDG_D, //LED Edge Brightness Decrease
  22. L_EDG_M, //LED Edge lighting mode
  23. L_PTN, //LED Pattern Select Next //Working
  24. L_PTP, //LED Pattern Select Previous //Working
  25. L_PSI, //LED Pattern Speed Increase //Working
  26. L_PSD, //LED Pattern Speed Decrease //Working
  27. L_RATIOD,
  28. L_RATIOI,
  29. L_T_MD, //LED Toggle Mode //Working
  30. L_T_ONF, //LED Toggle On / Off //Broken
  31. L_ON, //LED On //Broken
  32. L_OFF, //LED Off //Broken
  33. L_T_BR, //LED Toggle Breath Effect //Working
  34. L_T_PTD, //LED Toggle Scrolling Pattern Direction //Working
  35. U_T_AGCR, //USB Toggle Automatic GCR control //Working
  36. DBG_TOG, //DEBUG Toggle On / Off //
  37. DBG_MTRX, //DEBUG Toggle Matrix Prints //
  38. DBG_KBD, //DEBUG Toggle Keyboard Prints //
  39. DBG_MOU, //DEBUG Toggle Mouse Prints //
  40. DBG_FAC, //DEBUG Factory light testing (All on white)
  41. MD_BOOT //Restart into bootloader after hold timeout //Working
  42. };
  43. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  44. [0] = LAYOUT(
  45. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL,
  46. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_HOME,
  47. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP,
  48. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN,
  49. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT
  50. ),
  51. [1] = LAYOUT(
  52. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_MUTE,
  53. L_T_BR, L_PSD, L_BRI, L_PSI, L_EDG_I, _______, _______, _______, U_T_AGCR,_______, KC_PSCR, KC_SCRL, KC_PAUS, _______, KC_END,
  54. L_T_PTD, L_PTP, L_BRD, L_PTN, L_EDG_D, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLU,
  55. _______, L_T_MD, L_T_ONF, _______, L_EDG_M, MD_BOOT, NK_TOGG, _______, _______, _______, _______, _______, KC_PGUP, KC_VOLD,
  56. MO(2), _______, _______, DBG_FAC, KC_APP, _______, KC_HOME, KC_PGDN, KC_END
  57. ),
  58. [2] = LAYOUT(
  59. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  60. _______, _______, _______, EE_CLR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  61. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  62. _______, UC_PREV, UC_NEXT, _______, _______, QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______,
  63. _______, LAG_SWP, LAG_NRM, _______, _______, TG(3), _______, _______, _______
  64. ),
  65. [3] = LAYOUT(
  66. XP(0,1), XP(2,3), XP(4,5), XP(6,7), XP(8,9), XP(10,11), XP(12,13), XP(14,15), XP(16,17), XP(18,19), XP(20,21), XP(22,23), XP(24,25), _______, _______,
  67. _______, KC_QUES, XP(27,28), XP(29,31), X(32), XP(33,34), X(35), X(36), XP(37,38), XP(39,40), XP(41,42), XP(43,44), XP(45,46), _______, _______,
  68. _______, XP(47,48), X(49), X(50), KC_UNDS, XP(52,5), XP(53,54), XP(55,56), KC_QUOT, XP(59,60), XP(61,62), XP(63,64), _______, _______,
  69. _______, XP(65,66), X(67), XP(68,69), X(70), X(71), X(72), X(73), KC_PIPE, XP(75,76), X(77), XP(78,79), _______, _______,
  70. _______, _______, _______, _______, _______, TG(3), _______, _______, _______
  71. ),
  72. };
  73. #define MODS_SHIFT (get_mods() & MOD_BIT(KC_LSFT) || get_mods() & MOD_BIT(KC_RSFT))
  74. #define MODS_CTRL (get_mods() & MOD_BIT(KC_LCTL) || get_mods() & MOD_BIT(KC_RCTL))
  75. #define MODS_ALT (get_mods() & MOD_BIT(KC_LALT) || get_mods() & MOD_BIT(KC_RALT))
  76. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  77. static uint32_t key_timer;
  78. static uint8_t scroll_effect = 0;
  79. switch (keycode) {
  80. case L_BRI ... U_T_AGCR:
  81. if (record->event.pressed) {
  82. md_led_changed();
  83. }
  84. break;
  85. }
  86. switch (keycode) {
  87. case L_BRI:
  88. if (record->event.pressed) {
  89. if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX;
  90. else gcr_desired += LED_GCR_STEP;
  91. if (led_animation_breathing) gcr_breathe = gcr_desired;
  92. }
  93. return false;
  94. case L_BRD:
  95. if (record->event.pressed) {
  96. if (LED_GCR_STEP > gcr_desired) gcr_desired = 0;
  97. else gcr_desired -= LED_GCR_STEP;
  98. if (led_animation_breathing) gcr_breathe = gcr_desired;
  99. }
  100. return false;
  101. case L_EDG_M:
  102. if (record->event.pressed) {
  103. led_edge_mode++;
  104. if (led_edge_mode > LED_EDGE_MODE_MAX) {
  105. led_edge_mode = LED_EDGE_MODE_ALL;
  106. }
  107. }
  108. return false;
  109. case L_EDG_I:
  110. if (record->event.pressed) {
  111. led_edge_brightness += 0.1;
  112. if (led_edge_brightness > 1) { led_edge_brightness = 1; }
  113. }
  114. return false;
  115. case L_EDG_D:
  116. if (record->event.pressed) {
  117. led_edge_brightness -= 0.1;
  118. if (led_edge_brightness < 0) { led_edge_brightness = 0; }
  119. }
  120. return false;
  121. case L_RATIOI:
  122. if (record->event.pressed) {
  123. led_ratio_brightness += 0.2;
  124. if (led_ratio_brightness > 2.0) { led_ratio_brightness = 2.0; }
  125. }
  126. return false;
  127. case L_RATIOD:
  128. if (record->event.pressed) {
  129. led_ratio_brightness -= 0.2;
  130. if (led_ratio_brightness < 0.0) { led_ratio_brightness = 0.0; }
  131. }
  132. return false;
  133. case L_PTN:
  134. if (record->event.pressed) {
  135. if (led_animation_id == led_setups_count - 1) led_animation_id = 0;
  136. else led_animation_id++;
  137. }
  138. return false;
  139. case L_PTP:
  140. if (record->event.pressed) {
  141. if (led_animation_id == 0) led_animation_id = led_setups_count - 1;
  142. else led_animation_id--;
  143. }
  144. return false;
  145. case L_PSI:
  146. if (record->event.pressed) {
  147. led_animation_speed += ANIMATION_SPEED_STEP;
  148. }
  149. return false;
  150. case L_PSD:
  151. if (record->event.pressed) {
  152. led_animation_speed -= ANIMATION_SPEED_STEP;
  153. if (led_animation_speed < 0) led_animation_speed = 0;
  154. }
  155. return false;
  156. case L_T_MD:
  157. if (record->event.pressed) {
  158. led_lighting_mode++;
  159. if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL;
  160. }
  161. return false;
  162. case L_T_ONF:
  163. if (record->event.pressed) {
  164. led_enabled = !led_enabled;
  165. I2C3733_Control_Set(led_enabled);
  166. }
  167. return false;
  168. case L_ON:
  169. if (record->event.pressed) {
  170. led_enabled = 1;
  171. I2C3733_Control_Set(led_enabled);
  172. }
  173. return false;
  174. case L_OFF:
  175. if (record->event.pressed) {
  176. led_enabled = 0;
  177. I2C3733_Control_Set(led_enabled);
  178. }
  179. return false;
  180. case L_T_BR:
  181. if (record->event.pressed) {
  182. led_animation_breathing = !led_animation_breathing;
  183. if (led_animation_breathing) {
  184. gcr_breathe = gcr_desired;
  185. led_animation_breathe_cur = BREATHE_MIN_STEP;
  186. breathe_dir = 1;
  187. }
  188. }
  189. return false;
  190. case L_T_PTD:
  191. if (record->event.pressed) {
  192. scroll_effect++;
  193. if (scroll_effect == 1) { //Patterns with scroll move horizontal (Right to left)
  194. led_animation_direction = 1;
  195. led_animation_orientation = 0;
  196. led_animation_circular = 0;
  197. } else if (scroll_effect == 2) { //Patterns with scroll move vertical (Top to bottom)
  198. led_animation_direction = 1;
  199. led_animation_orientation = 1;
  200. led_animation_circular = 0;
  201. } else if (scroll_effect == 3) { //Patterns with scroll move vertical (Bottom to top)
  202. led_animation_direction = 0;
  203. led_animation_orientation = 1;
  204. led_animation_circular = 0;
  205. } else if (scroll_effect == 4) { //Patterns with scroll explode from center
  206. led_animation_direction = 0;
  207. led_animation_orientation = 0;
  208. led_animation_circular = 1;
  209. } else if (scroll_effect == 5) { //Patterns with scroll implode on center
  210. led_animation_direction = 1;
  211. led_animation_orientation = 0;
  212. led_animation_circular = 1;
  213. } else { //Patterns with scroll move horizontal (Left to right)
  214. scroll_effect = 0;
  215. led_animation_direction = 0;
  216. led_animation_orientation = 0;
  217. led_animation_circular = 0;
  218. }
  219. }
  220. return false;
  221. case U_T_AGCR:
  222. if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
  223. TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
  224. }
  225. return false;
  226. case DBG_FAC:
  227. if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
  228. led_lighting_mode = LED_MODE_NORMAL;
  229. led_edge_brightness = 1;
  230. led_edge_mode = LED_EDGE_MODE_ALL;
  231. led_animation_breathing = 0;
  232. led_animation_id = 7; //led_programs.c led_setups leds_white index
  233. gcr_desired = LED_GCR_MAX;
  234. led_enabled = 1;
  235. I2C3733_Control_Set(led_enabled);
  236. }
  237. return false;
  238. case DBG_TOG:
  239. if (record->event.pressed) {
  240. TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
  241. }
  242. return false;
  243. case DBG_MTRX:
  244. if (record->event.pressed) {
  245. TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
  246. }
  247. return false;
  248. case DBG_KBD:
  249. if (record->event.pressed) {
  250. TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
  251. }
  252. return false;
  253. case DBG_MOU:
  254. if (record->event.pressed) {
  255. TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
  256. }
  257. return false;
  258. case MD_BOOT:
  259. if (record->event.pressed) {
  260. key_timer = timer_read32();
  261. } else {
  262. if (timer_elapsed32(key_timer) >= 500) {
  263. reset_keyboard();
  264. }
  265. }
  266. return false;
  267. default:
  268. return true;
  269. }
  270. }
  271. led_instruction_t led_instructions[] = {
  272. { .flags = LED_FLAG_USE_ROTATE_PATTERN },
  273. { .flags = LED_FLAG_MATCH_ID | LED_FLAG_MATCH_LAYER | LED_FLAG_USE_RGB, .id0 = 0x1, .b = 253, .layer = 1 },
  274. { .flags = LED_FLAG_MATCH_ID | LED_FLAG_MATCH_LAYER | LED_FLAG_USE_RGB, .id0 = 0x1, .r = 253, .b = 253, .layer = 2 },
  275. { .flags = LED_FLAG_MATCH_LAYER | LED_FLAG_USE_PATTERN, .pattern_id = 8, .layer = 3 },
  276. { .end = 1 }
  277. };