lv_port_indev.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2006-2021, 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 <rtdevice.h>
  12. #include <lcd_port.h>
  13. static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
  14. static rt_int16_t last_x = 0;
  15. static rt_int16_t last_y = 0;
  16. lv_indev_t * touch_indev;
  17. static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
  18. {
  19. data->point.x = last_x;
  20. data->point.y = last_y;
  21. data->state = last_state;
  22. }
  23. void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
  24. {
  25. last_state = state;
  26. last_x = x;
  27. last_y = LCD_HEIGHT - y;
  28. }
  29. void lv_port_indev_init(void)
  30. {
  31. static lv_indev_drv_t indev_drv;
  32. lv_indev_drv_init(&indev_drv); /*Basic initialization*/
  33. indev_drv.type = LV_INDEV_TYPE_POINTER;
  34. indev_drv.read_cb = input_read;
  35. /*Register the driver in LVGL and save the created input device object*/
  36. touch_indev = lv_indev_drv_register(&indev_drv);
  37. }