1 #include "../lvgl.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/time.h>
5 #include "lv_test_core/lv_test_core.h"
6 #include "lv_test_widgets/lv_test_label.h"
7
8 #if LV_BUILD_TEST
9
10 static void hal_init(void);
11 static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
12
13 lv_color_t test_fb[LV_HOR_RES_MAX * LV_VER_RES_MAX];
14
main(void)15 int main(void)
16 {
17 printf("Call lv_init...\n");
18 lv_init();
19
20 hal_init();
21
22 lv_test_core();
23 lv_test_label();
24
25 printf("Exit with success!\n");
26 return 0;
27 }
28
29
30 #if LV_USE_FILESYSTEM
open_cb(struct _lv_fs_drv_t * drv,void * file_p,const char * path,lv_fs_mode_t mode)31 static lv_fs_res_t open_cb(struct _lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
32 {
33 (void) drv;
34 (void) mode;
35
36 FILE * fp = fopen(path, "rb"); // only reading is supported
37
38 *((FILE **)file_p) = fp;
39 return NULL == fp ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
40 }
41
close_cb(struct _lv_fs_drv_t * drv,void * file_p)42 static lv_fs_res_t close_cb(struct _lv_fs_drv_t * drv, void * file_p)
43 {
44 (void) drv;
45
46 FILE * fp = *((FILE **) file_p);
47 fclose(fp);
48 return LV_FS_RES_OK;
49 }
50
read_cb(struct _lv_fs_drv_t * drv,void * file_p,void * buf,uint32_t btr,uint32_t * br)51 static lv_fs_res_t read_cb(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
52 {
53 (void) drv;
54
55 FILE * fp = *((FILE **) file_p);
56 *br = fread(buf, 1, btr, fp);
57 return (*br <= 0) ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
58 }
59
seek_cb(struct _lv_fs_drv_t * drv,void * file_p,uint32_t pos)60 static lv_fs_res_t seek_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos)
61 {
62 (void) drv;
63
64 FILE * fp = *((FILE **) file_p);
65 fseek (fp, pos, SEEK_SET);
66
67 return LV_FS_RES_OK;
68 }
69
tell_cb(struct _lv_fs_drv_t * drv,void * file_p,uint32_t * pos_p)70 static lv_fs_res_t tell_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
71 {
72 (void) drv;
73
74 FILE * fp = *((FILE **) file_p);
75 *pos_p = ftell(fp);
76
77 return LV_FS_RES_OK;
78 }
79
ready_cb(struct _lv_fs_drv_t * drv)80 static bool ready_cb(struct _lv_fs_drv_t * drv)
81 {
82 (void) drv;
83 return true;
84 }
85 #endif
86
hal_init(void)87 static void hal_init(void)
88 {
89 static lv_disp_buf_t disp_buf;
90 lv_color_t * disp_buf1 = (lv_color_t *)malloc(LV_HOR_RES * LV_VER_RES * sizeof(lv_color_t));
91
92 lv_disp_buf_init(&disp_buf, disp_buf1, NULL, LV_HOR_RES * LV_VER_RES);
93
94 lv_disp_drv_t disp_drv;
95 lv_disp_drv_init(&disp_drv);
96 disp_drv.buffer = &disp_buf;
97 disp_drv.flush_cb = dummy_flush_cb;
98 lv_disp_drv_register(&disp_drv);
99
100 #if LV_USE_FILESYSTEM
101 lv_fs_drv_t drv;
102 lv_fs_drv_init(&drv); /*Basic initialization*/
103
104 drv.letter = 'f'; /*An uppercase letter to identify the drive */
105 drv.file_size = sizeof(FILE *); /*Size required to store a file object*/
106 drv.ready_cb = ready_cb; /*Callback to tell if the drive is ready to use */
107 drv.open_cb = open_cb; /*Callback to open a file */
108 drv.close_cb = close_cb; /*Callback to close a file */
109 drv.read_cb = read_cb; /*Callback to read a file */
110 drv.seek_cb = seek_cb; /*Callback to seek in a file (Move cursor) */
111 drv.tell_cb = tell_cb; /*Callback to tell the cursor position */
112
113 lv_fs_drv_register(&drv); /*Finally register the drive*/
114 #endif
115 }
116 #include <stdio.h>
117
dummy_flush_cb(lv_disp_drv_t * disp_drv,const lv_area_t * area,lv_color_t * color_p)118 static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
119 {
120 LV_UNUSED(area);
121 LV_UNUSED(color_p);
122
123 memcpy(test_fb, color_p, lv_area_get_size(area) * sizeof(lv_color_t));
124
125 lv_disp_flush_ready(disp_drv);
126 }
127
custom_tick_get(void)128 uint32_t custom_tick_get(void)
129 {
130 static uint64_t start_ms = 0;
131 if(start_ms == 0) {
132 struct timeval tv_start;
133 gettimeofday(&tv_start, NULL);
134 start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
135 }
136
137 struct timeval tv_now;
138 gettimeofday(&tv_now, NULL);
139 uint64_t now_ms;
140 now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
141
142 uint32_t time_ms = now_ms - start_ms;
143 return time_ms;
144 }
145
146 #endif
147
148