首页 > 其他分享 >1.LVGL快速移植

1.LVGL快速移植

时间:2023-11-27 10:35:34浏览次数:22  
标签:disp color 快速 drv lv buffer LVGL buf 移植

一、拷贝lvgl 整个文件夹到工程中,lv_conf_template.h 文件要重命名为lv_conf.h,该文件里面#if 0改成#if 1 ,如下所示

 

 

二、工程里面添加所有文件和头文件路径,这一步过程比较长长,但还是要做好,

然后编译,可能报错.Undefined symbol __aeabi_assert (referred from qrcodegen.o).,需要添加NDEBUG到预处理,进行暂时屏蔽断言

 

 

 三、注册屏幕驱动接口给lvgl

lv_port_disp.c是屏幕驱动接口,是移植重点,可以拷贝lvgl / env_support / rt_thread / lv_rt_thread_port.h进行修改

如下所示:

只有一个put_px()函数需要自己根据屏幕类型去实现,即画点函数

  1 /**
  2  * @file lv_port_disp_templ.c
  3  *
  4  */
  5 
  6 /*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
  7 #if 1
  8 
  9 /*********************
 10  *      INCLUDES
 11  *********************/
 12 #include "lv_port_disp.h"
 13 #include "../../lvgl.h"
 14 #include "main.h"
 15 #include "custom.h"
 16 
 17 /*********************
 18  *      DEFINES
 19  *********************/
 20 #define ONE_BUFFER 1
 21 #define TWO_BUFFER 0
 22 
 23 #define COLOR_SIZE         (CLCD_WIDTH * CLCD_HEIGHT)
 24 /**********************
 25  *      TYPEDEFS
 26  **********************/
 27 
 28 /**********************
 29  *  STATIC PROTOTYPES
 30  **********************/
 31 static void disp_init(void);
 32 
 33 static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
 34 //static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
 35 //        const lv_area_t * fill_area, lv_color_t color);
 36 
 37 /**********************
 38  *  STATIC VARIABLES
 39  **********************/
 40 
 41 /**********************
 42  *      MACROS
 43  **********************/
 44 
 45 /**********************
 46  *   GLOBAL FUNCTIONS
 47  **********************/
 48 
 49 void lv_port_disp_init(void)
 50 {
 51     /*-------------------------
 52      * Initialize your display
 53      * -----------------------*/
 54     disp_init();
 55 
 56     /*-----------------------------
 57      * Create a buffer for drawing
 58      *----------------------------*/
 59 
 60     /**
 61      * LVGL requires a buffer where it internally draws the widgets.
 62      * Later this buffer will passed to your display driver's `flush_cb` to copy its content to your display.
 63      * The buffer has to be greater than 1 display row
 64      *
 65      * There are 3 buffering configurations:
 66      * 1. Create ONE buffer:
 67      *      LVGL will draw the display's content here and writes it to your display
 68      *
 69      * 2. Create TWO buffer:
 70      *      LVGL will draw the display's content to a buffer and writes it your display.
 71      *      You should use DMA to write the buffer's content to the display.
 72      *      It will enable LVGL to draw the next part of the screen to the other buffer while
 73      *      the data is being sent form the first buffer. It makes rendering and flushing parallel.
 74      *
 75      * 3. Double buffering
 76      *      Set 2 screens sized buffers and set disp_drv.full_refresh = 1.
 77      *      This way LVGL will always provide the whole rendered screen in `flush_cb`
 78      *      and you only need to change the frame buffer's address.
 79      */
 80 
 81     /* Example for 1) */
 82     static lv_disp_draw_buf_t draw_buf_dsc_1;
 83     static lv_color_t buf_1[COLOR_SIZE];                          /*A buffer for 10 rows*/
 84     lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, COLOR_SIZE);   /*Initialize the display buffer*/
 85 
 86     /* Example for 2) */
 87     //static lv_disp_draw_buf_t draw_buf_dsc_2;
 88     //static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10];                        /*A buffer for 10 rows*/
 89     //static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10];                        /*An other buffer for 10 rows*/
 90     //lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*/
 91 
 92     /* Example for 3) also set disp_drv.full_refresh = 1 below*/
 93     //static lv_disp_draw_buf_t draw_buf_dsc_3;
 94     //static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES];            /*A screen sized buffer*/
 95     //static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES];            /*An other screen sized buffer*/
 96     //lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX);   /*Initialize the display buffer*/
 97 
 98     /*-----------------------------------
 99      * Register the display in LVGL
100      *----------------------------------*/
101 
102     static lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/
103     lv_disp_drv_init(&disp_drv);                    /*Basic initialization*/
104 
105     /*Set up the functions to access to your display*/
106 
107     /*Set the resolution of the display*/
108     disp_drv.hor_res = CLCD_HEIGHT;
109     disp_drv.ver_res = CLCD_WIDTH;
110 
111     /*Used to copy the buffer's content to the display*/
112     disp_drv.flush_cb = disp_flush;
113 
114     /*Set a display buffer*/
115     disp_drv.draw_buf = &draw_buf_dsc_1;
116 
117     /*Required for Example 3)*/
118     //disp_drv.full_refresh = 1
119 
120     /* Fill a memory array with a color if you have GPU.
121      * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
122      * But if you have a different GPU you can use with this callback.*/
123     //disp_drv.gpu_fill_cb = gpu_fill;
124 
125     /*Finally register the driver*/
126     lv_disp_drv_register(&disp_drv);
127 }
128 
129 /**********************
130  *   STATIC FUNCTIONS
131  **********************/
132 
133 /*Initialize your display and the required peripherals.*/
134 static void disp_init(void)
135 {
136     /*You code here*/
137     drv_clcd_init();
138 }
139 
140 /*Flush the content of the internal buffer the specific area on the display
141  *You can use DMA or any hardware acceleration to do this operation in the background but
142  *'lv_disp_flush_ready()' has to be called when finished.*/
143 static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
144 {
145     /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
146     #if 1
147     int32_t x;
148     int32_t y;
149     for(y = area->y1; y <= area->y2; y++)
150     {
151         for(x = area->x1; x <= area->x2; x++)
152         {
153             /*Put a pixel to the display. For example:*/
154             put_px(x, y, *((u16*)(color_p)));
155             color_p++;
156         }
157     }
158     #endif
159 
160     //LCD_Color_Fill(area->x1, area->y1, area->x2, area->y2, (uint16_t*)color_p);
161 
162     /*IMPORTANT!!!
163      *Inform the graphics library that you are ready with the flushing*/
164     lv_disp_flush_ready(disp_drv);
165 }
166 #if LV_USE_LOG
167 static void lv_rt_log(const char *buf)
168 {
169     SYSTEM_DEBUG(buf);
170 }
171 #endif /* LV_USE_LOG */
172 lv_ui guider_ui;
173 
174 void lv_100ask_demo_course_2_1_1(void)
175 {
176     #if 0
177     lv_obj_t * obj = lv_obj_create(lv_scr_act());
178     lv_obj_set_size(obj, LV_PCT(100), LV_PCT(10));
179     lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0);
180     #endif
181     setup_ui(&guider_ui);
182 
183     lv_obj_t * label = lv_label_create(lv_scr_act());
184     lv_label_set_text_fmt(label, "ver:%d.%d.%d\n",LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);
185     lv_obj_align(label, LV_ALIGN_DEFAULT, 0, 0);
186     lv_label_set_recolor(label,1);
187 
188 }
189 
190 static void lvgl_thread_entry(void *parameter)
191 {
192     #if LV_USE_LOG
193     lv_log_register_print_cb(lv_rt_log);
194     #endif /* LV_USE_LOG */
195     lv_init();
196     lv_port_disp_init();
197     //lv_port_indev_init();
198     //lv_user_gui_init();
199     //lv_disp_set_rotation(NULL,LV_DISP_ROT_90);
200 
201 #if 0
202     lv_100ask_demo_course_2_1_1();
203 #endif
204 
205     /* handle the tasks of LVGL */
206     while(1)
207     {
208         lv_task_handler();
209         rt_thread_mdelay(1);
210 
211     }
212 }
213 struct rt_thread lvgl_thread;
214 static rt_uint8_t task1_stack[4096];
215 
216 static int lvgl_thread_init(void)
217 {
218     rt_err_t err;
219 
220     err = rt_thread_init(&lvgl_thread, "LVGL", lvgl_thread_entry, RT_NULL, &task1_stack[0], sizeof(task1_stack), 2, 0);
221     if(err != RT_EOK)
222     {
223         SYSTEM_DEBUG("Failed to create LVGL thread");
224         return -1;
225     }
226     rt_thread_startup(&lvgl_thread);
227 
228     return 0;
229 }
230 INIT_ENV_EXPORT(lvgl_thread_init);
231 
232 
233 /*OPTIONAL: GPU INTERFACE*/
234 
235 /*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
236 //static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
237 //                    const lv_area_t * fill_area, lv_color_t color)
238 //{
239 //    /*It's an example code which should be done by your GPU*/
240 //    int32_t x, y;
241 //    dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
242 //
243 //    for(y = fill_area->y1; y <= fill_area->y2; y++) {
244 //        for(x = fill_area->x1; x <= fill_area->x2; x++) {
245 //            dest_buf[x] = color;
246 //        }
247 //        dest_buf+=dest_width;    /*Go to the next line*/
248 //    }
249 //}
250 
251 
252 #else /*Enable this file at the top*/
253 
254 /*This dummy typedef exists purely to silence -Wpedantic.*/
255 typedef int keep_pedantic_happy;
256 #endif

 我的屏幕画点函数如下:

 1 // 设置光标位置
 2 void LCD_SetCursor(uint16_t x, uint16_t y)
 3 {
 4 LCD_WR_REG(0x2A);
 5 LCD_WR_DATA(x);
 6 //LCD_WR_DATA((CLCD_HEIGHT- 1) & 0xFF);
 7 LCD_WR_DATA(x);
 8 
 9 LCD_WR_REG(0x2B);
10 LCD_WR_DATA(y);
11 //LCD_WR_DATA((CLCD_WIDTH- 1) & 0xFF);
12 LCD_WR_DATA(y);
13 
14 //LCD_WR_REG(0x2c);//
15 }
16 
17 void put_px(u16 x,u16 y, u16 color)
18 {
19 LCD_SetCursor(x, y);
20 LCD_WR_REG(0x2C);
21 LCD_WR_DATA(color);
22 }

 

