1From 06bc4e49d19df9721050729fbf0bab952b68a63c Mon Sep 17 00:00:00 2001 2From: Jiajian Wu <jair.wu@rock-chips.com> 3Date: Wed, 21 Dec 2022 14:43:36 +0800 4Subject: [PATCH 11/11] src: add lv_systick 5 6Signed-off-by: Jiajian Wu <jair.wu@rock-chips.com> 7--- 8 lv_conf.h | 6 +++--- 9 src/misc/lv_systick.c | 24 ++++++++++++++++++++++++ 10 src/misc/lv_systick.h | 7 +++++++ 11 3 files changed, 34 insertions(+), 3 deletions(-) 12 create mode 100644 src/misc/lv_systick.c 13 create mode 100644 src/misc/lv_systick.h 14 15diff --git a/lv_conf.h b/lv_conf.h 16index e9d494407..65c32bba2 100644 17--- a/lv_conf.h 18+++ b/lv_conf.h 19@@ -85,10 +85,10 @@ 20 21 /*Use a custom tick source that tells the elapsed time in milliseconds. 22 *It removes the need to manually update the tick with `lv_tick_inc()`)*/ 23-#define LV_TICK_CUSTOM 0 24+#define LV_TICK_CUSTOM 1 25 #if LV_TICK_CUSTOM 26- #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ 27- #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ 28+ #define LV_TICK_CUSTOM_INCLUDE "src/misc/lv_systick.h" /*Header for the system time function*/ 29+ #define LV_TICK_CUSTOM_SYS_TIME_EXPR (lv_systick()) /*Expression evaluating to current system time in ms*/ 30 #endif /*LV_TICK_CUSTOM*/ 31 32 /*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. 33diff --git a/src/misc/lv_systick.c b/src/misc/lv_systick.c 34new file mode 100644 35index 000000000..0b19020c8 36--- /dev/null 37+++ b/src/misc/lv_systick.c 38@@ -0,0 +1,24 @@ 39+#include <stdio.h> 40+#include <stdint.h> 41+#include <unistd.h> 42+#include <time.h> 43+#include <sys/time.h> 44+ 45+uint32_t lv_systick(void) 46+{ 47+ static uint64_t start_ms = 0; 48+ if(start_ms == 0) { 49+ struct timeval tv_start; 50+ gettimeofday(&tv_start, NULL); 51+ start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000; 52+ } 53+ 54+ struct timeval tv_now; 55+ gettimeofday(&tv_now, NULL); 56+ uint64_t now_ms; 57+ now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000; 58+ 59+ uint32_t time_ms = now_ms - start_ms; 60+ return time_ms; 61+} 62+ 63diff --git a/src/misc/lv_systick.h b/src/misc/lv_systick.h 64new file mode 100644 65index 000000000..0a801e878 66--- /dev/null 67+++ b/src/misc/lv_systick.h 68@@ -0,0 +1,7 @@ 69+#ifndef LV_SYSTICK_H 70+#define LV_SYSTICK_H 71+ 72+uint32_t lv_systick(void); 73+ 74+#endif 75+ 76-- 772.25.1 78 79