keymap.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2022 Aaron Hong (@hongaaronc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include QMK_KEYBOARD_H
  4. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  5. [0] = LAYOUT_all(
  6. KC_J, KC_U, KC_K, KC_I, KC_L, KC_O, KC_SCLN,
  7. KC_VOLD, KC_MUTE, KC_VOLU,
  8. KC_J, KC_U, KC_K, KC_I, KC_L, KC_O, KC_SCLN
  9. ),
  10. [1] = LAYOUT_all(
  11. _______, _______, _______, _______, _______, _______, _______,
  12. _______, _______, _______,
  13. _______, _______, _______, _______, _______, _______, _______
  14. ),
  15. [2] = LAYOUT_all(
  16. _______, _______, _______, _______, _______, _______, _______,
  17. _______, _______, _______,
  18. _______, _______, _______, _______, _______, _______, _______
  19. ),
  20. [3] = LAYOUT_all(
  21. _______, _______, _______, _______, _______, _______, _______,
  22. _______, _______, _______,
  23. _______, _______, _______, _______, _______, _______, _______
  24. )
  25. };
  26. #if defined(VIA_ENABLE) && defined(ENCODER_ENABLE)
  27. static uint8_t encoder_state[NUM_ENCODERS] = {0};
  28. static keypos_t encoder_cw[NUM_ENCODERS] = ENCODERS_CW_KEY;
  29. static keypos_t encoder_ccw[NUM_ENCODERS] = ENCODERS_CCW_KEY;
  30. void encoder_action_unregister(void) {
  31. for (int index = 0; index < NUM_ENCODERS; ++index) {
  32. if (encoder_state[index]) {
  33. keyevent_t encoder_event = (keyevent_t) {
  34. .key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
  35. .pressed = false,
  36. .time = (timer_read() | 1)
  37. };
  38. encoder_state[index] = 0;
  39. action_exec(encoder_event);
  40. }
  41. }
  42. }
  43. void encoder_action_register(uint8_t index, bool clockwise) {
  44. keyevent_t encoder_event = (keyevent_t) {
  45. .key = clockwise ? encoder_cw[index] : encoder_ccw[index],
  46. .pressed = true,
  47. .time = (timer_read() | 1)
  48. };
  49. encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
  50. action_exec(encoder_event);
  51. }
  52. void matrix_scan_user(void) {
  53. encoder_action_unregister();
  54. }
  55. bool encoder_update_user(uint8_t index, bool clockwise) {
  56. encoder_action_register(index, clockwise);
  57. return false;
  58. }
  59. #endif