pointing_device.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include <stdint.h>
  16. #include "host.h"
  17. #include "report.h"
  18. #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
  19. # include "pointing_device_auto_mouse.h"
  20. #endif
  21. #if defined(POINTING_DEVICE_DRIVER_adns5050)
  22. # include "drivers/sensors/adns5050.h"
  23. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  24. #elif defined(POINTING_DEVICE_DRIVER_pmw3320)
  25. # include "drivers/sensors/pmw3320.h"
  26. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  27. #elif defined(POINTING_DEVICE_DRIVER_adns9800)
  28. # include "spi_master.h"
  29. # include "drivers/sensors/adns9800.h"
  30. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  31. #elif defined(POINTING_DEVICE_DRIVER_analog_joystick)
  32. # include "analog.h"
  33. # include "drivers/sensors/analog_joystick.h"
  34. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  35. #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
  36. # include "drivers/sensors/cirque_pinnacle.h"
  37. # include "drivers/sensors/cirque_pinnacle_gestures.h"
  38. # include "pointing_device_gestures.h"
  39. #elif defined(POINTING_DEVICE_DRIVER_paw3204)
  40. # include "drivers/sensors/paw3204.h"
  41. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  42. #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
  43. # include "i2c_master.h"
  44. # include "drivers/sensors/pimoroni_trackball.h"
  45. // support for legacy pimoroni defines
  46. # ifdef PIMORONI_TRACKBALL_INVERT_X
  47. # define POINTING_DEVICE_INVERT_X
  48. # endif
  49. # ifdef PIMORONI_TRACKBALL_INVERT_Y
  50. # define POINTING_DEVICE_INVERT_Y
  51. # endif
  52. # ifdef PIMORONI_TRACKBALL_ROTATE
  53. # define POINTING_DEVICE_ROTATION_90
  54. # endif
  55. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  56. #elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
  57. # include "spi_master.h"
  58. # include "drivers/sensors/pmw33xx_common.h"
  59. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  60. #else
  61. void pointing_device_driver_init(void);
  62. report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report);
  63. uint16_t pointing_device_driver_get_cpi(void);
  64. void pointing_device_driver_set_cpi(uint16_t cpi);
  65. #endif
  66. typedef struct {
  67. void (*init)(void);
  68. report_mouse_t (*get_report)(report_mouse_t mouse_report);
  69. void (*set_cpi)(uint16_t);
  70. uint16_t (*get_cpi)(void);
  71. } pointing_device_driver_t;
  72. typedef enum {
  73. POINTING_DEVICE_BUTTON1,
  74. POINTING_DEVICE_BUTTON2,
  75. POINTING_DEVICE_BUTTON3,
  76. POINTING_DEVICE_BUTTON4,
  77. POINTING_DEVICE_BUTTON5,
  78. POINTING_DEVICE_BUTTON6,
  79. POINTING_DEVICE_BUTTON7,
  80. POINTING_DEVICE_BUTTON8,
  81. } pointing_device_buttons_t;
  82. #ifdef MOUSE_EXTENDED_REPORT
  83. # define XY_REPORT_MIN INT16_MIN
  84. # define XY_REPORT_MAX INT16_MAX
  85. typedef int32_t clamp_range_t;
  86. #else
  87. # define XY_REPORT_MIN INT8_MIN
  88. # define XY_REPORT_MAX INT8_MAX
  89. typedef int16_t clamp_range_t;
  90. #endif
  91. void pointing_device_init(void);
  92. bool pointing_device_task(void);
  93. bool pointing_device_send(void);
  94. report_mouse_t pointing_device_get_report(void);
  95. void pointing_device_set_report(report_mouse_t mouse_report);
  96. uint16_t pointing_device_get_cpi(void);
  97. void pointing_device_set_cpi(uint16_t cpi);
  98. void pointing_device_init_kb(void);
  99. void pointing_device_init_user(void);
  100. report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report);
  101. report_mouse_t pointing_device_task_user(report_mouse_t mouse_report);
  102. uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button);
  103. report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report);
  104. void pointing_device_keycode_handler(uint16_t keycode, bool pressed);
  105. #if defined(SPLIT_POINTING_ENABLE)
  106. void pointing_device_set_shared_report(report_mouse_t report);
  107. uint16_t pointing_device_get_shared_cpi(void);
  108. # if !defined(POINTING_DEVICE_TASK_THROTTLE_MS)
  109. # define POINTING_DEVICE_TASK_THROTTLE_MS 1
  110. # endif
  111. # if defined(POINTING_DEVICE_COMBINED)
  112. void pointing_device_set_cpi_on_side(bool left, uint16_t cpi);
  113. report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report);
  114. report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report);
  115. report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report);
  116. report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report);
  117. # endif // defined(POINTING_DEVICE_COMBINED)
  118. #endif // defined(SPLIT_POINTING_ENABLE)