logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

adns5050.h (3079B)


  1. /* Copyright 2021 Colin Lam (Ploopy Corporation)
  2. * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  3. * Copyright 2019 Sunjun Kim
  4. * Copyright 2019 Hiroyuki Okada
  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 <stdbool.h>
  21. #include <stdint.h>
  22. #include "pointing_device.h"
  23. // CPI values
  24. // clang-format off
  25. #define CPI125 0x11
  26. #define CPI250 0x12
  27. #define CPI375 0x13
  28. #define CPI500 0x14
  29. #define CPI625 0x15
  30. #define CPI750 0x16
  31. #define CPI875 0x17
  32. #define CPI1000 0x18
  33. #define CPI1125 0x19
  34. #define CPI1250 0x1a
  35. #define CPI1375 0x1b
  36. // clang-format on
  37. #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
  38. // Definitions for the ADNS serial line.
  39. #ifndef ADNS5050_SCLK_PIN
  40. # ifdef POINTING_DEVICE_SCLK_PIN
  41. # define ADNS5050_SCLK_PIN POINTING_DEVICE_SCLK_PIN
  42. # else
  43. # error "No clock pin defined -- missing POINTING_DEVICE_SCLK_PIN or ADNS5050_SCLK_PIN"
  44. # endif
  45. #endif
  46. #ifndef ADNS5050_SDIO_PIN
  47. # ifdef POINTING_DEVICE_SDIO_PIN
  48. # define ADNS5050_SDIO_PIN POINTING_DEVICE_SDIO_PIN
  49. # else
  50. # error "No data pin defined -- missing POINTING_DEVICE_SDIO_PIN or ADNS5050_SDIO_PIN"
  51. # endif
  52. #endif
  53. #ifndef ADNS5050_CS_PIN
  54. # ifdef POINTING_DEVICE_CS_PIN
  55. # define ADNS5050_CS_PIN POINTING_DEVICE_CS_PIN
  56. # else
  57. # error "No chip select pin defined -- missing POINTING_DEVICE_CS_PIN or ADNS5050_CS_PIN define"
  58. # endif
  59. #endif
  60. typedef struct {
  61. int8_t dx;
  62. int8_t dy;
  63. } report_adns5050_t;
  64. const pointing_device_driver_t adns5050_pointing_device_driver;
  65. // A bunch of functions to implement the ADNS5050-specific serial protocol.
  66. // Note that the "serial.h" driver is insufficient, because it does not
  67. // manually manipulate a serial clock signal.
  68. void adns5050_init(void);
  69. void adns5050_sync(void);
  70. uint8_t adns5050_serial_read(void);
  71. void adns5050_serial_write(uint8_t data);
  72. uint8_t adns5050_read_reg(uint8_t reg_addr);
  73. void adns5050_write_reg(uint8_t reg_addr, uint8_t data);
  74. report_adns5050_t adns5050_read_burst(void);
  75. void adns5050_set_cpi(uint16_t cpi);
  76. uint16_t adns5050_get_cpi(void);
  77. int8_t convert_twoscomp(uint8_t data);
  78. bool adns5050_check_signature(void);
  79. void adns5050_power_down(void);
  80. report_mouse_t adns5050_get_report(report_mouse_t mouse_report);