cirque_pinnacle.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
  2. // based on https://github.com/cirque-corp/Cirque_Pinnacle_1CA027/tree/master/Circular_Trackpad
  3. // with modifications and changes for QMK
  4. // refer to documentation: Gen2 and Gen3 (Pinnacle ASIC) at https://www.cirque.com/documentation
  5. #include "cirque_pinnacle.h"
  6. #include "cirque_pinnacle_gestures.h"
  7. #include "wait.h"
  8. #include "timer.h"
  9. #include <stdlib.h>
  10. #ifndef CIRQUE_PINNACLE_ATTENUATION
  11. # ifdef CIRQUE_PINNACLE_CURVED_OVERLAY
  12. # define CIRQUE_PINNACLE_ATTENUATION EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_2X
  13. # else
  14. # define CIRQUE_PINNACLE_ATTENUATION EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_4X
  15. # endif
  16. #endif
  17. uint16_t scale_data = CIRQUE_PINNACLE_DEFAULT_SCALE;
  18. void cirque_pinnacle_clear_flags(void);
  19. void cirque_pinnacle_enable_feed(bool feedEnable);
  20. void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count);
  21. void RAP_Write(uint8_t address, uint8_t data);
  22. #if CIRQUE_PINNACLE_POSITION_MODE
  23. /* Logical Scaling Functions */
  24. // Clips raw coordinates to "reachable" window of sensor
  25. // NOTE: values outside this window can only appear as a result of noise
  26. void ClipCoordinates(pinnacle_data_t* coordinates) {
  27. if (coordinates->xValue < CIRQUE_PINNACLE_X_LOWER) {
  28. coordinates->xValue = CIRQUE_PINNACLE_X_LOWER;
  29. } else if (coordinates->xValue > CIRQUE_PINNACLE_X_UPPER) {
  30. coordinates->xValue = CIRQUE_PINNACLE_X_UPPER;
  31. }
  32. if (coordinates->yValue < CIRQUE_PINNACLE_Y_LOWER) {
  33. coordinates->yValue = CIRQUE_PINNACLE_Y_LOWER;
  34. } else if (coordinates->yValue > CIRQUE_PINNACLE_Y_UPPER) {
  35. coordinates->yValue = CIRQUE_PINNACLE_Y_UPPER;
  36. }
  37. }
  38. #endif
  39. uint16_t cirque_pinnacle_get_scale(void) {
  40. return scale_data;
  41. }
  42. void cirque_pinnacle_set_scale(uint16_t scale) {
  43. scale_data = scale;
  44. }
  45. // Scales data to desired X & Y resolution
  46. void cirque_pinnacle_scale_data(pinnacle_data_t* coordinates, uint16_t xResolution, uint16_t yResolution) {
  47. #if CIRQUE_PINNACLE_POSITION_MODE
  48. uint32_t xTemp = 0;
  49. uint32_t yTemp = 0;
  50. ClipCoordinates(coordinates);
  51. xTemp = coordinates->xValue;
  52. yTemp = coordinates->yValue;
  53. // translate coordinates to (0, 0) reference by subtracting edge-offset
  54. xTemp -= CIRQUE_PINNACLE_X_LOWER;
  55. yTemp -= CIRQUE_PINNACLE_Y_LOWER;
  56. // scale coordinates to (xResolution, yResolution) range
  57. coordinates->xValue = (uint16_t)(xTemp * xResolution / CIRQUE_PINNACLE_X_RANGE);
  58. coordinates->yValue = (uint16_t)(yTemp * yResolution / CIRQUE_PINNACLE_Y_RANGE);
  59. #else
  60. int32_t xTemp = 0, yTemp = 0;
  61. ldiv_t temp;
  62. static int32_t xRemainder, yRemainder;
  63. temp = ldiv(((int32_t)coordinates->xDelta) * (int32_t)xResolution + xRemainder, (int32_t)CIRQUE_PINNACLE_X_RANGE);
  64. xTemp = temp.quot;
  65. xRemainder = temp.rem;
  66. temp = ldiv(((int32_t)coordinates->yDelta) * (int32_t)yResolution + yRemainder, (int32_t)CIRQUE_PINNACLE_Y_RANGE);
  67. yTemp = temp.quot;
  68. yRemainder = temp.rem;
  69. coordinates->xDelta = (int16_t)xTemp;
  70. coordinates->yDelta = (int16_t)yTemp;
  71. #endif
  72. }
  73. // Clears Status1 register flags (SW_CC and SW_DR)
  74. void cirque_pinnacle_clear_flags(void) {
  75. RAP_Write(HOSTREG__STATUS1, HOSTREG__STATUS1_DEFVAL & ~(HOSTREG__STATUS1__COMMAND_COMPLETE | HOSTREG__STATUS1__DATA_READY));
  76. wait_us(50);
  77. }
  78. // Enables/Disables the feed
  79. void cirque_pinnacle_enable_feed(bool feedEnable) {
  80. uint8_t feedconfig1;
  81. RAP_ReadBytes(HOSTREG__FEEDCONFIG1, &feedconfig1, 1);
  82. if (feedEnable) {
  83. feedconfig1 |= HOSTREG__FEEDCONFIG1__FEED_ENABLE;
  84. } else {
  85. feedconfig1 &= ~HOSTREG__FEEDCONFIG1__FEED_ENABLE;
  86. }
  87. RAP_Write(HOSTREG__FEEDCONFIG1, feedconfig1);
  88. }
  89. /* ERA (Extended Register Access) Functions */
  90. // Reads <count> bytes from an extended register at <address> (16-bit address),
  91. // stores values in <*data>
  92. void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) {
  93. uint8_t ERAControlValue = 0xFF;
  94. uint16_t timeout_timer;
  95. cirque_pinnacle_enable_feed(false); // Disable feed
  96. RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_HIGH, (uint8_t)(address >> 8)); // Send upper byte of ERA address
  97. RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_LOW, (uint8_t)(address & 0x00FF)); // Send lower byte of ERA address
  98. for (uint16_t i = 0; i < count; i++) {
  99. RAP_Write(HOSTREG__EXT_REG_AXS_CTRL, HOSTREG__EREG_AXS__INC_ADDR_READ | HOSTREG__EREG_AXS__READ); // Signal ERA-read (auto-increment) to Pinnacle
  100. // Wait for status register 0x1E to clear
  101. timeout_timer = timer_read();
  102. do {
  103. RAP_ReadBytes(HOSTREG__EXT_REG_AXS_CTRL, &ERAControlValue, 1);
  104. } while ((ERAControlValue != 0x00) && (timer_elapsed(timeout_timer) <= CIRQUE_PINNACLE_TIMEOUT));
  105. RAP_ReadBytes(HOSTREG__EXT_REG_AXS_VALUE, data + i, 1);
  106. cirque_pinnacle_clear_flags();
  107. }
  108. }
  109. // Writes a byte, <data>, to an extended register at <address> (16-bit address)
  110. void ERA_WriteByte(uint16_t address, uint8_t data) {
  111. uint8_t ERAControlValue = 0xFF;
  112. uint16_t timeout_timer;
  113. cirque_pinnacle_enable_feed(false); // Disable feed
  114. RAP_Write(HOSTREG__EXT_REG_AXS_VALUE, data); // Send data byte to be written
  115. RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_HIGH, (uint8_t)(address >> 8)); // Upper byte of ERA address
  116. RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_LOW, (uint8_t)(address & 0x00FF)); // Lower byte of ERA address
  117. RAP_Write(HOSTREG__EXT_REG_AXS_CTRL, HOSTREG__EREG_AXS__WRITE); // Signal an ERA-write to Pinnacle
  118. // Wait for status register 0x1E to clear
  119. timeout_timer = timer_read();
  120. do {
  121. RAP_ReadBytes(HOSTREG__EXT_REG_AXS_CTRL, &ERAControlValue, 1);
  122. } while ((ERAControlValue != 0x00) && (timer_elapsed(timeout_timer) <= CIRQUE_PINNACLE_TIMEOUT));
  123. cirque_pinnacle_clear_flags();
  124. }
  125. bool cirque_pinnacle_set_adc_attenuation(uint8_t adcGain) {
  126. uint8_t adcconfig = 0x00;
  127. ERA_ReadBytes(EXTREG__TRACK_ADCCONFIG, &adcconfig, 1);
  128. adcGain &= EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_MASK;
  129. if (adcGain == (adcconfig & EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_MASK)) {
  130. return false;
  131. }
  132. adcconfig &= ~EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_MASK;
  133. adcconfig |= adcGain;
  134. ERA_WriteByte(EXTREG__TRACK_ADCCONFIG, adcconfig);
  135. ERA_ReadBytes(EXTREG__TRACK_ADCCONFIG, &adcconfig, 1);
  136. return true;
  137. }
  138. // Changes thresholds to improve detection of fingers
  139. // Not needed for flat overlay?
  140. void cirque_pinnacle_tune_edge_sensitivity(void) {
  141. uint8_t widezmin = 0x00;
  142. ERA_ReadBytes(EXTREG__XAXIS_WIDEZMIN, &widezmin, 1);
  143. ERA_WriteByte(EXTREG__XAXIS_WIDEZMIN, 0x04); // magic number from Cirque sample code
  144. ERA_ReadBytes(EXTREG__XAXIS_WIDEZMIN, &widezmin, 1);
  145. ERA_ReadBytes(EXTREG__YAXIS_WIDEZMIN, &widezmin, 1);
  146. ERA_WriteByte(EXTREG__YAXIS_WIDEZMIN, 0x03); // magic number from Cirque sample code
  147. ERA_ReadBytes(EXTREG__YAXIS_WIDEZMIN, &widezmin, 1);
  148. }
  149. // Perform calibration
  150. void cirque_pinnacle_calibrate(void) {
  151. uint8_t calconfig;
  152. uint16_t timeout_timer;
  153. RAP_ReadBytes(HOSTREG__CALCONFIG1, &calconfig, 1);
  154. calconfig |= HOSTREG__CALCONFIG1__CALIBRATE;
  155. RAP_Write(HOSTREG__CALCONFIG1, calconfig);
  156. // Calibration takes ~100ms according to GT-AN-090624, doubling the timeout just to be safe
  157. timeout_timer = timer_read();
  158. do {
  159. RAP_ReadBytes(HOSTREG__CALCONFIG1, &calconfig, 1);
  160. } while ((calconfig & HOSTREG__CALCONFIG1__CALIBRATE) && (timer_elapsed(timeout_timer) <= 200));
  161. cirque_pinnacle_clear_flags();
  162. }
  163. // Enable/disable cursor smoothing, smoothing is enabled by default
  164. void cirque_pinnacle_cursor_smoothing(bool enable) {
  165. uint8_t feedconfig3;
  166. RAP_ReadBytes(HOSTREG__FEEDCONFIG3, &feedconfig3, 1);
  167. if (enable) {
  168. feedconfig3 &= ~HOSTREG__FEEDCONFIG3__DISABLE_CROSS_RATE_SMOOTHING;
  169. } else {
  170. feedconfig3 |= HOSTREG__FEEDCONFIG3__DISABLE_CROSS_RATE_SMOOTHING;
  171. }
  172. RAP_Write(HOSTREG__FEEDCONFIG3, feedconfig3);
  173. }
  174. // Check sensor is connected
  175. bool cirque_pinnacle_connected(void) {
  176. uint8_t current_zidle = 0;
  177. uint8_t temp_zidle = 0;
  178. RAP_ReadBytes(HOSTREG__ZIDLE, &current_zidle, 1);
  179. RAP_Write(HOSTREG__ZIDLE, HOSTREG__ZIDLE_DEFVAL);
  180. RAP_ReadBytes(HOSTREG__ZIDLE, &temp_zidle, 1);
  181. if (temp_zidle == HOSTREG__ZIDLE_DEFVAL) {
  182. RAP_Write(HOSTREG__ZIDLE, current_zidle);
  183. return true;
  184. }
  185. return false;
  186. }
  187. /* Pinnacle-based TM040040/TM035035/TM023023 Functions */
  188. bool cirque_pinnacle_init(void) {
  189. #if defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
  190. spi_init();
  191. #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c)
  192. i2c_init();
  193. #endif
  194. bool touchpad_init = true;
  195. // send a RESET command now, in case QMK had a soft-reset without a power cycle
  196. RAP_Write(HOSTREG__SYSCONFIG1, HOSTREG__SYSCONFIG1__RESET);
  197. wait_ms(30); // Pinnacle needs 10-15ms to boot, so wait long enough before configuring
  198. RAP_Write(HOSTREG__SYSCONFIG1, HOSTREG__SYSCONFIG1_DEFVAL);
  199. wait_us(50);
  200. // Host clears SW_CC flag
  201. cirque_pinnacle_clear_flags();
  202. #if CIRQUE_PINNACLE_POSITION_MODE
  203. RAP_Write(HOSTREG__FEEDCONFIG2, HOSTREG__FEEDCONFIG2_DEFVAL);
  204. #else
  205. // FeedConfig2 (Feature flags for Relative Mode Only)
  206. uint8_t feedconfig2 = HOSTREG__FEEDCONFIG2__GLIDE_EXTEND_DISABLE | HOSTREG__FEEDCONFIG2__INTELLIMOUSE_MODE;
  207. # if !defined(CIRQUE_PINNACLE_TAP_ENABLE)
  208. feedconfig2 |= HOSTREG__FEEDCONFIG2__ALL_TAP_DISABLE;
  209. # endif
  210. # if !defined(CIRQUE_PINNACLE_SECONDARY_TAP_ENABLE)
  211. feedconfig2 |= HOSTREG__FEEDCONFIG2__SECONDARY_TAP_DISABLE;
  212. # elif !defined(CIRQUE_PINNACLE_TAP_ENABLE)
  213. # error CIRQUE_PINNACLE_TAP_ENABLE must be defined for CIRQUE_PINNACLE_SECONDARY_TAP_ENABLE to work
  214. # endif
  215. # if !defined(CIRQUE_PINNACLE_SIDE_SCROLL_ENABLE)
  216. feedconfig2 |= HOSTREG__FEEDCONFIG2__SCROLL_DISABLE;
  217. # endif
  218. RAP_Write(HOSTREG__FEEDCONFIG2, feedconfig2);
  219. #endif
  220. // FeedConfig1 (Data Output Flags)
  221. RAP_Write(HOSTREG__FEEDCONFIG1, CIRQUE_PINNACLE_POSITION_MODE ? HOSTREG__FEEDCONFIG1__DATA_TYPE__REL0_ABS1 : HOSTREG__FEEDCONFIG1_DEFVAL);
  222. #if CIRQUE_PINNACLE_POSITION_MODE
  223. // Host sets z-idle packet count to 5 (default is 0x1E/30)
  224. RAP_Write(HOSTREG__ZIDLE, 5);
  225. #endif
  226. bool calibrate = cirque_pinnacle_set_adc_attenuation(CIRQUE_PINNACLE_ATTENUATION);
  227. #ifdef CIRQUE_PINNACLE_CURVED_OVERLAY
  228. cirque_pinnacle_tune_edge_sensitivity();
  229. calibrate = true;
  230. #endif
  231. if (calibrate) {
  232. // Force a calibration after setting ADC attenuation
  233. cirque_pinnacle_calibrate();
  234. }
  235. cirque_pinnacle_enable_feed(true);
  236. #ifndef CIRQUE_PINNACLE_SKIP_SENSOR_CHECK
  237. touchpad_init = cirque_pinnacle_connected();
  238. #endif
  239. return touchpad_init;
  240. }
  241. pinnacle_data_t cirque_pinnacle_read_data(void) {
  242. uint8_t data_ready = 0;
  243. uint8_t data[6] = {0};
  244. pinnacle_data_t result = {0};
  245. // Check if there is valid data available
  246. RAP_ReadBytes(HOSTREG__STATUS1, &data_ready, 1);
  247. if ((data_ready & HOSTREG__STATUS1__DATA_READY) == 0) {
  248. // no data available yet
  249. result.valid = false; // be explicit
  250. return result;
  251. }
  252. // Read all data bytes
  253. RAP_ReadBytes(HOSTREG__PACKETBYTE_0, data, 6);
  254. // Get ready for the next data sample
  255. cirque_pinnacle_clear_flags();
  256. #if CIRQUE_PINNACLE_POSITION_MODE
  257. // Decode data for absolute mode
  258. // Register 0x13 is unused in this mode (palm detection area)
  259. result.buttonFlags = data[0] & 0x3F; // bit0 to bit5 are switch 0-5, only hardware button presses (from input pin on the Pinnacle chip)
  260. result.xValue = data[2] | ((data[4] & 0x0F) << 8); // merge high and low bits for X
  261. result.yValue = data[3] | ((data[4] & 0xF0) << 4); // merge high and low bits for Y
  262. result.zValue = data[5] & 0x3F; // Z is only lower 6 bits, upper 2 bits are reserved/unused
  263. result.touchDown = (result.xValue != 0 || result.yValue != 0); // (0,0) is a "magic coordinate" to indicate "finger touched down"
  264. #else
  265. // Decode data for relative mode
  266. // Registers 0x16 and 0x17 are unused in this mode
  267. result.buttons = data[0] & 0x07; // Only three buttons are supported
  268. if ((data[0] & 0x10) && data[1] != 0) {
  269. result.xDelta = -((int16_t)256 - (int16_t)(data[1]));
  270. } else {
  271. result.xDelta = data[1];
  272. }
  273. if ((data[0] & 0x20) && data[2] != 0) {
  274. result.yDelta = ((int16_t)256 - (int16_t)(data[2]));
  275. } else {
  276. result.yDelta = -((int16_t)data[2]);
  277. }
  278. result.wheelCount = ((int8_t*)data)[3];
  279. #endif
  280. #ifdef CIRQUE_PINNACLE_REACHABLE_CALIBRATION
  281. static uint16_t xMin = UINT16_MAX, yMin = UINT16_MAX, yMax = 0, xMax = 0;
  282. if (result.xValue < xMin) xMin = result.xValue;
  283. if (result.xValue > xMax) xMax = result.xValue;
  284. if (result.yValue < yMin) yMin = result.yValue;
  285. if (result.yValue > yMax) yMax = result.yValue;
  286. pd_dprintf("%s: xLo=%3d xHi=%3d yLo=%3d yHi=%3d\n", __FUNCTION__, xMin, xMax, yMin, yMax);
  287. #endif
  288. result.valid = true;
  289. return result;
  290. }
  291. #ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
  292. static bool cursor_glide_enable = true;
  293. static cursor_glide_context_t glide = {.config = {
  294. .coef = 102, /* Good default friction coef */
  295. .interval = 10, /* 100sps */
  296. .trigger_px = 10, /* Default threshold in case of hover, set to 0 if you'd like */
  297. }};
  298. void cirque_pinnacle_enable_cursor_glide(bool enable) {
  299. cursor_glide_enable = enable;
  300. }
  301. void cirque_pinnacle_configure_cursor_glide(float trigger_px) {
  302. glide.config.trigger_px = trigger_px;
  303. }
  304. #endif
  305. #if CIRQUE_PINNACLE_POSITION_MODE
  306. # ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
  307. static bool is_touch_down;
  308. bool auto_mouse_activation(report_mouse_t mouse_report) {
  309. return is_touch_down || mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons;
  310. }
  311. # endif
  312. report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
  313. uint16_t scale = cirque_pinnacle_get_scale();
  314. pinnacle_data_t touchData = cirque_pinnacle_read_data();
  315. mouse_xy_report_t report_x = 0, report_y = 0;
  316. static uint16_t x = 0, y = 0, last_scale = 0;
  317. # if defined(CIRQUE_PINNACLE_TAP_ENABLE)
  318. mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
  319. # endif
  320. # ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
  321. cursor_glide_t glide_report = {0};
  322. if (cursor_glide_enable) {
  323. glide_report = cursor_glide_check(&glide);
  324. }
  325. # endif
  326. if (!touchData.valid) {
  327. # ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
  328. if (cursor_glide_enable && glide_report.valid) {
  329. report_x = glide_report.dx;
  330. report_y = glide_report.dy;
  331. goto mouse_report_update;
  332. }
  333. # endif
  334. return mouse_report;
  335. }
  336. if (touchData.touchDown) {
  337. pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue);
  338. }
  339. # ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
  340. is_touch_down = touchData.touchDown;
  341. # endif
  342. // Scale coordinates to arbitrary X, Y resolution
  343. cirque_pinnacle_scale_data(&touchData, scale, scale);
  344. if (!cirque_pinnacle_gestures(&mouse_report, touchData)) {
  345. if (last_scale && scale == last_scale && x && y && touchData.xValue && touchData.yValue) {
  346. report_x = CONSTRAIN_HID_XY((int16_t)(touchData.xValue - x));
  347. report_y = CONSTRAIN_HID_XY((int16_t)(touchData.yValue - y));
  348. }
  349. x = touchData.xValue;
  350. y = touchData.yValue;
  351. last_scale = scale;
  352. # ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
  353. if (cursor_glide_enable) {
  354. if (touchData.touchDown) {
  355. cursor_glide_update(&glide, report_x, report_y, touchData.zValue);
  356. } else if (!glide_report.valid) {
  357. glide_report = cursor_glide_start(&glide);
  358. if (glide_report.valid) {
  359. report_x = glide_report.dx;
  360. report_y = glide_report.dy;
  361. }
  362. }
  363. }
  364. # endif
  365. }
  366. # ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
  367. mouse_report_update:
  368. # endif
  369. mouse_report.x = report_x;
  370. mouse_report.y = report_y;
  371. return mouse_report;
  372. }
  373. uint16_t cirque_pinnacle_get_cpi(void) {
  374. return CIRQUE_PINNACLE_PX_TO_INCH(cirque_pinnacle_get_scale());
  375. }
  376. void cirque_pinnacle_set_cpi(uint16_t cpi) {
  377. cirque_pinnacle_set_scale(CIRQUE_PINNACLE_INCH_TO_PX(cpi));
  378. }
  379. // clang-format off
  380. const pointing_device_driver_t cirque_pinnacle_pointing_device_driver = {
  381. .init = cirque_pinnacle_init,
  382. .get_report = cirque_pinnacle_get_report,
  383. .set_cpi = cirque_pinnacle_set_cpi,
  384. .get_cpi = cirque_pinnacle_get_cpi
  385. };
  386. // clang-format on
  387. #else
  388. report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
  389. pinnacle_data_t touchData = cirque_pinnacle_read_data();
  390. // Scale coordinates to arbitrary X, Y resolution
  391. cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale());
  392. if (touchData.valid) {
  393. mouse_report.buttons = touchData.buttons;
  394. mouse_report.x = CONSTRAIN_HID_XY(touchData.xDelta);
  395. mouse_report.y = CONSTRAIN_HID_XY(touchData.yDelta);
  396. mouse_report.v = touchData.wheelCount;
  397. }
  398. return mouse_report;
  399. }
  400. // clang-format off
  401. const pointing_device_driver_t cirque_pinnacle_pointing_device_driver = {
  402. .init = cirque_pinnacle_init,
  403. .get_report = cirque_pinnacle_get_report,
  404. .set_cpi = cirque_pinnacle_set_scale,
  405. .get_cpi = cirque_pinnacle_get_scale
  406. };
  407. // clang-format on
  408. #endif