logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

cirque_pinnacle.h (4884B)


  1. // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
  2. #pragma once
  3. #include "cirque_pinnacle_regdefs.h"
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #include "pointing_device_internal.h"
  7. #include "pointing_device.h"
  8. #ifndef CIRQUE_PINNACLE_TIMEOUT
  9. # define CIRQUE_PINNACLE_TIMEOUT 20 // I2C timeout in milliseconds
  10. #endif
  11. #define CIRQUE_PINNACLE_ABSOLUTE_MODE 1
  12. #define CIRQUE_PINNACLE_RELATIVE_MODE 0
  13. #ifndef CIRQUE_PINNACLE_POSITION_MODE
  14. # define CIRQUE_PINNACLE_POSITION_MODE CIRQUE_PINNACLE_ABSOLUTE_MODE
  15. #endif
  16. #define CIRQUE_PINNACLE_DEFAULT_SCALE 1024
  17. #ifndef CIRQUE_PINNACLE_DIAMETER_MM
  18. # define CIRQUE_PINNACLE_DIAMETER_MM 40
  19. #endif
  20. #if CIRQUE_PINNACLE_POSITION_MODE
  21. // Coordinate scaling values
  22. # ifndef CIRQUE_PINNACLE_X_LOWER
  23. # define CIRQUE_PINNACLE_X_LOWER 127 // min "reachable" X value
  24. # endif
  25. # ifndef CIRQUE_PINNACLE_X_UPPER
  26. # define CIRQUE_PINNACLE_X_UPPER 1919 // max "reachable" X value
  27. # endif
  28. # ifndef CIRQUE_PINNACLE_Y_LOWER
  29. # define CIRQUE_PINNACLE_Y_LOWER 63 // min "reachable" Y value
  30. # endif
  31. # ifndef CIRQUE_PINNACLE_Y_UPPER
  32. # define CIRQUE_PINNACLE_Y_UPPER 1471 // max "reachable" Y value
  33. # endif
  34. # ifndef CIRQUE_PINNACLE_X_RANGE
  35. # define CIRQUE_PINNACLE_X_RANGE (CIRQUE_PINNACLE_X_UPPER - CIRQUE_PINNACLE_X_LOWER)
  36. # endif
  37. # ifndef CIRQUE_PINNACLE_Y_RANGE
  38. # define CIRQUE_PINNACLE_Y_RANGE (CIRQUE_PINNACLE_Y_UPPER - CIRQUE_PINNACLE_Y_LOWER)
  39. # endif
  40. # if defined(POINTING_DEVICE_GESTURES_SCROLL_ENABLE)
  41. # define CIRQUE_PINNACLE_CIRCULAR_SCROLL_ENABLE
  42. # endif
  43. #else
  44. # define CIRQUE_PINNACLE_X_RANGE 256
  45. # define CIRQUE_PINNACLE_Y_RANGE 256
  46. # if defined(POINTING_DEVICE_GESTURES_SCROLL_ENABLE)
  47. # define CIRQUE_PINNACLE_SIDE_SCROLL_ENABLE
  48. # endif
  49. #endif
  50. #if !defined(POINTING_DEVICE_TASK_THROTTLE_MS)
  51. # define POINTING_DEVICE_TASK_THROTTLE_MS 10 // Cirque Pinnacle in normal operation produces data every 10ms. Advanced configuration for pen/stylus usage might require lower values.
  52. #endif
  53. #if defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c)
  54. # include "i2c_master.h"
  55. // Cirque's 7-bit I2C Slave Address
  56. # ifndef CIRQUE_PINNACLE_ADDR
  57. # define CIRQUE_PINNACLE_ADDR I2C_ADDRESS_DEFAULT
  58. # endif
  59. #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
  60. # include "spi_master.h"
  61. # ifndef CIRQUE_PINNACLE_CLOCK_SPEED
  62. # define CIRQUE_PINNACLE_CLOCK_SPEED 10000000
  63. # endif
  64. # ifndef CIRQUE_PINNACLE_SPI_LSBFIRST
  65. # define CIRQUE_PINNACLE_SPI_LSBFIRST false
  66. # endif
  67. # ifndef CIRQUE_PINNACLE_SPI_MODE
  68. # define CIRQUE_PINNACLE_SPI_MODE 1
  69. # endif
  70. # ifndef CIRQUE_PINNACLE_SPI_DIVISOR
  71. # ifdef __AVR__
  72. # define CIRQUE_PINNACLE_SPI_DIVISOR (F_CPU / CIRQUE_PINNACLE_CLOCK_SPEED)
  73. # else
  74. # define CIRQUE_PINNACLE_SPI_DIVISOR 64
  75. # endif
  76. # ifndef CIRQUE_PINNACLE_SPI_CS_PIN
  77. # ifdef POINTING_DEVICE_CS_PIN
  78. # define CIRQUE_PINNACLE_SPI_CS_PIN POINTING_DEVICE_CS_PIN
  79. # else
  80. # error "No Chip Select pin has been defined -- missing POINTING_DEVICE_CS_PIN or CIRQUE_PINNACLE_SPI_CS_PIN define"
  81. # endif
  82. # endif
  83. # endif
  84. #endif
  85. #define DIVIDE_UNSIGNED_ROUND(numerator, denominator) (((numerator) + ((denominator) / 2)) / (denominator))
  86. #define CIRQUE_PINNACLE_INCH_TO_PX(inch) (DIVIDE_UNSIGNED_ROUND((inch) * (uint32_t)CIRQUE_PINNACLE_DIAMETER_MM * 10, 254))
  87. #define CIRQUE_PINNACLE_PX_TO_INCH(px) (DIVIDE_UNSIGNED_ROUND((px) * (uint32_t)254, CIRQUE_PINNACLE_DIAMETER_MM * 10))
  88. // Convenient way to store and access measurements
  89. typedef struct {
  90. bool valid; // true if valid data was read, false if no data was ready
  91. #if CIRQUE_PINNACLE_POSITION_MODE
  92. uint16_t xValue;
  93. uint16_t yValue;
  94. uint16_t zValue;
  95. uint8_t buttonFlags;
  96. bool touchDown;
  97. #else
  98. int16_t xDelta;
  99. int16_t yDelta;
  100. int8_t wheelCount;
  101. uint8_t buttons;
  102. #endif
  103. } pinnacle_data_t;
  104. #define cirque_pinnacle_i2c_pointing_device_driver cirque_pinnacle_pointing_device_driver
  105. #define cirque_pinnacle_spi_pointing_device_driver cirque_pinnacle_pointing_device_driver
  106. const pointing_device_driver_t cirque_pinnacle_pointing_device_driver;
  107. void cirque_pinnacle_init(void);
  108. void cirque_pinnacle_calibrate(void);
  109. void cirque_pinnacle_cursor_smoothing(bool enable);
  110. pinnacle_data_t cirque_pinnacle_read_data(void);
  111. void cirque_pinnacle_scale_data(pinnacle_data_t* coordinates, uint16_t xResolution, uint16_t yResolution);
  112. uint16_t cirque_pinnacle_get_scale(void);
  113. void cirque_pinnacle_set_scale(uint16_t scale);
  114. uint16_t cirque_pinnacle_get_cpi(void);
  115. void cirque_pinnacle_set_cpi(uint16_t cpi);
  116. report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report);