pointing_device.h 5.3 KB

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