1
2 #if LV_BUILD_TEST
3 #include "lv_test_init.h"
4 #include "lv_test_indev.h"
5 #include <sys/time.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "../unity/unity.h"
9
10 #define HOR_RES 800
11 #define VER_RES 480
12
13 static void hal_init(void);
14 static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
15
16 lv_indev_t * lv_test_mouse_indev;
17 lv_indev_t * lv_test_keypad_indev;
18 lv_indev_t * lv_test_encoder_indev;
19
20 lv_color_t test_fb[HOR_RES * VER_RES];
21 static lv_color_t disp_buf1[HOR_RES * VER_RES];
22
lv_test_init(void)23 void lv_test_init(void)
24 {
25 lv_init();
26 hal_init();
27 }
28
lv_test_deinit(void)29 void lv_test_deinit(void)
30 {
31 lv_mem_deinit();
32 }
33
hal_init(void)34 static void hal_init(void)
35 {
36 static lv_disp_draw_buf_t draw_buf;
37
38 lv_disp_draw_buf_init(&draw_buf, disp_buf1, NULL, HOR_RES * VER_RES);
39
40 static lv_disp_drv_t disp_drv;
41 lv_disp_drv_init(&disp_drv);
42 disp_drv.draw_buf = &draw_buf;
43 disp_drv.flush_cb = dummy_flush_cb;
44 disp_drv.hor_res = HOR_RES;
45 disp_drv.ver_res = VER_RES;
46 lv_disp_drv_register(&disp_drv);
47
48 static lv_indev_drv_t indev_mouse_drv;
49 lv_indev_drv_init(&indev_mouse_drv);
50 indev_mouse_drv.type = LV_INDEV_TYPE_POINTER;
51 indev_mouse_drv.read_cb = lv_test_mouse_read_cb;
52 lv_test_mouse_indev = lv_indev_drv_register(&indev_mouse_drv);
53
54 static lv_indev_drv_t indev_keypad_drv;
55 lv_indev_drv_init(&indev_keypad_drv);
56 indev_keypad_drv.type = LV_INDEV_TYPE_KEYPAD;
57 indev_keypad_drv.read_cb = lv_test_keypad_read_cb;
58 lv_test_keypad_indev = lv_indev_drv_register(&indev_keypad_drv);
59
60 static lv_indev_drv_t indev_encoder_drv;
61 lv_indev_drv_init(&indev_encoder_drv);
62 indev_encoder_drv.type = LV_INDEV_TYPE_ENCODER;
63 indev_encoder_drv.read_cb = lv_test_encoder_read_cb;
64 lv_test_encoder_indev = lv_indev_drv_register(&indev_encoder_drv);
65 }
66
dummy_flush_cb(lv_disp_drv_t * disp_drv,const lv_area_t * area,lv_color_t * color_p)67 static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
68 {
69 LV_UNUSED(area);
70 LV_UNUSED(color_p);
71
72 memcpy(test_fb, color_p, lv_area_get_size(area) * sizeof(lv_color_t));
73
74 lv_disp_flush_ready(disp_drv);
75 }
76
custom_tick_get(void)77 uint32_t custom_tick_get(void)
78 {
79 static uint64_t start_ms = 0;
80 if(start_ms == 0) {
81 struct timeval tv_start;
82 gettimeofday(&tv_start, NULL);
83 start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
84 }
85
86 struct timeval tv_now;
87 gettimeofday(&tv_now, NULL);
88 uint64_t now_ms;
89 now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
90
91 uint32_t time_ms = now_ms - start_ms;
92 return time_ms;
93 }
94
lv_test_assert_fail(void)95 void lv_test_assert_fail(void)
96 {
97 TEST_FAIL();
98 }
99
100 #endif
101