【技术分享】星空派GD32开发板LVGL移植经验分享

发布者:真诚友爱最新更新时间:2024-11-08 来源: elecfans关键字:GD32开发板 手机看文章 扫描二维码
随时随地手机看文章

今天有点空,我们移植一下LVGL~
先看效果图:

8f6ab62a-5280-11ec-b2e9-dac502259ad0.jpg

8fa1d646-5280-11ec-b2e9-dac502259ad0.jpg

8fd58914-5280-11ec-b2e9-dac502259ad0.jpg


在这之前,我们得调试好屏幕及触摸~
我们以之前的LCD那个程序为模板,开始添加LVGL文件。


先下载LVGL源文件包(点击“阅读原文”查看原贴即可下载)解压下来,将GUI添加进工程:


其中由于LVGL的特性,需要添加C99支持,并屏蔽一些类型的警告:


勾选C99,并在Misc Controls 中填入 --diag_suppress=68 --diag_supp
ress=111 --diag_suppress=550:


9021e4e4-5280-11ec-b2e9-dac502259ad0.png


添加LVGL的心跳,这了由于已经用了SYStiCK作为延时定时器。


我们这了新开一个定时器1,并设定为1ms中断,为LVGL提供心跳节拍~


#include 'timer.h'

#include 'lvgl.h'


//1秒产生一次中断 int_time = CLK / ((prescaler+1) * (period+1))

void TIM1_Int_Init(u16 arr,u16 psc)

{

 timer_parameter_struct timer_parameter;


 rcu_periph_clock_enable(RCU_TIMER1);


 //预分频

 timer_parameter.prescaler = psc,

 //对齐模式

 timer_parameter.alignedmode = TIMER_COUNTER_EDGE,

 //定时器增长方向

 timer_parameter.counterdirection = TIMER_COUNTER_UP,

 //定时器自动加载值

 timer_parameter.period = arr,

 //时钟分频值

 timer_parameter.clockdivision = TIMER_CKDIV_DIV4,


 timer_init(TIMER1, &timer_parameter);


 timer_interrupt_enable(TIMER1, TIMER_INT_UP);

 nvic_irq_enable(TIMER1_IRQn, 0, 2);


 timer_enable(TIMER1);

}



void TIMER1_IRQHandler()

{

 IF (timer_interrupt_flag_get(TIMER1, TIMER_INT_UP) != RESET)

 {

  lv_tick_inc(1);//lvgl的1ms心跳

  timer_interrupt_flag_clear(TIMER1, TIMER_INT_UP);

 }

}



在main初始化里面设定:


 TIM1_Int_Init(999,119);//定时器初始化(1ms 中断),用于给 lvgl 提供 1ms 的心跳节拍

其余就是一些常见的config的配置:

对lv_conf.h进行如下修改:


/**

 * [url=home.php?mod=space&uid=1455510]@file[/url] lv_conf.h

 *

 */


/*

 * COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER

 */


#if 1 /*Set it to '1' to enable content*/


#ifndef LV_CONF_H

#define LV_CONF_H

/* clang-format off */


#include 


/*====================

  Graphical settings

 *====================*/


/* Maximal horizontal and vertical resolution to support by the library.*/

#define LV_HOR_RES_MAX     (320) //320

#define LV_VER_RES_MAX     (480) //480


/* Color depth:

 * - 1: 1 byte per pixel

 * - 8: RGB233

 * - 16: RGB565

 * - 32: ARGB8888

 */

#define LV_COLOR_DEPTH   16


/* Swap the 2 bytes of RGB565 color.

 * Useful if the display has a 8 bit inteRFace (e.g. SPI)*/

#define LV_COLOR_16_SWAP  0


/* 1: Enable screen transparency.

 * Useful for OSD or other overlapping GUIs.

 * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/

#define LV_COLOR_SCREEN_TRANSP  0


/*Images pixels with this color will not be drawn (with chroma keying)*/

#define LV_COLOR_TRANSP  LV_COLOR_LIME     /*LV_COLOR_LIME: pure green*/


/* Enable anti-aliasing (lines, and radiuses will be smoothed) */

#define LV_ANTIALIAS    1


/* Default display refresh period.

 * Can be changed in the display driver (`lv_disp_drv_t`).*/

#define LV_DISP_DEF_REFR_PERIOD   30   /*[ms]*/


/* Dot Per Inch: used to initialize default sizes.

 * E.g. a button with width = LV_DPI / 2 -> half inch wide

 * (Not so important, you can adjust it to modify default sizes and spaces)*/

#define LV_DPI       60   /*[px]*/


/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */

typedef int16_t lv_coord_t;


/*=========================

  Memory manager settings

 *=========================*/


/* LittelvGL's internal memory manager's settings.

 * The graphical objects and other related data are stored here. */


/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */

#define LV_MEM_CUSTOM   0

#if LV_MEM_CUSTOM == 0

/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/

# define LV_MEM_SIZE  (16U * 1024U)


/* Complier prefix for a big array declaration */

# define LV_MEM_ATTR


/* Set an address for the memory pool instead of allocating it as an array.

 * Can be in external SRAM too. */

# define LV_MEM_ADR     0


/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */

# define LV_MEM_AUTO_DEFRAG 1

#else    /*LV_MEM_CUSTOM*/

# define LV_MEM_CUSTOM_INCLUDE   /*Header for the dynamic memory function*/

# define LV_MEM_CUSTOM_ALLOC  malloc    /*Wrapper to malloc*/

# define LV_MEM_CUSTOM_FREE  free     /*Wrapper to free*/

#endif   /*LV_MEM_CUSTOM*/


/* Garbage Collector settings

 * Used if lvgl is binded to higher level language and the memory is managed by that language */

#define LV_ENABLE_GC 0

