App:Library:LVGL:docs:Porting:Display interface
https://docs.lvgl.io/8.2/porting/display.html
英文 | 自動翻訳 |
---|---|
Display interface
英文 | 自動翻訳 |
---|---|
To register a display for LVGL, a
|
Draw buffer
英文 | 自動翻訳 |
---|---|
Draw buffer(s) are simple array(s) that LVGL uses to render the screen content. Once rendering is ready the content of the draw buffer is sent to the display using the A draw buffer can be initialized via a /*A static or global variable to store the buffers*/
static lv_disp_draw_buf_t disp_buf;
/*Static or global buffer(s). The second buffer is optional*/
static lv_color_t buf_1[MY_DISP_HOR_RES * 10];
static lv_color_t buf_2[MY_DISP_HOR_RES * 10];
/*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, MY_DISP_HOR_RES*10);
Note that As you can see above, the draw buffer may be smaller than the screen. In this case, larger areas are redrawn in smaller segments that fit into the draw buffer(s). If only a small area changes (e.g. a button is pressed) then only that area will be refreshed. A larger buffer results in better performance but above 1/10 screen sized buffer(s) there is no significant performance improvement. Therefore it's recommended to choose the size of the draw buffer(s) to be at least 1/10 screen sized. |
Buffering modes
英文 | 自動翻訳 |
---|---|
There are several settings to adjust the number draw buffers and buffering/refreshing modes. You can measure the performance of different configurations using the benchmark example. |
One buffer
英文 | 自動翻訳 |
---|---|
If only one buffer is used LVGL draws the content of the screen into that draw buffer and sends it to the display. LVGL then needs to wait until the content of the buffer is sent to the display before drawing something new in it. |
Two buffers
英文 | 自動翻訳 |
---|---|
If two buffers are used LVGL can draw into one buffer while the content of the other buffer is sent to the display in the background. DMA or other hardware should be used to transfer data to the display so the MCU can continue drawing. This way, the rendering and refreshing of the display become parallel operations. |
Full refresh
英文 | 自動翻訳 |
---|---|
In the display driver ( |
Direct mode
英文 | 自動翻訳 |
---|---|
If the
The get the redrawn areas to copy use the following functions |
Display driver
英文 | 自動翻訳 |
---|---|
Once the buffer initialization is ready a
Note that |
Mandatory fields
英文 | 自動翻訳 |
---|---|
In the most simple case only the following fields of
|
Optional fields
英文 | 自動翻訳 |
---|---|
There are some optional display driver data fields:
Some other optional callbacks to make it easier and more optimal to work with monochrome, grayscale or other non-standard RGB displays:
LVGL has built-in support to several GPUs (see
|
Examples
英文 | 自動翻訳 |
---|---|
All together it looks like this: static lv_disp_drv_t disp_drv; /*A variable to hold the drivers. Must be static or global.*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.draw_buf = &disp_buf; /*Set an initialized buffer*/
disp_drv.flush_cb = my_flush_cb; /*Set a flush callback to draw to the display*/
disp_drv.hor_res = 320; /*Set the horizontal resolution in pixels*/
disp_drv.ver_res = 240; /*Set the vertical resolution in pixels*/
lv_disp_t * disp;
disp = lv_disp_drv_register(&disp_drv); /*Register the driver and save the created display objects*/
Here are some simple examples of the callbacks: void my_flush_cb(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
*`put_px` is just an example, it needs to implemented by you.*/
int32_t x, y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
put_px(x, y, *color_p);
color_p++;
}
}
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
void my_gpu_fill_cb(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, const lv_area_t * dest_area, const lv_area_t * fill_area, lv_color_t color);
{
/*It's an example code which should be done by your GPU*/
uint32_t x, y;
dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
for(y = fill_area->y1; y < fill_area->y2; y++) {
for(x = fill_area->x1; x < fill_area->x2; x++) {
dest_buf[x] = color;
}
dest_buf+=dest_width; /*Go to the next line*/
}
}
void my_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area)
{
/* Update the areas as needed.
* For example it makes the area to start only on 8th rows and have Nx8 pixel height.*/
area->y1 = area->y1 & 0x07;
area->y2 = (area->y2 & 0x07) + 8;
}
void my_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
/* Write to the buffer as required for the display.
* For example it writes only 1-bit for monochrome displays mapped vertically.*/
buf += buf_w * (y >> 3) + x;
if(lv_color_brightness(color) > 128) (*buf) |= (1 << (y % 8));
else (*buf) &= ~(1 << (y % 8));
}
void my_monitor_cb(lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px)
{
printf("%d px refreshed in %d ms\n", time, ms);
}
void my_clean_dcache_cb(lv_disp_drv_t * disp_drv, uint32)
{
/* Example for Cortex-M (CMSIS) */
SCB_CleanInvalidateDCache();
}
|
Rotation
英文 | 自動翻訳 |
---|---|
LVGL supports rotation of the display in 90 degree increments. You can select whether you'd like software rotation or hardware rotation. If you select software rotation ( There is a noticeable amount of overhead to performing rotation in software. Hardware rotation is available to avoid unwanted slowdowns. In this mode, LVGL draws into the buffer as if your screen width and height were swapped. You are responsible for rotating the provided pixels yourself. The default rotation of your display when it is initialized can be set using the (Note for users upgrading from 7.10.0 and older: these new rotation enum values match up with the old 0/1 system for rotating 90 degrees, so legacy code should continue to work as expected. Software rotation is also disabled by default for compatibility.) Display rotation can also be changed at runtime using the Support for software rotation is a new feature, so there may be some glitches/bugs depending on your configuration. If you encounter a problem please open an issue on GitHub. |
Further reading
英文 | 自動翻訳 |
---|---|
|
API
@description Display Driver HAL interface header file
Typedefs
英文 | 自動翻訳 |
---|---|
typedef struct _lv_disp_draw_buf_t lv_disp_draw_buf_t
typedef struct _lv_disp_drv_t lv_disp_drv_t
typedef struct _lv_disp_t lv_disp_t
|
Enums
英文 | 自動翻訳 |
---|---|
enum lv_disp_rot_t
|
Functions
英文 | 自動翻訳 |
---|---|
void lv_disp_drv_init(lv_disp_drv_t *driver)
void lv_disp_draw_buf_init(lv_disp_draw_buf_t *draw_buf, void *buf1, void *buf2, uint32_t size_in_px_cnt)
lv_disp_t *lv_disp_drv_register(lv_disp_drv_t *driver)
void lv_disp_drv_update(lv_disp_t *disp, lv_disp_drv_t *new_drv)
void lv_disp_remove(lv_disp_t *disp)
void lv_disp_set_default(lv_disp_t *disp)
lv_disp_t *lv_disp_get_default(void)
lv_coord_t lv_disp_get_hor_res(lv_disp_t *disp)
lv_coord_t lv_disp_get_ver_res(lv_disp_t *disp)
lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t *disp)
lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t *disp)
lv_coord_t lv_disp_get_offset_x(lv_disp_t *disp)
lv_coord_t lv_disp_get_offset_y(lv_disp_t *disp)
bool lv_disp_get_antialiasing(lv_disp_t *disp)
lv_coord_t lv_disp_get_dpi(const lv_disp_t *disp)
void lv_disp_set_rotation(lv_disp_t *disp, lv_disp_rot_t rotation)
lv_disp_rot_t lv_disp_get_rotation(lv_disp_t *disp)
lv_disp_t *lv_disp_get_next(lv_disp_t *disp)
lv_disp_draw_buf_t *lv_disp_get_draw_buf(lv_disp_t *disp)
void lv_disp_drv_use_generic_set_px_cb(lv_disp_drv_t *disp_drv, lv_img_cf_t cf) struct _lv_disp_draw_buf_t
struct _lv_disp_drv_t
struct _lv_disp_t
|