本篇将介绍如何快速在zephyr中移植lvgl
【工程复制】
复制zephyr\samples\drivers\display到app目录下面。
【代码修改】
1、修改prj.con内容如下:
CONFIG_LOG=y CONFIG_DISPLAY=y CONFIG_DISPLAY_LOG_LEVEL_ERR=y # GT911 touch init in the lcd_par_s035 shield hangs the boot when INPUT # is enabled (the shield's Kconfig.defconfig defaults INPUT=y under LVGL), # leaving the display uninitialized. Keep it off until touch is needed. CONFIG_INPUT=n CONFIG_MAIN_STACK_SIZE=4096 CONFIG_LVGL=y CONFIG_LV_Z_MEM_POOL_SIZE=16384 # Default 1024 is tight for the LCDIC DMA write chain CONFIG_LV_Z_FLUSH_THREAD_STACK_SIZE=4096 CONFIG_LV_USE_LOG=y CONFIG_LV_USE_LABEL=y CONFIG_LV_FONT_MONTSERRAT_14=y
注意 CONFIG_INPUT需要设置为n,由于GT911的驱动还没有配置好,要不会卡死。
2、CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(display_lvgl)
target_sources(app PRIVATE src/main.c)3、修改main.c内容如下:
/*
* Copyright (c) 2018 Jan Van Winkel
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/display.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <lvgl.h>
LOG_MODULE_REGISTER(app, LOG_LEVEL_INF);
static uint32_t count;
int main(void)
{
char count_str[11] = {0};
const struct device *display_dev;
lv_obj_t *hello_world_label;
lv_obj_t *count_label;
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
LOG_ERR("Display device not ready, aborting");
return 0;
}
hello_world_label = lv_label_create(lv_screen_active());
lv_label_set_text(hello_world_label, "Hello world!");
lv_obj_align(hello_world_label, LV_ALIGN_CENTER, 0, 0);
count_label = lv_label_create(lv_screen_active());
lv_obj_align(count_label, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_timer_handler();
display_blanking_off(display_dev);
while (1) {
if ((count % 100) == 0U) {
sprintf(count_str, "%d", count / 100U);
lv_label_set_text(count_label, count_str);
}
lv_timer_handler();
++count;
k_sleep(K_MSEC(10));
}
return 0;
}在这段代码中,添加了一个文本标签,以及一个计数器标签,在大循环中动态更新count_label。
编译
nxp官方的LCD-PAR-S035已经给我写好了驱动,我们只需要在编译时添加
-- -DSHIELD=lcd_par_s035_spi
就可以把LCD屏的驱动给添加进去。
编译的命令为:
west build -b frdm_rw612 -p -- -DSHIELD=lcd_par_s035_spi
编译后结果如下:

【下载】
执行west flash即可将固件下载到开发板。
【效果】
下载后可以看到LCD屏点亮,实现效果图如下:

【经验教训】
官方的LCD屏中,与现在的版本的触摸驱动还有没有完美匹配。因此需要先禁用INPUT,即触摸屏。
我要赚赏金
