LVGL V8

本文详细介绍了LVGL模拟器在Visual Studio 2019中的配置和使用方法,包括解决无法下载数据包的问题、字体和图标资源的集成、图表的样式设置以及性能优化。此外,还涉及了LVGL样式设置、内存管理和堆栈溢出预防等方面,为LVGL应用开发提供实用技巧。
摘要由CSDN通过智能技术生成

本文适用于LVGL V8版本

LVGL simulator vs2019

官方工程 lv_sim_visual_studio
使用注意事项:
1、将官方工程从github上下载下来,最好使用git 将整个工程clone下来,因为工程内部有依赖,如果只是将工程Download下来,无法正常运行。

git clone --recurse-submodules https://github.com/lvgl/lv_sim_visual_studio.git

2、工程Clone下来后,需要根据不同的平台配置
在这里插入图片描述
3、在点击生成时,总是需要很长时间,并提示无法下载数据包“VC-LTL”
解决办法:
1、删除LVGL.Simulator.vcxproj中的(用记事本打开)
<Import Project="Mile.Project\Mile.Project.Runtime.VC-LTL.props" />
在这里插入图片描述
2、下载新的VC-LTL
VC-LTL
将VC-LTL Binary下载并解压至D:\Src\VC-LTL(具体位置无任何要求),双击D:\Src\VC-LTL\Install.cmd即可。

脚本会在HKCU\Code\VC-LTL创建注册表。

将属性表VC-LTL helper for Visual Studio.props复制到你的工程目录,你可以打开属性管理器(视图 - 属性管理器),然后Release配置上右键添加现有属性表,然后选择VC-LTL helper for Visual Studio.props即可
在这里插入图片描述

Boxing model

在这里插入图片描述

Alignment

在这里插入图片描述

字体

font awesome

Font Awesome
Font Awesome download
1001fonts
Monospaced Font 等宽字体
里飞网-LVGL
LvglFontTool V0.4在lvglv8中使用

emoji

OpenSansEmoji

图标

https://materialdesignicons.com/
https://fontello.com/
https://www.iconfont.cn/
https://www.softicons.com/

chart

通过lv_obj_set_style_size设置数据点的显示大小,设置为0,不显示。

	lv_chart_set_type(chart1, LV_CHART_TYPE_LINE );
 	/*Set point size to 0 so the lines are smooth */
 	lv_obj_set_style_size(chart1, 0, LV_PART_INDICATOR);

通过lv_obj_set_style_pad_gap设置数据之间显示间隔(用于一个图表显示多个系列)

 lv_chart_set_type(chart2, LV_CHART_TYPE_BAR);
 /* 设置同一x值之间的间距 */
 lv_obj_set_style_pad_gap(chart2, 0, LV_PART_ITEMS);
  /* 设置相邻x值之间的间距 */
 lv_obj_set_style_pad_gap(chart2, 2, LV_PART_MAIN);

