pointing_device.h 6.1 KB

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