下面的步骤展示了如何在带有显示器和触摸板的GD32VF103V-EVAL开发板上上设置LittlevGL。
2 熟悉一下GD32VF103中触摸屏例程。GD32VF103V_EVAL_Demo_Suites\Projects\14_EXMC_TouchScreen
3 基于这个例子移植LittlevGL,把lvgl目录内容加载该项目中,把 lv_conf_template.h 复制一份为 lv_conf.h,放在上级目录。
形成这个目录结构
lv_conf.h
lvgl/
形成这个目录结构
lv_conf.h
lvgl/
4 由于,开发板屏幕是320*240,设置lv_conf.h中,
#define LV_HOR_RES_MAX (240)
#define LV_VER_RES_MAX (320)
5 porting下lv_port_disp_template.c中,实现并注册一个函数,该函数可以将像素数组复制到显示器的某个区域:
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;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
/* Put a pixel to the display. For example: */
lcd_point_set(x,y,*color_p);
color_p++;
}
}
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
另外lv_port_disp_init()
中改为
/*Set the resolution of the display*/
disp_drv.hor_res = 240;
disp_drv.ver_res = 320;
6 同理,port/下lv_port_indev_template.c。touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)移植触摸屏驱动。主要利用touch_panel.c实现下面两个函数。
/*Return true is the touchpad is pressed*/
static bool touchpad_is_pressed(void)
{
/*Your code comes here*/
if(touch_scan() == 1)
{
printf("touchpad_is_pressed true");
return true;
}else
{
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,y坐标。
*x = touch_coordinate_x_get1();
printf("x = %d \r\n", *x);
*y =320 - touch_coordinate_y_get1();
printf("y = %d \r\n", *y);
}
7 main()测试如下:
int main(void)
{
exmc_lcd_init();
touch_panel_gpio_configure();
delay_1ms(50);
device_code = lcd_register_read(0x0000);
lcd_init();
lcd_clear(LCD_COLOR_WHITE);
lv_init();
lv_port_disp_init();
lv_port_indev_init();
lv_tutorial_hello_world();
while(true)
{
delay_1ms(10);
lv_tick_inc(10);
lv_task_handler();
}
}
其中 lv_tutorial_hello_world()是来源lv_examples-master\lv_tutorial\1_hello_world.c
8 编译,出现如下错误section `.bss' will not fit in region `ram'
处理方法是:
Lv_conf.h中
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (32U * 1024U)
改为
# define LV_MEM_SIZE (8U * 1024U)
9 编译下载运行如下:
PS:
目前只是在GD32VF103运行了一个最简单LittlevGL例子。待深究后再更新。