LVGL在单色屏上运行

LVGL在单色屏上运行


本文主要讲述LVGL在单色屏应用中的实现思路,并已验证通过。网上关于lvgl移植的文章有很多了,本文不加以赘述。
     

一、环境准备

  1. 版本:LVGL 8.2
  2. 屏幕:中景园ZJY213S0700
  3. 屏幕驱动芯片:ST7302

二、实现步骤

  1. 在lv_port_disp.c文件中,增加代码。
static void disp_init(void)
{
    /*You code here*/
	task_lcd_init();
}
  1. 在lv_port_disp.c文件中,增加画点函数。
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
    /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/

	int32_t x;
	int32_t y;

	for(y = area->y1; y <= area->y2; y++)
    {
        for(x = area->x1; x <= area->x2; x++)
        {
            if(color_p->full>0)
            {
                lcd_draw_point(x,y,1);
            }
            else
            {
                lcd_draw_point(x,y,0);
            }
            color_p++;
        }

    }
	lcd_refresh();

    /*IMPORTANT!!!
     *Inform the graphics library that you are ready with the flushing*/
    lv_disp_flush_ready(disp_drv);
}
  1. 修改lv_conf.h文件,配置好色深和屏幕分辨率,因使用的是单色屏,所以将LV_COLOR_DEPTH配置为1。
#define LV_COLOR_DEPTH 1
#define MY_DISP_HOR_RES (250)
#define MY_DISP_VER_RES (122)
  1. 测试代码
    lvgl的一些控件对单色屏是不支持的,关键点在于需要对其颜色进行配置。
void lv_demo_button(void)
{
    lv_style_t style;

    lv_style_init(&style);
    lv_style_set_bg_color(&style, lv_color_write());
    lv_style_set_outline_width(&style, 2);

    lv_obj_set_style_bg_color(lv_scr_act(),   lv_color_white(), 0);

    lv_obj_t * btn = lv_btn_create(lv_scr_act());     /*Add a button the current screen*/
    lv_obj_set_pos(btn, 20, 20);                            /*Set its position*/
    lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
    lv_obj_add_style(btn,&style,LV_STATE_DEFAULT);

    lv_obj_t * label = lv_label_create(btn);          /*Add a label to the button*/
    lv_label_set_text(label, "Button");                     /*Set the labels text*/
    lv_obj_set_style_text_color(label,lv_color_black(),0);
    lv_obj_center(label);
}

      吾辈必当勤勉,持书仗剑耀中华。

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值