HPM6700/6400 display control system (LCD and 2D graphics acceleration unit, LVGL)
[Copy link]
The HPM6700/6400 series MCU is a high-performance real-time RISC-V microcontroller from Shanghai Xianji Semiconductor Technology Co., Ltd., which provides great computing power, efficient control capabilities and rich multimedia functions for industrial automation and edge computing applications. The HPM6700/6400 comes with a display control system, including an LCD controller and a 2D graphics acceleration unit, which is also very powerful and can easily drive a 1366x768 high-resolution LCD screen and achieve a high refresh rate of 60fps.
This article mainly introduces the display control system of HPM6700/6400 , including LCD controller and 2D graphics acceleration unit, and uses the LVGL graphics library to develop application examples to facilitate developers to quickly develop.
The graphic display interface LCDC of the HPM6700/6400 series supports connecting to a variety of LCD (TFT) displays of different types and resolutions. LCDC supports 24-bit parallel data lines, clock signal PCLK, and HSYNC and VSYNC synchronization signals. LCDC can act as a bus master to read image data from on-chip and off-chip memories and send them to an external display. The features of LCDC are as follows:
-
Support up to 24-bit RGB display interface;
-
Built-in DMA, reads video memory data as bus master;
-
Supports configurable resolution displays with refresh rates up to 1366x768, 60 fps;
-
Support multiple data formats input ARGB8888, RGB565, YUV422/YCbCr422, Y8, 1bpp, 2bpp, 4bpp and 8bpp;
-
Supports up to 8 layers of Alpha Blending, of which 2 main layers support progressive YUV422/YCbCr422;
-
The maximum pixclk supported is 85MHz.
LCDC Functional Block Diagram
2D Graphics Acceleration Unit (PDMA)
-
This product supports 1 2D graphics acceleration unit PDMA. PDMA supports processing line-by-line image data and supports processing graphics of various sizes and color formats by pixel;
-
Supports fetching data from two layers at the same time, and each layer can be enabled and controlled independently;
-
Support image format conversion, including ARGB8888, RGB565, YUV422H1P image conversion;
-
Support image rotation of 0°/90°/180°/270°;
-
Support horizontal and vertical flip;
-
Support image scaling, X/Y stretching and compression;
-
Support image screenshots.
PDMA Functional Block Diagram
LVGL Application Development
1. Introduction to LVGL
LVGL (Lightweight and Versatile Graphics Library) is a free, open-source graphics library that provides everything you need to create embedded GUIs with easy-to-use graphical elements, beautiful visual effects, and a low memory footprint.
Key Features:
-
Powerful building blocks such as buttons, charts, lists, sliders, images, etc.;
-
Advanced graphics with animation, anti-aliasing, opacity, smooth scrolling Various input devices such as touchpad, mouse, keyboard, encoder, etc.;
-
Support multiple languages with UTF-8 encoding;
-
Multiple display support, such as TFT, monochrome display;
-
Fully customizable graphic elements;
-
Independent of any microcontroller or display used hardware;
-
Scalable to operate with very little memory (64 KB flash, 16 KB RAM);
-
Operating system, external storage and GPU are supported but not required;
-
Single framebuffer operation, even with advanced graphics effects;
-
Written in C for maximum compatibility (compatible with C++);
-
The simulator enables embedded GUI design on a PC without embedded hardware.
-
Portable to MicroPython;
-
Tutorials, examples, and themes to get started quickly;
-
Rich documentation tutorials;
-
Free and open source under the MIT license.
2. LVGL transplantation and adaptation
The official has ported and adapted LVGL, the code structure is as follows:
./lvgl library itself
./lv_drivers Display and input device drivers
./lv_examples Examples and demonstrations
Lvgl official website (https://docs.lvgl.io)
Lvgl official blog site (https://blog.lvgl.io)
Sim online simulator website (https://sim.lvgl.io)
lv_sim_... Simulator projects for various IDEs and platforms
lv_port_... Porting to other development boards
lv_binding_... Bindings to other languages
lv _… Porting to other platforms
Among them, lvgl, lv_examples, and lv_drivers are the most maintained and focused core repositories.
lv_drivers display interface:
To set up the display, the lv_disp_draw_buf_t and lv_disp_drv_t variables must be initialized.
lv_disp_draw_buf_t structure that stores display buffer information
lv_disp_drv_t HAL registers the display driver, interacts with the display, and handles graphics-related structures and callback functions.
Display Buffer:
Regarding the buffer size, there are 3 cases:
(1) One buffer: LVGL saves the content of the screen into a buffer and sends it to the display. The buffer can be smaller than the screen. In this case, the larger area will be redrawn into multiple parts. If only a small area changes (such as pressing a button), only that part of the area will be refreshed.
(2) Two non-screen-sized buffers: LVGL with two buffers can use one as the display buffer while sending the contents of the other buffer to the background display. DMA or other hardware should be used to transfer data to the display to allow the CPU to draw at the same time. In this way, rendering and refreshing are processed in parallel. Similar to the case of one buffer, if the buffer is smaller than the area to be refreshed, LVGL will draw the display content in blocks.
(3) Two screen-sized buffers: In contrast to two non-screen-sized buffers, LVGL will always provide the contents of the entire screen, not just chunks. This way, the driver can simply change the address of the frame buffer to the buffer received from LVGL. Therefore, this approach works well when the MCU has an LCD/TFT interface and the frame buffer is just a location in RAM.
Display Driver:
Once the buffer initialization is ready, the display driver needs to be initialized.
To initialize lv_disp_drv_t, you need to use lv_disp_drv_init(&disp_drv) to initialize. Finally, to register the display device for LVGL, you need to call lv_disp_drv_register(&disp_drv).
In the simplest case, only the following two fields of lv_disp_drv_t need to be set:
draw_buf Pointer to an initialized lv_disp_buf_t variable.
flush_cb callback function, used to copy the contents of the buffer to a specific area of the display. When the flush is ready, you need to call lv_disp_flush_ready(). LVGL may render the screen in multiple blocks, so flush_cb is called multiple times. Use lv_disp_flush_is_last() to see which block was rendered last.
Among them, there are some optional data fields:
hor_res Horizontal resolution of the display. (Defaults to LV_HOR_RES_MAX in lv_conf.h)
ver_res The vertical resolution of the display. (Defaults to LV_VER_RES_MAX in lv_conf.h)
color_chroma_key Color keying supports transparent colors. (Default is LV_COLOR_TRANSP in lv_conf.h)
user_data Custom user data of the driver. Its type can be modified in lv_conf.h.
anti-aliasing Use anti-aliasing (edge smoothing). Defaults to LV_ANTIALIAS in lv_conf.h.
rotated If 1 swap hor_res and ver_res. LVGL draws in the same direction in both cases (lines from top to bottom), so you also need to reconfigure the driver to change the fill direction for your display.
screen_transp If 1, the screen can have transparent or opaque style. Requires LV_COLOR_SCREEN_TRANSP to be enabled in lv_conf.h.
To use the GPU, the following callbacks can be used:
gpu_fill_cb fills an area in memory with color.
gpu_blend_cb blends two memory buffers using opacity.
gpu_wait_cb If any GPU function returns while the GPU is still running LVGL, this function will be used when you need to ensure the GPU is ready for rendering.
Some other optional callbacks to make working with monochrome, grayscale or other non-standard RGB displays easier and more optimized:
rounder_cb Rounds the coordinates of the area to be redrawn. E.g. 2x2 pixels can be converted to 2x8. This can be used if the display controller can only refresh areas of a certain height or width (usually 8 px high for monochrome displays).
set_px_cb Write a custom function for display buffer. This can be used to store pixels more compactly if the display has a special color format. (e.g. 1-bit monochrome, 2-bit grayscale, etc.). This way the buffer used in lv_disp_buf_t can be smaller to hold only the number of bits needed for a given region size. set_px_cb does not work with two screen sized buffers for display buffer configuration.
monitor_cb callback function tells how many pixels were refreshed in how much time.
clean_dcache_cb Callback to clear all caches related to display
lv_drivers display interface:
To set up the input device, you must initialize the lv_indev_drv_t variable, the type (indev_drv.type) can be:
LV_INDEV_TYPE_POINTER Touchpad or mouse
LV_INDEV_TYPE_KEYPAD Keyboard or keypad
LV_INDEV_TYPE_ENCODER Encoder with left, right, push options
LV_INDEV_TYPE_BUTTON External button presses the screen
3. Application Development
There are many functional controls in the LVGL graphics library, which will not be introduced in detail here. For detailed API introduction, please refer to the LVGL official website.
The main functions of LVGL controls are:
Before using the lvgl graphics library, we must also initialize lvgl and other related components. The order of initialization is:
Call lv_init() to initialize the lvgl library;
Initialize the driver;
Register display and input device drivers in LVGL;
Call lv_tick_inc(x) every x milliseconds in the interrupt to inform lvgl of the elapsed time;
Every x milliseconds, lv_task_handler() is called regularly to handle tasks related to lvgl.
SquareLine_Studio Designer:
(1) Create a project
(2) Control layout design
(4) Code adaptation project
(5) Add event response code
Operation effect:
Performance Testing:
-
FPS frame rate: the number of frames per second that the LCD graphics refresh;
-
LVGL will refresh the screen regularly through internal ticks;
-
10 means 1000ms/10ms=100FPS;
-
This macro defines the upper limit of LVGL screen refresh frame rate, setting the full frame rate to 100 frames;
-
Use full-size double buffer.
Test results:
This article introduces the HPM6700/6400 LCD controller and 2D graphics acceleration unit module, as well as the LVGL graphics interface library functions and porting adaptation points, and develops an application example based on the LVGL graphics interface library to drive the LCD screen . According to the measured results, the LCD frame rate can reach 60fps . The official HPM-SDK has ported and adapted the LVGL graphics library, and also provides a demo example based on LVGL. Users can use the HPM6700/6400 SDK to complete LCD-related application development very conveniently.
|