标签:disp,color,快速,drv,lv,buffer,LVGL,buf,移植
From: https://www.cnblogs.com/ycpkbql/p/17858689.html

相关文章

  • Java开发者的Python快速进修指南:网络编程及并发编程
    今天我们将对网络编程和多线程技术进行讲解,这两者的原理大家都已经了解了,因此我们主要关注的是它们的写法区别。虽然这些区别并不是非常明显,但我们之所以将网络编程和多线程一起讲解,是因为在学习Java的socket知识时,我们通常会将它们结合使用,以实现服务器对多个客户端连接的阻塞IO......
  • Java开发者的Python快速进修指南:自定义模块及常用模块
    好的,按照我们平常的惯例,我先来讲一下今天这节课的内容,以及Java和Python在某些方面的相似之处。Python使用import语句来导入包,而Java也是如此。然而,两者之间的区别在于Python没有类路径的概念,它直接使用.py文件的文件名作为导入路径,并将其余的工作交给Python解释器来扫描和处理。另......
  • XcodesApp快速下载切换指定版本的xcode
    XcodesApp地址:https://github.com/RobotsAndPencils/XcodesApp⭐️:3.6k语言:Swift作为一名Apple开发者,你的macOS上是否经常会安装多个版本的Xcode呢?特别是当Xcode新的测试版本出来后。然后是否需要经常在多个Xcode版本之间切换呢?这些推荐一个开源工具,是目前安装和在......
  • Java开发者的Python快速进修指南:面向对象进阶
    在上一期中,我们对Python中的对象声明进行了初步介绍。这一期,我们将深入探讨对象继承、组合以及多态这三个核心概念。不过,这里不打算赘述太多理论,因为我们都知道,Python与Java在这些方面的主要区别主要体现在语法上。例如,Python支持多重继承,这意味着一个类可以同时继承多个父类的属性......
  • Java开发者的Python快速进修指南:面向对象--高级篇
    首先,让我来介绍一下今天的主题。今天我们将讨论封装、反射以及单例模式。除此之外,我们不再深入其他内容。关于封装功能,Python与Java大致相同,但写法略有不同,因为Python没有修饰符。而对于反射来说,我认为它比Java简单得多,不需要频繁地获取方法和属性,而是有专门的方法来实现。最后,我......
  • 通过 docker-compose 快速部署 Rancher 保姆级教程
    目录一、概述二、开始编排部署Rancher1)部署docker2)部署docker-compose3)创建网络4)构建镜像5)编排docker-compose.yaml部署6)接入K8s集群1)部署k8s集群测试(已有可忽略)2)k8s上执行命令接入集群一、概述Rancher是一个开源的容器管理平台,它为企业提供了一个简化容器化应用部署......
  • 一个NET8 AOT编译的辅助项目,让你的任何可执行应用快速部署为服务
    ......
  • 快速上手llama2.c
    title:快速上手llama2.cbanner_img:https://github.com/karpathy/llama2.c/blob/master/assets/llama_cute.jpgdate:2023-7-2516:19:00tags:-踩坑快速上手llama2.cllama2.c一个完整的解决方案,可以使用PyTorch从头开始训练的Llama2LLM(LightweightLanguageModel)模型......
  • 快速上手llama2.c(更新版)
    title:快速上手llama2.c(更新版)banner_img:https://github.com/karpathy/llama2.c/blob/master/assets/llama_cute.jpgdate:2023-7-2816:31:00tags:-踩坑快速上手llama2.c(更新版)在上一次我同时在我的博客和知乎发布了快速上手llama2.c之后,我一个小透明也收获了不......
  • 让电脑开机飞起,打开快速启动功能
    一、介绍  正常配置的电脑,开机在两分钟以上就属于较慢的范畴,可以通过Win10系统中的快速启动功能提高开机速度。二、操作流程1、打开控制面板,选择硬件和声音;2、选择更改电源按钮的功能;3、勾上启用快速启动(推荐);4、如果是灰色不能操作,点击上面的更改当前不可用的设置即可。三、其他......