lv_port_indev.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-07-07 liYony The first version (FT6336)
  9. * 2022-07-08 liYony Add FT6206
  10. */
  11. #include <lvgl.h>
  12. #include <rtdevice.h>
  13. #include <lcd_port.h>
  14. #define DBG_TAG "LVGL.port.indev"
  15. #define DBG_LVL DBG_INFO
  16. #include <rtdbg.h>
  17. /* Add the include file of the package you are using */
  18. #ifdef BSP_USING_TOUCH_FT6X36
  19. #include <ft6236.h>
  20. #elif defined(BSP_USING_TOUCH_FT6206)
  21. #include <ft6206.h>
  22. #endif /* BSP_USING_TOUCH_FT6X36 */
  23. /* Touch chip connection information */
  24. #define BSP_TOUCH_I2C_BUS_NAME "i2c1"
  25. #define BSP_TOUCH_I2C_RESET_PIN 119 /* PH.7 */
  26. /* RT-Thread touch device name */
  27. #define TOUCH_DEV_NAME "touch"
  28. lv_indev_t * touch_indev;
  29. rt_device_t touch_dev;
  30. struct rt_touch_data *read_data;
  31. static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
  32. {
  33. rt_device_read(touch_dev, 0, read_data, 1);
  34. if (read_data->event == RT_TOUCH_EVENT_NONE)
  35. return;
  36. /* Since the origin of the LCD screen and the origin of the touch screen are
  37. * different, the parameters passed in here need to be simply converted. */
  38. #ifdef BSP_USING_TOUCH_FT6X36
  39. data->point.x = read_data->y_coordinate;
  40. data->point.y = LCD_HEIGHT - read_data->x_coordinate;
  41. #elif defined(BSP_USING_TOUCH_FT6206)
  42. data->point.x = read_data->x_coordinate;
  43. data->point.y = LCD_HEIGHT - read_data->y_coordinate;
  44. #endif /* BSP_USING_TOUCH_FT6X36 */
  45. if (read_data->event == RT_TOUCH_EVENT_DOWN)
  46. data->state = LV_INDEV_STATE_PR;
  47. if (read_data->event == RT_TOUCH_EVENT_MOVE)
  48. data->state = LV_INDEV_STATE_PR;
  49. if (read_data->event == RT_TOUCH_EVENT_UP)
  50. data->state = LV_INDEV_STATE_REL;
  51. }
  52. void lv_port_indev_init(void)
  53. {
  54. static lv_indev_drv_t indev_drv;
  55. lv_indev_drv_init(&indev_drv); /*Basic initialization*/
  56. indev_drv.type = LV_INDEV_TYPE_POINTER;
  57. indev_drv.read_cb = input_read;
  58. /*Register the driver in LVGL and save the created input device object*/
  59. touch_indev = lv_indev_drv_register(&indev_drv);
  60. }
  61. static int lv_hw_touch_init(void)
  62. {
  63. struct rt_touch_config cfg;
  64. cfg.dev_name = BSP_TOUCH_I2C_BUS_NAME;
  65. #ifdef BSP_USING_TOUCH_FT6X36
  66. rt_hw_ft6236_init(TOUCH_DEV_NAME, &cfg, BSP_TOUCH_I2C_RESET_PIN);
  67. #elif defined(BSP_USING_TOUCH_FT6206)
  68. rt_hw_ft6206_init(TOUCH_DEV_NAME, &cfg);
  69. #endif /* BSP_USING_TOUCH_FT6X36 */
  70. touch_dev = rt_device_find(TOUCH_DEV_NAME);
  71. if (rt_device_open(touch_dev, RT_DEVICE_FLAG_RDONLY) != RT_EOK)
  72. {
  73. LOG_E("Can't open touch device:%s", TOUCH_DEV_NAME);
  74. return -RT_ERROR;
  75. }
  76. read_data = (struct rt_touch_data *)rt_calloc(1, sizeof(struct rt_touch_data));
  77. return RT_EOK;
  78. }
  79. INIT_COMPONENT_EXPORT(lv_hw_touch_init);