| 1 |
.. include:: /include/substitutions.txt |
| 2 |
.. _stm32_ltdc_driver: |
| 3 |
|
| 4 |
========================= |
| 5 |
STM32 LTDC Display Driver |
| 6 |
========================= |
| 7 |
|
| 8 |
Some STM32s have a specialized peripheral called |
| 9 |
LTDC (LCD-TFT Display Controller) for driving displays. |
| 10 |
|
| 11 |
|
| 12 |
Usage Modes With LVGL |
| 13 |
********************* |
| 14 |
|
| 15 |
The driver within LVGL is designed to work with an |
| 16 |
already-configured LTDC peripheral. It relies on the |
| 17 |
STM32 HAL to detect information about the configuration. |
| 18 |
The color format of the created LVGL display will |
| 19 |
match the LTDC layer's color format. Use STM32CubeIDE |
| 20 |
or STM32CubeMX to generate LTDC initialization code. |
| 21 |
It is an STM32 HAL-based driver and relies on being |
| 22 |
able to include ``"main.h"`` from within LVGL to get |
| 23 |
access to STM32 HAL definitions and function prototypes. |
| 24 |
|
| 25 |
There are some different use cases for LVGL's driver. |
| 26 |
All permutations of the below options are well supported. |
| 27 |
|
| 28 |
- single or double buffered |
| 29 |
- direct or partial render mode |
| 30 |
- OS or no OS |
| 31 |
- parallelized flushing with DMA2D (only for partial render mode) |
| 32 |
|
| 33 |
If OS is enabled, a synchronization primitive will be used to |
| 34 |
give the thread a chance to yield to other threads while blocked, |
| 35 |
improving CPU utilization. See :c:macro:`LV_USE_OS` in your lv_conf.h |
| 36 |
|
| 37 |
|
| 38 |
LTDC Layers |
| 39 |
*********** |
| 40 |
|
| 41 |
This driver creates an LVGL display |
| 42 |
which is only concerned with a specific layer of the LTDC peripheral, meaning |
| 43 |
two LVGL LTDC displays can be created and operate independently on the separate |
| 44 |
layers. |
| 45 |
|
| 46 |
|
| 47 |
Direct Render Mode |
| 48 |
****************** |
| 49 |
|
| 50 |
For direct render mode, invoke :cpp:func:`lv_st_ltdc_create_direct` like this: |
| 51 |
|
| 52 |
.. code-block:: c |
| 53 |
|
| 54 |
void * my_ltdc_framebuffer_address = (void *)0x20000000u; |
| 55 |
uint32_t my_ltdc_layer_index = 0; /* typically 0 or 1 */ |
| 56 |
lv_display_t * disp = lv_st_ltdc_create_direct(my_ltdc_framebuffer_address, |
| 57 |
optional_other_full_size_buffer, |
| 58 |
my_ltdc_layer_index); |
| 59 |
|
| 60 |
``my_ltdc_framebuffer_address`` is the framebuffer configured for use by |
| 61 |
LTDC. ``optional_other_full_size_buffer`` can be another buffer which is the same |
| 62 |
size as the default framebuffer for double-buffered |
| 63 |
mode, or ``NULL`` otherwise. ``my_ltdc_layer_index`` is the layer index of the |
| 64 |
LTDC layer to create the display for. |
| 65 |
|
| 66 |
For the best visial results, ``optional_other_full_size_buffer`` should be used |
| 67 |
if enough memory is available. Single-buffered mode is what you should use |
| 68 |
if memory is very scarce. Chips with a CPU data cache have unavoidable visual |
| 69 |
artifacts when using single-buffered direct mode. If there is almost enough |
| 70 |
memory for double-buffered direct mode, but not quite, then use partial render mode. |
| 71 |
|
| 72 |
To clarify what ``my_ltdc_framebuffer_address`` exactly is, it's the value of |
| 73 |
``pLayerCfg.FBStartAdress`` when the LTDC layer is configured using the STM32 HAL, |
| 74 |
which is written to the ``CFBAR`` register of the LTDC layer peripheral. |
| 75 |
|
| 76 |
.. image:: /_static/images/stm32cubemx-ltdc-fbaddr.png |
| 77 |
|
| 78 |
|
| 79 |
Partial Render Mode |
| 80 |
******************* |
| 81 |
|
| 82 |
For partial render mode, invoke :cpp:func:`lv_st_ltdc_create_partial` like this: |
| 83 |
|
| 84 |
.. code-block:: c |
| 85 |
|
| 86 |
static uint8_t partial_buf1[65536]; |
| 87 |
static uint8_t optional_partial_buf2[65536]; |
| 88 |
uint32_t my_ltdc_layer_index = 0; /* typically 0 or 1 */ |
| 89 |
lv_display_t * disp = lv_st_ltdc_create_partial(partial_buf1, |
| 90 |
optional_partial_buf2, |
| 91 |
65536, |
| 92 |
my_ltdc_layer_index); |
| 93 |
|
| 94 |
The driver will use the information in the LTDC layer configuration to find the |
| 95 |
layer's framebuffer and flush to it. |
| 96 |
|
| 97 |
Providing a second partial buffer can improve CPU utilization and increase |
| 98 |
performance compared to |
| 99 |
a single buffer if :c:macro:`LV_ST_LTDC_USE_DMA2D_FLUSH` is enabled. |
| 100 |
|
| 101 |
|
| 102 |
Linker Script |
| 103 |
************* |
| 104 |
|
| 105 |
You should ensure the LTDC framebuffer memory is actually reserved in the linker script. |
| 106 |
This is a file that normally has the extension ``.ld``. |
| 107 |
In the below example, ``1125K`` is specified because the color depth is 24 (3 bytes per pixel), |
| 108 |
the display width is 800, the display height is 480, and ``1K`` means 1024 bytes. |
| 109 |
3 |times| 800 |times| 480 |divide| 1024 = 1125. You should ensure the sum of the RAM entries |
| 110 |
(``FB_RAM`` + ``RAM``) equals the total RAM of the device. |
| 111 |
|
| 112 |
.. code-block:: |
| 113 |
|
| 114 |
/* Memories definition */ |
| 115 |
MEMORY |
| 116 |
{ |
| 117 |
FB_RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 1125K /* single 24bit 800x480 buffer */ |
| 118 |
RAM (xrw) : ORIGIN = 0x20119400, LENGTH = 1883K |
| 119 |
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 4096K |
| 120 |
} |
| 121 |
|
| 122 |
If the framebuffer is not reserved in the linker script or the framebuffer is not set during |
| 123 |
board initialization, you may absolutely set it at runtime before creating the LVGL display. |
| 124 |
|
| 125 |
.. code-block:: c |
| 126 |
|
| 127 |
/* like this */ |
| 128 |
HAL_LTDC_SetAddress(&hltdc, (uint32_t)my_ltdc_framebuffer_address, my_ltdc_layer_index); |
| 129 |
|
| 130 |
/* and then... */ |
| 131 |
|
| 132 |
lv_display_t * disp; |
| 133 |
disp = lv_st_ltdc_create_direct(my_ltdc_framebuffer_address, |
| 134 |
optional_other_full_size_buffer, |
| 135 |
my_ltdc_layer_index); |
| 136 |
/* or */ |
| 137 |
disp = lv_st_ltdc_create_partial(partial_buf1, |
| 138 |
optional_partial_buf2, |
| 139 |
partial_buf_size, |
| 140 |
my_ltdc_layer_index); |
| 141 |
|
| 142 |
|
| 143 |
Display Rotation |
| 144 |
**************** |
| 145 |
|
| 146 |
The driver supports display rotation with |
| 147 |
:cpp:expr:`lv_display_set_rotation(disp, rotation)` where rotation is one of |
| 148 |
:cpp:enumerator:`LV_DISP_ROTATION_90`, :cpp:enumerator:`LV_DISP_ROTATION_180`, |
| 149 |
or :cpp:enumerator:`LV_DISP_ROTATION_270`. The rotation is initially |
| 150 |
:cpp:enumerator:`LV_DISP_ROTATION_0`. |
| 151 |
|
| 152 |
The rotation is done in software and only works if the display was |
| 153 |
created using :cpp:func:`lv_st_ltdc_create_partial`. |
| 154 |
:c:macro:`LV_ST_LTDC_USE_DMA2D_FLUSH` will be have no effect if rotation |
| 155 |
is used. |
| 156 |
|
| 157 |
|
| 158 |
Interop with the DMA2D and NeoChrom Draw Units |
| 159 |
********************************************** |
| 160 |
|
| 161 |
:c:macro:`LV_ST_LTDC_USE_DMA2D_FLUSH` can be enabled to use DMA2D to flush |
| 162 |
partial buffers in parallel with other LVGL tasks, whether or not OS is |
| 163 |
enabled. If the display is not partial, then there is no need to enable this |
| 164 |
option. |
| 165 |
|
| 166 |
It must not be enabled at the same time as :c:macro:`LV_USE_DRAW_DMA2D`. |
| 167 |
See the :ref:`DMA2D support <dma2d>`. |
| 168 |
|
| 169 |
NeoChrom can be enabled at the same time as LTDC. They will not interfere |
| 170 |
with each other at all. |