hpm_gt911.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_GT911_H
  8. #define HPM_GT911_H
  9. #include "board.h"
  10. #include "hpm_common.h"
  11. #include "hpm_i2c_drv.h"
  12. #ifdef BOARD_GT911_ADDR
  13. /* if i2c addres is specified by board, use it */
  14. #define GT911_I2C_ADDR BOARD_GT911_ADDR
  15. /* no auto probe in this case */
  16. #define GT911_NO_AUTO_PROBE 1
  17. #else
  18. #undef GT911_I2C_ADDR
  19. /* enable auto probe */
  20. #ifndef GT911_NO_AUTO_PROBE
  21. #define GT911_NO_AUTO_PROBE 0
  22. #endif
  23. /* i2c device address candidates */
  24. #define GT911_I2C_ADDR0 (0x14U)
  25. #define GT911_I2C_ADDR1 (0x5DU)
  26. #endif
  27. #define GT911_PRODUCT_ID (0x313139U)
  28. /*
  29. * GT911 registers at operation mode
  30. */
  31. #define GT911_CMD (0x8040U)
  32. #define GT911_CMD_READ_COORD_STAT (0U)
  33. #define GT911_CMD_READ_RAW_DATA (1U)
  34. #define GT911_CMD_SOFT_RESET (2U)
  35. #define GT911_CMD_READ_SCREEN_OFF (5U)
  36. #define GT911_CONFIG (0x8047U)
  37. #define GT911_ID_B0 (0x8140U)
  38. #define GT911_ID_B1 (0x8141U)
  39. #define GT911_ID_B2 (0x8142U)
  40. #define GT911_ID_B4 (0x8143U)
  41. #define GT911_FW_VERSION_L (0x8144U)
  42. #define GT911_FW_VERSION_H (0x8145U)
  43. #define GT911_TOUCH_XL (0x8146U)
  44. #define GT911_TOUCH_XH (0x8147U)
  45. #define GT911_TOUCH_YL (0x8148U)
  46. #define GT911_TOUCH_YH (0x8149U)
  47. #define GT911_VENDOR_ID (0x814AU)
  48. #define GT911_STATUS (0x814EU)
  49. #define GT911_GET_STATUS_NUM_OF_POINTS(x) ((x) & 0xFU)
  50. #define GT911_GET_STATUS_LARGE_DETECT(x) (((x) & 0x40U) >> 6)
  51. #define GT911_GET_STATUS_BUFFER_STAT(x) (((x) & 0x80U) >> 7)
  52. #define GT911_FIRST_POINT (0x814FU)
  53. #define GT911_MAX_TOUCH_POINTS (5U)
  54. #define GT911_CONFIG_DATA_SIZE (186U)
  55. #define GT911_CONFIG_DATA_RESOLUTION_XL (1U)
  56. #define GT911_CONFIG_DATA_RESOLUTION_XH (2U)
  57. #define GT911_CONFIG_DATA_RESOLUTION_YL (3U)
  58. #define GT911_CONFIG_DATA_RESOLUTION_YH (4U)
  59. #define GT911_CONFIG_DATA_TOUCH_NUMBER (5U)
  60. #define GT911_CONFIG_DATA_MODULE_SWITCH1 (6U)
  61. typedef struct {
  62. uint8_t track_id;
  63. uint8_t x_l;
  64. uint8_t x_h;
  65. uint8_t y_l;
  66. uint8_t y_h;
  67. uint8_t size_l;
  68. uint8_t size_h;
  69. uint8_t reserved;
  70. } gt911_touch_point_t;
  71. typedef struct {
  72. uint8_t status;
  73. gt911_touch_point_t points[GT911_MAX_TOUCH_POINTS];
  74. } gt911_touch_data_t;
  75. typedef struct {
  76. I2C_Type *ptr;
  77. } gt911_context_t;
  78. #ifdef __cplusplus
  79. extern "C" {
  80. #endif
  81. /*
  82. * gt911 initialization routine
  83. */
  84. hpm_stat_t gt911_init(gt911_context_t *context, uint16_t width, uint16_t height);
  85. /*
  86. * gt911 read touch data
  87. */
  88. hpm_stat_t gt911_read_touch_data(gt911_context_t *context,
  89. gt911_touch_data_t *touch_data);
  90. /*
  91. * gt911 read data
  92. */
  93. hpm_stat_t gt911_read_data(gt911_context_t *context, uint16_t addr,
  94. uint8_t *buf, uint32_t size);
  95. /*
  96. * gt911 write value to given register
  97. */
  98. hpm_stat_t gt911_write_register(gt911_context_t *context,
  99. uint16_t reg, uint8_t val);
  100. /*
  101. * gt911 read value of given register
  102. */
  103. hpm_stat_t gt911_read_register(gt911_context_t *context, uint16_t reg, uint8_t *buf);
  104. /*
  105. * gt911 read config data
  106. */
  107. hpm_stat_t gt911_read_config(gt911_context_t *context, uint8_t *buf, uint8_t size);
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif /* HPM_GT911_H */