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.

342 lines
16 KiB

  1. // Copyright 2022 Vino Rodrigues (@vinorodrigues)
  2. // Copyright 2022 IDOBAO (@idobaokb)
  3. // SPDX-License-Identifier: GPL-2.0-or-later
  4. /* ------------------------------------------------------------------
  5. * This is the IDOBAO factory default keymap ;)
  6. * ------------------------------------------------------------------ */
  7. #include QMK_KEYBOARD_H
  8. #include "version.h"
  9. #ifdef RGB_MATRIX_ENABLE
  10. typedef union {
  11. uint32_t raw;
  12. struct {
  13. bool rgb_disable_perkey:1;
  14. #ifndef ID67_DISABLE_UNDERGLOW
  15. bool rgb_disable_underglow:1;
  16. #endif // ID67_DISABLE_UNDERGLOW
  17. };
  18. } user_config_t;
  19. #endif // RGB_MATRIX_ENABLE
  20. enum {
  21. KC_MCON = USER00, // macOS Open Mission Control
  22. KC_LPAD, // macOS Open Launchpad
  23. #ifdef RGB_MATRIX_ENABLE
  24. RGB_TPK, // Toggle Per-Key
  25. #ifndef ID67_DISABLE_UNDERGLOW
  26. RGB_TUG, // Toggle Underglow
  27. #endif // ID67_DISABLE_UNDERGLOW
  28. #endif //RGB_MATRIX_ENABLE
  29. KB_VRSN = USER09 // debug, type version
  30. };
  31. #ifndef RGB_MATRIX_ENABLE
  32. #define RGB_TPK _______
  33. #define RGB_TUG _______
  34. #else
  35. #ifdef ID67_DISABLE_UNDERGLOW
  36. #define RGB_TUG _______
  37. #endif // ID67_DISABLE_UNDERGLOW
  38. #endif // RGB_MATRIX_ENABLE
  39. enum macos_consumer_usages {
  40. _AC_SHOW_ALL_WINDOWS = 0x29F, // mapped to KC_MCON
  41. _AC_SHOW_ALL_APPS = 0x2A0 // mapped to KC_LPAD
  42. };
  43. /* Special Keys */
  44. #define SK_LT1C LT(1, KC_CAPS) // Layer Tap 1, i.e., Tap = Caps Lock, Hold = Layer 1
  45. #define SK_LT2A LT(2, KC_APP) // Layer Tap 2, i.e., Tap = Menu, Hold = Layer 2
  46. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  47. /*
  48. *
  49. * Esc 1 2 3 4 5 6 7 8 9 0 - = Backspc ~
  50. *
  51. * Tab Q W E R T Y U I O P [ ] \ Del
  52. *
  53. * *Caps* A S D F G H J K L ; ' Enter PUp *Caps* => `LT(1, KC_CAPS)`
  54. *
  55. * Shift Z X C V B N M , . / Shft Up PDn
  56. *
  57. * CtrlWin Alt Fn1 *Mn* Lf Dn Rt *Mn* => `LT(2, KC_APP)`
  58. *
  59. */
  60. [0] = LAYOUT_65_ansi_blocker(
  61. 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_TILD,
  62. 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_DEL,
  63. SK_LT1C, 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,
  64. 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,
  65. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, MO(1), SK_LT2A, KC_LEFT, KC_DOWN, KC_RGHT
  66. ),
  67. /*
  68. *
  69. * F1 F2 F3 F4 F5 F6 F7 F8 F9 F10F11F12
  70. *
  71. * TogUp ModHu+Hu-Sa+Sa-Br+Br- TUGTPK
  72. *
  73. * Lf Dn Rt InsHomPUp
  74. *
  75. * RSTSp+Sp- Vl-MutVl+DelEndPDn
  76. *
  77. *
  78. *
  79. */
  80. [1] = LAYOUT_65_ansi_blocker(
  81. 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, _______, _______,
  82. _______, RGB_TOG, KC_UP, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, RGB_TUG, RGB_TPK, _______, _______,
  83. KC_CAPS, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, KC_INS, KC_HOME, KC_PGUP, _______, _______,
  84. _______, QK_BOOT, RGB_SPI, RGB_SPD, KB_VRSN, KC_VOLD, KC_MUTE, KC_VOLU, KC_DEL, KC_END, KC_PGDN, _______, _______, _______,
  85. _______, _______, _______, _______, _______, _______, _______, _______, _______
  86. ),
  87. /*
  88. *
  89. *
  90. *
  91. *
  92. *
  93. *
  94. *
  95. *
  96. *
  97. *
  98. *
  99. */
  100. [2] = LAYOUT_65_ansi_blocker(
  101. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  102. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  103. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  104. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  105. _______, _______, _______, _______, _______, _______, _______, _______, _______
  106. ),
  107. [3] = LAYOUT_65_ansi_blocker(
  108. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  109. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  110. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  111. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  112. _______, _______, _______, _______, _______, _______, _______, _______, _______
  113. )
  114. };
  115. #ifdef RGB_MATRIX_ENABLE
  116. /*
  117. * RGB Stuff
  118. */
  119. #define ID67_CAPS_LOCK_KEY_INDEX 36 // position of Caps Lock key
  120. #define ID67_CAPS_LOCK_MAX_BRIGHTNESS 0xFF
  121. #ifdef RGB_MATRIX_MAXIMUM_BRIGHTNESS
  122. #undef ID67_CAPS_LOCK_MAX_BRIGHTNESS
  123. #define ID67_CAPS_LOCK_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS
  124. #endif
  125. #define ID67_CAPS_LOCK_VAL_STEP 8
  126. #ifdef RGB_MATRIX_VAL_STEP
  127. #undef ID67_CAPS_LOCK_VAL_STEP
  128. #define ID67_CAPS_LOCK_VAL_STEP RGB_MATRIX_VAL_STEP
  129. #endif
  130. user_config_t user_config;
  131. void id67_update_rgb_mode(void) {
  132. uint8_t flags = LED_FLAG_ALL;
  133. if (user_config.rgb_disable_perkey
  134. #ifndef ID67_DISABLE_UNDERGLOW
  135. && user_config.rgb_disable_underglow
  136. #endif // ID67_DISABLE_UNDERGLOW
  137. ) {
  138. flags = 0; // All OFF Condition
  139. } else {
  140. if (user_config.rgb_disable_perkey) {
  141. #ifndef ID67_DISABLE_UNDERGLOW
  142. flags = LED_FLAG_UNDERGLOW | 0xF0;
  143. #else
  144. flags = 0xF0;
  145. #endif // ID67_DISABLE_UNDERGLOW
  146. }
  147. #ifndef ID67_DISABLE_UNDERGLOW
  148. if (user_config.rgb_disable_underglow) {
  149. flags = LED_FLAG_MODIFIER | LED_FLAG_KEYLIGHT | LED_FLAG_INDICATOR | 0xF0;
  150. }
  151. #endif // ID67_DISABLE_UNDERGLOW
  152. }
  153. if (flags == 0) {
  154. rgb_matrix_set_flags(0);
  155. rgb_matrix_set_color_all(HSV_OFF);
  156. } else {
  157. rgb_matrix_set_flags(flags);
  158. rgb_matrix_enable_noeeprom();
  159. }
  160. eeconfig_update_kb(user_config.raw); // write back to EEPROM
  161. }
  162. void id67_get_rgb_mode(void) {
  163. user_config.raw = eeconfig_read_kb(); // read config from EEPROM
  164. id67_update_rgb_mode();
  165. }
  166. void keyboard_post_init_user(void) {
  167. id67_get_rgb_mode();
  168. }
  169. void eeconfig_init_user(void) {
  170. // EEPROM is getting reset!
  171. user_config.raw = 0;
  172. id67_update_rgb_mode();
  173. }
  174. bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
  175. // Caps Lock key stuff
  176. if (host_keyboard_led_state().caps_lock) {
  177. uint8_t v = rgb_matrix_get_val();
  178. if (v < ID67_CAPS_LOCK_VAL_STEP) {
  179. v = ID67_CAPS_LOCK_VAL_STEP;
  180. } else if (v < (ID67_CAPS_LOCK_MAX_BRIGHTNESS - ID67_CAPS_LOCK_VAL_STEP)) {
  181. if (!user_config.rgb_disable_perkey) {
  182. v += ID67_CAPS_LOCK_VAL_STEP; // inc. by one more step than current brightness
  183. } // else leave as current brightness
  184. } else {
  185. v = ID67_CAPS_LOCK_MAX_BRIGHTNESS;
  186. }
  187. rgb_matrix_set_color(ID67_CAPS_LOCK_KEY_INDEX, v, v, v); // white, brightness adjusted
  188. } else if (user_config.rgb_disable_perkey) {
  189. rgb_matrix_set_color(ID67_CAPS_LOCK_KEY_INDEX, HSV_OFF); // off
  190. }
  191. return false;
  192. }
  193. #endif // RGB_MATRIX_ENABLE
  194. /*
  195. * Extra keys and RGB Toggle handler
  196. */
  197. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  198. switch (keycode) {
  199. // handle RGB toggle key - this ensures caps lock always works
  200. #ifdef RGB_MATRIX_ENABLE
  201. case QK_BOOT:
  202. if (record->event.pressed) {
  203. rgb_matrix_set_color_all(RGB_MATRIX_MAXIMUM_BRIGHTNESS, 0, 0); // All red
  204. rgb_matrix_driver.flush();
  205. }
  206. return true;
  207. case RGB_TOG:
  208. /* roll through the LED modes
  209. * | Level | Per-key | Underglow |
  210. * |-------------|---------|-----------|
  211. * | 0 (default) | on | on |
  212. * | 1 | OFF | on |
  213. * | 2 | on | OFF |
  214. * | 3 | OFF | OFF |
  215. *
  216. * for ID67_DISABLE_UNDERGLOW
  217. * | Level | Per-key |
  218. * |-------------|---------|
  219. * | 0 (default) | on |
  220. * | 1 | OFF |
  221. */
  222. if (record->event.pressed) {
  223. if ((!user_config.rgb_disable_perkey)
  224. #ifndef ID67_DISABLE_UNDERGLOW
  225. && (!user_config.rgb_disable_underglow)
  226. #endif // ID67_DISABLE_UNDERGLOW
  227. ) {
  228. user_config.rgb_disable_perkey = 1;
  229. #ifndef ID67_DISABLE_UNDERGLOW
  230. } else if (user_config.rgb_disable_perkey && (!user_config.rgb_disable_underglow)) {
  231. user_config.rgb_disable_perkey = 0;
  232. user_config.rgb_disable_underglow = 1;
  233. } else if ((!user_config.rgb_disable_perkey) && user_config.rgb_disable_underglow) {
  234. user_config.rgb_disable_perkey = 1;
  235. #endif // ID67_DISABLE_UNDERGLOW
  236. } else {
  237. user_config.rgb_disable_perkey = 0;
  238. #ifndef ID67_DISABLE_UNDERGLOW
  239. user_config.rgb_disable_underglow = 0;
  240. #endif // ID67_DISABLE_UNDERGLOW
  241. }
  242. id67_update_rgb_mode();
  243. }
  244. return false;
  245. case RGB_TPK:
  246. if (record->event.pressed) {
  247. user_config.rgb_disable_perkey ^= 1;
  248. id67_update_rgb_mode();
  249. }
  250. return false;
  251. #ifndef ID67_DISABLE_UNDERGLOW
  252. case RGB_TUG:
  253. if (record->event.pressed) {
  254. user_config.rgb_disable_underglow ^= 1;
  255. id67_update_rgb_mode();
  256. }
  257. return false;
  258. #endif // ID67_DISABLE_UNDERGLOW
  259. case EE_CLR:
  260. if (!record->event.pressed) { // on release
  261. id67_get_rgb_mode();
  262. }
  263. return true; // let this one pass on
  264. #endif // RGB_MATRIX_ENABLE
  265. // print firmware version
  266. case KB_VRSN:
  267. if (!get_mods()) {
  268. if (!record->event.pressed) {
  269. SEND_STRING(QMK_KEYBOARD ":" QMK_KEYMAP " (v" QMK_VERSION ")");
  270. }
  271. }
  272. return false;
  273. // @see: https://github.com/qmk/qmk_firmware/issues/10111#issuecomment-752300353
  274. case KC_MCON:
  275. if (record->event.pressed) {
  276. host_consumer_send(_AC_SHOW_ALL_WINDOWS);
  277. } else {
  278. host_consumer_send(0);
  279. }
  280. return false;
  281. case KC_LPAD:
  282. if (record->event.pressed) {
  283. host_consumer_send(_AC_SHOW_ALL_APPS);
  284. } else {
  285. host_consumer_send(0);
  286. }
  287. return false;
  288. default:
  289. return true; /* Process all other keycodes normally */
  290. }
  291. }