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.

79 lines
2.4 KiB

  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. // Registers
  22. #define REG_PRODUCT_ID 0x00
  23. #define REG_REVISION_ID 0x01
  24. #define REG_MOTION 0x02
  25. #define REG_DELTA_X 0x03
  26. #define REG_DELTA_Y 0x04
  27. #define REG_SQUAL 0x05
  28. #define REG_SHUTTER_UPPER 0x06
  29. #define REG_SHUTTER_LOWER 0x07
  30. #define REG_MAXIMUM_PIXEL 0x08
  31. #define REG_PIXEL_SUM 0x09
  32. #define REG_MINIMUM_PIXEL 0x0a
  33. #define REG_PIXEL_GRAB 0x0b
  34. #define REG_MOUSE_CONTROL 0x0d
  35. #define REG_MOUSE_CONTROL2 0x19
  36. #define REG_LED_DC_MODE 0x22
  37. #define REG_CHIP_RESET 0x3a
  38. #define REG_PRODUCT_ID2 0x3e
  39. #define REG_INV_REV_ID 0x3f
  40. #define REG_MOTION_BURST 0x63
  41. // CPI values
  42. #define CPI125 0x11
  43. #define CPI250 0x12
  44. #define CPI375 0x13
  45. #define CPI500 0x14
  46. #define CPI625 0x15
  47. #define CPI750 0x16
  48. #define CPI875 0x17
  49. #define CPI1000 0x18
  50. #define CPI1125 0x19
  51. #define CPI1250 0x1a
  52. #define CPI1375 0x1b
  53. #ifdef CONSOLE_ENABLE
  54. void print_byte(uint8_t byte);
  55. #endif
  56. typedef struct {
  57. int8_t dx;
  58. int8_t dy;
  59. } report_adns_t;
  60. // A bunch of functions to implement the ADNS5050-specific serial protocol.
  61. // Note that the "serial.h" driver is insufficient, because it does not
  62. // manually manipulate a serial clock signal.
  63. void adns_init(void);
  64. void adns_sync(void);
  65. uint8_t adns_serial_read(void);
  66. void adns_serial_write(uint8_t data);
  67. uint8_t adns_read_reg(uint8_t reg_addr);
  68. void adns_write_reg(uint8_t reg_addr, uint8_t data);
  69. report_adns_t adns_read_burst(void);
  70. int8_t convert_twoscomp(uint8_t data);
  71. void adns_set_cpi(uint8_t cpi);
  72. bool adns_check_signature(void);