touch.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-05-20 tyustli the first version
  9. */
  10. #ifndef __TOUCH_H__
  11. #define __TOUCH_H__
  12. #include <rtthread.h>
  13. #include "pin.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #ifdef RT_USING_RTC
  18. #define rt_touch_get_ts() time(RT_NULL) /* API for the touch to get the timestamp */
  19. #else
  20. #define rt_touch_get_ts() rt_tick_get() /* API for the touch to get the timestamp */
  21. #endif
  22. /* Touch vendor types */
  23. #define RT_TOUCH_VENDOR_UNKNOWN (0) /* unknown */
  24. #define RT_TOUCH_VENDOR_GT (1) /* GTxx series */
  25. #define RT_TOUCH_VENDOR_FT (2) /* FTxx series */
  26. /* Touch ic type*/
  27. #define RT_TOUCH_TYPE_NONE (0) /* touch ic none */
  28. #define RT_TOUCH_TYPE_CAPACITANCE (1) /* capacitance ic */
  29. #define RT_TOUCH_TYPE_RESISTANCE (2) /* resistance ic */
  30. /* Touch control cmd types */
  31. #define RT_TOUCH_CTRL_GET_ID (RT_DEVICE_CTRL_BASE(Touch) + 0) /* Get device id */
  32. #define RT_TOUCH_CTRL_GET_INFO (RT_DEVICE_CTRL_BASE(Touch) + 1) /* Get touch info */
  33. #define RT_TOUCH_CTRL_SET_MODE (RT_DEVICE_CTRL_BASE(Touch) + 2) /* Set touch's work mode. ex. RT_TOUCH_MODE_POLLING,RT_TOUCH_MODE_INT */
  34. #define RT_TOUCH_CTRL_SET_X_RANGE (RT_DEVICE_CTRL_BASE(Touch) + 3) /* Set x coordinate range */
  35. #define RT_TOUCH_CTRL_SET_Y_RANGE (RT_DEVICE_CTRL_BASE(Touch) + 4) /* Set y coordinate range */
  36. #define RT_TOUCH_CTRL_SET_X_TO_Y (RT_DEVICE_CTRL_BASE(Touch) + 5) /* Set X Y coordinate exchange */
  37. #define RT_TOUCH_CTRL_DISABLE_INT (RT_DEVICE_CTRL_BASE(Touch) + 6) /* Disable interrupt */
  38. #define RT_TOUCH_CTRL_ENABLE_INT (RT_DEVICE_CTRL_BASE(Touch) + 7) /* Enable interrupt */
  39. #define RT_TOUCH_CTRL_POWER_ON (RT_DEVICE_CTRL_BASE(Touch) + 8) /* Touch Power On */
  40. #define RT_TOUCH_CTRL_POWER_OFF (RT_DEVICE_CTRL_BASE(Touch) + 9) /* Touch Power Off */
  41. #define RT_TOUCH_CTRL_GET_STATUS (RT_DEVICE_CTRL_BASE(Touch) + 10) /* Get Touch Power Status */
  42. /* Touch event */
  43. #define RT_TOUCH_EVENT_NONE (0) /* Touch none */
  44. #define RT_TOUCH_EVENT_UP (1) /* Touch up event */
  45. #define RT_TOUCH_EVENT_DOWN (2) /* Touch down event */
  46. #define RT_TOUCH_EVENT_MOVE (3) /* Touch move event */
  47. struct rt_touch_info
  48. {
  49. rt_uint8_t type; /* The touch type */
  50. rt_uint8_t vendor; /* Vendor of touchs */
  51. rt_uint8_t point_num; /* Support point num */
  52. rt_int32_t range_x; /* X coordinate range */
  53. rt_int32_t range_y; /* Y coordinate range */
  54. };
  55. struct rt_touch_config
  56. {
  57. #ifdef RT_TOUCH_PIN_IRQ
  58. struct rt_device_pin_mode irq_pin; /* Interrupt pin, The purpose of this pin is to notification read data */
  59. #endif
  60. char *dev_name; /* The name of the communication device */
  61. void *user_data;
  62. };
  63. typedef struct rt_touch_device *rt_touch_t;
  64. struct rt_touch_device
  65. {
  66. struct rt_device parent; /* The standard device */
  67. struct rt_touch_info info; /* The touch info data */
  68. struct rt_touch_config config; /* The touch config data */
  69. const struct rt_touch_ops *ops; /* The touch ops */
  70. rt_err_t (*irq_handle)(rt_touch_t touch); /* Called when an interrupt is generated, registered by the driver */
  71. };
  72. struct rt_touch_data
  73. {
  74. rt_uint8_t event; /* The touch event of the data */
  75. rt_uint8_t track_id; /* Track id of point */
  76. rt_uint8_t width; /* Point of width */
  77. rt_uint16_t x_coordinate; /* Point of x coordinate */
  78. rt_uint16_t y_coordinate; /* Point of y coordinate */
  79. rt_tick_t timestamp; /* The timestamp when the data was received */
  80. };
  81. struct rt_touch_ops
  82. {
  83. rt_size_t (*touch_readpoint)(struct rt_touch_device *touch, void *buf, rt_size_t touch_num);
  84. rt_err_t (*touch_control)(struct rt_touch_device *touch, int cmd, void *arg);
  85. };
  86. int rt_hw_touch_register(rt_touch_t touch,
  87. const char *name,
  88. rt_uint32_t flag,
  89. void *data);
  90. /* if you doesn't use pin device. you must call this function in your touch irq callback */
  91. void rt_hw_touch_isr(rt_touch_t touch);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* __TOUCH_H__ */