pointing_device.h 6.3 KB

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