lv_port_indev.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. * 2021-10-18 Meco Man The first version
  9. */
  10. #include <lvgl.h>
  11. #include <stdbool.h>
  12. #include <rtdevice.h>
  13. #include <board.h>
  14. #include <drv_lcd.h>
  15. lv_indev_t *touch_indev;
  16. static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
  17. static rt_int16_t last_x = 0;
  18. static rt_int16_t last_y = 0;
  19. static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
  20. {
  21. data->point.x = last_x;
  22. data->point.y = last_y;
  23. data->state = last_state;
  24. }
  25. void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
  26. {
  27. last_state = state;
  28. #ifdef BSP_USING_TOUCH_CAP
  29. last_x = LCD_W - y;
  30. last_y = x;
  31. #endif /* BSP_USING_TOUCH_CAP */
  32. #ifdef BSP_USING_TOUCH_RES
  33. last_x = x;
  34. last_y = y;
  35. #endif /* BSP_USING_TOUCH_RES */
  36. }
  37. void lv_port_indev_init(void)
  38. {
  39. static lv_indev_drv_t indev_drv;
  40. lv_indev_drv_init(&indev_drv); /*Basic initialization*/
  41. indev_drv.type = LV_INDEV_TYPE_POINTER;
  42. indev_drv.read_cb = input_read;
  43. /*Register the driver in LVGL and save the created input device object*/
  44. touch_indev = lv_indev_drv_register(&indev_drv);
  45. }