1============================
2ST7796 LCD Controller driver
3============================
4
5Overview
6--------
7
8The `ST7796S <https://www.buydisplay.com/download/ic/ST7796S.pdf>`__ is a single-chip controller/driver for 262K-color, graphic type TFT-LCD. It consists of 960
9source lines and 480 gate lines driving circuits. The ST7796S is capable of connecting directly to an external
10microprocessor, and accepts 8-bit/9-bit/16-bit/18-bit parallel interface, SPI, and the ST7796S also provides
11MIPI interface. Display data can be stored in the on-chip display data RAM of 320x480x18 bits. It can perform
12display data RAM read-/write-operation with no external clock to minimize power consumption. In addition,
13because of the integrated power supply circuit necessary to drive liquid crystal; it is possible to make a display
14system with fewest components.
15
16The ST7796 LCD controller `driver <https://github.com/lvgl/lvgl/src/drivers/display/st7796>`__ is a platform-agnostic driver, based on the `generic MIPI driver <https://github.com/lvgl/lvgl/doc/integration/drivers/display/gen_mipi.rst>`__.
17It implements display initialization, supports display rotation and implements the display flush callback. The user needs to implement only two platform-specific functions to send
18a command or pixel data to the controller via SPI or parallel bus. Typically these are implemented by calling the appropriate SDK library functions on the given platform.
19
20Prerequisites
21-------------
22
23There are no prerequisites.
24
25Configuring the driver
26----------------------
27
28Enable the ST7796 driver support in lv_conf.h, by cmake compiler define or by KConfig
29
30.. code-block:: c
31
32	#define LV_USE_ST7796  1
33
34Usage
35-----
36
37You need to implement two platform-dependent functions:
38
39.. code-block:: c
40
41	/* Send short command to the LCD. This function shall wait until the transaction finishes. */
42	int32_t my_lcd_send_cmd(lv_display_t *disp, const uint8_t *cmd, size_t cmd_size, const uint8_t *param, size_t param_size)
43	{
44		...
45	}
46
47	/* Send large array of pixel data to the LCD. If necessary, this function has to do the byte-swapping. This function can do the transfer in the background. */
48	int32_t my_lcd_send_color(lv_display_t *disp, const uint8_t *cmd, size_t cmd_size, uint8_t *param, size_t param_size)
49	{
50		...
51	}
52
53To create an ST7796-based display use the function
54
55.. code-block:: c
56
57	/**
58	 * Create an LCD display with ST7796 driver
59	 * @param hor_res       horizontal resolution
60	 * @param ver_res       vertical resolution
61	 * @param flags         default configuration settings (mirror, RGB ordering, etc.)
62	 * @param send_cmd      platform-dependent function to send a command to the LCD controller (usually uses polling transfer)
63	 * @param send_color    platform-dependent function to send pixel data to the LCD controller (usually uses DMA transfer: must implement a 'ready' callback)
64	 * @return              pointer to the created display
65	 */
66	lv_display_t * lv_st7796_create(uint32_t hor_res, uint32_t ver_res, lv_lcd_flag_t flags,
67									lv_st7796_send_cmd_cb_t send_cmd_cb, lv_st7796_send_color_cb_t send_color_cb);
68
69
70For additional details and a working example see the `generic MIPI driver documentation <https://github.com/lvgl/lvgl/doc/integration/drivers/display/gen_mipi.rst>`__.
71
72.. note::
73
74	You can find a step-by-step guide and the actual implementation of the callbacks on an STM32F746 using STM32CubeIDE and the ST HAL libraries here: :ref:`lcd_stm32_guide`
75
76