pmw3360.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  2. * Copyright 2019 Sunjun Kim
  3. * Copyright 2020 Ploopy Corporation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <stdint.h>
  20. #ifndef PMW3360_CPI
  21. # define PMW3360_CPI 1600
  22. #endif
  23. #ifndef PMW3360_CLOCK_SPEED
  24. # define PMW3360_CLOCK_SPEED 2000000
  25. #endif
  26. #ifndef PMW3360_SPI_LSBFIRST
  27. # define PMW3360_SPI_LSBFIRST false
  28. #endif
  29. #ifndef PMW3360_SPI_MODE
  30. # define PMW3360_SPI_MODE 3
  31. #endif
  32. #ifndef PMW3360_SPI_DIVISOR
  33. # ifdef __AVR__
  34. # define PMW3360_SPI_DIVISOR (F_CPU / PMW3360_CLOCK_SPEED)
  35. # else
  36. # define PMW3360_SPI_DIVISOR 64
  37. # endif
  38. #endif
  39. #ifndef PMW3360_LIFTOFF_DISTANCE
  40. # define PMW3360_LIFTOFF_DISTANCE 0x02
  41. #endif
  42. #ifndef ROTATIONAL_TRANSFORM_ANGLE
  43. # define ROTATIONAL_TRANSFORM_ANGLE 0x00
  44. #endif
  45. #ifndef PMW3360_CS_PIN
  46. # error "No chip select pin defined -- missing PMW3360_CS_PIN"
  47. #endif
  48. /*
  49. The pmw33660 and pmw3389 use the same registers and timing and such.
  50. The only differences between the two is the firmware used, and the
  51. range for the DPI. So add a semi-secret hack to allow use of the
  52. pmw3389's firmware blob. Also, can set the max cpi range too.
  53. This should work for the 3390 and 3391 too, in theory.
  54. */
  55. #ifndef PMW3360_FIRMWARE_H
  56. # define PMW3360_FIRMWARE_H "pmw3360_firmware.h"
  57. #endif
  58. typedef struct {
  59. int8_t motion;
  60. bool isMotion; // True if a motion is detected.
  61. bool isOnSurface; // True when a chip is on a surface
  62. int16_t dx; // displacement on x directions. Unit: Count. (CPI * Count = Inch value)
  63. int8_t mdx;
  64. int16_t dy; // displacement on y directions.
  65. int8_t mdy;
  66. } report_pmw3360_t;
  67. bool pmw3360_init(void);
  68. void pmw3360_upload_firmware(void);
  69. bool pmw3360_check_signature(void);
  70. uint16_t pmw3360_get_cpi(void);
  71. void pmw3360_set_cpi(uint16_t cpi);
  72. /* Reads and clears the current delta values on the sensor */
  73. report_pmw3360_t pmw3360_read_burst(void);