当前位置:主页 > 技术文档 > LittlevGL 下载

开源GUI-LittlevGL应用教程 超清版

  • 更新:2020-10-12 20:40:42
  • 大小:3.4 MB
  • 热度:511
  • 审核:空信然
  • 类别:技术文章
  • 格式:PDF

  • 资源介绍
  • 相关推荐

1、简介

Littlevgl是一种纯C语言编写的GUI,控件多且美,移植简单,只要对接一个显示接口,需要触摸的再加一个触摸控制接口。

2、移植

显示接口移植:

static void tft_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
        {
               /*Truncate the area to the screen*/
              int32_t act_x1 = x1 < 0 ? 0 : x1;
              int32_t act_y1 = y1 < 0 ? 0 : y1;
              int32_t act_x2 = x2 > LV_HOR_RES ? LV_HOR_RES  : x2;
              int32_t act_y2 = y2 > LV_VER_RES ? LV_VER_RES  : y2;

             uint32_t x;
             uint32_t y;

             /*Put the map to the remaining area*/
            for(y = act_y1; y <= act_y2; y++)      //填充屏幕的像素点
            {
               for(x = act_x1; x <= act_x2; x++)
               {
                    GUI_Point(x, y,  color_p->full);
                   color_p++;
               }
            }
             lv_flush_ready();
       }

       注册显示接口:

             lv_disp_drv_t disp;

             lv_disp_drv_init(&disp);
             disp.disp_flush = tft_flush;
             disp.disp_fill = lv_disp_fill;         //单点填充
             disp.disp_map = lv_disp_map;  //与tft_flush同样
             lv_disp_drv_register(&disp);  

      触摸接口:

             static lv_indev_t *indev;
             lv_indev_drv_t indev_drv;
             lv_indev_drv_init(&indev_drv);
             indev_drv.read = my_input_read;                        //触摸屏返回按压状态以及触摸位置
             indev_drv.type = LV_INDEV_TYPE_POINTER;   //有几种类型,这里采用的是触摸屏
             indev = lv_indev_drv_register(&indev_drv);

     以上接口对接好后,基本上就算移植好了。

3、汉字显示

Littlevgl本身不带有中文字库,需要取模后添加中文字库,这里推荐一个离线取模软件 Lvgl Font Tool V0.3,添加需要显示的汉字,自动生成文件。

引用:假设用改该软件生成的文件名为myfont.c,使用前需要在lv_font.h文件加上

LV_FONT_DECLARE(myfont);   //其实就是一个extern声明

之后就可以调用这个文件字库了。

调用:

1、样式调用

style.text.font = &my_font_name;

2、字库混合

lv_font_add(&myfont, &parent_font);

注意事项:keil中要使用中文,必须修改编码方式为UTF-8.

资源下载

资源下载地址1:https://pan.baidu.com/s/18SxV6lg9_7oe7rcGRCsycQ

相关资源

网友留言

LittlevGL基础教程
曹玉书

LittlevGL 是一个免费的开源图形库,提供了创建嵌入式 GUI 所需的一切,具有易于使用的组件,美观的视觉效果和低内存占用等特点。支持触摸屏操作,移植简单方便,开发者一直在不断完善更新。

LittlevGL 自带了丰富的控件:窗口、按键、标签、list、图表等,还可以自定义控件;支持很多特效:透明、阴影、自动显示隐藏滚动条、界面切换动画、图标打开关闭动画、平滑的拖拽控件、分层显示、反锯齿、仅耗少量内存的字体等等。

LittlevGL 常见于 MCU 级别的设备,支持各类输入输出接口与芯片,支持使用 GPU,以 C 编写,对于 Nano 来说十分适合。

littlevGL GUI例子使用
吴新立

开始移植

将下载的lv_examples-master复制到你的工程中,和lvgl同级目录下
将lv_examples-master重命名为lv_examples
将lv_examples文件中的lv_ex_conf_templ.h复制到lv_examples同级目录下
重命名lv_ex_conf_templ.h为lv_ex_conf.h,
打开lv_ex_conf.h,把#if 0 改成 #if 1

/**
 * @file lv_ex_conf.h
 *
 */
/*
 * COPY THIS FILE AS lv_ex_conf.h
 */

#if 1 /*Set it to "1" to enable the content*///就是这里

#ifndef LV_EX_CONF_H
#define LV_EX_CONF_H
.....

6.启用或禁用模块lv_ex_conf.h

在要用到示例的文件 #include "lv_examples.h",只需要包括这个文件的路径就可以了

下面是测试

测试函数 lv_test_theme_1(); 要#include "lv_test_theme_1.h"

lv_ex_conf.h-> 0文件中 改为1 如下

/*******************
 *   TEST USAGE
 *******************/
#define LV_USE_TESTS        1

lv_conf.h文件中 0 改为1

#define LV_USE_THEME_NIGHT      1   /*Dark elegant theme*/

4.最终添加

lv_theme_t * th = lv_theme_night_init(20, NULL);
lv_test_theme_1(th);