main.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * SPDX-License-Identifier: MIT
  3. * Copyright 2024 NXP
  4. */
  5. /*********************
  6. * INCLUDES
  7. *********************/
  8. #define _DEFAULT_SOURCE /* needed for usleep() */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include "lvgl.h"
  13. #include "gui_guider.h"
  14. #include "events_init.h"
  15. #include "custom.h"
  16. static void hal_init(void);
  17. lv_ui guider_ui;
  18. int main(void)
  19. {
  20. /* Initialize LVGL */
  21. lv_init();
  22. /* Initialize the HAL (display, input devices) for LVGL */
  23. hal_init();
  24. /* Create a GUI-Guider app */
  25. setup_ui(&guider_ui);
  26. events_init(&guider_ui);
  27. custom_init(&guider_ui);
  28. /* Handle LVGL tasks */
  29. #if LV_USE_WAYLAND
  30. bool completed;
  31. while (1) {
  32. completed = lv_wayland_timer_handler();
  33. if (completed) {
  34. /* wait only if the cycle was completed */
  35. usleep(LV_DEF_REFR_PERIOD * 1000);
  36. }
  37. /* Run until the last window closes */
  38. if (!lv_wayland_window_is_open(NULL)) {
  39. break;
  40. }
  41. }
  42. #else
  43. uint32_t idle_time;
  44. while(1) {
  45. /* Return the time to the next timer execution */
  46. idle_time = lv_timer_handler();
  47. usleep(idle_time * 1000);
  48. }
  49. #endif
  50. return 0;
  51. }
  52. /**
  53. * Initialize the Hardware Abstraction Layer (HAL) for the LVGL graphics library
  54. */
  55. static void hal_init(void)
  56. {
  57. lv_display_t *disp;
  58. #if LV_USE_WAYLAND
  59. disp = lv_wayland_window_create(LV_HOR_RES_MAX, LV_VER_RES_MAX, "GUI Guider", NULL);
  60. lv_group_t * g = lv_group_create();
  61. lv_group_set_default(g);
  62. lv_indev_set_group(lv_wayland_get_pointeraxis(disp), g);
  63. #elif LV_USE_LINUX_DRM
  64. disp = lv_linux_drm_create();
  65. #if LV_USE_EVDEV
  66. lv_indev_t * touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, LV_EVDEV_DEVICE);
  67. lv_indev_set_display(touch, disp);
  68. /* Set the cursor icon */
  69. LV_IMAGE_DECLARE(mouse_cursor_icon);
  70. lv_obj_t * cursor_obj = lv_image_create(lv_screen_active());
  71. lv_image_set_src(cursor_obj, &mouse_cursor_icon);
  72. lv_indev_set_cursor(touch, cursor_obj);
  73. #endif
  74. lv_linux_drm_set_file(disp, LV_LINUX_DRM_CARD, -1);
  75. #else
  76. #error Unsupported Backend
  77. #endif
  78. }