【米尔-芯驰D9国产车规级开发板】7、移植LVGL
[复制链接]
本帖最后由 walker2048 于 2023-10-21 11:49 编辑
运行LVGL简单界面的视频
lvgl
LVGL简介
LVGL(Light and Versatile Graphics Library)是一款开源的嵌入式图形库,旨在为嵌入式系统提供高性能和易于定制的图形用户界面(GUI)解决方案。LVGL 通常用于创建嵌入式系统的用户界面,例如智能家居设备、工业控制面板、医疗设备和嵌入式显示器。由于其轻量级和灵活性,它已经成为许多嵌入式开发者的首选图形库之一。
一、添加LVGL源码
习惯在自己的git仓里折腾,所以直接将lvgl v8.3的发行版本添加到git子仓里,放到components/lvgl/v8.3下。
执行以下命令
git submodule add -b release/v8.3 https://gitee.com/mirrors/lvgl.git components/lvgl/v8.3
git submodule update
这样就添加好源码了,接下来是适配到自己的构建系统里。
二、添加源码到构建系统中
在components/lvgl目录添加一个BUILD.gn文件,添加以下内容:
source_set("lvgl") {
# 移植源码
sources = [
"lv_port_disp.c",
"lv_port_indev.c",
]
# 官方核心源码
sources += [
"v8.3/src/core/lv_disp.c",
"v8.3/src/core/lv_event.c",
"v8.3/src/core/lv_group.c",
"v8.3/src/core/lv_indev.c",
"v8.3/src/core/lv_indev_scroll.c",
"v8.3/src/core/lv_obj.c",
"v8.3/src/core/lv_obj_class.c",
"v8.3/src/core/lv_obj_draw.c",
"v8.3/src/core/lv_obj_pos.c",
"v8.3/src/core/lv_obj_scroll.c",
"v8.3/src/core/lv_obj_style.c",
"v8.3/src/core/lv_obj_style_gen.c",
"v8.3/src/core/lv_obj_tree.c",
"v8.3/src/core/lv_refr.c",
"v8.3/src/core/lv_theme.c",
]
# 官方绘图部分源码
sources += [
"v8.3/src/draw/arm2d/lv_gpu_arm2d.c",
"v8.3/src/draw/lv_draw.c",
"v8.3/src/draw/lv_draw_arc.c",
"v8.3/src/draw/lv_draw_img.c",
"v8.3/src/draw/lv_draw_label.c",
"v8.3/src/draw/lv_draw_layer.c",
"v8.3/src/draw/lv_draw_line.c",
"v8.3/src/draw/lv_draw_mask.c",
"v8.3/src/draw/lv_draw_rect.c",
"v8.3/src/draw/lv_draw_transform.c",
"v8.3/src/draw/lv_draw_triangle.c",
"v8.3/src/draw/lv_img_buf.c",
"v8.3/src/draw/lv_img_cache.c",
"v8.3/src/draw/lv_img_decoder.c",
"v8.3/src/draw/nxp/lv_gpu_nxp.c",
"v8.3/src/draw/nxp/pxp/lv_draw_pxp_blend.c",
"v8.3/src/draw/nxp/pxp/lv_gpu_nxp_pxp.c",
"v8.3/src/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.c",
"v8.3/src/draw/nxp/vglite/lv_draw_vglite_arc.c",
"v8.3/src/draw/nxp/vglite/lv_draw_vglite_blend.c",
"v8.3/src/draw/nxp/vglite/lv_draw_vglite_rect.c",
"v8.3/src/draw/nxp/vglite/lv_gpu_nxp_vglite.c",
"v8.3/src/draw/sdl/lv_draw_sdl.c",
"v8.3/src/draw/sdl/lv_draw_sdl_arc.c",
"v8.3/src/draw/sdl/lv_draw_sdl_bg.c",
"v8.3/src/draw/sdl/lv_draw_sdl_composite.c",
"v8.3/src/draw/sdl/lv_draw_sdl_img.c",
"v8.3/src/draw/sdl/lv_draw_sdl_label.c",
"v8.3/src/draw/sdl/lv_draw_sdl_layer.c",
"v8.3/src/draw/sdl/lv_draw_sdl_line.c",
"v8.3/src/draw/sdl/lv_draw_sdl_mask.c",
"v8.3/src/draw/sdl/lv_draw_sdl_polygon.c",
"v8.3/src/draw/sdl/lv_draw_sdl_rect.c",
"v8.3/src/draw/sdl/lv_draw_sdl_stack_blur.c",
"v8.3/src/draw/sdl/lv_draw_sdl_texture_cache.c",
"v8.3/src/draw/sdl/lv_draw_sdl_utils.c",
"v8.3/src/draw/stm32_dma2d/lv_gpu_stm32_dma2d.c",
"v8.3/src/draw/sw/lv_draw_sw.c",
"v8.3/src/draw/sw/lv_draw_sw_arc.c",
"v8.3/src/draw/sw/lv_draw_sw_blend.c",
"v8.3/src/draw/sw/lv_draw_sw_dither.c",
"v8.3/src/draw/sw/lv_draw_sw_gradient.c",
"v8.3/src/draw/sw/lv_draw_sw_img.c",
"v8.3/src/draw/sw/lv_draw_sw_layer.c",
"v8.3/src/draw/sw/lv_draw_sw_letter.c",
"v8.3/src/draw/sw/lv_draw_sw_line.c",
"v8.3/src/draw/sw/lv_draw_sw_polygon.c",
"v8.3/src/draw/sw/lv_draw_sw_rect.c",
"v8.3/src/draw/sw/lv_draw_sw_transform.c",
"v8.3/src/draw/swm341_dma2d/lv_gpu_swm341_dma2d.c",
]
sources += [
"v8.3/src/extra/layouts/flex/lv_flex.c",
"v8.3/src/extra/layouts/grid/lv_grid.c",
"v8.3/src/extra/libs/bmp/lv_bmp.c",
"v8.3/src/extra/libs/ffmpeg/lv_ffmpeg.c",
"v8.3/src/extra/libs/freetype/lv_freetype.c",
"v8.3/src/extra/libs/fsdrv/lv_fs_fatfs.c",
"v8.3/src/extra/libs/fsdrv/lv_fs_posix.c",
"v8.3/src/extra/libs/fsdrv/lv_fs_stdio.c",
"v8.3/src/extra/libs/fsdrv/lv_fs_win32.c",
"v8.3/src/extra/libs/gif/gifdec.c",
"v8.3/src/extra/libs/gif/lv_gif.c",
"v8.3/src/extra/libs/png/lodepng.c",
"v8.3/src/extra/libs/png/lv_png.c",
"v8.3/src/extra/libs/qrcode/lv_qrcode.c",
"v8.3/src/extra/libs/qrcode/qrcodegen.c",
"v8.3/src/extra/libs/rlottie/lv_rlottie.c",
"v8.3/src/extra/libs/sjpg/lv_sjpg.c",
"v8.3/src/extra/libs/sjpg/tjpgd.c",
"v8.3/src/extra/lv_extra.c",
"v8.3/src/extra/others/fragment/lv_fragment.c",
"v8.3/src/extra/others/fragment/lv_fragment_manager.c",
"v8.3/src/extra/others/gridnav/lv_gridnav.c",
"v8.3/src/extra/others/ime/lv_ime_pinyin.c",
"v8.3/src/extra/others/imgfont/lv_imgfont.c",
"v8.3/src/extra/others/monkey/lv_monkey.c",
"v8.3/src/extra/others/msg/lv_msg.c",
"v8.3/src/extra/others/snapshot/lv_snapshot.c",
"v8.3/src/extra/themes/basic/lv_theme_basic.c",
"v8.3/src/extra/themes/default/lv_theme_default.c",
"v8.3/src/extra/themes/mono/lv_theme_mono.c",
"v8.3/src/extra/widgets/animimg/lv_animimg.c",
"v8.3/src/extra/widgets/calendar/lv_calendar.c",
"v8.3/src/extra/widgets/calendar/lv_calendar_header_arrow.c",
"v8.3/src/extra/widgets/calendar/lv_calendar_header_dropdown.c",
"v8.3/src/extra/widgets/chart/lv_chart.c",
"v8.3/src/extra/widgets/colorwheel/lv_colorwheel.c",
"v8.3/src/extra/widgets/imgbtn/lv_imgbtn.c",
"v8.3/src/extra/widgets/keyboard/lv_keyboard.c",
"v8.3/src/extra/widgets/led/lv_led.c",
"v8.3/src/extra/widgets/list/lv_list.c",
"v8.3/src/extra/widgets/menu/lv_menu.c",
"v8.3/src/extra/widgets/meter/lv_meter.c",
"v8.3/src/extra/widgets/msgbox/lv_msgbox.c",
"v8.3/src/extra/widgets/span/lv_span.c",
"v8.3/src/extra/widgets/spinbox/lv_spinbox.c",
"v8.3/src/extra/widgets/spinner/lv_spinner.c",
"v8.3/src/extra/widgets/tabview/lv_tabview.c",
"v8.3/src/extra/widgets/tileview/lv_tileview.c",
"v8.3/src/extra/widgets/win/lv_win.c",
]
sources += [
"v8.3/src/font/lv_font.c",
"v8.3/src/font/lv_font_dejavu_16_persian_hebrew.c",
"v8.3/src/font/lv_font_fmt_txt.c",
"v8.3/src/font/lv_font_loader.c",
"v8.3/src/font/lv_font_montserrat_10.c",
"v8.3/src/font/lv_font_montserrat_12.c",
"v8.3/src/font/lv_font_montserrat_12_subpx.c",
"v8.3/src/font/lv_font_montserrat_14.c",
"v8.3/src/font/lv_font_montserrat_16.c",
"v8.3/src/font/lv_font_montserrat_18.c",
"v8.3/src/font/lv_font_montserrat_20.c",
"v8.3/src/font/lv_font_montserrat_22.c",
"v8.3/src/font/lv_font_montserrat_24.c",
"v8.3/src/font/lv_font_montserrat_26.c",
"v8.3/src/font/lv_font_montserrat_28.c",
"v8.3/src/font/lv_font_montserrat_28_compressed.c",
"v8.3/src/font/lv_font_montserrat_30.c",
"v8.3/src/font/lv_font_montserrat_32.c",
"v8.3/src/font/lv_font_montserrat_34.c",
"v8.3/src/font/lv_font_montserrat_36.c",
"v8.3/src/font/lv_font_montserrat_38.c",
"v8.3/src/font/lv_font_montserrat_40.c",
"v8.3/src/font/lv_font_montserrat_42.c",
"v8.3/src/font/lv_font_montserrat_44.c",
"v8.3/src/font/lv_font_montserrat_46.c",
"v8.3/src/font/lv_font_montserrat_48.c",
"v8.3/src/font/lv_font_montserrat_8.c",
"v8.3/src/font/lv_font_simsun_16_cjk.c",
"v8.3/src/font/lv_font_unscii_16.c",
"v8.3/src/font/lv_font_unscii_8.c",
]
sources += [
"v8.3/src/hal/lv_hal_disp.c",
"v8.3/src/hal/lv_hal_indev.c",
"v8.3/src/hal/lv_hal_tick.c",
]
sources += [
"v8.3/src/misc/lv_anim.c",
"v8.3/src/misc/lv_anim_timeline.c",
"v8.3/src/misc/lv_area.c",
"v8.3/src/misc/lv_async.c",
"v8.3/src/misc/lv_bidi.c",
"v8.3/src/misc/lv_color.c",
"v8.3/src/misc/lv_fs.c",
"v8.3/src/misc/lv_gc.c",
"v8.3/src/misc/lv_ll.c",
"v8.3/src/misc/lv_log.c",
"v8.3/src/misc/lv_lru.c",
"v8.3/src/misc/lv_math.c",
"v8.3/src/misc/lv_mem.c",
"v8.3/src/misc/lv_printf.c",
"v8.3/src/misc/lv_style.c",
"v8.3/src/misc/lv_style_gen.c",
"v8.3/src/misc/lv_templ.c",
"v8.3/src/misc/lv_timer.c",
"v8.3/src/misc/lv_tlsf.c",
"v8.3/src/misc/lv_txt.c",
"v8.3/src/misc/lv_txt_ap.c",
"v8.3/src/misc/lv_utils.c",
]
sources += [
"v8.3/src/widgets/lv_arc.c",
"v8.3/src/widgets/lv_bar.c",
"v8.3/src/widgets/lv_btn.c",
"v8.3/src/widgets/lv_btnmatrix.c",
"v8.3/src/widgets/lv_canvas.c",
"v8.3/src/widgets/lv_checkbox.c",
"v8.3/src/widgets/lv_dropdown.c",
"v8.3/src/widgets/lv_img.c",
"v8.3/src/widgets/lv_label.c",
"v8.3/src/widgets/lv_line.c",
"v8.3/src/widgets/lv_objx_templ.c",
"v8.3/src/widgets/lv_roller.c",
"v8.3/src/widgets/lv_slider.c",
"v8.3/src/widgets/lv_switch.c",
"v8.3/src/widgets/lv_table.c",
"v8.3/src/widgets/lv_textarea.c",
]
sources += [
"v8.3/demos/benchmark/assets/img_benchmark_cogwheel_alpha16.c",
"v8.3/demos/benchmark/assets/img_benchmark_cogwheel_argb.c",
"v8.3/demos/benchmark/assets/img_benchmark_cogwheel_chroma_keyed.c",
"v8.3/demos/benchmark/assets/img_benchmark_cogwheel_indexed16.c",
"v8.3/demos/benchmark/assets/img_benchmark_cogwheel_rgb.c",
"v8.3/demos/benchmark/assets/img_benchmark_cogwheel_rgb565a8.c",
"v8.3/demos/benchmark/assets/lv_font_bechmark_montserrat_12_compr_az.c.c",
"v8.3/demos/benchmark/assets/lv_font_bechmark_montserrat_16_compr_az.c.c",
"v8.3/demos/benchmark/assets/lv_font_bechmark_montserrat_28_compr_az.c.c",
"v8.3/demos/benchmark/lv_demo_benchmark.c",
"v8.3/demos/keypad_encoder/lv_demo_keypad_encoder.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_corner_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_list_pause.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_list_pause_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_list_play.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_list_play_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_loop.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_loop_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_next.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_next_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_pause.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_pause_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_play.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_play_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_prev.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_prev_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_rnd.c",
"v8.3/demos/music/assets/img_lv_demo_music_btn_rnd_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_corner_left.c",
"v8.3/demos/music/assets/img_lv_demo_music_corner_left_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_corner_right.c",
"v8.3/demos/music/assets/img_lv_demo_music_corner_right_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_cover_1.c",
"v8.3/demos/music/assets/img_lv_demo_music_cover_1_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_cover_2.c",
"v8.3/demos/music/assets/img_lv_demo_music_cover_2_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_cover_3.c",
"v8.3/demos/music/assets/img_lv_demo_music_cover_3_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_1.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_1_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_2.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_2_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_3.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_3_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_4.c",
"v8.3/demos/music/assets/img_lv_demo_music_icon_4_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_list_border.c",
"v8.3/demos/music/assets/img_lv_demo_music_list_border_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_logo.c",
"v8.3/demos/music/assets/img_lv_demo_music_slider_knob.c",
"v8.3/demos/music/assets/img_lv_demo_music_slider_knob_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_wave_bottom.c",
"v8.3/demos/music/assets/img_lv_demo_music_wave_bottom_large.c",
"v8.3/demos/music/assets/img_lv_demo_music_wave_top.c",
"v8.3/demos/music/assets/img_lv_demo_music_wave_top_large.c",
"v8.3/demos/music/lv_demo_music.c",
"v8.3/demos/music/lv_demo_music_list.c",
"v8.3/demos/music/lv_demo_music_main.c",
"v8.3/demos/stress/lv_demo_stress.c",
"v8.3/demos/widgets/assets/img_clothes.c",
"v8.3/demos/widgets/assets/img_demo_widgets_avatar.c",
"v8.3/demos/widgets/assets/img_lvgl_logo.c",
"v8.3/demos/widgets/lv_demo_widgets.c",
]
}
然后,复制components/lvgl/v8.3/examples/porting/lv_port_disp_template.c文件到components/lvgl/lv_port_disp.c并修改成以下内容:
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-10-18 Meco Man The first version
*/
#include "disp_driver.h"
extern configuration config;
#define MY_DISP_HOR_RES 240
#define DISP_BUFFER_LINES 24
/*A static or global variable to store the buffers*/
static lv_disp_draw_buf_t disp_buf;
/*Descriptor of a display driver*/
static lv_disp_drv_t disp_drv;
/*Static or global buffer(s). The second buffer is optional*/
static lv_color_t buf_1[MY_DISP_HOR_RES * DISP_BUFFER_LINES];
/*Flush the content of the internal buffer the specific area on the display
*You can use DMA or any hardware acceleration to do this operation in the background but
*'lv_disp_flush_ready()' has to be called when finished.*/
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
/* color_p is a buffer pointer; the buffer is provided by LVGL */
disp_driver_flush(disp_drv, area, color_p);
/*IMPORTANT!!!
*Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
void lv_port_disp_init(void)
{
/*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, MY_DISP_HOR_RES * DISP_BUFFER_LINES);
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
/*Set the resolution of the display*/
disp_drv.hor_res = config.height;
disp_drv.ver_res = config.width;
/*Set a display buffer*/
disp_drv.draw_buf = &disp_buf;
/*Used to copy the buffer's content to the display*/
disp_drv.flush_cb = disp_flush;
/*Finally register the driver*/
lv_disp_drv_register(&disp_drv);
}
然后拷贝一份lv_conf.h放置到板级目录hardware/board/arm_linux_host
最后在build/config/BUILD.gn文件里添加lvgl的头文件目录,就可以了。
# Common Include dirs setup.
# --------------------------------
include_dirs = [
"//applications/${app}",
"//drivers/include",
"//drivers/display/lcd",
"//components/lvgl/v8.3",
"//components/fs/vfs/include",
"//components/fs/kv/include",
"//components/fs/fatfs/wrapper/include",
"//components/cli/include",
"//hardware/board/${product}",
]
三、在应用程序代码里添加lvgl代码
由于是在Linux上跑lvgl,需要添加一个自定义心跳函数
uint32_t custom_tick_get(void)
{
static uint64_t start_ms = 0;
if(start_ms == 0) {
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
}
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
uint64_t now_ms;
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
uint32_t time_ms = now_ms - start_ms;
return time_ms;
}
main.c的全部内容如下:
#include "disp_driver.h"
#include "src/widgets/lv_label.h"
#include "../../components/lvgl/v8.3/lvgl.h"
#define LV_ATTRIBUTE_TICK_INC
#include "ini.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
static lv_obj_t *meter;
static void set_value(void *indic, int32_t v) {
lv_meter_set_indicator_end_value(meter, indic, v);
}
extern configuration config;
static int handler(void *panel, const char *section, const char *name,
const char *value) {
configuration *pconfig = (configuration *)panel;
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
// find panel config
if (MATCH("panel", "path")) {
pconfig->disp_path = strdup(value);
} else if (MATCH("panel", "ic")) {
pconfig->disp_ic = strdup(value);
// find pin config
} else if (MATCH("pin", "pin_cs")) {
pconfig->pin_cs = atoi(value);
} else if (MATCH("pin", "pin_dc")) {
pconfig->pin_dc = atoi(value);
} else if (MATCH("pin", "bl_pwm")) {
pconfig->bl_pwm = atoi(value);
} else if (MATCH("pin", "pin_rst")) {
pconfig->pin_rst = atoi(value);
// find spi config
} else if (MATCH("spi", "speed_mh")) {
pconfig->spi_speed_mh = atoi(value);
} else if (MATCH("spi", "mode")) {
pconfig->spi_mode = atoi(value);
// find resolution config
} else if (MATCH("resolution", "offset_x")) {
pconfig->offset_x = atoi(value);
} else if (MATCH("resolution", "offset_y")) {
pconfig->offset_y = atoi(value);
} else if (MATCH("resolution", "width")) {
pconfig->width = atoi(value);
} else if (MATCH("resolution", "height")) {
pconfig->height = atoi(value);
} else if (MATCH("resolution", "orientation")) {
pconfig->orientation = atoi(value);
} else {
return 0; /* unknown section/name, error */
}
return 1;
}
/**
* A meter with multiple arcs
*/
void lv_example_meter_xxxx(void) {
meter = lv_meter_create(lv_scr_act());
lv_obj_center(meter);
lv_obj_set_size(meter, 200, 200);
/*Remove the circle from the middle*/
lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);
/*Add a scale first*/
lv_meter_scale_t *scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 11, 2, 10,
lv_palette_main(LV_PALETTE_GREY));
lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee),
10);
lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90);
/*Add a three arc indicator*/
lv_meter_indicator_t *indic1 =
lv_meter_add_arc(meter, scale, 10, lv_palette_main(LV_PALETTE_RED), 0);
lv_meter_indicator_t *indic2 = lv_meter_add_arc(
meter, scale, 10, lv_palette_main(LV_PALETTE_GREEN), -10);
lv_meter_indicator_t *indic3 = lv_meter_add_arc(
meter, scale, 10, lv_palette_main(LV_PALETTE_BLUE), -20);
/*Create an animation to set the value*/
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, set_value);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_repeat_delay(&a, 100);
lv_anim_set_playback_delay(&a, 100);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_time(&a, 500);
lv_anim_set_playback_time(&a, 200);
lv_anim_set_var(&a, indic1);
lv_anim_start(&a);
lv_anim_set_time(&a, 300);
lv_anim_set_playback_time(&a, 500);
lv_anim_set_var(&a, indic2);
lv_anim_start(&a);
lv_anim_set_time(&a, 100);
lv_anim_set_playback_time(&a, 1000);
lv_anim_set_var(&a, indic3);
lv_anim_start(&a);
}
int main(void) {
// panel config
config.disp_path = NULL;
config.disp_ic = "st7789";
// pin config
config.pin_cs = 0;
config.pin_dc = 0;
config.pin_rst = 0;
config.bl_pwm = 0;
// spi config
config.spi_speed_mh = 50;
config.spi_mode = 0;
// resolution config
config.offset_x = 0;
config.offset_y = 0;
config.width = 240;
config.height = 320;
config.orientation = 0;
if (ini_parse("disp.ini", handler, &config) < 0) {
printf("Can't load 'disp.ini'\n");
return 1;
}
printf("Config loaded from 'disp.ini': \n");
printf(" display=%s\n", config.disp_ic);
printf(" dev=%s, spi_speed=%dmhz, spi_mode=%d\n", config.disp_path,
config.spi_speed_mh, config.spi_mode);
printf(" cs=%d,dc=%d, rst=%d\n", config.pin_cs, config.pin_dc,
config.pin_rst);
printf(" bl=%d, offset.x=%d, offset.y=%d\n", config.bl_pwm,
config.offset_x, config.offset_y);
printf(" width=%d, height=%d\n", config.width, config.height);
lv_init();
disp_driver_init();
lv_port_disp_init();
lv_example_meter_xxxx();
printf("lvgl_example\n");
while (1) {
lv_task_handler();
usleep(30 * 1000);
}
return 0;
}
uint32_t custom_tick_get(void)
{
static uint64_t start_ms = 0;
if(start_ms == 0) {
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
}
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
uint64_t now_ms;
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
uint32_t time_ms = now_ms - start_ms;
return time_ms;
}
至此,就完成了lvgl的移植工作,编译也一切顺利。
拷贝到开发板上运行:
|