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);
}

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

你可能感兴趣的:(单片机,单片机,stm32,嵌入式,lvgl,嵌入式硬件)