| 1 |
.. include:: /include/substitutions.txt |
| 2 |
======== |
| 3 |
Overview |
| 4 |
======== |
| 5 |
|
| 6 |
NXP has integrated LVGL into the MCUXpresso SDK packages for several of our |
| 7 |
microcontrollers as an optional software component, allowing easy evaluation and |
| 8 |
migration into your product design. LVGL is a free and open-source embedded |
| 9 |
graphic library with features that enable you to create embedded GUIs with |
| 10 |
intuitive graphical elements, beautiful visual effects and a low memory |
| 11 |
footprint. The complete graphic framework includes a variety of widgets for you |
| 12 |
to use in the creation of your GUI, and supports more advanced functions such as |
| 13 |
animations and anti-aliasing. |
| 14 |
|
| 15 |
LVGL enables graphics in our free GUI Guider UI tool. It's available for use |
| 16 |
with NXP's general purpose and crossover microcontrollers, providing developers |
| 17 |
with a tool for creating complete, high quality GUI applications with LVGL. |
| 18 |
|
| 19 |
Creating new project with LVGL |
| 20 |
------------------------------ |
| 21 |
|
| 22 |
`Download an SDK for a supported board <https://www.nxp.com/design/software/embedded-software/littlevgl-open-source-graphics-library:LITTLEVGL-OPEN-SOURCE-GRAPHICS-LIBRARY?&tid=vanLITTLEVGL-OPEN-SOURCE-GRAPHICS-LIBRARY>`__ |
| 23 |
today and get started with your next GUI application. It comes fully configured |
| 24 |
with LVGL (and with PXP/VGLite/G2D support if the modules are present), no |
| 25 |
additional integration work is required. |
| 26 |
|
| 27 |
HW acceleration for NXP iMX RT platforms |
| 28 |
---------------------------------------- |
| 29 |
|
| 30 |
Depending on the RT platform used, the acceleration can be done by NXP PXP |
| 31 |
(PiXel Pipeline) and/or the Verisilicon GPU through an API named VGLite. Each |
| 32 |
accelerator has its own context that allows them to be used individually as well |
| 33 |
simultaneously (in LVGL multithreading mode). |
| 34 |
|
| 35 |
HW acceleration for NXP iMX platforms |
| 36 |
---------------------------------------- |
| 37 |
|
| 38 |
On MPU platforms, the acceleration can be done (hardware independent) by NXP G2D |
| 39 |
library. This accelerator has its own context that allows them to be used |
| 40 |
individually as well simultaneously with the CPU (in LVGL multithreading mode). |
| 41 |
|
| 42 |
PXP accelerator |
| 43 |
~~~~~~~~~~~~~~~ |
| 44 |
|
| 45 |
Basic configuration: |
| 46 |
^^^^^^^^^^^^^^^^^^^^ |
| 47 |
|
| 48 |
- Select NXP PXP engine in "lv_conf.h": Set :c:macro:`LV_USE_PXP` to `1`. |
| 49 |
- In order to use PXP as a draw unit, select in "lv_conf.h": Set :c:macro:`LV_USE_DRAW_PXP` to `1`. |
| 50 |
- In order to use PXP to rotate the screen, select in "lv_conf.h": Set :c:macro:`LV_USE_ROTATE_PXP` to `1`. |
| 51 |
- Enable PXP asserts in "lv_conf.h": Set :c:macro:`LV_USE_PXP_ASSERT` to `1`. |
| 52 |
There are few PXP assertions that can stop the program execution in case the |
| 53 |
:c:macro:`LV_ASSERT_HANDLER` is set to `while(1);` (Halt by default). Else, |
| 54 |
there will be logged just an error message via `LV_LOG_ERROR`. |
| 55 |
- If :c:macro:`SDK_OS_FREE_RTOS` symbol is defined, FreeRTOS implementation |
| 56 |
will be used, otherwise bare metal code will be included. |
| 57 |
|
| 58 |
Basic initialization: |
| 59 |
^^^^^^^^^^^^^^^^^^^^^ |
| 60 |
|
| 61 |
PXP draw initialization is done automatically in :cpp:func:`lv_init` once the |
| 62 |
PXP is enabled as a draw unit or to rotate the screen, no user code is required: |
| 63 |
|
| 64 |
.. code-block:: c |
| 65 |
|
| 66 |
#if LV_USE_DRAW_PXP || LV_USE_ROTATE_PXP |
| 67 |
lv_draw_pxp_init(); |
| 68 |
#endif |
| 69 |
|
| 70 |
During PXP initialization, a new draw unit `lv_draw_pxp_unit_t` will be created |
| 71 |
with the additional callbacks, if :c:macro:`LV_USE_DRAW_PXP` is set to `1`: |
| 72 |
|
| 73 |
.. code-block:: c |
| 74 |
|
| 75 |
lv_draw_pxp_unit_t * draw_pxp_unit = lv_draw_create_unit(sizeof(lv_draw_pxp_unit_t)); |
| 76 |
draw_pxp_unit->base_unit.evaluate_cb = _pxp_evaluate; |
| 77 |
draw_pxp_unit->base_unit.dispatch_cb = _pxp_dispatch; |
| 78 |
draw_pxp_unit->base_unit.delete_cb = _pxp_delete; |
| 79 |
|
| 80 |
|
| 81 |
and an addition thread `_pxp_render_thread_cb()` will be spawned in order to |
| 82 |
handle the supported draw tasks. |
| 83 |
|
| 84 |
.. code-block:: c |
| 85 |
|
| 86 |
#if LV_USE_PXP_DRAW_THREAD |
| 87 |
lv_thread_init(&draw_pxp_unit->thread, "pxpdraw", LV_THREAD_PRIO_HIGH, _pxp_render_thread_cb, 2 * 1024, draw_pxp_unit); |
| 88 |
#endif |
| 89 |
|
| 90 |
If `LV_USE_PXP_DRAW_THREAD` is not defined, then no additional draw thread will be created |
| 91 |
and the PXP drawing task will get executed on the same LVGL main thread. |
| 92 |
|
| 93 |
`_pxp_evaluate()` will get called after each task is being created and will |
| 94 |
analyze if the task is supported by PXP or not. If it is supported, then an |
| 95 |
preferred score and the draw unit id will be set to the task. An `score` equal |
| 96 |
to `100` is the default CPU score. Smaller score means that PXP is capable of |
| 97 |
drawing it faster. |
| 98 |
|
| 99 |
`_pxp_dispatch()` is the PXP dispatcher callback, it will take a ready to draw |
| 100 |
task (having the `DRAW_UNIT_ID_PXP` set) and will pass the task to the PXP draw |
| 101 |
unit for processing. |
| 102 |
|
| 103 |
`_pxp_delete()` will cleanup the PXP draw unit. |
| 104 |
|
| 105 |
|
| 106 |
Features supported: |
| 107 |
^^^^^^^^^^^^^^^^^^^ |
| 108 |
|
| 109 |
Several drawing features in LVGL can be offloaded to the PXP engine. The CPU is |
| 110 |
available for other operations while the PXP is running. A RTOS is required to |
| 111 |
block the LVGL drawing thread and switch to another task or suspend the CPU for |
| 112 |
power savings. |
| 113 |
|
| 114 |
Supported draw tasks are available in "src/draw/nxp/pxp/lv_draw_pxp.c": |
| 115 |
|
| 116 |
.. code-block:: c |
| 117 |
|
| 118 |
switch(t->type) { |
| 119 |
case LV_DRAW_TASK_TYPE_FILL: |
| 120 |
lv_draw_pxp_fill(t, t->draw_dsc, &t->area); |
| 121 |
break; |
| 122 |
case LV_DRAW_TASK_TYPE_IMAGE: |
| 123 |
lv_draw_pxp_img(t, t->draw_dsc, &t->area); |
| 124 |
break; |
| 125 |
case LV_DRAW_TASK_TYPE_LAYER: |
| 126 |
lv_draw_pxp_layer(t, t->draw_dsc, &t->area); |
| 127 |
break; |
| 128 |
default: |
| 129 |
break; |
| 130 |
} |
| 131 |
|
| 132 |
Additionally, the screen rotation can be handled by the PXP: |
| 133 |
|
| 134 |
.. code-block::c |
| 135 |
|
| 136 |
void lv_draw_pxp_rotate(const void * src_buf, void * dest_buf, int32_t src_width, int32_t src_height, |
| 137 |
int32_t src_stride, int32_t dest_stride, lv_display_rotation_t rotation, |
| 138 |
lv_color_format_t cf); |
| 139 |
|
| 140 |
- Fill area with color (w/o radius, w/o gradient) + optional opacity. |
| 141 |
- Blit source image RGB565/ARGB888/XRGB8888 over destination. |
| 142 |
RGB565/RGB888/ARGB888/XRGB8888 + optional opacity. |
| 143 |
- Recolor source image RGB565. |
| 144 |
- Scale and rotate (90, 180, 270 degree) source image RGB565. |
| 145 |
- Blending layers (w/ same supported formats as blitting). |
| 146 |
- Rotate screen (90, 180, 270 degree). |
| 147 |
|
| 148 |
|
| 149 |
Known limitations: |
| 150 |
^^^^^^^^^^^^^^^^^^ |
| 151 |
|
| 152 |
- PXP can only rotate the frames in angles that are multiple of 90 degrees. |
| 153 |
- Rotation is not supported for images unaligned to blocks of 16x16 pixels. PXP |
| 154 |
is set to process 16x16 blocks to optimize the system for memory bandwidth and |
| 155 |
image processing time. The output engine essentially truncates any output |
| 156 |
pixels after the desired number of pixels has been written. When rotating a |
| 157 |
source image and the output is not divisible by the block size, the incorrect |
| 158 |
pixels could be truncated and the final output image can look shifted. |
| 159 |
- Recolor or transformation for images w/ opacity or alpha channel can't be |
| 160 |
obtained in a single PXP pipeline configuration. Two or multiple steps would |
| 161 |
be required. |
| 162 |
- Buffer address must be aligned to 64 bytes: set :c:macro:`LV_DRAW_BUF_ALIGN` |
| 163 |
to `64` in "lv_conf.h". |
| 164 |
No stride alignment is required: set :c:macro:`LV_DRAW_BUF_STRIDE_ALIGN` to |
| 165 |
`1` in "lv_conf.h". |
| 166 |
|
| 167 |
Project setup: |
| 168 |
^^^^^^^^^^^^^^ |
| 169 |
|
| 170 |
- Add PXP related source files (and corresponding headers if available) to |
| 171 |
project: |
| 172 |
|
| 173 |
- "src/draw/nxp/pxp/lv_draw_buf_pxp.c": draw buffer callbacks |
| 174 |
- "src/draw/nxp/pxp/lv_draw_pxp_fill.c": fill area |
| 175 |
- "src/draw/nxp/pxp/lv_draw_pxp_img.c": blit image (w/ optional recolor or |
| 176 |
transformation) |
| 177 |
- "src/draw/nxp/pxp/lv_draw_pxp_layer.c": layer blending |
| 178 |
- "src/draw/nxp/pxp/lv_draw_pxp.c": draw unit initialization |
| 179 |
- "src/draw/nxp/pxp/lv_pxp_cfg.c": init, deinit, run/wait PXP device |
| 180 |
- "src/draw/nxp/pxp/lv_pxp_osa.c": OS abstraction (FreeRTOS or bare metal) |
| 181 |
- "src/draw/nxp/pxp/lv_pxp_utils.c": function helpers |
| 182 |
|
| 183 |
- PXP related code depends on two drivers provided by MCU SDK. These drivers |
| 184 |
need to be added to project: |
| 185 |
|
| 186 |
- fsl_pxp.c: PXP driver |
| 187 |
- fsl_cache.c: CPU cache handling functions |
| 188 |
|
| 189 |
|
| 190 |
PXP default configuration: |
| 191 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 192 |
|
| 193 |
- Implementation depends on multiple OS-specific functions. The struct |
| 194 |
:cpp:struct:`pxp_cfg_t` with callback pointers is used as a parameter for the |
| 195 |
:cpp:func:`lv_pxp_init` function. Default implementation for |
| 196 |
FreeRTOS in lv_pxp_osa.c. |
| 197 |
|
| 198 |
- :cpp:func:`pxp_interrupt_init`: Initialize PXP interrupt (HW setup, |
| 199 |
OS setup) |
| 200 |
- :cpp:func:`pxp_interrupt_deinit`: Deinitialize PXP interrupt (HW setup, |
| 201 |
OS setup) |
| 202 |
- :cpp:func:`pxp_run`: Start PXP job. Use OS-specific mechanism to block |
| 203 |
drawing thread. |
| 204 |
- :cpp:func:`pxp_wait`: Wait for PXP completion. |
| 205 |
|
| 206 |
|
| 207 |
VGLite accelerator |
| 208 |
~~~~~~~~~~~~~~~~~~ |
| 209 |
|
| 210 |
Extra drawing features in LVGL can be handled by the VGLite engine. The |
| 211 |
CPU is available for other operations while the VGLite is running. A |
| 212 |
RTOS is required to block the LVGL drawing thread and switch to another |
| 213 |
task or suspend the CPU for power savings. |
| 214 |
|
| 215 |
|
| 216 |
Basic configuration: |
| 217 |
^^^^^^^^^^^^^^^^^^^^ |
| 218 |
|
| 219 |
- Select NXP VGLite engine in "lv_conf.h": Set :c:macro:`LV_USE_DRAW_VGLITE` to |
| 220 |
`1`. :c:macro:`SDK_OS_FREE_RTOS` symbol needs to be defined so that FreeRTOS |
| 221 |
driver osal implementation will be enabled. |
| 222 |
- Enable VGLite asserts in "lv_conf.h": Set :c:macro:`LV_USE_VGLITE_ASSERT` to |
| 223 |
`1`. |
| 224 |
VGLite assertions will verify the driver API status code and in any error, it |
| 225 |
can stop the program execution in case the :c:macro:`LV_ASSERT_HANDLER` is set |
| 226 |
to `while(1);` (Halt by default). Else, there will be logged just an error |
| 227 |
message via `LV_LOG_ERROR`. |
| 228 |
|
| 229 |
Basic initialization: |
| 230 |
^^^^^^^^^^^^^^^^^^^^^ |
| 231 |
|
| 232 |
Initialize VGLite GPU before calling :cpp:func:`lv_init` by specifying the |
| 233 |
width/height of tessellation window. The default values for tessellation width |
| 234 |
and height, and command buffer size are in the SDK file "vglite_support.h". |
| 235 |
|
| 236 |
.. code-block:: c |
| 237 |
|
| 238 |
#if LV_USE_DRAW_VGLITE |
| 239 |
#include "vg_lite.h" |
| 240 |
#include "vglite_support.h" |
| 241 |
#endif |
| 242 |
... |
| 243 |
#if LV_USE_DRAW_VGLITE |
| 244 |
if(vg_lite_init(DEFAULT_VG_LITE_TW_WIDTH, DEFAULT_VG_LITE_TW_HEIGHT) != VG_LITE_SUCCESS) |
| 245 |
{ |
| 246 |
PRINTF("VGLite init error. STOP."); |
| 247 |
vg_lite_close(); |
| 248 |
while (1) |
| 249 |
; |
| 250 |
} |
| 251 |
|
| 252 |
if (vg_lite_set_command_buffer_size(VG_LITE_COMMAND_BUFFER_SIZE) != VG_LITE_SUCCESS) |
| 253 |
{ |
| 254 |
PRINTF("VGLite set command buffer. STOP."); |
| 255 |
vg_lite_close(); |
| 256 |
while (1) |
| 257 |
; |
| 258 |
} |
| 259 |
#endif |
| 260 |
|
| 261 |
VGLite draw initialization is done automatically in :cpp:func:`lv_init` once |
| 262 |
the VGLite is enabled, no user code is required: |
| 263 |
|
| 264 |
.. code-block:: c |
| 265 |
|
| 266 |
#if LV_USE_DRAW_VGLITE |
| 267 |
lv_draw_vglite_init(); |
| 268 |
#endif |
| 269 |
|
| 270 |
During VGLite initialization, a new draw unit `lv_draw_vglite_unit_t` will be |
| 271 |
created with the additional callbacks: |
| 272 |
|
| 273 |
.. code-block:: c |
| 274 |
|
| 275 |
lv_draw_vglite_unit_t * draw_vglite_unit = lv_draw_create_unit(sizeof(lv_draw_vglite_unit_t)); |
| 276 |
draw_vglite_unit->base_unit.evaluate_cb = _vglite_evaluate; |
| 277 |
draw_vglite_unit->base_unit.dispatch_cb = _vglite_dispatch; |
| 278 |
draw_vglite_unit->base_unit.delete_cb = _vglite_delete; |
| 279 |
|
| 280 |
and an addition thread `_vglite_render_thread_cb()` will be spawned in order to |
| 281 |
handle the supported draw tasks. |
| 282 |
|
| 283 |
.. code-block:: c |
| 284 |
|
| 285 |
#if LV_USE_VGLITE_DRAW_THREAD |
| 286 |
lv_thread_init(&draw_vglite_unit->thread, "vglitedraw", LV_THREAD_PRIO_HIGH, _vglite_render_thread_cb, 2 * 1024, draw_vglite_unit); |
| 287 |
#endif |
| 288 |
|
| 289 |
If `LV_USE_VGLITE_DRAW_THREAD` is not defined, then no additional draw thread will be created |
| 290 |
and the VGLite drawing task will get executed on the same LVGL main thread. |
| 291 |
|
| 292 |
`_vglite_evaluate()` will get called after each task is being created and will |
| 293 |
analyze if the task is supported by VGLite or not. If it is supported, then an |
| 294 |
preferred score and the draw unit id will be set to the task. An `score` equal |
| 295 |
to `100` is the default CPU score. Smaller score means that VGLite is capable of |
| 296 |
drawing it faster. |
| 297 |
|
| 298 |
`_vglite_dispatch()` is the VGLite dispatcher callback, it will take a ready to |
| 299 |
draw task (having the `DRAW_UNIT_ID_VGLITE` set) and will pass the task to the |
| 300 |
VGLite draw unit for processing. |
| 301 |
|
| 302 |
`_vglite_delete()` will cleanup the VGLite draw unit. |
| 303 |
|
| 304 |
|
| 305 |
Advanced configuration: |
| 306 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 307 |
|
| 308 |
- Enable VGLite blit split in "lv_conf.h": |
| 309 |
Set :c:macro:`LV_USE_VGLITE_BLIT_SPLIT` to `1`. |
| 310 |
Enabling the blit split workaround will mitigate any quality degradation issue |
| 311 |
on screen's dimension > 352 pixels. |
| 312 |
|
| 313 |
.. code-block:: c |
| 314 |
|
| 315 |
#define VGLITE_BLIT_SPLIT_THR 352 |
| 316 |
|
| 317 |
- By default, the blit split threshold is set to 352. Blits with width or height |
| 318 |
higher than this value will be done in multiple steps. Value must be multiple |
| 319 |
of stride alignment in px. For most color formats, the alignment is 16px |
| 320 |
(except the index formats). Transformation will not be supported once with |
| 321 |
the blit split. |
| 322 |
|
| 323 |
- Enable VGLite draw task synchronously in "lv_conf.h": |
| 324 |
Set :c:macro:`LV_USE_VGLITE_DRAW_ASYNC` to `1`. |
| 325 |
Multiple draw tasks can be queued and flushed them once to the GPU based on |
| 326 |
the GPU idle status. If GPU is busy, the task will be queued, and the VGLite |
| 327 |
dispatcher will ask for a new available task. If GPU is idle, the queue with |
| 328 |
any pending tasks will be flushed to the GPU. The completion status of draw |
| 329 |
task will be sent to the main LVGL thread asynchronously. |
| 330 |
|
| 331 |
Features supported: |
| 332 |
^^^^^^^^^^^^^^^^^^^ |
| 333 |
|
| 334 |
Several drawing features in LVGL can be offloaded to the VGLite engine. The CPU |
| 335 |
is available for other operations while the GPU is running. RTOS is required to |
| 336 |
block the LVGL drawing thread and switch to another task or suspend the CPU for |
| 337 |
power savings. |
| 338 |
|
| 339 |
Supported draw tasks are available in "src/draw/nxp/vglite/lv_draw_vglite.c": |
| 340 |
|
| 341 |
.. code-block:: c |
| 342 |
|
| 343 |
switch(t->type) { |
| 344 |
case LV_DRAW_TASK_TYPE_LABEL: |
| 345 |
lv_draw_vglite_label(t, t->draw_dsc, &t->area); |
| 346 |
break; |
| 347 |
case LV_DRAW_TASK_TYPE_FILL: |
| 348 |
lv_draw_vglite_fill(t, t->draw_dsc, &t->area); |
| 349 |
break; |
| 350 |
case LV_DRAW_TASK_TYPE_BORDER: |
| 351 |
lv_draw_vglite_border(t, t->draw_dsc, &t->area); |
| 352 |
break; |
| 353 |
case LV_DRAW_TASK_TYPE_IMAGE: |
| 354 |
lv_draw_vglite_img(t, t->draw_dsc, &t->area); |
| 355 |
break; |
| 356 |
case LV_DRAW_TASK_TYPE_ARC: |
| 357 |
lv_draw_vglite_arc(t, t->draw_dsc, &t->area); |
| 358 |
break; |
| 359 |
case LV_DRAW_TASK_TYPE_LINE: |
| 360 |
lv_draw_vglite_line(t, t->draw_dsc); |
| 361 |
break; |
| 362 |
case LV_DRAW_TASK_TYPE_LAYER: |
| 363 |
lv_draw_vglite_layer(t, t->draw_dsc, &t->area); |
| 364 |
break; |
| 365 |
case LV_DRAW_TASK_TYPE_TRIANGLE: |
| 366 |
lv_draw_vglite_triangle(t, t->draw_dsc); |
| 367 |
break; |
| 368 |
default: |
| 369 |
break; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
All the below operation can be done in addition with optional opacity. |
| 374 |
|
| 375 |
- Fill area with color (w/ radius or gradient). |
| 376 |
- Blit source image (any format from ``_vglite_src_cf_supported()``) over |
| 377 |
destination (any format from ``_vglite_dest_cf_supported()``). |
| 378 |
- Recolor source image. |
| 379 |
- Scale and rotate (any decimal degree) source image. |
| 380 |
- Blending layers (w/ same supported formats as blitting). |
| 381 |
- Draw letters (blit bitmap letters / raster font). |
| 382 |
- Draw full borders (LV_BORDER_SIDE_FULL). |
| 383 |
- Draw arcs (w/ rounded edges). |
| 384 |
- Draw lines (w/ dash or rounded edges). |
| 385 |
- Draw triangles with color (w/ gradient). |
| 386 |
|
| 387 |
|
| 388 |
Known limitations: |
| 389 |
^^^^^^^^^^^^^^^^^^ |
| 390 |
|
| 391 |
- Source image alignment: The byte alignment requirement for a pixel depends on |
| 392 |
the specific pixel format. Both buffer address and buffer stride must be |
| 393 |
aligned. As general rule, the alignment is set to 16 pixels. This makes the |
| 394 |
buffer address alignment to be 32 bytes for RGB565 and 64 bytes for ARGB8888. |
| 395 |
- For pixel engine (PE) destination, the alignment should be 64 bytes for all |
| 396 |
tiled (4x4) buffer layouts. The pixel engine has no additional alignment |
| 397 |
requirement for linear buffer layouts (:c:macro:`VG_LITE_LINEAR`). |
| 398 |
|
| 399 |
|
| 400 |
Project setup: |
| 401 |
^^^^^^^^^^^^^^ |
| 402 |
|
| 403 |
- Add VGLite related source files (and corresponding headers if available) to |
| 404 |
project: |
| 405 |
|
| 406 |
- "src/draw/nxp/vglite/lv_draw_buf_vglite.c": draw buffer callbacks |
| 407 |
- "src/draw/nxp/vglite/lv_draw_vglite_arc.c": draw arc |
| 408 |
- "src/draw/nxp/vglite/lv_draw_vglite_border.c": draw border |
| 409 |
- "src/draw/nxp/vglite/lv_draw_vglite_fill.c": fill area |
| 410 |
- "src/draw/nxp/vglite/lv_draw_vglite_img.c": blit image (w/ optional recolor or transformation) |
| 411 |
- "src/draw/nxp/vglite/lv_draw_vglite_label.c": draw label |
| 412 |
- "src/draw/nxp/vglite/lv_draw_vglite_layer.c": layer blending |
| 413 |
- "src/draw/nxp/vglite/lv_draw_vglite_line.c": draw line |
| 414 |
- "src/draw/nxp/vglite/lv_draw_vglite_triangle.c": draw triangle |
| 415 |
- "src/draw/nxp/vglite/lv_draw_vglite.c": draw unit initialization |
| 416 |
- "src/draw/nxp/vglite/lv_vglite_buf.c": init/get vglite buffer |
| 417 |
- "src/draw/nxp/vglite/lv_vglite_matrix.c": set vglite matrix |
| 418 |
- "src/draw/nxp/vglite/lv_vglite_path.c": create vglite path data |
| 419 |
- "src/draw/nxp/vglite/lv_vglite_utils.c": function helpers |
| 420 |
|
| 421 |
G2D accelerator |
| 422 |
~~~~~~~~~~~~~~~ |
| 423 |
Basic configuration: |
| 424 |
^^^^^^^^^^^^^^^^^^^^ |
| 425 |
|
| 426 |
- Select NXP G2D engine in "lv_conf.h": Set :c:macro:`LV_USE_G2D` to `1`. |
| 427 |
- In order to use G2D as a draw unit, select in "lv_conf.h": Set :c:macro:`LV_USE_DRAW_G2D` to `1`. |
| 428 |
- Enable G2D asserts in "lv_conf.h": Set :c:macro:`LV_USE_G2D_ASSERT` to `1`. |
| 429 |
There are few G2D assertions that can stop the program execution in case the |
| 430 |
:c:macro:`LV_ASSERT_HANDLER` is set to `while(1);` (Halt by default). Else, |
| 431 |
there will be logged just an error message via `LV_LOG_ERROR`. |
| 432 |
|
| 433 |
Basic initialization: |
| 434 |
^^^^^^^^^^^^^^^^^^^^^ |
| 435 |
|
| 436 |
G2D draw initialization is done automatically in :cpp:func:`lv_init` once the |
| 437 |
G2D is enabled as a draw unit , no user code is required: |
| 438 |
|
| 439 |
.. code:: c |
| 440 |
|
| 441 |
#if LV_USE_DRAW_G2D |
| 442 |
lv_draw_g2d_init(); |
| 443 |
#endif |
| 444 |
|
| 445 |
During G2D initialization, a new draw unit `lv_draw_g2d_unit_t` will be created |
| 446 |
with the additional callbacks, if :c:macro:`LV_USE_DRAW_G2D` is set to `1`: |
| 447 |
|
| 448 |
.. code:: c |
| 449 |
|
| 450 |
lv_draw_g2d_unit_t * draw_g2d_unit = lv_draw_create_unit(sizeof(lv_draw_g2d_unit_t)); |
| 451 |
draw_g2d_unit->base_unit.evaluate_cb = _g2d_evaluate; |
| 452 |
draw_g2d_unit->base_unit.dispatch_cb = _g2d_dispatch; |
| 453 |
draw_g2d_unit->base_unit.delete_cb = _g2d_delete; |
| 454 |
|
| 455 |
and an addition thread `_g2d_render_thread_cb()` will be spawned in order to |
| 456 |
handle the supported draw tasks. |
| 457 |
|
| 458 |
.. code:: c |
| 459 |
|
| 460 |
#if LV_USE_G2D_DRAW_THREAD |
| 461 |
lv_thread_init(&draw_g2d_unit->thread, LV_THREAD_PRIO_HIGH, _g2d_render_thread_cb, 2 * 1024, draw_g2d_unit); |
| 462 |
#endif |
| 463 |
|
| 464 |
If `LV_USE_G2D_DRAW_THREAD` is not defined, then no additional draw thread will be created |
| 465 |
and the G2D drawing task will get executed on the same LVGL main thread. |
| 466 |
|
| 467 |
`_g2d_evaluate()` will get called after each task is being created and will |
| 468 |
analyze if the task is supported by G2D or not. If it is supported, then an |
| 469 |
preferred score and the draw unit id will be set to the task. An `score` equal |
| 470 |
to `100` is the default CPU score. Smaller score means that G2D is capable of |
| 471 |
drawing it faster. |
| 472 |
|
| 473 |
`_g2d_dispatch()` is the G2D dispatcher callback, it will take a ready to draw |
| 474 |
task (having the `DRAW_UNIT_ID_G2D` set) and will pass the task to the G2D draw |
| 475 |
unit for processing. |
| 476 |
|
| 477 |
`_g2d_delete()` will cleanup the G2D draw unit. |
| 478 |
|
| 479 |
Features supported: |
| 480 |
^^^^^^^^^^^^^^^^^^^ |
| 481 |
|
| 482 |
Several drawing features in LVGL can be offloaded to the G2D engine. The CPU is |
| 483 |
available for other operations while the G2D is running. Linux OS is required to |
| 484 |
block the LVGL drawing thread and switch to another task or suspend the CPU for |
| 485 |
power savings. |
| 486 |
|
| 487 |
Supported draw tasks are available in "src/draw/nx/g2d/lv_draw_g2d.c": |
| 488 |
|
| 489 |
.. code:: c |
| 490 |
|
| 491 |
switch(t->type) { |
| 492 |
case LV_DRAW_TASK_TYPE_FILL: |
| 493 |
lv_draw_g2d_fill(u, t->draw_dsc, &t->area); |
| 494 |
break; |
| 495 |
case LV_DRAW_TASK_TYPE_IMAGE: |
| 496 |
lv_draw_g2d_img(u, t->draw_dsc, &t->area); |
| 497 |
break; |
| 498 |
default: |
| 499 |
break; |
| 500 |
} |
| 501 |
|
| 502 |
- Fill area with color (w/o radius, w/o gradient) + optional opacity. |
| 503 |
- Blit source image ARGB8888 over destination. |
| 504 |
ARGB8888 + optional opacity. |
| 505 |
- Scale source image ARGB8888. |
| 506 |
|
| 507 |
Known limitations: |
| 508 |
^^^^^^^^^^^^^^^^^^ |
| 509 |
|
| 510 |
- G2D/PXP can only rotate at 90\ |deg| angles. |
| 511 |
- Rotation is not supported for images unaligned to blocks of 16x16 pixels. G2D/PXP |
| 512 |
is set to process 16x16 blocks to optimize the system for memory bandwidth and |
| 513 |
image processing time. The output engine essentially truncates any output |
| 514 |
pixels after the desired number of pixels has been written. When rotating a |
| 515 |
source image and the output is not divisible by the block size, the incorrect |
| 516 |
pixels could be truncated and the final output image can look shifted. |
| 517 |
- Recolor or transformation for images w/ opacity or alpha channel can't be |
| 518 |
obtained in a single G2D/PXP pipeline configuration. Two or multiple steps would |
| 519 |
be required. |
| 520 |
- Buffer address must be aligned to 64 bytes: set :c:macro:`LV_DRAW_BUF_ALIGN` |
| 521 |
to `64` in "lv_conf.h". |
| 522 |
No stride alignment is required: set :c:macro:`LV_DRAW_BUF_STRIDE_ALIGN` to |
| 523 |
`1` in "lv_conf.h". |
| 524 |
|
| 525 |
Project setup: |
| 526 |
^^^^^^^^^^^^^^ |
| 527 |
|
| 528 |
- Add G2D related source files (and corresponding headers if available) to |
| 529 |
project: |
| 530 |
|
| 531 |
- "src/draw/nxp/g2d/lv_draw_buf_g2d.c": draw buffer callbacks |
| 532 |
- "src/draw/nxp/g2d/lv_draw_g2d_fill.c": fill area |
| 533 |
- "src/draw/nxp/g2d/lv_draw_g2d_img.c": blit image (w/ optional recolor or |
| 534 |
transformation) |
| 535 |
- "src/draw/nxp/g2d/lv_draw_g2d.c": draw unit initialization |
| 536 |
- "src/draw/nxp/g2d/lv_draw_g2d_buf_map.c": hash map for g2d buffers |
| 537 |
- "src/draw/nxp/g2d/lv_g2d_utils.c": function helpers |
| 538 |
|