adns9800.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright 2020 Alexander Tulloh
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <stdint.h>
  18. #ifndef ADNS9800_CPI
  19. # define ADNS9800_CPI 1600
  20. #endif
  21. #ifndef ADNS9800_CLOCK_SPEED
  22. # define ADNS9800_CLOCK_SPEED 2000000
  23. #endif
  24. #ifndef ADNS9800_SPI_LSBFIRST
  25. # define ADNS9800_SPI_LSBFIRST false
  26. #endif
  27. #ifndef ADNS9800_SPI_MODE
  28. # define ADNS9800_SPI_MODE 3
  29. #endif
  30. #ifndef ADNS9800_SPI_DIVISOR
  31. # ifdef __AVR__
  32. # define ADNS9800_SPI_DIVISOR (F_CPU / ADNS9800_CLOCK_SPEED)
  33. # else
  34. # define ADNS9800_SPI_DIVISOR 64
  35. # endif
  36. #endif
  37. #ifndef ADNS9800_CS_PIN
  38. # ifdef POINTING_DEVICE_CS_PIN
  39. # define ADNS9800_CS_PIN POINTING_DEVICE_CS_PIN
  40. # else
  41. # error "No chip select pin defined -- missing POINTING_DEVICE_CS_PIN or ADNS9800_CS_PIN"
  42. # endif
  43. #endif
  44. typedef struct {
  45. /* 200 - 8200 CPI supported */
  46. uint16_t cpi;
  47. } config_adns9800_t;
  48. typedef struct {
  49. int16_t x;
  50. int16_t y;
  51. } report_adns9800_t;
  52. void adns9800_init(void);
  53. config_adns9800_t adns9800_get_config(void);
  54. void adns9800_set_config(config_adns9800_t);
  55. uint16_t adns9800_get_cpi(void);
  56. void adns9800_set_cpi(uint16_t cpi);
  57. /* Reads and clears the current delta values on the ADNS sensor */
  58. report_adns9800_t adns9800_get_report(void);