Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the transplantation of LVGL on rt-thread?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What is the transplant of LVGL on rt-thread? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Programming of display driver

First of all, according to the lcd driver framework of rt-thread to complete the preparation of the driver, you can refer to the following structure to complete the implementation of related functions.

Struct rt_device_graphic_ops {void (* set_pixel) (const char * pixel, int x, int y); void (* get_pixel) (char * pixel, int x, int y); void (* draw_hline) (const char * pixel, int x1, int x2, int y); void (* draw_vline) (const char * pixel, int x, int y1, int y2) Void (* blit_line) (const char * pixel, int x, int y, rt_size_t size);}

After the completion of the function writing, the operation structure is defined.

Struct rt_device_graphic_ops fsmc_lcd_ops = {LCD_DrawPoint, LCD_ReadPoint, LCD_HLine, RT_NULL, LCD_BlitLine,}

Then, fill in the specific information of the display device and mount the device to the device driver list.

Int drv_lcd_hw_init (void) {rt_err_t result = RT_EOK; struct rt_device * device = & _ lcd.parent; / * memset _ lcd to zero * / memset (& _ lcd, 0x00, sizeof (_ lcd)); _ lcd.lcd_info.bits_per_pixel = 16; _ lcd.lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; device- > type = RT_Device_Class_Graphic # ifdef RT_USING_DEVICE_OPS device- > ops = & lcd_ops;#else device- > init = drv_lcd_init; device- > control = drv_lcd_control;#endif device- > user_data = & fsmc_lcd_ops; rt_device_register (device, "lcd", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE); return result;} INIT_DEVICE_EXPORT (drv_lcd_hw_init); rt-thread display driver docks with LVGL

For a detailed description of the relevant parameters, equipment and migration of lvgl, please see the official migration instructions, which will not be explained too much here.

This part of docking mainly introduces the docking part of lvgl display driver and rt-thread driver interface in lv_port_disp.c file.

Display initialization

This part mainly completes the operation of finding and opening the display device.

/ * Initialize your display and the required peripherals. * / static void disp_init (void) {/ * You code here*/ lcd_device = rt_device_find ("lcd"); if (! lcd_device) {LOG_E ("find% s failed!", "lcd"); return;} rt_device_open (lcd_device, RT_DEVICE_FLAG_RDWR);} display data brushing

This part needs to complete the writing of the display pixel content of the specified area, can carry out pixel operation or row and column operation, and can be adjusted according to the characteristics of its own display screen. The scheme entered in this part will also affect the refresh rate of the display. You need to choose the scheme with the fastest refresh speed.

/ * Flush the content of the internal buffer the specific area on the display * You can use DMA or any hardware acceleration to do this operation in the background but * 'lv_disp_flush_ready ()' has to be called when finished. * / 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; yy2; yforth +) / {/ / for (x = area- > x1; x x2) ) / / {/ * Put a pixel to the display. For example: * / * put_px (x, y, * color_p) * / rt_graphix_ops (lcd_device)-> set_pixel ((const char *) & color_p- > full, x, y); / / color_p++; / /} / /} int32_t y; int32_t width; for (y = area- > y1; yy2) ) {width = (area- > x2-area- > x1 + 1); rt_graphix_ops (lcd_device)-> blit_line ((const char *) & color_p- > full, area- > x1, y, width); color_p + = width;} / * Inform the graphics library that you are ready with the flushing*/ lv_disp_flush_ready (disp_drv);} system call

There are two functions in lvgl that depend on system calls: lv_tick_inc and lv_task_handler (). Note that these two functions cannot be placed in the same thread to avoid errors in the related event response mechanism. We can create a software timer and a task to handle lvgl system calls, respectively.

Rt_thread_t tid; tid = rt_thread_create ("lvgl_task", lvgl_task, RT_NULL, 4096, 20,4); if (tid! = RT_NULL) rt_thread_startup (tid); rt_timer_t timer1 = rt_timer_create ("timer1", lvgl_tick, RT_NULL, 10, RT_TIMER_FLAG_PERIODIC); if (timer1! = RT_NULL) rt_timer_start (timer1)

In lvgl_task, we call the lv_task_handler () function periodically.

Static void lvgl_task (void * parameter) {while (true) {rt_thread_delay (10); lv_task_handler ();}}

Accordingly, in the soft timer, we can inject the time interval into the lv_tick_inc in the timeout processing according to the interval of the software timer.

Static void lvgl_tick (void * parameter) {lv_tick_inc (10);}

So far, the porting and docking of rt-thread and lvgl has been completed, and the application layer code can be written.

This is the answer to the question about how to transplant LVGL on rt-thread. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report