paw3204.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright 2021 Gompa (@Gompa)
  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. #include <stdbool.h>
  19. #ifndef PAW3204_SCLK_PIN
  20. # ifdef POINTING_DEVICE_SCLK_PIN
  21. # define PAW3204_SCLK_PIN POINTING_DEVICE_SCLK_PIN
  22. # else
  23. # error "No clock pin defined -- missing POINTING_DEVICE_SCLK_PIN or PAW3204_SCLK_PIN"
  24. # endif
  25. #endif
  26. #ifndef PAW3204_SDIO_PIN
  27. # ifdef POINTING_DEVICE_SDIO_PIN
  28. # define PAW3204_SDIO_PIN POINTING_DEVICE_SDIO_PIN
  29. # else
  30. # error "No data pin defined -- missing POINTING_DEVICE_SDIO_PIN or PAW3204_SDIO_PIN"
  31. # endif
  32. #endif
  33. typedef struct {
  34. int16_t x;
  35. int16_t y;
  36. bool isMotion;
  37. } report_paw3204_t;
  38. /**
  39. * @brief Initializes the sensor so it is in a working state and ready to
  40. * be polled for data.
  41. *
  42. * @return true Initialization was a success
  43. * @return false Initialization failed, do not proceed operation
  44. */
  45. void paw3204_init(void);
  46. /**
  47. * @brief Reads and clears the current delta, and motion register values on the
  48. * given sensor.
  49. *
  50. * @return pmw33xx_report_t Current values of the sensor, if errors occurred all
  51. * fields are set to zero
  52. */
  53. report_paw3204_t paw3204_read(void);
  54. /**
  55. * @brief Sets the given CPI value the sensor. CPI is often refereed to
  56. * as the sensors sensitivity. Values outside of the allowed range are
  57. * constrained into legal values.
  58. *
  59. * @param cpi CPI value to set
  60. */
  61. void paw3204_set_cpi(uint16_t cpi);
  62. /**
  63. * @brief Gets the currently set CPI value from the sensor. CPI is often
  64. * refereed to as the sensors sensitivity.
  65. *
  66. * @return uint16_t Current CPI value of the sensor
  67. */
  68. uint16_t paw3204_get_cpi(void);