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.

257 lines
7.8 KiB

[Keymap] Add DZ60, Levinson keymaps, twschum user files (#7358) * Adds layout for DZ60rev2 plate B, options 4 and 10 * Use KC_TRANS for layer keys * Format layer0 with visual key size layout * Add RGB controls; add start description; add KC_LOCK * Update comments on rules.mk for DZ60 * Gets keymap compiling * Fix wiring for shift on row 3 * Hold a with other key to send Ctrl-A before other key * Adds compile-time defined mac-compatability media keycodes * Adds logic in place for capturing taps (w/ timeout) * Add send_keys(...) which can send up to 64 nested keycodes * Implement send_keys callable with n repeats * Tweaks some of the keymap * Add reset keycode; add disable to custom shortcuts * Adds a special "off" layer where bonus mod goes to layer 0, every other key KC_NO * Adjust timeout; mousekey settings * Changes layout of Home,End,PgUp/Dn on the dedicated arrow keys L1/L2 * PoC on rgb lighted layer indication * Refactors color table defines * Adds logic for controlling layer lights * Only change state on one side of the event lol * Switch back to Tapping Toggle for layer 4 * Add custom config file for keyboard; TT and mousekey settings * Code cleanup; starting to refactor special ctrl tapping keys functions * Move defines and reak out functions * Remove debugging light * Adjust keymaps; add enter * Adds a couple custom macros * Add simplified version of keymap to help debug issues * Adds basi numpad configuration for levinson keyboard half * Use ANSI ctrl key as layer 1 for better one hand (`) * Adapt to new 8bit hue from #5547; layer enum use everywhere * Move custom code out to users/ space * Flip col pins, move key assignments to "left hand" * Update readme * Implement placeholder macros * Notes * Reduce tapping time for SFT_T(/) * Adds vim features; refactors things * Adds fork of the vim features written by xton * Use correct backspace keycode * Add VIM_ESC * Add "OFF" to the RGB/HSV definitions * Clean up rules, use new "OFF" definition * Add windows KC_CALCULATOR key to numpad * Reformat layers with better guide; change layer names * Add sleep key * Change timeout delay * Add a "code paste" which surrounds a ^V with ``` * Try removing shift tap on rshift / * Update macros * Update the "code paste" macro * Update keymap with reset, calc, equals * Update keyboards/dz60/keymaps/twschum_b_4_10_simple/keymap.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/dz60/keymaps/twschum_b_4_10/keymap.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update users/twschum/twschum.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update users/twschum/twschum.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Revert quantum/rgblight_list.h * Better name for split space layout; rename KEYMAP->LAYOUT * Rename KEYMAP->LAYOUT * Use simpler :flash command * Clean up layout files * Use qmk's MOD_MASK_CTRL * Sync lufa submodule * Cleanup from noroadsleft's PR comments * Modernize vim layer code
4 years ago
  1. #include "twschum.h"
  2. #ifdef TWSCHUM_TAPPING_CTRL_PREFIX
  3. // state for the great state machine of custom actions!
  4. #define TIMEOUT_DELAY 200 // ms
  5. static uint16_t idle_timer;
  6. static bool timeout_is_active = false;
  7. static bool ctrl_shortcuts_enabled_g = false;
  8. //static bool B_down = 0; // TODO just use top bit from count
  9. //static int8_t B_count = 0;
  10. #define N_TAPPING_CTRL_KEYS 2
  11. static struct Tapping_ctrl_key_t special_keys_g[N_TAPPING_CTRL_KEYS] = {
  12. {false, 0, KC_B}, {false, 0, KC_A}
  13. };
  14. static inline void start_idle_timer(void) {
  15. idle_timer = timer_read();
  16. timeout_is_active = true;
  17. }
  18. static inline void clear_state_after_idle_timeout(void) {
  19. idle_timer = 0;
  20. timeout_is_active = false;
  21. // send timed out plain keys from tapping ctrl mod
  22. for (int i = 0; i < N_TAPPING_CTRL_KEYS; ++i) {
  23. struct Tapping_ctrl_key_t* key = special_keys_g + i;
  24. repeat_send_keys(key->count, key->keycode);
  25. key->count = 0;
  26. }
  27. }
  28. inline void matrix_scan_user(void) {
  29. if (timeout_is_active && timer_elapsed(idle_timer) > TIMEOUT_DELAY) {
  30. clear_state_after_idle_timeout();
  31. }
  32. }
  33. static inline bool tap_ctrl_event(struct Tapping_ctrl_key_t* key, keyrecord_t* record) {
  34. if (!ctrl_shortcuts_enabled_g) {
  35. // normal operation, just send the plain keycode
  36. if (record->event.pressed) {
  37. register_code(key->keycode);
  38. }
  39. else {
  40. unregister_code(key->keycode);
  41. }
  42. return false;
  43. }
  44. key->down = record->event.pressed;
  45. // increment count and reset timer when key pressed
  46. // start the timeout when released
  47. if (key->down) {
  48. ++(key->count);
  49. timeout_is_active = false;
  50. idle_timer = 0;
  51. }
  52. else {
  53. if (key->count) {
  54. start_idle_timer();
  55. }
  56. }
  57. return false;
  58. }
  59. static inline bool tap_ctrl_other_pressed(void) {
  60. for (int i = 0; i < N_TAPPING_CTRL_KEYS; ++i) {
  61. struct Tapping_ctrl_key_t* key = special_keys_g + i;
  62. if (key->count) {
  63. if (key->down) {
  64. // another key has been pressed while the leader key is down,
  65. // so send number of ctrl-KEY combos before the other key
  66. repeat_send_keys(key->count, KC_LCTL, key->keycode);
  67. key->count = 0;
  68. }
  69. else {
  70. // another key pressed after leader key released,
  71. // need to send the plain keycode plus potential mods
  72. if (get_mods() & MOD_MASK_CTRL) {
  73. // make sure to send a shift if prssed
  74. repeat_send_keys(key->count, KC_RSHIFT, key->keycode);
  75. }
  76. else {
  77. repeat_send_keys(key->count, key->keycode);
  78. }
  79. key->count = 0;
  80. }
  81. return true; // will send the other keycode
  82. }
  83. }
  84. return true; // safe default
  85. }
  86. #endif /* TWSCHUM_TAPPING_CTRL_PREFIX */
  87. /* Use RGB underglow to indicate layer
  88. * https://docs.qmk.fm/reference/customizing-functionality
  89. */
  90. // add to quantum/rgblight_list.h
  91. #ifdef RGBLIGHT_ENABLE
  92. static bool rgb_layers_enabled = true;
  93. static bool rgb_L0_enabled = false;
  94. layer_state_t layer_state_set_user(layer_state_t state) {
  95. if (!rgb_layers_enabled) {
  96. return state;
  97. }
  98. switch (get_highest_layer(state)) {
  99. case _Base:
  100. if (rgb_L0_enabled) {
  101. rgblight_sethsv_noeeprom(_Base_HSV_ON);
  102. }
  103. else {
  104. rgblight_sethsv_noeeprom(_Base_HSV_OFF);
  105. }
  106. break;
  107. case _Vim:
  108. rgblight_sethsv_noeeprom(_Vim_HSV);
  109. break;
  110. case _Fn:
  111. rgblight_sethsv_noeeprom(_Fn_HSV);
  112. break;
  113. case _Nav:
  114. rgblight_sethsv_noeeprom(_Nav_HSV);
  115. break;
  116. case _Num:
  117. rgblight_sethsv_noeeprom(_Num_HSV);
  118. break;
  119. case _Cfg:
  120. rgblight_sethsv_noeeprom(_Cfg_HSV);
  121. break;
  122. case _None:
  123. rgblight_sethsv_noeeprom(_None_HSV);
  124. break;
  125. }
  126. return state;
  127. }
  128. #endif /* RGBLIGHT_ENABLE */
  129. /* process_record_vimlayer: handles the VIM_ keycodes from xtonhasvim's vim
  130. * emulation layer
  131. * add process_record_keymap to allow specific keymap to still add keys
  132. * Makes the callstack look like:
  133. * process_record_
  134. * _quantum
  135. * _kb
  136. * _user
  137. * _keymap
  138. * _vimlayer
  139. */
  140. __attribute__ ((weak))
  141. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  142. return true;
  143. }
  144. /* Return True to continue processing keycode, false to stop further processing
  145. * process_record_keymap to be call by process_record_user in the vim addon */
  146. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  147. /* keymap gets first whack, then vimlayer */
  148. if(!process_record_keymap(keycode, record)) return false;
  149. if(!process_record_vimlayer(keycode, record)) return false;
  150. switch (keycode) {
  151. /* KC_MAKE is a keycode to be used with any keymap
  152. * Outputs `make <keyboard>:<keymap>`
  153. * Holding shift will add the appropriate flashing command (:dfu,
  154. * :teensy, :avrdude, :dfu-util) for a majority of keyboards.
  155. * Holding control will add some commands that will speed up compiling
  156. * time by processing multiple files at once
  157. * For the boards that lack a shift key, or that you want to always
  158. * attempt the flashing part, you can add FLASH_BOOTLOADER = yes to the
  159. * rules.mk of that keymap.
  160. */
  161. case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
  162. if (!record->event.pressed) {
  163. uint8_t temp_mod = get_mods();
  164. uint8_t temp_osm = get_oneshot_mods();
  165. clear_mods(); clear_oneshot_mods();
  166. SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP);
  167. #ifndef FLASH_BOOTLOADER
  168. if ( (temp_mod | temp_osm) & MOD_MASK_SHIFT ) {
  169. SEND_STRING(":flash");
  170. }
  171. #endif
  172. if ( (temp_mod | temp_osm) & MOD_MASK_CTRL) {
  173. SEND_STRING(" -j8 --output-sync");
  174. }
  175. SEND_STRING(SS_TAP(X_ENTER));
  176. set_mods(temp_mod);
  177. }
  178. break;
  179. #ifdef RGBLIGHT_ENABLE
  180. case TG_LAYER_RGB:
  181. if (record->event.pressed) {
  182. rgb_layers_enabled = !rgb_layers_enabled;
  183. }
  184. return false;
  185. case TG_L0_RGB:
  186. if (record->event.pressed) {
  187. rgb_L0_enabled = !rgb_L0_enabled;
  188. }
  189. return false;
  190. #endif
  191. case SALT_CMD:
  192. if (!record->event.pressed) {
  193. SEND_STRING(SALT_CMD_MACRO);
  194. }
  195. return false;
  196. case LESS_PD:
  197. if (!record->event.pressed) {
  198. SEND_STRING(LESS_PD_MACRO);
  199. }
  200. return false;
  201. case CODE_PASTE:
  202. if (!record->event.pressed) {
  203. SEND_STRING(CODE_PASTE_MACRO);
  204. }
  205. return false;
  206. #ifdef TWSCHUM_TAPPING_CTRL_PREFIX
  207. case EN_CTRL_SHORTCUTS:
  208. if (record->event.pressed) {
  209. ctrl_shortcuts_enabled_g = !ctrl_shortcuts_enabled_g;
  210. start_idle_timer(); // need to clear out state in some cases
  211. }
  212. return false;
  213. case CTRL_A:
  214. return tap_ctrl_event(&special_keys_g[1], record);
  215. case CTRL_B:
  216. return tap_ctrl_event(&special_keys_g[0], record);
  217. default:
  218. if (record->event.pressed) {
  219. return tap_ctrl_other_pressed();
  220. }
  221. #endif
  222. }
  223. return true;
  224. }
  225. #ifdef RGBLIGHT_ENABLE
  226. void matrix_init_user(void) {
  227. // called once on board init
  228. rgblight_enable();
  229. }
  230. #endif
  231. void suspend_power_down_user(void) {
  232. // TODO shut off backlighting
  233. }
  234. void suspend_wakeup_init_user(void) {
  235. // TODO turn on backlighting
  236. }