LVGL在单色屏上运行

编程入门 行业动态 更新时间:2024-10-22 19:24:56

LVGL在<a href=https://www.elefans.com/category/jswz/34/1688038.html style=单色屏上运行"/>

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

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

更多推荐

LVGL在单色屏上运行

本文发布于:2024-03-09 09:47:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1724642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单色   LVGL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!