keymap.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #include QMK_KEYBOARD_H
  2. enum alt_keycodes {
  3. L_BRI = SAFE_RANGE, //LED Brightness Increase //Working
  4. L_BRD, //LED Brightness Decrease //Working
  5. L_EDG_I, //LED Edge Brightness Increase
  6. L_EDG_D, //LED Edge Brightness Decrease
  7. L_EDG_M, //LED Edge lighting mode
  8. L_PTN, //LED Pattern Select Next //Working
  9. L_PTP, //LED Pattern Select Previous //Working
  10. L_PSI, //LED Pattern Speed Increase //Working
  11. L_PSD, //LED Pattern Speed Decrease //Working
  12. L_RATIOD,
  13. L_RATIOI,
  14. L_T_MD, //LED Toggle Mode //Working
  15. L_T_ONF, //LED Toggle On / Off //Broken
  16. L_ON, //LED On //Broken
  17. L_OFF, //LED Off //Broken
  18. L_T_BR, //LED Toggle Breath Effect //Working
  19. L_T_PTD, //LED Toggle Scrolling Pattern Direction //Working
  20. U_T_AGCR, //USB Toggle Automatic GCR control //Working
  21. DBG_TOG, //DEBUG Toggle On / Off //
  22. DBG_MTRX, //DEBUG Toggle Matrix Prints //
  23. DBG_KBD, //DEBUG Toggle Keyboard Prints //
  24. DBG_MOU, //DEBUG Toggle Mouse Prints //
  25. DBG_FAC, //DEBUG Factory light testing (All on white)
  26. MD_BOOT //Restart into bootloader after hold timeout //Working
  27. };
  28. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  29. [0] = LAYOUT(
  30. 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,
  31. 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,
  32. 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,
  33. 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,
  34. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT
  35. ),
  36. [1] = LAYOUT(
  37. 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,
  38. L_T_BR, L_PSD, L_BRI, L_PSI, L_EDG_I, _______, _______, _______, U_T_AGCR,_______, KC_PSCR, KC_SCRL, KC_PAUS, _______, KC_END,
  39. L_T_PTD, L_PTP, L_BRD, L_PTN, L_EDG_D, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLU,
  40. _______, L_T_MD, L_T_ONF, _______, L_EDG_M, MD_BOOT, NK_TOGG, _______, _______, _______, _______, _______, KC_PGUP, KC_VOLD,
  41. _______, _______, _______, DBG_FAC, _______, _______, KC_HOME, KC_PGDN, KC_END
  42. ),
  43. /*
  44. [X] = LAYOUT(
  45. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  46. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  47. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  48. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  49. _______, _______, _______, _______, _______, _______, _______, _______, _______
  50. ),
  51. */
  52. };
  53. #define MODS_SHIFT (get_mods() & MOD_BIT(KC_LSFT) || get_mods() & MOD_BIT(KC_RSFT))
  54. #define MODS_CTRL (get_mods() & MOD_BIT(KC_LCTL) || get_mods() & MOD_BIT(KC_RCTL))
  55. #define MODS_ALT (get_mods() & MOD_BIT(KC_LALT) || get_mods() & MOD_BIT(KC_RALT))
  56. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  57. static uint32_t key_timer;
  58. static uint8_t scroll_effect = 0;
  59. switch (keycode) {
  60. case L_BRI ... U_T_AGCR:
  61. if (record->event.pressed) {
  62. md_led_changed();
  63. }
  64. break;
  65. }
  66. switch (keycode) {
  67. case L_BRI:
  68. if (record->event.pressed) {
  69. if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX;
  70. else gcr_desired += LED_GCR_STEP;
  71. if (led_animation_breathing) gcr_breathe = gcr_desired;
  72. }
  73. return false;
  74. case L_BRD:
  75. if (record->event.pressed) {
  76. if (LED_GCR_STEP > gcr_desired) gcr_desired = 0;
  77. else gcr_desired -= LED_GCR_STEP;
  78. if (led_animation_breathing) gcr_breathe = gcr_desired;
  79. }
  80. return false;
  81. case L_EDG_M:
  82. if (record->event.pressed) {
  83. led_edge_mode++;
  84. if (led_edge_mode > LED_EDGE_MODE_MAX) {
  85. led_edge_mode = LED_EDGE_MODE_ALL;
  86. }
  87. }
  88. return false;
  89. case L_EDG_I:
  90. if (record->event.pressed) {
  91. led_edge_brightness += 0.1;
  92. if (led_edge_brightness > 1) { led_edge_brightness = 1; }
  93. }
  94. return false;
  95. case L_EDG_D:
  96. if (record->event.pressed) {
  97. led_edge_brightness -= 0.1;
  98. if (led_edge_brightness < 0) { led_edge_brightness = 0; }
  99. }
  100. return false;
  101. case L_RATIOI:
  102. if (record->event.pressed) {
  103. led_ratio_brightness += 0.2;
  104. if (led_ratio_brightness > 2.0) { led_ratio_brightness = 2.0; }
  105. }
  106. return false;
  107. case L_RATIOD:
  108. if (record->event.pressed) {
  109. led_ratio_brightness -= 0.2;
  110. if (led_ratio_brightness < 0.0) { led_ratio_brightness = 0.0; }
  111. }
  112. return false;
  113. case L_PTN:
  114. if (record->event.pressed) {
  115. if (led_animation_id == led_setups_count - 1) led_animation_id = 0;
  116. else led_animation_id++;
  117. }
  118. return false;
  119. case L_PTP:
  120. if (record->event.pressed) {
  121. if (led_animation_id == 0) led_animation_id = led_setups_count - 1;
  122. else led_animation_id--;
  123. }
  124. return false;
  125. case L_PSI:
  126. if (record->event.pressed) {
  127. led_animation_speed += ANIMATION_SPEED_STEP;
  128. }
  129. return false;
  130. case L_PSD:
  131. if (record->event.pressed) {
  132. led_animation_speed -= ANIMATION_SPEED_STEP;
  133. if (led_animation_speed < 0) led_animation_speed = 0;
  134. }
  135. return false;
  136. case L_T_MD:
  137. if (record->event.pressed) {
  138. led_lighting_mode++;
  139. if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL;
  140. }
  141. return false;
  142. case L_T_ONF:
  143. if (record->event.pressed) {
  144. led_enabled = !led_enabled;
  145. I2C3733_Control_Set(led_enabled);
  146. }
  147. return false;
  148. case L_ON:
  149. if (record->event.pressed) {
  150. led_enabled = 1;
  151. I2C3733_Control_Set(led_enabled);
  152. }
  153. return false;
  154. case L_OFF:
  155. if (record->event.pressed) {
  156. led_enabled = 0;
  157. I2C3733_Control_Set(led_enabled);
  158. }
  159. return false;
  160. case L_T_BR:
  161. if (record->event.pressed) {
  162. led_animation_breathing = !led_animation_breathing;
  163. if (led_animation_breathing) {
  164. gcr_breathe = gcr_desired;
  165. led_animation_breathe_cur = BREATHE_MIN_STEP;
  166. breathe_dir = 1;
  167. }
  168. }
  169. return false;
  170. case L_T_PTD:
  171. if (record->event.pressed) {
  172. scroll_effect++;
  173. if (scroll_effect == 1) { //Patterns with scroll move horizontal (Right to left)
  174. led_animation_direction = 1;
  175. led_animation_orientation = 0;
  176. led_animation_circular = 0;
  177. } else if (scroll_effect == 2) { //Patterns with scroll move vertical (Top to bottom)
  178. led_animation_direction = 1;
  179. led_animation_orientation = 1;
  180. led_animation_circular = 0;
  181. } else if (scroll_effect == 3) { //Patterns with scroll move vertical (Bottom to top)
  182. led_animation_direction = 0;
  183. led_animation_orientation = 1;
  184. led_animation_circular = 0;
  185. } else if (scroll_effect == 4) { //Patterns with scroll explode from center
  186. led_animation_direction = 0;
  187. led_animation_orientation = 0;
  188. led_animation_circular = 1;
  189. } else if (scroll_effect == 5) { //Patterns with scroll implode on center
  190. led_animation_direction = 1;
  191. led_animation_orientation = 0;
  192. led_animation_circular = 1;
  193. } else { //Patterns with scroll move horizontal (Left to right)
  194. scroll_effect = 0;
  195. led_animation_direction = 0;
  196. led_animation_orientation = 0;
  197. led_animation_circular = 0;
  198. }
  199. }
  200. return false;
  201. case U_T_AGCR:
  202. if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
  203. TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
  204. }
  205. return false;
  206. case DBG_FAC:
  207. if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
  208. led_lighting_mode = LED_MODE_NORMAL;
  209. led_edge_brightness = 1;
  210. led_edge_mode = LED_EDGE_MODE_ALL;
  211. led_animation_breathing = 0;
  212. led_animation_id = 7; //led_programs.c led_setups leds_white index
  213. gcr_desired = LED_GCR_MAX;
  214. led_enabled = 1;
  215. I2C3733_Control_Set(led_enabled);
  216. }
  217. return false;
  218. case DBG_TOG:
  219. if (record->event.pressed) {
  220. TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
  221. }
  222. return false;
  223. case DBG_MTRX:
  224. if (record->event.pressed) {
  225. TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
  226. }
  227. return false;
  228. case DBG_KBD:
  229. if (record->event.pressed) {
  230. TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
  231. }
  232. return false;
  233. case DBG_MOU:
  234. if (record->event.pressed) {
  235. TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
  236. }
  237. return false;
  238. case MD_BOOT:
  239. if (record->event.pressed) {
  240. key_timer = timer_read32();
  241. } else {
  242. if (timer_elapsed32(key_timer) >= 500) {
  243. reset_keyboard();
  244. }
  245. }
  246. return false;
  247. default:
  248. return true; //Process all other keycodes normally
  249. }
  250. }
  251. led_instruction_t led_instructions[] = {
  252. //LEDs are normally inactive, no processing is performed on them
  253. //Flags are used in matching criteria for an LED to be active and indicate how to color it
  254. //Flags can be found in tmk_core/protocol/arm_atsam/md_rgb_matrix.h (prefixed with LED_FLAG_)
  255. //LED IDs can be found in config_led.h in the keyboard's directory
  256. //Examples are below
  257. //All LEDs use the user's selected pattern (this is the factory default)
  258. { .flags = LED_FLAG_USE_ROTATE_PATTERN },
  259. //Specific LEDs use the user's selected pattern while all others are off
  260. // { .flags = LED_FLAG_MATCH_ID | LED_FLAG_USE_ROTATE_PATTERN, .id0 = 0xFFFFFFFF, .id1 = 0xAAAAAAAA, .id2 = 0x55555555, .id3 = 0x11111111 },
  261. //Specific LEDs use specified RGB values while all others are off
  262. // { .flags = LED_FLAG_MATCH_ID | LED_FLAG_USE_RGB, .id0 = 0xFF, .id1 = 0x00FF, .id2 = 0x0000FF00, .id3 = 0xFF000000, .r = 75, .g = 150, .b = 225 },
  263. //All LEDs use the user's selected pattern
  264. //On layer 1, all key LEDs (except the top row which keeps active pattern) are red while all edge LEDs are green
  265. //When layer 1 is active, key LEDs use red (id0 32 - 16: 1111 1111 1111 1111 1000 0000 0000 0000 = 0xFFFF8000) (except top row 15 - 1)
  266. //When layer 1 is active, key LEDs use red (id1 64 - 33: 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF)
  267. //When layer 1 is active, key LEDs use red (id2 67 - 65: 0000 0000 0000 0000 0000 0000 0000 0111 = 0x00000007)
  268. //When layer 1 is active, edge LEDs use green (id2 95 - 68: 1111 1111 1111 1111 1111 1111 1111 1000 = 0xFFFFFFF8)
  269. //When layer 1 is active, edge LEDs use green (id3 105 - 96: 0000 0000 0000 0000 0000 0011 1111 1111 = 0x000003FF)
  270. // { .flags = LED_FLAG_USE_ROTATE_PATTERN },
  271. // { .flags = LED_FLAG_MATCH_ID | LED_FLAG_MATCH_LAYER | LED_FLAG_USE_RGB, .id0 = 0xFFFF8000, .id1 = 0xFFFFFFFF, .id2 = 0x00000007, .r = 255, .layer = 1 },
  272. // { .flags = LED_FLAG_MATCH_ID | LED_FLAG_MATCH_LAYER | LED_FLAG_USE_RGB, .id2 = 0xFFFFFFF8, .id3 = 0x000003FF, .g = 127, .layer = 1 },
  273. //All key LEDs use red while edge LEDs use the active pattern
  274. //All key LEDs use red (id0 32 - 1: 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF)
  275. //All key LEDs use red (id1 64 - 33: 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF)
  276. //All key LEDs use red (id2 67 - 65: 0000 0000 0000 0000 0000 0000 0000 0111 = 0x00000007)
  277. //Edge uses active pattern (id2 95 - 68: 1111 1111 1111 1111 1111 1111 1111 1000 = 0xFFFFFFF8)
  278. //Edge uses active pattern (id3 105 - 96: 0000 0000 0000 0000 0000 0011 1111 1111 = 0x000003FF)
  279. // { .flags = LED_FLAG_MATCH_ID | LED_FLAG_USE_RGB, .id0 = 0xFFFFFFFF, .id1 = 0xFFFFFFFF, .id2 = 0x00000007, .r = 255 },
  280. // { .flags = LED_FLAG_MATCH_ID | LED_FLAG_USE_ROTATE_PATTERN , .id2 = 0xFFFFFFF8, .id3 = 0x000003FF },
  281. //end must be set to 1 to indicate end of instruction set
  282. { .end = 1 }
  283. };