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.

115 lines
3.5 KiB

  1. /* Copyright 2021 Colin Lam (Ploopy Corporation)
  2. * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  3. * Copyright 2019 Sunjun Kim
  4. * Copyright 2019 Hiroyuki Okada
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "trackball_nano.h"
  20. #include "wait.h"
  21. #ifndef OPT_DEBOUNCE
  22. # define OPT_DEBOUNCE 5 // (ms) Time between scroll events
  23. #endif
  24. #ifndef SCROLL_BUTT_DEBOUNCE
  25. # define SCROLL_BUTT_DEBOUNCE 100 // (ms) Time between scroll events
  26. #endif
  27. #ifndef OPT_THRES
  28. # define OPT_THRES 150 // (0-1024) Threshold for actication
  29. #endif
  30. #ifndef OPT_SCALE
  31. # define OPT_SCALE 1 // Multiplier for wheel
  32. #endif
  33. #ifndef PLOOPY_DPI_OPTIONS
  34. # define PLOOPY_DPI_OPTIONS \
  35. { 375, 750, 1375 }
  36. # ifndef PLOOPY_DPI_DEFAULT
  37. # define PLOOPY_DPI_DEFAULT 2
  38. # endif
  39. #endif
  40. #ifndef PLOOPY_DPI_DEFAULT
  41. # define PLOOPY_DPI_DEFAULT 2
  42. #endif
  43. keyboard_config_t keyboard_config;
  44. uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
  45. #define DPI_OPTION_SIZE ARRAY_SIZE(dpi_array)
  46. void cycle_dpi(void) {
  47. keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
  48. pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
  49. #ifdef CONSOLE_ENABLE
  50. uprintf("DPI is now %d\n", dpi_array[keyboard_config.dpi_config]);
  51. #endif
  52. }
  53. // TODO: Implement libinput profiles
  54. // https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html
  55. // Compile time accel selection
  56. // Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC
  57. // Trackball State
  58. bool is_scroll_clicked = false;
  59. bool BurstState = false; // init burst state for Trackball module
  60. uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
  61. void pointing_device_init_kb(void) {
  62. // set the DPI.
  63. pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
  64. }
  65. // Hardware Setup
  66. void keyboard_pre_init_kb(void) {
  67. // debug_enable = true;
  68. // debug_matrix = true;
  69. // debug_mouse = true;
  70. // debug_encoder = true;
  71. /* Ground all output pins connected to ground. This provides additional
  72. * pathways to ground. If you're messing with this, know this: driving ANY
  73. * of these pins high will cause a short. On the MCU. Ka-blooey.
  74. */
  75. #ifdef UNUSABLE_PINS
  76. const pin_t unused_pins[] = UNUSABLE_PINS;
  77. for (uint8_t i = 0; i < ARRAY_SIZE(unused_pins); i++) {
  78. setPinOutput(unused_pins[i]);
  79. writePinLow(unused_pins[i]);
  80. }
  81. #endif
  82. keyboard_pre_init_user();
  83. }
  84. void eeconfig_init_kb(void) {
  85. keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
  86. eeconfig_update_kb(keyboard_config.raw);
  87. eeconfig_init_user();
  88. }
  89. void matrix_init_kb(void) {
  90. // is safe to just read DPI setting since matrix init
  91. // comes before pointing device init.
  92. keyboard_config.raw = eeconfig_read_kb();
  93. if (keyboard_config.dpi_config > DPI_OPTION_SIZE) {
  94. eeconfig_init_kb();
  95. }
  96. matrix_init_user();
  97. }