「App:Library:LVGL:docs:Porting:Display interface」の版間の差分
23行目: | 23行目: | ||
| | | | ||
|} | |} | ||
+ | |||
== Draw buffer == | == Draw buffer == | ||
52行目: | 53行目: | ||
| | | | ||
|} | |} | ||
+ | |||
== Buffering modes == | == Buffering modes == | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
There are several settings to adjust the number draw buffers and buffering/refreshing 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. | You can measure the performance of different configurations using the benchmark example. | ||
+ | | | ||
+ | |} | ||
+ | |||
=== One buffer === | === One buffer === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
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. | 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 === | === Two buffers === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
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. | 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 === | === Full refresh === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
In the display driver (<code style="color: #bb0000;">lv_disp_drv_t</code>) enabling the <code style="color: #bb0000;">full_refresh</code> bit will force LVGL to always redraw the whole screen. This works in both ''one buffer'' and ''two buffers'' modes. If <code style="color: #bb0000;">full_refresh</code> is enabled and two screen sized draw buffers are provided, LVGL's display handling works like "traditional" double buffering. This means the <code style="color: #bb0000;">flush_cb</code> callback only has to update the address of the framebuffer (<code style="color: #bb0000;">color_p</code> parameter). This configuration should be used if the MCU has an LCD controller peripheral and not with an external display controller (e.g. ILI9341 or SSD1963) accessed via serial link. The latter will generally be too slow to maintain high frame rates with full screen redraws. | In the display driver (<code style="color: #bb0000;">lv_disp_drv_t</code>) enabling the <code style="color: #bb0000;">full_refresh</code> bit will force LVGL to always redraw the whole screen. This works in both ''one buffer'' and ''two buffers'' modes. If <code style="color: #bb0000;">full_refresh</code> is enabled and two screen sized draw buffers are provided, LVGL's display handling works like "traditional" double buffering. This means the <code style="color: #bb0000;">flush_cb</code> callback only has to update the address of the framebuffer (<code style="color: #bb0000;">color_p</code> parameter). This configuration should be used if the MCU has an LCD controller peripheral and not with an external display controller (e.g. ILI9341 or SSD1963) accessed via serial link. The latter will generally be too slow to maintain high frame rates with full screen redraws. | ||
+ | | | ||
+ | |} | ||
+ | |||
=== Direct mode === | === Direct mode === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
If the <code style="color: #bb0000;">direct_mode</code> flag is enabled in the display driver LVGL will draw directly into a screen sized frame buffer. That is the draw buffer(s) needs to be screen sized. It this case <code style="color: #bb0000;">flush_cb</code> will be called only once when all dirty areas are redrawn. With <code style="color: #bb0000;">direct_mode</code> the frame buffer always contains the current frame as it should be displayed on the screen. If 2 frame buffers are provided as draw buffers LVGL will alter the buffers but always draw only the dirty areas. Therefore the 2 buffers needs to synchronized in <code style="color: #bb0000;">flush_cb</code> like this: | If the <code style="color: #bb0000;">direct_mode</code> flag is enabled in the display driver LVGL will draw directly into a screen sized frame buffer. That is the draw buffer(s) needs to be screen sized. It this case <code style="color: #bb0000;">flush_cb</code> will be called only once when all dirty areas are redrawn. With <code style="color: #bb0000;">direct_mode</code> the frame buffer always contains the current frame as it should be displayed on the screen. If 2 frame buffers are provided as draw buffers LVGL will alter the buffers but always draw only the dirty areas. Therefore the 2 buffers needs to synchronized in <code style="color: #bb0000;">flush_cb</code> like this: | ||
74行目: | 113行目: | ||
The get the redrawn areas to copy use the following functions <code style="color: #bb0000;">_lv_refr_get_disp_refreshing()</code> returns the display being refreshed <code style="color: #bb0000;">disp->inv_areas[LV_INV_BUF_SIZE]</code> contains the invalidated areas <code style="color: #bb0000;">disp->inv_area_joined[LV_INV_BUF_SIZE]</code> if 1 that area was joined into another one and should be ignored <code style="color: #bb0000;">disp->inv_p</code> number of valid elements in <code style="color: #bb0000;">inv_areas</code> | The get the redrawn areas to copy use the following functions <code style="color: #bb0000;">_lv_refr_get_disp_refreshing()</code> returns the display being refreshed <code style="color: #bb0000;">disp->inv_areas[LV_INV_BUF_SIZE]</code> contains the invalidated areas <code style="color: #bb0000;">disp->inv_area_joined[LV_INV_BUF_SIZE]</code> if 1 that area was joined into another one and should be ignored <code style="color: #bb0000;">disp->inv_p</code> number of valid elements in <code style="color: #bb0000;">inv_areas</code> | ||
+ | | | ||
+ | |} | ||
+ | |||
== Display driver == | == Display driver == | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
Once the buffer initialization is ready a <code style="color: #bb0000;">lv_disp_drv_t</code> display driver needs to be: | Once the buffer initialization is ready a <code style="color: #bb0000;">lv_disp_drv_t</code> display driver needs to be: | ||
83行目: | 130行目: | ||
Note that <code style="color: #bb0000;">lv_disp_drv_t</code> also needs to be a static, global or dynamically allocated variable. | Note that <code style="color: #bb0000;">lv_disp_drv_t</code> also needs to be a static, global or dynamically allocated variable. | ||
+ | | | ||
+ | |} | ||
+ | |||
=== Mandatory fields === | === Mandatory fields === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
In the most simple case only the following fields of <code style="color: #bb0000;">lv_disp_drv_t</code> need to be set: | In the most simple case only the following fields of <code style="color: #bb0000;">lv_disp_drv_t</code> need to be set: | ||
91行目: | 146行目: | ||
* <code style="color: #bb0000;">ver_res</code> vertical resolution of the display in pixels. | * <code style="color: #bb0000;">ver_res</code> vertical resolution of the display in pixels. | ||
* <code style="color: #bb0000;">flush_cb</code> a callback function to copy a buffer's content to a specific area of the display. <code style="color: #bb0000;">lv_disp_flush_ready(&disp_drv)</code> needs to be called when flushing is ready. LVGL might render the screen in multiple chunks and therefore call <code style="color: #bb0000;">flush_cb</code> multiple times. To see if the current one is the last chunk of rendering use <code style="color: #bb0000;">lv_disp_flush_is_last(&disp_drv)</code>. | * <code style="color: #bb0000;">flush_cb</code> a callback function to copy a buffer's content to a specific area of the display. <code style="color: #bb0000;">lv_disp_flush_ready(&disp_drv)</code> needs to be called when flushing is ready. LVGL might render the screen in multiple chunks and therefore call <code style="color: #bb0000;">flush_cb</code> multiple times. To see if the current one is the last chunk of rendering use <code style="color: #bb0000;">lv_disp_flush_is_last(&disp_drv)</code>. | ||
+ | | | ||
+ | |} | ||
+ | |||
=== Optional fields === | === Optional fields === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
There are some optional display driver data fields: | There are some optional display driver data fields: | ||
118行目: | 181行目: | ||
* <code style="color: #bb0000;">gpu_fill_cb</code> fill an area in the memory with a color. | * <code style="color: #bb0000;">gpu_fill_cb</code> fill an area in the memory with a color. | ||
* <code style="color: #bb0000;">gpu_wait_cb</code> if any GPU function returns while the GPU is still working, LVGL will use this function when required to make sure GPU rendering is ready. | * <code style="color: #bb0000;">gpu_wait_cb</code> if any GPU function returns while the GPU is still working, LVGL will use this function when required to make sure GPU rendering is ready. | ||
− | + | | | |
+ | |} | ||
=== Examples === | === Examples === | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
All together it looks like this: | All together it looks like this: | ||
<syntaxhighlight lang="C++"> | <syntaxhighlight lang="C++"> | ||
196行目: | 265行目: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | | | ||
+ | |} | ||
+ | |||
== Rotation == | == Rotation == | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
LVGL supports rotation of the display in 90 degree increments. You can select whether you'd like software rotation or hardware rotation. | LVGL supports rotation of the display in 90 degree increments. You can select whether you'd like software rotation or hardware rotation. | ||
211行目: | 288行目: | ||
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. | 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 == | == Further reading == | ||
− | + | {| class="wikitable" | |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
* [https://github.com/lvgl/lvgl/blob/master/examples/porting/lv_port_disp_template.c '''lv_port_disp_template.c'''] for a template for your own driver. | * [https://github.com/lvgl/lvgl/blob/master/examples/porting/lv_port_disp_template.c '''lv_port_disp_template.c'''] for a template for your own driver. | ||
* [https://docs.lvgl.io/8.2/overview/drawing.html '''Drawing'''] to learn more about how rendering works in LVGL. | * [https://docs.lvgl.io/8.2/overview/drawing.html '''Drawing'''] to learn more about how rendering works in LVGL. | ||
* [https://docs.lvgl.io/8.2/overview/display.html '''Display features'''] to learn more about higher level display features. | * [https://docs.lvgl.io/8.2/overview/display.html '''Display features'''] to learn more about higher level display features. | ||
+ | | | ||
+ | |} | ||
+ | |||
== API == | == API == | ||
222行目: | 309行目: | ||
=== Typedefs === | === Typedefs === | ||
− | + | {| class="wikitable" | |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
<span style="background-color: #e7f2fa; color: #2980b9;">typedef struct _lv_disp_draw_buf_t lv_disp_draw_buf_t</span> | <span style="background-color: #e7f2fa; color: #2980b9;">typedef struct _lv_disp_draw_buf_t lv_disp_draw_buf_t</span> | ||
: Structure for holding display buffer information. | : Structure for holding display buffer information. | ||
232行目: | 323行目: | ||
: Display structure. | : Display structure. | ||
:<span style="background-color: #e7f2fa; color: #000000;">'''Note''' : <code style="color: #bb0000;">lv_disp_drv_t</code> should be the first member of the structure.</span> | :<span style="background-color: #e7f2fa; color: #000000;">'''Note''' : <code style="color: #bb0000;">lv_disp_drv_t</code> should be the first member of the structure.</span> | ||
+ | | | ||
+ | |} | ||
+ | |||
=== Enums === | === Enums === | ||
− | + | {| class="wikitable" | |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
<span style="background-color: #e7f2fa; color: #2980b9;">enum lv_disp_rot_t</span> | <span style="background-color: #e7f2fa; color: #2980b9;">enum lv_disp_rot_t</span> | ||
:: ''Values:'' | :: ''Values:'' | ||
244行目: | 342行目: | ||
:: | :: | ||
::: <span style="background-color: #eeeeee;">enumerator LV_DISP_ROT_270</span> | ::: <span style="background-color: #eeeeee;">enumerator LV_DISP_ROT_270</span> | ||
+ | | | ||
+ | |} | ||
=== Functions === | === Functions === | ||
− | + | {| class="wikitable" | |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
<span style="background-color: #e7f2fa; color: #2980b9;">void lv_disp_drv_init(lv_disp_drv_t *driver) </span> | <span style="background-color: #e7f2fa; color: #2980b9;">void lv_disp_drv_init(lv_disp_drv_t *driver) </span> | ||
: Initialize a display driver with default values. It is used to have known values in the fields and not junk in memory. After it you can safely set only the fields you need. | : Initialize a display driver with default values. It is used to have known values in the fields and not junk in memory. After it you can safely set only the fields you need. | ||
498行目: | 602行目: | ||
: <span style="background-color: #eeeeee;">uint32_t last_activity_time</span> | : <span style="background-color: #eeeeee;">uint32_t last_activity_time</span> | ||
:: Last time when there was activity on this display | :: Last time when there was activity on this display | ||
+ | | | ||
+ | |} | ||
---- | ---- | ||
[[App:Library:LVGL:docs:Porting|戻る : Previous]] | [[App:Library:LVGL:docs:Porting|戻る : Previous]] |
2022年6月22日 (水) 12:23時点における版
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
|