#if LV_ENABLE_GC != 0

# define LV_GC_INCLUDE 'gc.h'              /*Include Garbage Collector related things*/

# define LV_MEM_CUSTOM_REALLOC  your_realloc      /*Wrapper to realloc*/

# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size   /*Wrapper to lv_mem_get_size*/

#endif /* LV_ENABLE_GC */


/*=======================

  Input device settings

 *=======================*/


/* Input device default settings.

 * Can be changed in the Input device driver (`lv_indev_drv_t`)*/


/* Input device read period in milliseconds */

#define LV_INDEV_DEF_READ_PERIOD     30


/* Drag threshold in pixels */

#define LV_INDEV_DEF_DRAG_LIMIT      10


/* Drag throw slow-down in [%]. Greater value -> faster slow-down */

#define LV_INDEV_DEF_DRAG_THROW      20


/* Long press time in milliseconds.

 * Time to send `LV_EVENT_LONG_PRESSSED`) */

#define LV_INDEV_DEF_LONG_PRESS_TIME   400


/* repeated trigger period in long press [ms]

 * Time between `LV_EVENT_LONG_PRESSED_REPEAT */

#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100


/*==================

 * Feature usage

 *==================*/


/*1: Enable the Animations */

#define LV_USE_ANIMATION    1

#if LV_USE_ANIMATION


/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/

typedef void * lv_anim_user_data_t;


#endif


/* 1: Enable shadow drawing*/

#define LV_USE_SHADOW      1


/* 1: Enable object groups (for keyboard/encoder navigation) */

#define LV_USE_GROUP      1

#if LV_USE_GROUP

typedef void * lv_group_user_data_t;

#endif /*LV_USE_GROUP*/


/* 1: Enable GPU interface*/

#define LV_USE_GPU       0


/* 1: Enable file system (might be required for images */

#define LV_USE_FILESYSTEM    0

#if LV_USE_FILESYSTEM

/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/

typedef void * lv_fs_drv_user_data_t;

#endif


/*1: Add a `user_data` to drivers and objects*/

#define LV_USE_USER_DATA    0


/*========================

 * Image decoder and cache

 *========================*/


/* 1: Enable indexed (palette) images */

#define LV_IMG_CF_INDEXED    1


/* 1: Enable alpha indexed images */

#define LV_IMG_CF_ALPHA     1


/* Default image cache size. Image caching keeps the images opened.

 * If only the built-in image formats are used there is no real advantage of caching.

 * (I.e. no new image decoder is added)

 * With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.

 * However the opened images might consume additional RAM.

 * LV_IMG_CACHE_DEF_SIZE must be >= 1 */

#define LV_IMG_CACHE_DEF_SIZE    1


/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/

typedef void * lv_img_decoder_user_data_t;


/*=====================

 * Compiler settings

 *====================*/

/* Define a custom attribute to `lv_tick_inc` function */

#define LV_ATTRIBUTE_TICK_INC


/* Define a custom attribute to `lv_task_handler` function */

#define LV_ATTRIBUTE_TASK_HANDLER


/* With size optimization (-Os) the compiler might not align data to

 * 4 or 8 byte boundary. This alignment will be explicitly applied where needed.

 * E.g. __attribute__((aligned(4))) */

#define LV_ATTRIBUTE_MEM_ALIGN


/* Attribute to mark large constant arrays for example

 * font's bitmaps */

#define LV_ATTRIBUTE_LARGE_CONST    


/*===================

 * HAL settings

 *==================*/


/* 1: use a custom tick source.

 * It removes the need to manually update the tick with `lv_tick_inc`) */

#define LV_TICK_CUSTOM   0

#if LV_TICK_CUSTOM == 1

#define LV_TICK_CUSTOM_INCLUDE 'something.h'    /*Header for the sys time function*/

#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis())   /*Expression evaluating to current systime in ms*/

#endif  /*LV_TICK_CUSTOM*/


typedef void * lv_disp_drv_user_data_t;       /*Type of user data in the display driver*/

typedef void * lv_indev_drv_user_data_t;      /*Type of user data in the input device driver*/


/*================

 * Log settings

 *===============*/


/*1: Enable the log module*/

#define LV_USE_LOG   0

#if LV_USE_LOG

/* How important log should be added:

 * LV_LOG_LEVEL_TRACE    A lot of logs to give detaiLED information

 * LV_LOG_LEVEL_INFO    Log important events

 * LV_LOG_LEVEL_WARN    Log if something unwanted happened but didn't cause a problem

 * LV_LOG_LEVEL_ERROR    Only critical issue, when the system may fail

 * LV_LOG_LEVEL_NONE    Do not log anything

 */

# define LV_LOG_LEVEL  LV_LOG_LEVEL_WARN


/* 1: Print the log with 'printf';

 * 0: user need to register a callback with `lv_log_register_print`*/

# define LV_LOG_PRINTF  0

#endif /*LV_USE_LOG*/


/*================

 * THEME USAGE

 *================*/

#define LV_THEME_LIVE_UPDATE  1  /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/


#define LV_USE_THEME_TEMPL   1  /*Just for test*/

#define LV_USE_THEME_DEFAULT  1  /*Built mainly from the built-in styles. Consumes very few RAM*/

#define LV_USE_THEME_ALIEN   1  /*Dark futuristic theme*/

#define LV_USE_THEME_NIGHT   1  /*Dark elegant theme*/

#define LV_USE_THEME_MONO    1  /*Mono color theme for monochrome displays*/

[1] [2] [3]
关键字:GD32开发板 引用地址:【技术分享】星空派GD32开发板LVGL移植经验分享

上一篇:GD32开发实战指南(基础篇) 第10章 串口通信
下一篇:GD32开发实战指南(基础篇) 第5章 跳动的心脏-Systick

小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved