lv_port_indev.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
  15. static rt_int16_t last_x = 0;
  16. static rt_int16_t last_y = 0;
  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 nu_touch_inputevent_cb(rt_int16_t x, rt_int16_t y, rt_uint8_t state)
  24. {
  25. switch (state)
  26. {
  27. case RT_TOUCH_EVENT_UP:
  28. last_state = LV_INDEV_STATE_RELEASED;
  29. break;
  30. case RT_TOUCH_EVENT_MOVE:
  31. case RT_TOUCH_EVENT_DOWN:
  32. last_x = x;
  33. last_y = y;
  34. last_state = LV_INDEV_STATE_PRESSED;
  35. break;
  36. }
  37. }
  38. void lv_port_indev_init(void)
  39. {
  40. static lv_indev_drv_t indev_drv;
  41. /* Basic initialization */
  42. lv_indev_drv_init(&indev_drv);
  43. indev_drv.type = LV_INDEV_TYPE_POINTER;
  44. indev_drv.read_cb = input_read;
  45. /* Register the driver in LVGL and save the created input device object */
  46. lv_indev_drv_register(&indev_drv);
  47. }