pointing_device.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. typedef struct {
  19. void (*init)(void);
  20. report_mouse_t (*get_report)(report_mouse_t mouse_report);
  21. void (*set_cpi)(uint16_t);
  22. uint16_t (*get_cpi)(void);
  23. } pointing_device_driver_t;
  24. #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
  25. # include "pointing_device_auto_mouse.h"
  26. #endif
  27. #if defined(POINTING_DEVICE_DRIVER_adns5050)
  28. # include "drivers/sensors/adns5050.h"
  29. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  30. #elif defined(POINTING_DEVICE_DRIVER_pmw3320)
  31. # include "drivers/sensors/pmw3320.h"
  32. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  33. #elif defined(POINTING_DEVICE_DRIVER_adns9800)
  34. # include "spi_master.h"
  35. # include "drivers/sensors/adns9800.h"
  36. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  37. #elif defined(POINTING_DEVICE_DRIVER_analog_joystick)
  38. # include "analog.h"
  39. # include "drivers/sensors/analog_joystick.h"
  40. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  41. #elif defined(POINTING_DEVICE_DRIVER_azoteq_iqs5xx)
  42. # include "i2c_master.h"
  43. # include "drivers/sensors/azoteq_iqs5xx.h"
  44. #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
  45. # include "drivers/sensors/cirque_pinnacle.h"
  46. # include "pointing_device_gestures.h"
  47. #elif defined(POINTING_DEVICE_DRIVER_paw3204)
  48. # include "drivers/sensors/paw3204.h"
  49. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  50. #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
  51. # include "i2c_master.h"
  52. # include "drivers/sensors/pimoroni_trackball.h"
  53. // support for legacy pimoroni defines
  54. # ifdef PIMORONI_TRACKBALL_INVERT_X
  55. # define POINTING_DEVICE_INVERT_X
  56. # endif
  57. # ifdef PIMORONI_TRACKBALL_INVERT_Y
  58. # define POINTING_DEVICE_INVERT_Y
  59. # endif
  60. # ifdef PIMORONI_TRACKBALL_ROTATE
  61. # define POINTING_DEVICE_ROTATION_90
  62. # endif
  63. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  64. #elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
  65. # include "spi_master.h"
  66. # include "drivers/sensors/pmw33xx_common.h"
  67. # define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
  68. #else
  69. void pointing_device_driver_init(void);
  70. report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report);
  71. uint16_t pointing_device_driver_get_cpi(void);
  72. void pointing_device_driver_set_cpi(uint16_t cpi);
  73. #endif
  74. typedef enum {
  75. POINTING_DEVICE_BUTTON1,
  76. POINTING_DEVICE_BUTTON2,
  77. POINTING_DEVICE_BUTTON3,
  78. POINTING_DEVICE_BUTTON4,
  79. POINTING_DEVICE_BUTTON5,
  80. POINTING_DEVICE_BUTTON6,
  81. POINTING_DEVICE_BUTTON7,
  82. POINTING_DEVICE_BUTTON8,
  83. } pointing_device_buttons_t;
  84. #ifdef MOUSE_EXTENDED_REPORT
  85. # define XY_REPORT_MIN INT16_MIN
  86. # define XY_REPORT_MAX INT16_MAX
  87. typedef int32_t xy_clamp_range_t;
  88. #else
  89. # define XY_REPORT_MIN INT8_MIN
  90. # define XY_REPORT_MAX INT8_MAX
  91. typedef int16_t xy_clamp_range_t;
  92. #endif
  93. #ifdef WHEEL_EXTENDED_REPORT
  94. # define HV_REPORT_MIN INT16_MIN
  95. # define HV_REPORT_MAX INT16_MAX
  96. typedef int32_t hv_clamp_range_t;
  97. #else
  98. # define HV_REPORT_MIN INT8_MIN
  99. # define HV_REPORT_MAX INT8_MAX
  100. typedef int16_t hv_clamp_range_t;
  101. #endif
  102. #define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
  103. #define CONSTRAIN_HID_XY(amt) ((amt) < XY_REPORT_MIN ? XY_REPORT_MIN : ((amt) > XY_REPORT_MAX ? XY_REPORT_MAX : (amt)))
  104. void pointing_device_init(void);
  105. bool pointing_device_task(void);
  106. bool pointing_device_send(void);
  107. report_mouse_t pointing_device_get_report(void);
  108. void pointing_device_set_report(report_mouse_t mouse_report);
  109. uint16_t pointing_device_get_cpi(void);
  110. void pointing_device_set_cpi(uint16_t cpi);
  111. void pointing_device_init_kb(void);
  112. void pointing_device_init_user(void);
  113. report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report);
  114. report_mouse_t pointing_device_task_user(report_mouse_t mouse_report);
  115. uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button);
  116. report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report);
  117. void pointing_device_keycode_handler(uint16_t keycode, bool pressed);
  118. #if defined(SPLIT_POINTING_ENABLE)
  119. void pointing_device_set_shared_report(report_mouse_t report);
  120. uint16_t pointing_device_get_shared_cpi(void);
  121. # if !defined(POINTING_DEVICE_TASK_THROTTLE_MS)
  122. # define POINTING_DEVICE_TASK_THROTTLE_MS 1
  123. # endif
  124. # if defined(POINTING_DEVICE_COMBINED)
  125. void pointing_device_set_cpi_on_side(bool left, uint16_t cpi);
  126. report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report);
  127. report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report);
  128. report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report);
  129. report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report);
  130. # endif // defined(POINTING_DEVICE_COMBINED)
  131. #endif // defined(SPLIT_POINTING_ENABLE)