RT-Thread qemu LVGL9.5 LV_LOG_USER 输出打印适配

说明

  • RT-Thread : 5.2.0

  • LVGL 9.5

  • BSP : qemu-vexpress-a9

默认 LVGL LV_LOG_USER 没有输出,想对接到 RT-Thread 的控制台输出 rt_kprinf

LVGL 的 LOG开启

  • LVGL 的 lv_conf.h 中,配置设置如下,如果没有就添加
c 复制代码
#define LV_USE_LOG                  1
#define LV_LOG_LEVEL                LV_LOG_LEVEL_USER
  • 等级 LV_LOG_LEVEL_USER 说明 LV_LOG_USER 可以输出

注册 LVGL log 输出的 callback

  • lv_log_register_print_cb 可以设置 LVGL 的打印回调函数,回调函数中,采用 rt_kprintf 输出即可
c 复制代码
void rtt_log_cb(lv_log_level_t level, const char * buf)
{
    rt_kprintf(buf);
}

void lv_user_gui_init(void)
{
    lv_log_register_print_cb(rtt_log_cb);
    lv_example_button_1();
}

测试示例

c 复制代码
#include <stdint.h>
#include <stdio.h>
#include <rtthread.h>
#include <lvgl.h>

void rtt_log_cb(lv_log_level_t level, const char * buf)
{
    rt_kprintf(buf);
}

static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);

    if(code == LV_EVENT_CLICKED) {
        LV_LOG_USER("Clicked");
    }
    else if(code == LV_EVENT_VALUE_CHANGED) {
        LV_LOG_USER("Toggled");
    }
}

void lv_example_button_1(void)
{
    lv_obj_t * label;

    lv_obj_t * btn1 = lv_button_create(lv_screen_active());
    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
    lv_obj_remove_flag(btn1, LV_OBJ_FLAG_PRESS_LOCK);

    label = lv_label_create(btn1);
    lv_label_set_text(label, "Button");
    lv_obj_center(label);

    lv_obj_t * btn2 = lv_button_create(lv_screen_active());
    lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
    lv_obj_set_height(btn2, LV_SIZE_CONTENT);

    label = lv_label_create(btn2);
    lv_label_set_text(label, "Toggle");
    lv_obj_center(label);
}

void lv_user_gui_init(void)
{
    lv_log_register_print_cb(rtt_log_cb);
    lv_example_button_1();
}

int main(void)
{
    rt_kprintf("Hello RT-Thread!\n");

    return 0;
}

输出效果

  • LVGL 的 LOG 通过 RT-Thread 默认的 rt_kprintf 打印
相关推荐
tyustli3 天前
TF-M Secure 启动文件
qemu·tf-m·startup·mps2-an521·启动文件
tyustli4 天前
TF-M BL2 和 TFM_S 的配置和编译
qemu·tf-m·bl2·mps2-an521·tfm_s
tyustli5 天前
TF-M BL2 RAM 布局
qemu·tf-m·bl2·mps2-an521
tyustli8 天前
TF-M 使用 make 构建
qemu·make·mcuboot·tf-m·mps2-an521
张一西1 个月前
QEMU 模拟器学习(二)之 USB 设备之BOT & UAS协议
qemu·uas·bot
张一西1 个月前
QEMU 模拟器学习(二)之 USB 设备模拟与协议学习
qemu·usb·uas·bot
shimly1234561 个月前
(undone) 解析 qemu-6.0.0 源码 (4) 添加 niubi board - 2
qemu
冰山一脚20131 个月前
cirrus显卡驱动笔记
qemu·drm
shimly1234561 个月前
(done) 解析 qemu-6.0.0 源码 (2) 寻找入口函数 main
qemu
ggaofeng2 个月前
QEMU中硬盘用哪种协议读写速度快
qemu·磁盘类型