今天有點(diǎn)空,我們移植一下LVGL~
先看效果圖:
在這之前,我們得調(diào)試好屏幕及觸摸~
我們以之前的LCD那個(gè)程序為模板,開(kāi)始添加LVGL文件。
先下載LVGL源文件包(點(diǎn)擊“閱讀原文”查看原貼即可下載)解壓下來(lái),將GUI添加進(jìn)工程:
其中由于LVGL的特性,需要添加C99支持,并屏蔽一些類(lèi)型的警告:
勾選C99,并在Misc Controls 中填入 --diag_suppress=68 --diag_supp
ress=111 --diag_suppress=550:
添加LVGL的心跳,這了由于已經(jīng)用了SYStiCK作為延時(shí)定時(shí)器。
我們這了新開(kāi)一個(gè)定時(shí)器1,并設(shè)定為1ms中斷,為L(zhǎng)VGL提供心跳節(jié)拍~
#include 'timer.h'
#include 'lvgl.h'
//1秒產(chǎn)生一次中斷 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);
//預(yù)分頻
timer_parameter.prescaler = psc,
//對(duì)齊模式
timer_parameter.alignedmode = TIMER_COUNTER_EDGE,
//定時(shí)器增長(zhǎng)方向
timer_parameter.counterdirection = TIMER_COUNTER_UP,
//定時(shí)器自動(dòng)加載值
timer_parameter.period = arr,
//時(shí)鐘分頻值
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初始化里面設(shè)定:
TIM1_Int_Init(999,119);//定時(shí)器初始化(1ms 中斷),用于給 lvgl 提供 1ms 的心跳節(jié)拍
其余就是一些常見(jiàn)的config的配置:
對(duì)lv_conf.h進(jìn)行如下修改:
/**
* [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*/
上一篇:GD32開(kāi)發(fā)實(shí)戰(zhàn)指南(基礎(chǔ)篇) 第10章 串口通信
下一篇:GD32開(kāi)發(fā)實(shí)戰(zhàn)指南(基礎(chǔ)篇) 第5章 跳動(dòng)的心臟-Systick
- 熱門(mén)資源推薦
- 熱門(mén)放大器推薦
-
GD32F4xx+RTC+Alarm 實(shí)現(xiàn)秒中斷,通過(guò)串口打印時(shí)間
-
GD32470+FreeRtos+Fatfs+SDIO+SD
-
基于ESP32-S3-LCD-EV-Board的物聯(lián)網(wǎng)多功能平臺(tái)代碼
-
基于ESP32-S3-LCD-EV-Board的物聯(lián)網(wǎng)多功能平臺(tái)
-
開(kāi)關(guān)電源外圍元器件選擇與檢測(cè)
-
運(yùn)算放大器的設(shè)計(jì)與應(yīng)用
-
智能鋰電池充電器
-
實(shí)時(shí)控制系統(tǒng)軟件設(shè)計(jì)原理及應(yīng)用
設(shè)計(jì)資源 培訓(xùn) 開(kāi)發(fā)板 精華推薦
- 【下載】LAT1526 利用SPI的下溢實(shí)現(xiàn)回顯功能
- 【下載】LAT1509 STM32G0B1的FDCAN進(jìn)行通信丟包和多包案例分享
- 【下載】LAT1511 運(yùn)行Ux_Host_HUB_HID_MSC通過(guò)Hub連接U盤(pán)讀寫(xiě)不穩(wěn)定問(wèn)題分析
- 【下載】LAT1466 USB x Device HID Standalone的移植
- 【下載】LAT1488 STM32 USBxDevice MSC standalone移植示例
- 【下載】LAT1482 STM32G0單線(xiàn)串口通信幀錯(cuò)誤問(wèn)題解析
- 基于51系列單片機(jī)的智能照明控制系統(tǒng)設(shè)計(jì)方案
- 基于STM32的四旋翼飛行器控制系統(tǒng)
- 單片機(jī)應(yīng)用編程技巧解析
- 基于89C52的教室智能節(jié)能照明系統(tǒng)設(shè)計(jì)
- 一種新型的雨量光照傳感器的設(shè)計(jì)
- 智能護(hù)眼臺(tái)燈設(shè)計(jì)
- 蓄電池高能脈沖充電系統(tǒng)設(shè)計(jì)
- 基于51單片機(jī)定時(shí)器的電子時(shí)鐘設(shè)計(jì)方案
- 瑞薩電子推出面向單電機(jī)應(yīng)用優(yōu)化的卓越MCU, 涵蓋電動(dòng)工具、家用電器等廣泛應(yīng)用場(chǎng)景
- LT6656AIDC-3.3、3.3V 擴(kuò)展電源范圍電壓基準(zhǔn)的典型應(yīng)用
- 具有 400kHz 電荷泵開(kāi)關(guān)的 LT8495IFE 寬輸入和輸出范圍 SEPIC 轉(zhuǎn)換器的典型應(yīng)用電路
- LT1113 雙路低噪聲、精密、JFET 輸入運(yùn)算放大器的典型應(yīng)用
- MIC2097-2YMT限流配電開(kāi)關(guān)典型應(yīng)用
- VND5E050J評(píng)估板
- ADA4637-1ARZ-RL帶保護(hù)反相放大器的典型應(yīng)用電路
- STGIPS10K60T專(zhuān)用電源IC和模塊的典型應(yīng)用
- 工業(yè)縫紉機(jī)(變頻器)
- 使用 Analog Devices 的 LT1021CIN8-10 的參考設(shè)計(jì)
- 48.4W、5V、12V DC 到 DC 多輸出電源
- ICDIA 2025 創(chuàng)芯展圓滿(mǎn)落幕!
- 中興微電子亮相ICDIA 2025,共話(huà)RISC-V架構(gòu)推動(dòng)AI算力普惠化進(jìn)程
- 動(dòng)力電池“三國(guó)殺”:中企提前鎖定勝局,日韓廠商集體失守
- 研究人員開(kāi)發(fā)出人工智能雷達(dá)技術(shù) 可用于高分辨率3D城市制圖
- 上半年動(dòng)力電池TOP15:寧德時(shí)代和比亞迪裝車(chē)近200GWh 兩家公司新上榜
- 半年砸下數(shù)千億元!“并購(gòu)”浪潮下,汽車(chē)芯片大戰(zhàn)再起風(fēng)云
- 奇瑞人形機(jī)器人9月開(kāi)售并將面向個(gè)人用戶(hù),機(jī)器人時(shí)代該來(lái)了嗎?
- 華為李文廣:華為智能駕駛規(guī)劃曝光,加速追趕特斯拉
- 功能迭代和功能安全的矛盾及車(chē)端應(yīng)用層-下
- 功能迭代和功能安全的矛盾及車(chē)端應(yīng)用層-中
- 7nm工藝將arm服務(wù)器芯片推向極致
- 德國(guó)電動(dòng)車(chē)充電站面臨聯(lián)邦卡特爾局的反壟斷調(diào)查
- 今年最大并購(gòu)誕生,ADI正式收購(gòu)Maxim
- STM8SF103單片機(jī)的ADC采樣電壓設(shè)計(jì)
- openmv舵機(jī)云臺(tái) 自動(dòng)追蹤色塊 STM32源程序
- 倍捷連接器PEI-Genesis慶祝成立75周年
- stm8s實(shí)現(xiàn)串口中斷接,中斷發(fā)功能
- 大數(shù)據(jù)中心的痛點(diǎn),竟能如此解決?TI芯科技賦能中國(guó)新基建
- ARM(包括ARMv7 工作模式介紹)寄存器、工作模式和指令集
- ARM 中斷發(fā)生時(shí) PC,LR,SPSR,CPSR寄存器相關(guān)問(wèn)題總結(jié)