pointing_device.h 4.6 KB

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