adns9800.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # error "No chip select pin defined -- missing ADNS9800_CS_PIN"
  39. #endif
  40. typedef struct {
  41. /* 200 - 8200 CPI supported */
  42. uint16_t cpi;
  43. } config_adns9800_t;
  44. typedef struct {
  45. int16_t x;
  46. int16_t y;
  47. } report_adns9800_t;
  48. void adns9800_init(void);
  49. config_adns9800_t adns9800_get_config(void);
  50. void adns9800_set_config(config_adns9800_t);
  51. uint16_t adns9800_get_cpi(void);
  52. void adns9800_set_cpi(uint16_t cpi);
  53. /* Reads and clears the current delta values on the ADNS sensor */
  54. report_adns9800_t adns9800_get_report(void);