From 1d92e1854c19c06c553243d29170bb4d1a9e3863 Mon Sep 17 00:00:00 2001
From: Marek Vasut <marex@denx.de>
Date: Tue, 9 May 2023 02:57:30 +0200
Subject: [PATCH 1/2] wayland: Switch to custom timer tick

The OE LVGL is configured to obtain timer tick from system timer
instead of using ad-hoc mechanisms to emulate timer tick using
threads or such. Use system timer to provide the tick.

The tick handling implementation comes from:
https://github.com/lvgl/lv_port_linux_frame_buffer.git
as of commit adf2c4490e17a1b9ec1902cc412a24b3b8235c8e

Upstream-Status: Inappropriate [Upstream repo is archived]
Signed-off-by: Marek Vasut <marex@denx.de>
---
 src/drivers/wayland.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/drivers/wayland.c b/src/drivers/wayland.c
index 633dc18..bcebf4d 100644
--- a/src/drivers/wayland.c
+++ b/src/drivers/wayland.c
@@ -6,6 +6,7 @@
 #if defined(USE_WAYLAND) && USE_WAYLAND
 
 #include <pthread.h>
+#include <sys/time.h>
 #include <unistd.h>
 
 #include <lv_drivers/wayland/wayland.h>
@@ -18,13 +19,22 @@
 #define WAYLAND_VER_RES      320
 #endif
 
-static void * tick_thread(void * data)
+uint32_t custom_tick_get(void)
 {
-    (void) data;
-    while(true) {
-        usleep(5 * 1000);
-        lv_tick_inc(5);
-    }
+	static uint64_t start_ms = 0;
+	if(start_ms == 0) {
+		struct timeval tv_start;
+		gettimeofday(&tv_start, NULL);
+		start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
+	}
+
+	struct timeval tv_now;
+	gettimeofday(&tv_now, NULL);
+	uint64_t now_ms;
+	now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
+
+	uint32_t time_ms = now_ms - start_ms;
+	return time_ms;
 }
 
 
@@ -47,8 +57,6 @@ void hal_init(void)
 
     lv_group_t * g = lv_group_create();
     lv_group_set_default(g);
-    static pthread_t hal_thread;
-    pthread_create(&hal_thread, NULL, tick_thread, NULL);
 }
 
 #endif
-- 
2.39.2

