commit | author | age
|
b64b1d
|
1 |
/********************************************************************************* |
G |
2 |
* Copyright: (C) 2021 LingYun IoT System Studio |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: lvgl_demo.c |
|
6 |
* Description: This file is LVGL demo program. |
|
7 |
* |
|
8 |
* Version: 1.0.0(2021年09月27日) |
|
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "2021年09月27日 22时16分52秒" |
|
11 |
* |
|
12 |
********************************************************************************/ |
|
13 |
|
|
14 |
#include <stdio.h> |
|
15 |
#include <unistd.h> |
|
16 |
#include <pthread.h> |
|
17 |
#include <time.h> |
|
18 |
#include <sys/time.h> |
|
19 |
|
|
20 |
#include "lvgl/lvgl.h" |
|
21 |
#include "lv_drivers/display/fbdev.h" |
|
22 |
#include "lv_drivers/indev/evdev.h" |
|
23 |
#include "lv_demos/lv_demo.h" |
|
24 |
|
|
25 |
#define DISP_BUF_SIZE (128 * 1024) |
|
26 |
|
|
27 |
|
|
28 |
int main(void) |
|
29 |
{ |
|
30 |
lv_disp_drv_t disp_drv; |
|
31 |
lv_indev_drv_t indev_drv; |
|
32 |
static lv_color_t buf[DISP_BUF_SIZE]; /* buffer for LVGL to draw the screen's content */ |
|
33 |
static lv_disp_draw_buf_t disp_buf; /* Initialize a descriptor for the buffer */ |
|
34 |
|
|
35 |
/* LVGL context init */ |
|
36 |
lv_init(); |
|
37 |
|
|
38 |
/* Linux frame buffer device init */ |
|
39 |
fbdev_init(); |
|
40 |
|
|
41 |
/* linux touchscreen device init */ |
|
42 |
lv_indev_drv_init(&indev_drv); |
|
43 |
indev_drv.type =LV_INDEV_TYPE_POINTER; |
|
44 |
indev_drv.read_cb =evdev_read; |
|
45 |
lv_indev_drv_register(&indev_drv); |
|
46 |
|
|
47 |
/* Initialize and register a display driver */ |
|
48 |
lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE); |
|
49 |
lv_disp_drv_init(&disp_drv); |
|
50 |
disp_drv.draw_buf = &disp_buf; |
|
51 |
disp_drv.flush_cb = fbdev_flush; |
|
52 |
disp_drv.hor_res = 800; |
|
53 |
disp_drv.ver_res = 480; |
|
54 |
lv_disp_drv_register(&disp_drv); |
|
55 |
|
|
56 |
/* Create a Demo */ |
|
57 |
//lv_demo_widgets(); |
|
58 |
lv_demo_music(); |
|
59 |
//lv_demo_keypad_encoder(); |
|
60 |
//lv_demo_stress(); |
|
61 |
|
|
62 |
/* Handle LitlevGL tasks (tickless mode) */ |
|
63 |
while(1) { |
|
64 |
lv_task_handler(); |
|
65 |
usleep(5000); |
|
66 |
} |
|
67 |
|
|
68 |
return 0; |
|
69 |
} |
|
70 |
|
|
71 |
/* Set in lv_conf.h as LV_TICK_CUSTOM_SYS_TIME_EXPR */ |
|
72 |
uint32_t millis(void) |
|
73 |
{ |
|
74 |
static uint64_t start_ms = 0; |
|
75 |
struct timeval tv_start; |
|
76 |
struct timeval tv_now; |
|
77 |
uint64_t now_ms; |
|
78 |
uint32_t time_ms; |
|
79 |
|
|
80 |
if(start_ms == 0) |
|
81 |
{ |
|
82 |
gettimeofday(&tv_start, NULL); |
|
83 |
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000; |
|
84 |
} |
|
85 |
|
|
86 |
gettimeofday(&tv_now, NULL); |
|
87 |
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000; |
|
88 |
|
|
89 |
time_ms = now_ms - start_ms; |
|
90 |
return time_ms; |
|
91 |
} |