图文移植LVGL9.3.0到STM32F429

一、移植准备
        硬件:正点原子 阿波罗 STM32F429
        软件:STM32F429_base工程 
                   LVGL代码:https://github.com/lvgl/lvgl.git

二、移植
1. 下载源码后,代码结构如下:

2. 在STM32F429_base工程Middlewares目录中新建LVGL文件夹,并把上图LVGL源码中选中的3个文件夹和3个文件拷贝其中,并将lv_conf_template.h改为lv_conf.h,如下所示:

  • demos文件夹里提供了一些高级演示,展示LVGL的综合应用和复杂功能。比如:
lv_demo_widgets():展示LVGL中所有控件的用法和样式;
lv_demo_benchmark():用于测试LVGL的性能;
lv_demo_stress(): 用于LVGL的压力测试;
  • examples文件夹里提供了许多 基础示例,展示如何使用 LVGL 的核心功能和控件,比如按钮、标签、滑块的创建,事件、动画、样式的使用,以及与输入设备间的交互等;
        如果用不到这些基础示例,只用保留porting文件夹即可。
  • src文件夹是 核心源代码 的存放位置,包含了 LVGL 库的所有实现代码。这个文件夹是 LVGL 的核心部分,提供了图形库的基础功能、控件、渲染引擎、内存管理、事件处理等关键模块。比如:
            core:核心模块,包含 LVGL 的核心功能实现,如对象系统、事件处理、动画、样式等; 
            widgets:
    控件模块,包含所有内置控件的实现,如按钮、标签、滑块、图表等;

            draw:渲染模块,包含渲染引擎的实现,支持软件渲染和硬件加速;
             font:字体和文本模块,包含字体管理和内置字体的实现;
            indev:输入设备模块, 包含输入设备驱动的实现,如触摸屏、编码器、按键等;
            fs:文件系统和图像解码,包含文件系统接口的实现,以及第三方库的集成,如图像解码库(PNG、JPEG 等);
            misc:综合模块,包含一些杂项功能,如日志、数学工具、内存管理等。
  • lv_conf.h 是 LVGL的配置文件模板,用于自定义 LVGL 的行为和功能。通过配置该文件,可以根据硬件资源和项目需求调整 LVGL 的核心功能、内存管理、显示驱动、输入设备驱动等。包括以下几个方面:
  • lv_version.h,当前LVGL版本信息:9.3.0,如下:
  • lvgl.h 核心源代码头文件的集合。
3. 添加lvgl到Keil工程中,并修改。
        1). 按照代码结构,把src和exampl,demos里面的代码添加到工程中,如下图所示。如果不使用lvgl示例,demos文件夹不用添加,examples里需要添加proting文件夹内容。实际应用中,可根据需要添加src里的核心内容文件。

        2). 添加头文件路径:

        3). 如果用到lv_demo_widgets,lv_demo_benchmark,或者lv_demo_stress这些demo,需要的栈空间比较大,因此需要把栈空间调大,否则会出现hard_fault错误,如下图所示。

        4). 配置lv_conf.h文件,并根据需要打开其中相关配置开关;

详细代码如下:
/**
 * @file lv_conf.h
 * Configuration file for v9.3.0-dev
 */

/*
 * Copy this file as `lv_conf.h`
 * 1. simply next to `lvgl` folder
 * 2. or to any other place and
 *    - define `LV_CONF_INCLUDE_SIMPLE`;
 *    - add the path as an include path.
 */

/* clang-format off */
#if 1 /* Set this to "1" to enable content */

#ifndef LV_CONF_H
#define LV_CONF_H

/* If you need to include anything here, do it inside the `__ASSEMBLY__` guard */
#if  0 && defined(__ASSEMBLY__)
#include "my_include.h"
#endif

/*====================
   COLOR SETTINGS
 *====================*/

/** Color depth: 1 (I1), 8 (L8), 16 (RGB565), 24 (RGB888), 32 (XRGB8888) */
#define LV_COLOR_DEPTH 16

/*=========================
   STDLIB WRAPPER SETTINGS
 *=========================*/

/** Possible values
 * - LV_STDLIB_BUILTIN:     LVGL's built in implementation
 * - LV_STDLIB_CLIB:        Standard C functions, like malloc, strlen, etc
 * - LV_STDLIB_MICROPYTHON: MicroPython implementation
 * - LV_STDLIB_RTTHREAD:    RT-Thread implementation
 * - LV_STDLIB_CUSTOM:      Implement the functions externally
 */
#define LV_USE_STDLIB_MALLOC    LV_STDLIB_BUILTIN

/** Possible values
 * - LV_STDLIB_BUILTIN:     LVGL's built in implementation
 * - LV_STDLIB_CLIB:        Standard C functions, like malloc, strlen, etc
 * - LV_STDLIB_MICROPYTHON: MicroPython implementation
 * - LV_STDLIB_RTTHREAD:    RT-Thread implementation
 * - LV_STDLIB_CUSTOM:      Implement the functions externally
 */
#define LV_USE_STDLIB_STRING    LV_STDLIB_BUILTIN

