logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (13701B)


  1. #include QMK_KEYBOARD_H
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include "taphold.h"
  5. #include "ds1307.h"
  6. /* Note: don't forget there's some more code in qmk_firmware/users/anderson dir */
  7. #define _MAIN 0
  8. #define _ALPHA 1
  9. #define _BETA 2
  10. enum custom_keycodes {
  11. KC_MAIN = SAFE_RANGE,
  12. KC_ALPHA,
  13. KC_BETA,
  14. KC_SET_TIME,
  15. };
  16. /* TapHold is my own implementation of the `LT` macro. It's processed in `process_record_user()`. */
  17. #define TAPHOLD_CONFIG_SIZE 3
  18. taphold_t taphold_config[TAPHOLD_CONFIG_SIZE] = {
  19. {.key=KC_ALPHA, .mode=TAPHOLD_LAYER, .shortAction=KC_ESC, .longAction=_ALPHA},
  20. {.key=KC_BETA, .mode=TAPHOLD_LAYER, .shortAction=KC_EQL, .longAction=_BETA},
  21. {.key=KC_RCTL, .mode=TAPHOLD_MOD, .shortAction=KC_MINS, .longAction=KC_LCTL},
  22. };
  23. uint16_t taphold_config_size = TAPHOLD_CONFIG_SIZE;
  24. uint32_t taphold_timeout = 90;
  25. /* Colors */
  26. uint32_t layer_colors[3] = {
  27. [_MAIN] = 0xFF0010,
  28. [_ALPHA] = 0x4020FF,
  29. [_BETA] = 0x20FF00,
  30. };
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. /* Main layer
  33. │MUTE │ │L_MOD│
  34. ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓
  35. ┃ TAB ┃ Q │ W │ E │ R │ T ┃ Y │ U │ I │ O │ P ┃ BSP ┃
  36. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  37. ┃𝛼/ESC┃ A │ S │ D │ F │ G ┃ H │ J │ K │ L │ ; ┃ RET ┃
  38. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  39. ┃SHIFT┃ Z │ X │ C │ V │ B ┃ N │ M │ , │ . │ / ┃CTL/-┃
  40. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  41. ┃LCTRL┃ │ │ ALT │ GUI │SPACE┃SPACE│ 𝛽/= │ ' │ │ ┃ \ ┃
  42. ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛
  43. */
  44. [_MAIN] = LAYOUT(
  45. KC_MUTE, _______,
  46. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  47. KC_ALPHA,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT,
  48. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RCTL,
  49. KC_LCTL, _______, _______, KC_LALT, KC_LGUI, KC_SPC, KC_SPC, KC_BETA, KC_QUOT, _______, _______, KC_BSLS
  50. ),
  51. /* Alpha layer (𝛼)
  52. │ │ │ │
  53. ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓
  54. ┃ ┃PREV │PLAY │NEXT │ │NUMLK┃ - │ ^^^ │ ^ │ vvv │ ~ ┃ DEL ┃
  55. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  56. ┃ ┃ │VOL -│VOL +│ │CPSLK┃HOME │ <-- │ v │ --> │ ` ┃ \ ┃
  57. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  58. ┃ ┃ │ │ │ │SCRLK┃ END │ = │ [ │ ] │ ( ┃ ) ┃
  59. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  60. ┃ ┃ │ │ │ │ ┃ │ │ │ │ ┃ ┃
  61. ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛
  62. */
  63. [_ALPHA] = LAYOUT(
  64. _______, _______,
  65. _______, KC_MPRV, KC_MPLY, KC_MNXT, _______, KC_NUM, KC_MINS, KC_PGUP, KC_UP, KC_PGDN, KC_TILD, KC_DEL,
  66. _______, _______, KC_VOLD, KC_VOLU, _______, KC_CAPS, KC_HOME, KC_LEFT, KC_DOWN, KC_RIGHT,KC_GRV, KC_BSLS,
  67. _______, _______, _______, _______, _______, KC_SCRL, KC_END, KC_EQL, KC_LBRC, KC_RBRC, KC_LPRN ,KC_RPRN,
  68. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  69. ),
  70. /* Beta layer (𝛽)
  71. │ │ │ │
  72. ┏━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┯━━━━━┯━━━━━┯━━━━━┯━━━━━┳━━━━━┓
  73. ┃ RGB ┃ 1 │ 2 │ 3 │ 4 │ 5 ┃ 6 │ 7 │ 8 │ 9 │ 0 ┃ F12 ┃
  74. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  75. ┃L_MOD┃ F1 │ F2 │ F3 │ F4 │ F5 ┃ F6 │ F7 │ F8 │ F9 │ F10 ┃ F11 ┃
  76. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  77. ┃ ┃QK_BOOT│DB_TOGG│ │ │TIME ┃SLEEP│ │ { │ } │PTSCR┃ ┃
  78. ┣━━━━━╉─────┼─────┼─────┼─────┼─────╂─────┼─────┼─────┼─────┼─────╊━━━━━┫
  79. ┃ ┃ │ │ │ │ ┃ │ │ │ │ ┃ ┃
  80. ┗━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┷━━━━━┷━━━━━┷━━━━━┷━━━━━┻━━━━━┛
  81. */
  82. [_BETA] = LAYOUT(
  83. _______, _______,
  84. UG_TOGG, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_F12,
  85. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
  86. _______, QK_BOOT, DB_TOGG, _______, _______, KC_SET_TIME,KC_SLEP,_______,KC_LCBR,KC_RCBR, KC_PSCR, _______,
  87. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  88. )
  89. };
  90. static bool alpha_pressed = false;
  91. static bool beta_pressed = false;
  92. static bool ctrl_pressed = false;
  93. static bool alt_pressed = false;
  94. static bool shift_pressed = false;
  95. static bool gui_pressed = false;
  96. void keyboard_post_init_user(void) {
  97. /* debug_enable = true; */
  98. /* debug_matrix = true; */
  99. }
  100. void eeconfig_init_user(void) {
  101. set_unicode_input_mode(UNICODE_MODE_LINUX);
  102. }
  103. static uint32_t last_update = 0;
  104. static uint8_t hours, minutes, seconds;
  105. void matrix_scan_user(void) {
  106. uint32_t now = timer_read32();
  107. if (now - last_update > 500) {
  108. ds1307_get_time(&hours, &minutes, &seconds);
  109. last_update = now;
  110. }
  111. }
  112. static bool is_in_set_time = false;
  113. static char new_time[6];
  114. static uint8_t new_time_index = 0;
  115. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  116. if (keycode == KC_SET_TIME && record->event.pressed) {
  117. is_in_set_time = true;
  118. new_time_index = 0;
  119. } else if (is_in_set_time) {
  120. if (!record->event.pressed && keycode >= KC_1 && keycode <= KC_0) {
  121. new_time[new_time_index++] = (keycode == KC_0) ? 0 : keycode - KC_1 + 1;
  122. if (new_time_index == 6) {
  123. is_in_set_time = false;
  124. ds1307_set_time(
  125. (new_time[0]) * 10 + (new_time[1]),
  126. (new_time[2]) * 10 + (new_time[3]),
  127. (new_time[4]) * 10 + (new_time[5])
  128. );
  129. for (int i = 0; i < 6; i++) {
  130. tap_code(KC_BACKSPACE);
  131. }
  132. }
  133. }
  134. }
  135. if (keycode == KC_LCTL || keycode == KC_RCTL) {
  136. ctrl_pressed = record->event.pressed;
  137. } else if (keycode == KC_LALT) {
  138. alt_pressed = record->event.pressed;
  139. } else if (keycode == KC_LSFT) {
  140. shift_pressed = record->event.pressed;
  141. } else if (keycode == KC_LGUI) {
  142. gui_pressed = record->event.pressed;
  143. } else if (keycode == KC_ALPHA) {
  144. alpha_pressed = record->event.pressed;
  145. } else if (keycode == KC_BETA) {
  146. beta_pressed = record->event.pressed;
  147. }
  148. if (keycode == QK_BOOT) {
  149. rgblight_setrgb(255, 255, 0);
  150. }
  151. if (keycode == KC_LCTL) {
  152. /* Some Overlay1_Enable fuckery! */
  153. (record->event.pressed ? register_code : unregister_code)(KC_LCTL);
  154. return false;
  155. }
  156. return taphold_process(keycode, record);
  157. }
  158. bool encoder_update_user(uint8_t index, bool clockwise) {
  159. if (index == 0) {
  160. if (!alpha_pressed) {
  161. tap_code(clockwise ? KC_VOLD : KC_VOLU);
  162. } else {
  163. tap_code(clockwise ? KC_MPRV : KC_MNXT);
  164. }
  165. } else if (index == 1) {
  166. if (!alpha_pressed) {
  167. tap_code(clockwise ? KC_UP : KC_DOWN);
  168. } else {
  169. tap_code(clockwise ? KC_PGUP : KC_PGDN);
  170. }
  171. }
  172. return true;
  173. }
  174. #ifdef OLED_ENABLE
  175. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  176. return OLED_ROTATION_0;
  177. }
  178. bool oled_task_user(void) {
  179. /* Host Keyboard Layer Status */
  180. uint8_t current_layer = get_highest_layer(layer_state);
  181. /* Layer */
  182. static const char PROGMEM icons[4][3][6] = {
  183. {
  184. { 0x80, 0x81, 0x82, 0x83, 0x84, 0 },
  185. { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0 },
  186. { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0 }
  187. },
  188. {
  189. { 0x85, 0x86, 0x87, 0x88, 0x89, 0 },
  190. { 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0 },
  191. { 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0 }
  192. },
  193. {
  194. { 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0 },
  195. { 0xaa, 0xab, 0xac, 0xad, 0xae, 0 },
  196. { 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0 }
  197. },
  198. {
  199. { 0x8f, 0x90, 0x91, 0x92, 0x93, 0 },
  200. { 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0 },
  201. { 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0 }
  202. }
  203. };
  204. uint8_t icon_index = current_layer == _MAIN ? 3 : current_layer == _ALPHA ? 1 : 2;
  205. for (int i = 0; i < 3; i++) {
  206. oled_set_cursor(0, i + 1);
  207. oled_write_P(icons[icon_index][i], false);
  208. }
  209. /* Time */
  210. oled_set_cursor(6, 0);
  211. // oled_write_P(PSTR("-D48 Custom-\n"), false);
  212. char buf[16];
  213. sprintf(
  214. buf,
  215. "%02d:%02d:%02d", hours, minutes, seconds
  216. );
  217. oled_write(buf, false);
  218. /* Modifiers */
  219. static const char PROGMEM mods[][2] = {
  220. {0x94, 0x95}, // CTL
  221. {0x96, 0x97}, // ALT
  222. {0x98, 0x99}, // GUI
  223. {0x9a, 0x9b}, // SFT
  224. /* {0x9c, 0x9d}, // EMPTY */
  225. };
  226. char mod_data[13] = "\x9c\x9d\x9c\x9d\x9c\x9d\x9c\x9d \x07\x07\x07\0";
  227. if (ctrl_pressed) strncpy(mod_data, mods[0], 2);
  228. if (alt_pressed) strncpy(mod_data + 2, mods[1], 2);
  229. if (gui_pressed) strncpy(mod_data + 4, mods[2], 2);
  230. if (shift_pressed) strncpy(mod_data + 6, mods[3], 2);
  231. led_t led_usb_state = host_keyboard_led_state();
  232. if (led_usb_state.num_lock) mod_data[9] = 'N';
  233. if (led_usb_state.caps_lock) mod_data[10] = 'C';
  234. if (led_usb_state.scroll_lock) mod_data[11] = 'S';
  235. oled_set_cursor(6, 1);
  236. oled_write(mod_data, false);
  237. /* Matrix */
  238. static const char PROGMEM matrix_chars[] = {
  239. 0xb4, // None
  240. 0xb5, // Upper
  241. 0xb6, // Lower
  242. 0xb7 // Both
  243. };
  244. for (uint8_t row = 1; row < MATRIX_ROWS; row += 2) {
  245. // Skip first row because it's used by the encoders.
  246. uint16_t bits1 = matrix_get_row(row);
  247. uint16_t bits2 = matrix_get_row(row + 1);
  248. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  249. uint8_t matrix_char = matrix_chars[((bits1 & (1 << col)) ? 1 : 0) | ((bits2 & (1 << col)) ? 2 : 0)];
  250. oled_set_cursor(6 + col, 2 + (row - 1) / 2);
  251. oled_write_char(matrix_char, false);
  252. }
  253. }
  254. return false;
  255. }
  256. #endif