pointing_device.h 5.0 KB

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