You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.2 KiB

  1. /* Copyright 2021 Alabastard (@Alabastard-64)
  2. * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  3. * Copyright 2019 Sunjun Kim
  4. * Copyright 2020 Ploopy Corporation
  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. #ifndef PMW3389_CPI
  22. # define PMW3389_CPI 2000
  23. #endif
  24. #ifndef PMW3389_CLOCK_SPEED
  25. # define PMW3389_CLOCK_SPEED 2000000
  26. #endif
  27. #ifndef PMW3389_SPI_LSBFIRST
  28. # define PMW3389_SPI_LSBFIRST false
  29. #endif
  30. #ifndef PMW3389_SPI_MODE
  31. # define PMW3389_SPI_MODE 3
  32. #endif
  33. #ifndef PMW3389_SPI_DIVISOR
  34. # ifdef __AVR__
  35. # define PMW3389_SPI_DIVISOR (F_CPU / PMW3389_CLOCK_SPEED)
  36. # else
  37. # define PMW3389_SPI_DIVISOR 64
  38. # endif
  39. #endif
  40. #ifndef PMW3389_LIFTOFF_DISTANCE
  41. # define PMW3389_LIFTOFF_DISTANCE 0x02
  42. #endif
  43. #ifndef ROTATIONAL_TRANSFORM_ANGLE
  44. # define ROTATIONAL_TRANSFORM_ANGLE 0x00
  45. #endif
  46. #ifndef PMW3389_CS_PIN
  47. # error "No chip select pin defined -- missing PMW3389_CS_PIN"
  48. #endif
  49. typedef struct {
  50. int8_t motion;
  51. bool isMotion; // True if a motion is detected.
  52. bool isOnSurface; // True when a chip is on a surface
  53. int16_t dx; // displacement on x directions. Unit: Count. (CPI * Count = Inch value)
  54. int8_t mdx;
  55. int16_t dy; // displacement on y directions.
  56. int8_t mdy;
  57. } report_pmw3389_t;
  58. bool pmw3389_init(void);
  59. void pmw3389_upload_firmware(void);
  60. bool pmw3389_check_signature(void);
  61. uint16_t pmw3389_get_cpi(void);
  62. void pmw3389_set_cpi(uint16_t cpi);
  63. /* Reads and clears the current delta values on the sensor */
  64. report_pmw3389_t pmw3389_read_burst(void);