设置X轴坐标,索引值是偶数的不显示

 lv_obj_add_event_cb(chart2, chart_event_cb, LV_EVENT_ALL, NULL);
 static void chart_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);
    if(code == LV_EVENT_DRAW_PART_BEGIN) {
        lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
        /*Set the markers' text*/
        if(dsc->part == LV_PART_TICKS && dsc->id == LV_CHART_AXIS_PRIMARY_X) {
            if(lv_chart_get_type(obj) == LV_CHART_TYPE_BAR) {
              /* 设置X轴坐标,索引值是偶数的不显示 */
                if (dsc->value%2==0)
                {
                    lv_snprintf(dsc->text, dsc->text_length, "%s"," ");
                }
                //lv_snprintf(dsc->text, dsc->text_length, "%s", month[dsc->value]);
            } else {
                const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"};
                lv_snprintf(dsc->text, dsc->text_length, "%s", month[dsc->value]);
            }
        }

CHART_AXIS

如果要显示坐标轴的值,必须为坐标轴留出显示空间,可通过grid设置。
lv_obj_t *chart1 = lv_chart_create( parent );chart1的空间只是用于显示图表并不包括坐标轴的显示

static lv_coord_t grid_chart_row_dsc[] = {40, LV_GRID_FR( 1 ), LV_GRID_TEMPLATE_LAST};
static lv_coord_t grid_chart_col_dsc[] = {80, LV_GRID_FR( 1 ),80, LV_GRID_TEMPLATE_LAST};
 lv_chart_set_axis_tick( chart1, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 9, 2, true, 80 );
 lv_chart_set_axis_tick( chart1, LV_CHART_AXIS_SECONDARY_Y, 10, 5, 9, 2, true, 80 );

chart bar 大小设置

bar 的大小由lv_chart_set_point_count(chart, point_num);v_chart_set_zoom_x(chart, factor);lv_obj_set_style_pad_gap(chart2, 0, LV_PART_ITEMS);lv_obj_set_style_pad_gap(chart2, 2, LV_PART_MAIN);四者共同决定。
当chart大小设定后,如果不设置lv_chart_set_zoom_x,LVGL根据pad_gap的大小及point_count,平均分配每个bar的宽度。
当设定lv_chart_set_zoom_x后,相当于将chart的宽度放大,此时会出现滚动条,在point_count不变的情况下,bar的宽度会增大。

lable

  1. Text recolor
    In the text, you can use commands to recolor parts of the text. For example: “Write a #ff0000 red# word”. This feature can be enabled individually for each label by lv_label_set_recolor() function.
    注意事项:
    #ff0000之后必须留空格,否则无法识别指令,结束符#不用留空格
    在这里插入图片描述
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES

/**
 * Show line wrap, re-color, line align and text scrolling.
 */
void lv_example_label_1(void)
{
    lv_obj_t * label1 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP);     /*Break the long lines*/
    lv_label_set_recolor(label1, true);                      /*Enable re-coloring by commands in the text*/
    lv_label_set_text(label1, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center "
                              "and wrap long text automatically.");
    lv_obj_set_width(label1, 150);  /*Set smaller width to make the lines wrap*/
    lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_align(label1, LV_ALIGN_CENTER, 0, -40);


    lv_obj_t * label2 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR);     /*Circular scroll*/
    lv_obj_set_width(label2, 150);
    lv_label_set_text(label2, "It is a circularly scrolling text. ");
    lv_obj_align(label2, LV_ALIGN_CENTER, 0, 40);
}

#endif

Text recolor
In the text, you can use commands to recolor parts of the text. For example: “Write a #ff0000 red# word”. This feature can be enabled individually for each label by lv_label_set_recolor() function.

textarea

 ta = lv_textarea_create( lv_scr_act() );
  lv_obj_add_style( ta, &init_style, 0 );
  lv_obj_set_size( ta, SCR_TOTAL_HOR_RES, SCR_TOTAL_VER_RES );
  /* 修改光标的透明度 */
  lv_obj_set_style_bg_opa ( ta, LV_OPA_COVER, LV_PART_CURSOR );
  /* 修改光标的颜色 */
  lv_obj_set_style_bg_color( ta, lv_palette_lighten( LV_PALETTE_ORANGE, 1 ), LV_PART_CURSOR );
  lv_obj_set_style_bg_color( ta, SCR_BG_COLOR, LV_PART_MAIN );
  lv_obj_set_style_pad_all ( ta, 50, LV_PART_MAIN );
  lv_obj_set_style_pad_gap( ta, 10, LV_PART_MAIN );
  lv_obj_set_style_text_color( ta, lv_color_white(), LV_PART_MAIN );

lv_obj_set_align 、lv_obj_align、lv_obj_align_to区别

void lv_obj_set_align(struct _lv_obj_t * obj, lv_align_t align)用于设置obj在父控件中的对齐方式,没有偏移。
void lv_obj_align(struct _lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs)=lv_obj_set_align(obj, align) + lv_obj_set_pos(obj, x_ofs, y_ofs),用于设置obj在父控件中的对齐方式及偏移值。
void lv_obj_align_to(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs)用于设置obj相对base的对齐方式及偏移值。

/**
 * Change the alignment of an object.
 * @param obj       pointer to an object to align
 * @param align     type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used.
 */
void lv_obj_set_align(struct _lv_obj_t * obj, lv_align_t align);

/**
 * Change the alignment of an object and set new coordinates.
 * Equivalent to:
 * lv_obj_set_align(obj, align);
 * lv_obj_set_pos(obj, x_ofs, y_ofs);
 * @param obj       pointer to an object to align
 * @param align     type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used.
 * @param x_ofs     x coordinate offset after alignment
 * @param y_ofs     y coordinate offset after alignment
 */
void lv_obj_align(struct _lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs);

/**
 * Align an object to an other object.
 * @param obj       pointer to an object to align
 * @param base      pointer to an other object (if NULL `obj`s parent is used). 'obj' will be aligned to it.
 * @param align     type of alignment (see 'lv_align_t' enum)
 * @param x_ofs     x coordinate offset after alignment
 * @param y_ofs     y coordinate offset after alignment
 * @note            if the position or size of `base` changes `obj` needs to be aligned manually again
 */
