lvgl移植

LVGL移植

初始化需要

1
2
3
4
lv_init();
lv_port_disp_init(); // 显示器初始化
lv_port_indev_init(); // 输入设备初始化(如果没有实现就注释掉)
lv_port_fs_init(); // 文件系统设备初始化(如果没有实现就注释掉)

修改lvgl/src/examples/porting下接口

显示接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "lv_port_disp.h"
#include "lvgl/lvgl.h"
#include "lcd.h"
static void disp_init(void);
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
#define MY_DISP_HOR_RES (320)
void lv_port_disp_init(void)
{
/*-------------------------
* Initialize your display
* -----------------------*/
disp_init();
static lv_disp_draw_buf_t draw_buf_dsc_1;
static lv_color_t buf_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/
lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/

/*Set up the functions to access to your display*/

/*Set the resolution of the display*/
disp_drv.hor_res = 320;
disp_drv.ver_res = 480;

/*Used to copy the buffer's content to the display*/
disp_drv.flush_cb = disp_flush;

/*Set a display buffer*/
disp_drv.draw_buf = &draw_buf_dsc_1;
lv_disp_drv_register(&disp_drv);
}
static void disp_init(void)
{
/*You code here*/
LCD_Init();
}
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/

int32_t x;
int32_t y;
LCD_SetWindow(area->x1, area->y1, area->x2, area->y2);
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
/*Put a pixel to the display. For example:*/
/*put_px(x, y, *color_p)*/
LCD_WRITE_DATA(*(uint16_t*)color_p);
color_p++;
}
}
// LCD_Draw(area->x1,area->y1,area->x2,area->y2,(uint16_t *)color_p);
/*IMPORTANT!!!
*Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}

输入设备

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;

/*Save the pressed coordinates and the state*/
/*Save the pressed coordinates and the state*/
if(!XPT2046_EXTI_Read())
{
touchpad_get_xy(&last_x, &last_y);
data->state = LV_INDEV_STATE_PR;
printf("x=%d,y=%d\r\n",last_x,last_y);
} else
{
data->state = LV_INDEV_STATE_REL;
}

/*Set the last pressed coordinates*/
data->point.x = last_x;
data->point.y = last_y;
}

/*Return true is the touchpad is pressed*/
static bool touchpad_is_pressed(void)
{
/*Your code comes here*/

return false;
}

/*Get the x and y coordinates if the touchpad is pressed*/
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{
/*Your code comes here*/
(*x) = 319-XPT2046_ReadAdc_Fliter(XPT2046_CHANNEL_Y)*320/4095;
(*y) = 479-XPT2046_ReadAdc_Fliter(XPT2046_CHANNEL_X)*480/4095;//4095-
}

文件系统

心跳1~10,一般取5

1
2
3
4
lv_tick_inc( tick );
lv_task_handler();

lv_conf.h

GUI Guider

-->

请我喝杯咖啡吧~

支付宝
微信