/** Possible values
 * - LV_STDLIB_BUILTIN:     LVGL's built in implementation
 * - LV_STDLIB_CLIB:        Standard C functions, like malloc, strlen, etc
 * - LV_STDLIB_MICROPYTHON: MicroPython implementation
 * - LV_STDLIB_RTTHREAD:    RT-Thread implementation
 * - LV_STDLIB_CUSTOM:      Implement the functions externally
 */
#define LV_USE_STDLIB_SPRINTF   LV_STDLIB_BUILTIN

#define LV_STDINT_INCLUDE       <stdint.h>
#define LV_STDDEF_INCLUDE       <stddef.h>
#define LV_STDBOOL_INCLUDE      <stdbool.h>
#define LV_INTTYPES_INCLUDE     <inttypes.h>
#define LV_LIMITS_INCLUDE       <limits.h>
#define LV_STDARG_INCLUDE       <stdarg.h>

#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
    /** Size of memory available for `lv_malloc()` in bytes (>= 2kB) */
    #define LV_MEM_SIZE (2*64 * 1024U)          /**< [bytes] */

    /** Size of the memory expand for `lv_malloc()` in bytes */
    #define LV_MEM_POOL_EXPAND_SIZE 0

    /** Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too. */
    #define LV_MEM_ADR 0     /**< 0: unused*/
    /* Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc */
    #if LV_MEM_ADR == 0
        #undef LV_MEM_POOL_INCLUDE
        #undef LV_MEM_POOL_ALLOC
    #endif
#endif  /*LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN*/

/*====================
   HAL SETTINGS
 *====================*/

/** Default display refresh, input device read and animation step period. */
#define LV_DEF_REFR_PERIOD  33      /**< [ms] */

/** Default Dots Per Inch. Used to initialize default sizes such as widgets sized, style paddings.
 * (Not so important, you can adjust it to modify default sizes and spaces.) */
#define LV_DPI_DEF 130              /**< [px/inch] */

/*=================
 * OPERATING SYSTEM
 *=================*/
/** Select operating system to use. Possible options:
 * - LV_OS_NONE
 * - LV_OS_PTHREAD
 * - LV_OS_FREERTOS
 * - LV_OS_CMSIS_RTOS2
 * - LV_OS_RTTHREAD
 * - LV_OS_WINDOWS
 * - LV_OS_MQX
 * - LV_OS_SDL2
 * - LV_OS_CUSTOM */
#define LV_USE_OS   LV_OS_NONE

#if LV_USE_OS == LV_OS_CUSTOM
    #define LV_OS_CUSTOM_INCLUDE <stdint.h>
#endif
#if LV_USE_OS == LV_OS_FREERTOS
	/*
	 * Unblocking an RTOS task with a direct notification is 45% faster and uses less RAM
	 * than unblocking a task using an intermediary object such as a binary semaphore.
	 * RTOS task notifications can only be used when there is only one task that can be the recipient of the event.
	 */
	#define LV_USE_FREERTOS_TASK_NOTIFY 1
#endif

/*========================
 * RENDERING CONFIGURATION
 *========================*/

/** Align stride of all layers and images to this bytes */
#define LV_DRAW_BUF_STRIDE_ALIGN                1

/** Align start address of draw_buf addresses to this bytes*/
#define LV_DRAW_BUF_ALIGN                       4

/** Using matrix for transformations.
 * Requirements:
 * - `LV_USE_MATRIX = 1`.
 * - Rendering engine needs to support 3x3 matrix transformations. */
#define LV_DRAW_TRANSFORM_USE_MATRIX            0

/* If a widget has `style_opa < 255` (not `bg_opa`, `text_opa` etc) or not NORMAL blend mode
 * it is buffered into a "simple" layer before rendering. The widget can be buffered in smaller chunks.
 * "Transformed layers" (if `transform_angle/zoom` are set) use larger buffers
 * and can't be drawn in chunks. */

/** The target buffer size for simple layer chunks. */
#define LV_DRAW_LAYER_SIMPLE_BUF_SIZE    (24 * 1024)    /**< [bytes]*/

/* Limit the max allocated memory for simple and transformed layers.
 * It should be at least `LV_DRAW_LAYER_SIMPLE_BUF_SIZE` sized but if transformed layers are also used
 * it should be enough to store the largest widget too (width x height x 4 area).
 * Set it to 0 to have no limit. */
#define LV_DRAW_LAYER_MAX_MEMORY 0  /**< No limit by default [bytes]*/

/** Stack size of drawing thread.
 * NOTE: If FreeType or ThorVG is enabled, it is recommended to set it to 32KB or more.
 */
#define LV_DRAW_THREAD_STACK_SIZE    (8 * 1024)         /**< [bytes]*/

#define LV_USE_DRAW_SW 1
#if LV_USE_DRAW_SW == 1
    /*
     * Selectively disable color format support in order to reduce code size.
     * NOTE: some features use certain color formats internally, e.g.
     * - gradients use RGB888
     * - bitmaps with transparency may use ARGB8888
     */
    #define LV_DRAW_SW_SUPPORT_RGB565       1
    #define LV_DRAW_SW_SUPPORT_RGB565A8     1
    #define LV_DRAW_SW_SUPPORT_RGB888       1
    #define LV_DRAW_SW_SUPPORT_XRGB8888     1
    #define LV_DRAW
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值