void lv_obj_align_to(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs,lv_coord_t y_ofs);

lv_obj_set_style_pad_right

lv_obj_set_style_pad_right设置的是当前控件的孩子距离边框的偏移,如下代码表示:btn1的孩子距离按键右边框偏移为10,按键内部一般会有label,就是创建的label会距离右边框偏移为10。

lv_obj_set_style_pad_right(btn1,10,LV_PART_MAIN);

arc

  lv_obj_t *arc = lv_arc_create( parent );
  /* 设置arc大小 */
  lv_obj_set_size( arc, size, size );
  /* 设置背景arc颜色  */
  lv_obj_set_style_arc_color( arc, color, LV_PART_MAIN );
  /* 设置前景arc颜色 */
  lv_obj_set_style_arc_color( arc, color, LV_PART_INDICATOR );
  /* 设置背景arc宽度 */
  lv_obj_set_style_arc_width( arc, 5, LV_PART_MAIN );
  /* 设置前景arc宽度 */
  lv_obj_set_style_arc_width( arc, 5, LV_PART_INDICATOR );
  /* 设置前景arc开合角度 */
  lv_arc_set_angles( arc, 0, 310 );
  /* 设置背景arc开合角度 */
  lv_arc_set_bg_angles( arc, 0, 310 );
  /* 设置arc旋转角度 */
  lv_arc_set_rotation( arc, 25 );
  /* 删除knob显示 */
  lv_obj_remove_style( arc, NULL, LV_PART_KNOB ); /*Be sure the knob is not displayed*/
//  lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);  /*To not allow adjusting by click*/
  lv_obj_align( arc, align, x_ofs, y_ofs );

Layouts

lv_obj_set_flex_flow(obj, flex_flow)

lv_obj_set_flex_flow用于设置obj的孩子是如何布局的,使用该函数会自动将obj的布局方式修改为LV_LAYOUT_FLEX,不需要手动设置lv_obj_set_layout布局方式。

/*
The possible values for flex_flow are:
LV_FLEX_FLOW_ROW Place the children in a row without wrapping
LV_FLEX_FLOW_COLUMN Place the children in a column without wrapping
LV_FLEX_FLOW_ROW_WRAP Place the children in a row with wrapping
LV_FLEX_FLOW_COLUMN_WRAP Place the children in a column with wrapping
LV_FLEX_FLOW_ROW_REVERSE Place the children in a row without wrapping but in reversed order
LV_FLEX_FLOW_COLUMN_REVERSE Place the children in a column without wrapping but in reversed order
LV_FLEX_FLOW_ROW_WRAP_REVERSE Place the children in a row with wrapping but in reversed order
LV_FLEX_FLOW_COLUMN_WRAP_REVERSE Place the children in a column with wrapping but in reversed order
*/
void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow)
{
    lv_obj_set_style_flex_flow(obj, flow, 0);
    lv_obj_set_style_layout(obj, LV_LAYOUT_FLEX, 0);
}

速度优化

  1. 优化图像计算速度
    开启 LV_USE_GPU_STM32_DMA2D,使用DMA2D硬件计算。
    在lv_gpu_stm32_dma2d.c中,使能lv_gpu_stm32_dma2d_fill_mask
  2. 优化数据传输速度
    在my_disp_flush中使用DMA (MEM2MEM 模式)传输,替代for循环发送。
static void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
  int32_t x, y;
  /*It's a very slow but simple implementation.
   *`set_pixel` needs to be written by you to a set pixel on the screen*/
  lcd_block_write( area->x1, area->x2, area->y1, area->y2 );
//  for( y = area->y1; y <= area->y2; y++ )
//  {
//    for( x = area->x1; x <= area->x2; x++ )
//    {
      set_pixel( x, y, *color_p );
//      lcd_set_color( ( uint16_t )( color_p->full ) );
//      color_p++;
//    }
//  }
  HAL_DMA_Start( &hdma_memtomem_dma1_stream3, ( uint32_t )color_p, BANK1_LCD_DATA_REG, ( area->x2 - area->x1 + 1 ) * ( area->y2 - area->y1 + 1 ) );

  if( HAL_DMA_PollForTransfer( &hdma_memtomem_dma1_stream3, HAL_DMA_FULL_TRANSFER, 10 ) == HAL_OK )
  {
    lv_disp_flush_ready( disp );       /* Indicate you are ready with the flushing*/
  }

