1
0

hpm_gt9xx.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_GT9XX_H
  8. #define HPM_GT9XX_H
  9. #include "board.h"
  10. #include "hpm_common.h"
  11. #include "hpm_i2c_drv.h"
  12. #ifdef BOARD_GT9XX_ADDR
  13. /* if i2c addres is specified by board, use it */
  14. #define GT9XX_I2C_ADDR BOARD_GT9XX_ADDR
  15. /* no auto probe in this case */
  16. #define GT9XX_NO_AUTO_PROBE 1
  17. #else
  18. #undef GT9XX_I2C_ADDR
  19. /* enable auto probe */
  20. #ifndef GT9XX_NO_AUTO_PROBE
  21. #define GT9XX_NO_AUTO_PROBE 0
  22. #endif
  23. /* i2c device address candidates */
  24. #define GT9XX_I2C_ADDR0 (0x14U)
  25. #define GT9XX_I2C_ADDR1 (0x5DU)
  26. #endif
  27. #define GT9XX_PRODUCT_ID (0x313139U)
  28. /*
  29. * GT9XX registers at operation mode
  30. */
  31. #define GT9XX_CMD (0x8040U)
  32. #define GT9XX_CMD_READ_COORD_STAT (0U)
  33. #define GT9XX_CMD_READ_RAW_DATA (1U)
  34. #define GT9XX_CMD_SOFT_RESET (2U)
  35. #define GT9XX_CMD_READ_SCREEN_OFF (5U)
  36. #define GT9XX_CONFIG (0x8047U)
  37. #define GT9XX_ID_B0 (0x8140U)
  38. #define GT9XX_ID_B1 (0x8141U)
  39. #define GT9XX_ID_B2 (0x8142U)
  40. #define GT9XX_ID_B4 (0x8143U)
  41. #define GT9XX_FW_VERSION_L (0x8144U)
  42. #define GT9XX_FW_VERSION_H (0x8145U)
  43. #define GT9XX_TOUCH_XL (0x8146U)
  44. #define GT9XX_TOUCH_XH (0x8147U)
  45. #define GT9XX_TOUCH_YL (0x8148U)
  46. #define GT9XX_TOUCH_YH (0x8149U)
  47. #define GT9XX_VENDOR_ID (0x814AU)
  48. #define GT9XX_STATUS (0x814EU)
  49. #define GT9XX_GET_STATUS_NUM_OF_POINTS(x) ((x) & 0xFU)
  50. #define GT9XX_GET_STATUS_LARGE_DETECT(x) (((x) & 0x40U) >> 6)
  51. #define GT9XX_GET_STATUS_BUFFER_STAT(x) (((x) & 0x80U) >> 7)
  52. #define GT9XX_FIRST_POINT (0x814FU)
  53. #define GT9XX_MAX_TOUCH_POINTS (5U)
  54. #define GT9XX_CONFIG_DATA_SIZE (186U)
  55. #define GT9XX_CONFIG_DATA_CONFIG_VERSION (0U)
  56. #define GT9XX_CONFIG_DATA_RESOLUTION_XL (1U)
  57. #define GT9XX_CONFIG_DATA_RESOLUTION_XH (2U)
  58. #define GT9XX_CONFIG_DATA_RESOLUTION_YL (3U)
  59. #define GT9XX_CONFIG_DATA_RESOLUTION_YH (4U)
  60. #define GT9XX_CONFIG_DATA_TOUCH_NUMBER (5U)
  61. #define GT9XX_CONFIG_DATA_MODULE_SWITCH1 (6U)
  62. typedef struct {
  63. uint8_t track_id;
  64. uint8_t x_l;
  65. uint8_t x_h;
  66. uint8_t y_l;
  67. uint8_t y_h;
  68. uint8_t size_l;
  69. uint8_t size_h;
  70. uint8_t reserved;
  71. } gt9xx_touch_point_t;
  72. typedef struct {
  73. uint8_t status;
  74. gt9xx_touch_point_t points[GT9XX_MAX_TOUCH_POINTS];
  75. } gt9xx_touch_data_t;
  76. typedef struct {
  77. I2C_Type *ptr;
  78. uint16_t abs_x_max;
  79. uint16_t abs_y_max;
  80. bool exchange_xy;
  81. bool reverse_x;
  82. bool reverse_y;
  83. } gt9xx_context_t;
  84. #ifdef __cplusplus
  85. extern "C" {
  86. #endif
  87. /*
  88. * gt9xx initialization routine
  89. */
  90. hpm_stat_t gt9xx_init(gt9xx_context_t *context, uint16_t width, uint16_t height);
  91. /*
  92. * gt9xx read touch data
  93. */
  94. hpm_stat_t gt9xx_read_touch_data(gt9xx_context_t *context,
  95. gt9xx_touch_data_t *touch_data);
  96. /*
  97. * gt9xx read data
  98. */
  99. hpm_stat_t gt9xx_read_data(gt9xx_context_t *context, uint16_t addr,
  100. uint8_t *buf, uint32_t size);
  101. /*
  102. * gt9xx write value to given register
  103. */
  104. hpm_stat_t gt9xx_write_register(gt9xx_context_t *context,
  105. uint16_t reg, uint8_t val);
  106. /*
  107. * gt9xx read value of given register
  108. */
  109. hpm_stat_t gt9xx_read_register(gt9xx_context_t *context, uint16_t reg, uint8_t *buf);
  110. /*
  111. * gt9xx read config data
  112. */
  113. hpm_stat_t gt9xx_read_config(gt9xx_context_t *context, uint8_t *buf, uint8_t size);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif /* HPM_GT9XX_H */