1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/tests/lv_test_main.c

154 lines
3.6 KiB
C
Raw Normal View History

2020-01-16 14:27:12 +01:00
#include "../lvgl.h"
#include <stdio.h>
2020-02-15 02:19:44 +01:00
#include <stdlib.h>
#include "lv_test_core/lv_test_core.h"
2020-08-31 13:57:18 +02:00
#include "lv_test_widgets/lv_test_label.h"
2020-01-16 14:27:12 +01:00
2020-02-09 10:59:38 +01:00
#if LV_BUILD_TEST
#include <sys/time.h>
2020-01-16 14:27:12 +01:00
2021-02-12 14:22:48 +01:00
#define HOR_RES 800
#define VER_RES 480
2020-01-16 14:27:12 +01:00
static void hal_init(void);
static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
2021-02-12 14:22:48 +01:00
lv_color_t test_fb[HOR_RES * VER_RES];
2020-08-31 13:57:18 +02:00
2020-02-15 02:19:44 +01:00
int main(void)
2020-01-16 14:27:12 +01:00
{
printf("Call lv_init...\n");
lv_init();
hal_init();
lv_test_core();
2020-08-31 13:57:18 +02:00
lv_test_label();
2020-01-16 14:27:12 +01:00
printf("Exit with success!\n");
return 0;
}
2020-08-12 14:29:50 +02:00
#if LV_USE_FILESYSTEM
2020-09-02 10:25:46 +02:00
static void * open_cb(struct _lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
{
(void) drv;
(void) mode;
FILE * fp = fopen(path, "rb"); // only reading is supported
2020-09-02 10:25:46 +02:00
return fp;
}
static lv_fs_res_t close_cb(struct _lv_fs_drv_t * drv, void * file_p)
{
(void) drv;
2020-09-02 10:25:46 +02:00
fclose(file_p);
return LV_FS_RES_OK;
}
static lv_fs_res_t read_cb(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
(void) drv;
2020-09-02 10:25:46 +02:00
*br = fread(buf, 1, btr, file_p);
return (*br <= 0) ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
}
2020-09-02 10:25:46 +02:00
static lv_fs_res_t seek_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t w)
{
(void) drv;
2020-09-02 10:25:46 +02:00
uint32_t w2;
switch(w) {
case LV_FS_SEEK_SET:
w2 = SEEK_SET;
break;
case LV_FS_SEEK_CUR:
w2 = SEEK_CUR;
break;
case LV_FS_SEEK_END:
w2 = SEEK_END;
break;
default:
w2 = SEEK_SET;
}
fseek (file_p, pos, w2);
return LV_FS_RES_OK;
}
static lv_fs_res_t tell_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
{
(void) drv;
2020-09-02 10:25:46 +02:00
*pos_p = ftell(file_p);
return LV_FS_RES_OK;
}
2020-08-12 14:29:50 +02:00
#endif
2020-01-16 14:27:12 +01:00
static void hal_init(void)
{
static lv_disp_buf_t disp_buf;
2020-03-05 15:39:11 +01:00
lv_color_t * disp_buf1 = (lv_color_t *)malloc(LV_HOR_RES * LV_VER_RES * sizeof(lv_color_t));
2020-01-16 14:27:12 +01:00
2020-08-31 13:57:18 +02:00
lv_disp_buf_init(&disp_buf, disp_buf1, NULL, LV_HOR_RES * LV_VER_RES);
2020-01-16 14:27:12 +01:00
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = dummy_flush_cb;
2021-02-12 14:22:48 +01:00
disp_drv.hor_res = HOR_RES;
disp_drv.ver_res = VER_RES;
2020-01-16 14:27:12 +01:00
lv_disp_drv_register(&disp_drv);
2020-08-12 14:29:50 +02:00
#if LV_USE_FILESYSTEM
lv_fs_drv_t drv;
lv_fs_drv_init(&drv); /*Basic initialization*/
2020-09-02 10:25:46 +02:00
drv.letter = 'F'; /*An uppercase letter to identify the drive */
drv.open_cb = open_cb; /*Callback to open a file */
drv.close_cb = close_cb; /*Callback to close a file */
drv.read_cb = read_cb; /*Callback to read a file */
drv.seek_cb = seek_cb; /*Callback to seek in a file (Move cursor) */
drv.tell_cb = tell_cb; /*Callback to tell the cursor position */
2020-08-12 14:29:50 +02:00
lv_fs_drv_register(&drv); /*Finally register the drive*/
#endif
2020-01-16 14:27:12 +01:00
}
2020-08-31 13:57:18 +02:00
#include <stdio.h>
2020-01-16 14:27:12 +01:00
static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
2020-05-24 13:13:07 +02:00
LV_UNUSED(area);
LV_UNUSED(color_p);
2020-08-31 13:57:18 +02:00
memcpy(test_fb, color_p, lv_area_get_size(area) * sizeof(lv_color_t));
2020-01-16 14:27:12 +01:00
lv_disp_flush_ready(disp_drv);
}
uint32_t custom_tick_get(void)
{
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;
}
#endif