lv_port_indev.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * 2021-12-17 Wayne Add input event
  10. */
  11. #include <lvgl.h>
  12. #include <stdbool.h>
  13. #include <rtdevice.h>
  14. #include "touch.h"
  15. static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
  16. static rt_int16_t last_x = 0;
  17. static rt_int16_t last_y = 0;
  18. static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
  19. {
  20. data->point.x = last_x;
  21. data->point.y = last_y;
  22. data->state = last_state;
  23. }
  24. void nu_touch_inputevent_cb(rt_int16_t x, rt_int16_t y, rt_uint8_t state)
  25. {
  26. switch (state)
  27. {
  28. case RT_TOUCH_EVENT_UP:
  29. last_state = LV_INDEV_STATE_RELEASED;
  30. break;
  31. case RT_TOUCH_EVENT_MOVE:
  32. case RT_TOUCH_EVENT_DOWN:
  33. last_x = x;
  34. last_y = y;
  35. last_state = LV_INDEV_STATE_PRESSED;
  36. break;
  37. }
  38. }
  39. void lv_port_indev_init(void)
  40. {
  41. static lv_indev_drv_t indev_drv;
  42. /* Basic initialization */
  43. lv_indev_drv_init(&indev_drv);
  44. indev_drv.type = LV_INDEV_TYPE_POINTER;
  45. indev_drv.read_cb = input_read;
  46. /* Register the driver in LVGL and save the created input device object */
  47. lv_indev_drv_register(&indev_drv);
  48. }