当前位置:网站首页>Lvgl8.1 hi3536c platform use

Lvgl8.1 hi3536c platform use

2022-06-12 04:56:00 hi_ LeTian

LVGL8.1 Hi3536C Platform use

Why use LVGL

There are still many embedded platforms UI The library of can be selected , There are open source 、 Closed source , Free of charge ! I have used emWIN,MiniGUI,QT, It also has its own set of UI library . I learned about it earlier LVGL, But there is no deep understanding , In the past, it seemed that there was still a lot missing UI Components of the library , It may be used in product development. There are many things that need to be handled by yourself .

The products made in recent years have human-computer interaction interfaces , It's all about UI Interface interaction , The main use is QT, But in embedded LINUX System ,QT In memory usage , And display on the large screen , And there are UI When interacting , It was very difficult to respond , With the help of hardware 2D Acceleration is not very easy , High resolution , It still needs a lot of optimization , The effect is not so good . I did one before VGA Output embedded products , use QT When the output , The refresh speed is obviously slow , Later, the lower floor was also replaced by DFB There are some improvements , But the effect is also average .

In a recent want to , When making new products, we should consider changing other products UI Plan to achieve it , Learned more UI programme , I saw LVGL Of DEMO, It feels like this in embedded systems UI effect , One tight Demo They all feel very modern , Look at the code inside , Realization way , Element attributes , The control methods are very modern . Looking at the code structure, it is very simple , In embedded systems , Keep it simple , It can take a few layers to replace the bottom , The way , It means that we can , Very deep and simple customization in our system , Application products ,UI The functional feeling of is also just suitable .LVGL At the same time, it will be updated soon , Unlike other old ones UI The library basically stops updating or is rarely updated every few years , Native controls can only be described as old , The operating experience is also very old MFC Style experience .

LVGL Related websites

Official website

https://lvgl.io/

Github Code

https://github.com/lvgl

Use version

Here we use the latest one directly 8.1 Version of .

Download the corresponding source code

LVGL

lvgl-8.1.0.tar.gz
LVGL UI library .

LV_DRIVERS

lv_drivers-release-v8.1
The bottom layer drawing method is involved, such as Framebuffer The way , still DRM The way , Whether to use SDL, Input and output such as mouse , keyboard , Touch, etc .

LV_PORT

lv_port_linux_frame_buffer-master, Use here Framebuffer The way , So in git Download a configured project directly from .

lv_demos

lv_demos-release-v8.1 Some corresponding demo.

compile LVGL

  • 1: decompression lv_port_linux_frame_buffer-master In a directory , Empty... Will be used in the directory lv_demos,lv_drivers,lvgl Empty directory , And there are related configuration files ;

  • 2: decompression lvgl-8.1.0.tar.gz ,lv_drivers-release-v8.1, And put it in the previous step lv_port in ;

  • 3: To facilitate integration with applications , We put LVGL Compile into a library , Here's a change lv_port Inside Makefile, Add the following configuration to it :

          lib: $(AOBJS) $(COBJS)
            $(AR) rv liblvgl.a $(AOBJS) $(COBJS)
    
  • 4: In this way, we can integrate our UI 了 .

In Haisi Hi3536c Run in LVGL

If you want to Hi3536c Run on the platform lvgl The program , We basically need the following two things in the first step :

  • 1: initialization Hi3536c Upper mpp Some modules in the system, such as vo,hifb;
  • 2: function LVGL Code ;

Here it is PUPANVR Project realization , stay PUPANVR There is a hal_media The library of , The initialization of hardware related platforms is implemented in this library .
The following code implements the operation LVGL Of Demo operation :

	#include "lvgl/examples/lv_examples.h"
	#include "lvgl/lvgl.h"
	#include "lvgl/lv_port_indev.h"
	#include "lv_drivers/display/fbdev.h"
	#include "lv_drivers/indev/evdev.h"
	#include "lv_demos/lv_demo.h"
	#include <unistd.h>
	#include <pthread.h>
	#include <time.h>
	#include <sys/time.h>

	int lvgl_test(void)
	{
		/*LittlevGL init*/
		lv_init();

		/*Linux frame buffer device init*/
		fbdev_init();


		/*A small buffer for LittlevGL to draw the screen's content*/
		static lv_color_t buf[DISP_BUF_SIZE];

		/*Initialize a descriptor for the buffer*/
		static lv_disp_draw_buf_t disp_buf;
		lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);

		/*Initialize and register a display driver*/
		static lv_disp_drv_t disp_drv;
		lv_disp_drv_init(&disp_drv);
		disp_drv.draw_buf   = &disp_buf;
		disp_drv.flush_cb   = fbdev_flush;
		disp_drv.hor_res    = 1920;
		disp_drv.ver_res    = 1080;
		lv_disp_drv_register(&disp_drv);
		
		//lv_port_indev_init();

		/*Create a Demo*/
		lv_demo_widgets();
		//lv_demo_benchmark();
		//lv_demo_keypad_encoder();
		//lv_demo_music();
		//lv_demo_stress();

		//lv_example_arc_1();
		/*Handle LitlevGL tasks (tickless mode)*/
		while(1) {
			lv_task_handler();
			usleep(5000);
		}

		return 0;
	}

	int main(int argc, char** argv)
	{
		int ret = 0;
		ret = sys_init();
		if(ret != 0)
		{
			LOG(ERROR) << "sys_init failure! ret:" << ret << endl;
			return -1;
		}

		ret = hal_media_init();
		if(ret != 0)
		{
			LOG(ERROR) << "hal_media_init failure!" << endl;
			return -1;
		}

		
		lvgl_test();

		while(1)
		{
			sleep(1);
		}

		return 0;
	}

hal_media_init Initializes the operation of Haspin , lvgl_test That is to call lvgl Of demo Program .

Add mouse support

Use here lv_drivers/indev/evdev.h Method to introduce mouse support .
First, in the lv_drivers Inside USE_EVDEV Macro on , In the code above lvgl_test() Add one indev Device operation registration support for .

	lv_indev_t * indev_mouse;

	int lv_indev_init()
	{
		static lv_indev_drv_t indev_drv;
		evdev_init();

		/*Register a mouse input device*/
		lv_indev_drv_init(&indev_drv);
		indev_drv.type = LV_INDEV_TYPE_POINTER;
		indev_drv.read_cb = evdev_read;
		indev_mouse = lv_indev_drv_register(&indev_drv);

		/*Set cursor. For simplicity set a HOME symbol now.*/
		lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act());
		lv_img_set_src(mouse_cursor, LV_SYMBOL_SETTINGS);
		lv_indev_set_cursor(indev_mouse, mouse_cursor);

		return 0;
	}
	
 stay lvgl_test Inside  lv_disp_drv_register And call lv_indev_init that will do !

Running like this Demo Can UI Using the mouse to interact !
UI It's fresh , Modern feeling , There are many kinds of mobile phones nowadays , The way of platform interaction can be reflected in the above ! Omit the embedded system , stay UI Special effects need to be achieved in .

From the above use process ,LVGL Even a complete compilation project has not been completed ! But this just shows his simplicity ! It's not a fault , The opposite is more like a good thing !

There are few levels of abstraction , Easy to transplant ! There is no other burden !

原网站

版权声明
本文为[hi_ LeTian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010623364881.html