logo

qmk_firmware

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

pmw3320.h (4559B)


  1. /* Copyright 2021 Colin Lam (Ploopy Corporation)
  2. * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  3. * Copyright 2019 Sunjun Kim
  4. * Copyright 2019 Hiroyuki Okada
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #pragma once
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include "pointing_device.h"
  23. #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
  24. // Definitions for the PMW3320 serial line.
  25. #ifndef PMW3320_SCLK_PIN
  26. # ifdef POINTING_DEVICE_SCLK_PIN
  27. # define PMW3320_SCLK_PIN POINTING_DEVICE_SCLK_PIN
  28. # else
  29. # error "No clock pin defined -- missing POINTING_DEVICE_SCLK_PIN or PMW3320_SCLK_PIN"
  30. # endif
  31. #endif
  32. #ifndef PMW3320_SDIO_PIN
  33. # ifdef POINTING_DEVICE_SDIO_PIN
  34. # define PMW3320_SDIO_PIN POINTING_DEVICE_SDIO_PIN
  35. # else
  36. # error "No data pin defined -- missing POINTING_DEVICE_SDIO_PIN or PMW3320_SDIO_PIN"
  37. # endif
  38. #endif
  39. #ifndef PMW3320_CS_PIN
  40. # ifdef POINTING_DEVICE_CS_PIN
  41. # define PMW3320_CS_PIN POINTING_DEVICE_CS_PIN
  42. # else
  43. # error "No chip select pin defined -- missing POINTING_DEVICE_CS_PIN or PMW3320_CS_PIN define"
  44. # endif
  45. #endif
  46. typedef struct {
  47. int8_t dx;
  48. int8_t dy;
  49. } report_pmw3320_t;
  50. const pointing_device_driver_t pmw3320_pointing_device_driver;
  51. // A bunch of functions to implement the PMW3320-specific serial protocol.
  52. // Mostly taken from ADNS5050 driver.
  53. // Note that the "serial.h" driver is insufficient, because it does not
  54. // manually manipulate a serial clock signal.
  55. void pmw3320_init(void);
  56. void pmw3320_sync(void);
  57. uint8_t pmw3320_serial_read(void);
  58. void pmw3320_serial_write(uint8_t data);
  59. uint8_t pmw3320_read_reg(uint8_t reg_addr);
  60. void pmw3320_write_reg(uint8_t reg_addr, uint8_t data);
  61. report_pmw3320_t pmw3320_read_burst(void);
  62. void pmw3320_set_cpi(uint16_t cpi);
  63. uint16_t pmw3320_get_cpi(void);
  64. int8_t convert_twoscomp(uint8_t data);
  65. bool pmw3320_check_signature(void);
  66. report_mouse_t pmw3320_get_report(report_mouse_t mouse_report);
  67. #if !defined(PMW3320_CPI)
  68. # define PMW3320_CPI 1000
  69. #endif
  70. #define PMW3320_CPI_STEP 250
  71. #define PMW3320_CPI_MIN 250
  72. #define PMW3320_CPI_MAX 3500
  73. // PMW3320 register addresses
  74. // clang-format off
  75. #define REG_Product_ID 0x00
  76. #define REG_Revision_ID 0x01
  77. #define REG_Motion 0x02
  78. #define REG_Delta_X 0x03
  79. #define REG_Delta_Y 0x04
  80. #define REG_SQUAL 0x05
  81. #define REG_Shutter_Upper 0x06
  82. #define REG_Shutter_Lower 0x07
  83. #define REG_Maximum_Pixel 0x08
  84. #define REG_Pixel_Accum 0x09
  85. #define REG_Minimum_Pixel 0x0a
  86. #define REG_Pixel_Grab 0x0b
  87. #define REG_Delta_XY 0x0c
  88. #define REG_Resolution 0x0d
  89. #define REG_Run_Downshift 0x0e
  90. #define REG_Rest1_Period 0x0f
  91. #define REG_Rest1_Downshift 0x10
  92. #define REG_Rest2_Preiod 0x11
  93. #define REG_Rest2_Downshift 0x12
  94. #define REG_Rest3_Period 0x13
  95. #define REG_Min_SQ_Run 0x17
  96. #define REG_Axis_Control 0x1a
  97. #define REG_Performance 0x22
  98. #define REG_Low_Motion_Jitter 0x23
  99. #define REG_Shutter_Max_HI 0x36
  100. #define REG_Shutter_Max_LO 0x37
  101. #define REG_Frame_Rate 0x39
  102. #define REG_Power_Up_Reset 0x3a
  103. #define REG_Shutdown 0x3b
  104. #define REG_Inverse_Revision_ID 0x3f
  105. #define REG_Led_Control 0x40
  106. #define REG_Motion_Control 0x41
  107. #define REG_Burst_Read_First 0x42
  108. #define REG_Rest_Mode_Status 0x45
  109. #define REG_Inverse_Product_ID 0x4f
  110. #define REG_Motion_Burst 0x63
  111. // clang-format on