//    lv_gpu_stm32_dma2d_copy((lv_color_t *)BANK1_LCD_DATA_REG,area->x2 - area->x1 + 1,color_p,area->x2 - area->x1 + 1,area->x2 - area->x1 + 1,area->y2 - area->y1 + 1);
//  MX_DMA2D_Init();
//  HAL_DMA2D_Start(&hdma2d, (uint32_t)color_p, BANK1_LCD_DATA_REG, area->x2 - area->x1 + 1, area->y2 - area->y1 + 1 );
//
//  if( HAL_DMA2D_PollForTransfer( &hdma2d, 10 ) == HAL_OK )
//  {
//    lv_disp_flush_ready( disp );       /* Indicate you are ready with the flushing*/
//  }
}

内存溢出

lvgl V7.7.2内存泄漏问题
当连续退出进入界面时,内存溢出
LVGL:Out of memory,can‘t allocate a new buffer (increase your LV_MEM_SIZE/heap size
内存溢出解决办法及设计

  1. 在退出页面时,使用lv_obj_clean删除页面所有的控件。如果不删除页面控件,连续多次退出进入界面后页面控件会不断的申请内存,内存会溢出。
  2. 在创建页面控件style时,先使用lv_style_reset复位style,再lv_style_init设置样式。如果直接使用lv_style_init创建,连续多次退出进入界面后lv_style_init会不断的申请内存,内存会溢出。
    使用lv_obj_set_style_xx创建的为当前控件独有的Local style,会随着控件的删除而自动删除,不需要手动删除该style(local styles are allocated automatically, and freed when the object is deleted)

lv_table 内存泄漏

LVGL v8.1.0 lv_table 内存泄漏问题

自定义控件

  1. 在“lv_widgets.h”中添加控件头文件位置
    在这里插入图片描述
  2. 在“lv_theme_default.c”中添加控件初始样式
    在这里插入图片描述
  3. 在“lv_conf.h”中添加控件使能配置

在这里插入图片描述

LVGL 样式

  1. 通用样式初始化
    lv_disp_drv_register–>lv_theme_default_init–>style_init(使用lv_style_set_xxx给样式添加内容,此时只是初始化了样式,并没有将样式绑定到控件)
  2. 绑定样式到控件(以textarea举例)
    lv_textarea_create–>lv_obj_class_init_obj–>lv_theme_apply–>apply_theme–>theme.apply_cb–>theme_apply(lv_theme_default.c)(此时使用lv_obj_add_style给控件添加样式)

修改控件指定状态样式

lv_obj_set_style_XXX(xxx, xxx, LV_PART_XXX| LV_STATE_XXX);
LV_PART_XXX用来指示设置的是控件的哪个部分(LV_PART_MAIN表示控件本身)
LV_STATE_XXX用来指示设置的是何状态(如果不写,就是LV_STATE_DEFAULT)

The objects can be in the combination of the following states:

LV_STATE_DEFAULT (0x0000) Normal, released state

LV_STATE_CHECKED (0x0001) Toggled or checked state

LV_STATE_FOCUSED (0x0002) Focused via keypad or encoder or clicked via touchpad/mouse

LV_STATE_FOCUS_KEY (0x0004) Focused via keypad or encoder but not via touchpad/mouse

LV_STATE_EDITED (0x0008) Edit by an encoder

LV_STATE_HOVERED (0x0010) Hovered by mouse (not supported now)

LV_STATE_PRESSED (0x0020) Being pressed

LV_STATE_SCROLLED (0x0040) Being scrolled

LV_STATE_DISABLED (0x0080) Disabled state

LV_STATE_USER_1 (0x1000) Custom state

LV_STATE_USER_2 (0x2000) Custom state

LV_STATE_USER_3 (0x4000) Custom state

LV_STATE_USER_4 (0x8000) Custom state

An object can be in a combination of states such as being focused and pressed at the same time. This is represented as LV_STATE_FOCUSED | LV_STATE_PRESSED.
lv_obj_set_style_bg_color(slider, lv_color_red(), LV_PART_INDICATOR | LV_STATE_FOCUSED);

LVGL无法正常运行

LVGL在执行时,如果控件嵌套很多,LVGL的函数会递归调用,会大量使用stack,如果stack分配不足,会导致堆栈溢出

  1. 在使用FreeRTOS时,stack是由FreeRTOS已分配的内存来分配的,不受系统stack影响
 osThreadDef( gui_task, gui_process_task, osPriorityAboveNormal, 0, 1000 );
 osThreadCreate( osThread( gui_task ), NULL );
  1. 使用裸机,不使用RTOS时,函数调用的堆栈是从系统stack分配的,此时需要加大系统stack,否则可能会出现堆栈溢出
    在这里插入图片描述

在这里插入图片描述

### 回答1: LVGL V8 是一款高性能嵌入式图形库,它的中文手册对于中国开发者来说是一份非常重要的资料。LVGL V8 中文手册详细介绍了该库的各种特性、使用方法和实现原理。其中包括了 LVGL V8 的基础结构、对象、图元、样式等基础概念,还有详细的 API 参考和使用示例。 手册开头介绍了 LVGL V8 的基础知识,包括该库的基础设计、适用范围、适配平台等内容。接着,手册通过一个简单的 Hello World 项目介绍了如何在开发板上使用 LVGL V8,还介绍了如何使用 LVGL 的物理内存布局优化机制,避免使用较大的内存块。 在 LVGL V8 的中文手册中,对象是最核心的概念,手册详细介绍了各种对象的类型与用法,如基础对象、容器对象、文本对象、图像对象等。手册还介绍了 LVGL 的事件模型,解释了事件回调函数的使用方法和意义。除此之外,手册还介绍了 LVGL 的样式系统、动画框架等细节内容。 总体来说,LVGL V8 的中文手册非常详细,对于希望在嵌入式平台上使用 LVGL 开发界面的开发者来说,是一份非常重要的资料。手册详细介绍了该库的各种概念和细节,并提供了丰富的使用示例,非常适合初学者和专业开发人员使用。 ### 回答2: lvgl v8中文手册是一个相当详细、全面的用户手册,该手册主要是为了方便开发者在使用lvgl v8时可以快速入门,解决在实际开发过程中所遇到的各种问题。以下是本人对lvgl v8中文手册的一些了解和使用体验。 首先,lvgl v8中文手册的内容十分详细和系统,涉及的知识点涵盖了lvgl v8的核心概念、基础组件、布局、主题、动画、图像等方面的内容,而且每一章节都有大量的实例代码和图例,方便用户理解和学习。 其次,lvgl v8中文手册的组织结构十分清晰,每个章节都有明确的标题和目录,使得用户可以轻松找到所需的内容。而且,手册中的例子和代码片段也很详细,可以帮助用户更加深入地理解各个组件的使用方法和实现原理。 另外,lvgl v8中文手册还给出了各种样式、主题以及动画效果,这些都是使用lvgl v8时需要注意的一些方面,而且lvgl v8中文手册给出的解决方案和最佳实践也很实用,可以帮助用户在开发过程中避免一些常见的错误。 总之,lvgl v8中文手册是一个非常优秀的开发文档,对需要使用lvgl v8的开发者来说是一个不可或缺的参考工具,对于刚开始接触和了解lvgl v8的用户,这个手册更是一个非常好的教程,可以帮助他们顺利入门。 ### 回答3: LVGL v8是一款基于C语言开发的开源GUI库,具有轻量级、高效、可裁剪、跨平台等特点,适用于各种嵌入式应用的UI设计和开发。其中文手册详细介绍了LVGL v8库的使用方法、API接口、示例代码等内容,可以很好地帮助开发人员学习和掌握该库的使用。 手册的目录结构清晰、条理分明,涵盖了LVGL v8库的各个方面,包括库的概述、主循环、基本对象、容器对象、图形对象、矢量对象、特效、输入和操作、图像和字体、样式、动画、调试等内容。每个章节都以简洁明了的语言和示例代码的形式进行介绍,非常易于理解和实践。 在手册中,我们可以了解到LVGL v8库是如何创建窗口和控件、设置样式和属性、注册事件回调函数、处理输入事件等等。在对于各种对象的使用中,将以控件为主展示其使用方法。例如,对于文本框,手册详细介绍了其创建方式、风格设置、插入文本、删除文本、获取文本内容等相关功能。除此之外,手册中还介绍了LVGL v8库的特效、输入和操作、图像和字体、样式、动画等方面的内容。 总体上,LVGL v8中文手册内容丰富、详细全面、易于理解和操作。对于开发人员而言,该手册是一本不可多得的优秀参考书,可以帮助他们轻松地掌握LVGL v8的使用,并在实际项目中进行灵活高效的UI设计开发。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值