# ESP LCD ST77903 RGB Implementation of the ST77903 LCD controller with [esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/lcd.html) component. | LCD controller | Communication interface | Component name | Link to datasheet | | :------------: | :---------------------: | :------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | ST77903 | QSPI/RGB | esp_lcd_ST77903 | [PDF1](https://dl.espressif.com/AE/esp-iot-solution/ST77903_SPEC_P0.5.pdf)| ## Initialization Code ### RGB Interface For most RGB LCDs, they typically use a "3-Wire SPI + Parallel RGB" interface. The "3-Wire SPI" interface is used for transmitting command data and the "Parallel RGB" interface is used for sending pixel data. It's recommended to use the [esp_lcd_panel_io_additions](https://components.espressif.com/components/espressif/esp_lcd_panel_io_additions) component to bit-bang the "3-Wire SPI" interface through **GPIO** or an **IO expander** (like [TCA9554](https://components.espressif.com/components/espressif/esp_io_expander_tca9554)). To do this, please first add this component to your project manually. Then, refer to the following code to initialize the ST77903 controller. ```c ESP_LOGI(TAG, "Install 3-wire SPI panel IO"); spi_line_config_t line_config = { .cs_io_type = IO_TYPE_EXPANDER, // Set to `IO_TYPE_GPIO` if using GPIO, same to below .cs_expander_pin = EXAMPLE_LCD_IO_SPI_CS, .scl_io_type = IO_TYPE_GPIO, .scl_gpio_num = EXAMPLE_LCD_IO_SPI_SCK, .sda_io_type = IO_TYPE_GPIO, .sda_gpio_num = EXAMPLE_LCD_IO_SPI_SDO, .io_expander = expander_handle, // Set to NULL if not using IO expander }; esp_lcd_panel_io_3wire_spi_config_t io_config = ST77903_RGB_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0); esp_lcd_panel_io_handle_t io_handle = NULL; ESP_ERROR_CHECK(esp_lcd_new_panel_io_3wire_spi(&io_config, &io_handle)); /** * Uncomment these line if use custom initialization commands. * The array should be declared as static const and positioned outside the function. */ // static const st77903_lcd_init_cmd_t lcd_init_cmds[] = { // // {cmd, { data }, data_size, delay_ms} // {0xf0, (uint8_t []){0xc3}, 1, 0}, // {0xf0, (uint8_t []){0x96}, 1, 0}, // {0xf0, (uint8_t []){0xa5}, 1, 0}, // ... // }; ESP_LOGI(TAG, "Install st77903 panel driver"); esp_lcd_panel_handle_t panel_handle = NULL; const esp_lcd_rgb_panel_config_t rgb_config = { .clk_src = LCD_CLK_SRC_DEFAULT, .psram_trans_align = 64, .data_width = 8, .bits_per_pixel = 24, .de_gpio_num = EXAMPLE_PIN_NUM_LCD_RGB_DE, .pclk_gpio_num = EXAMPLE_PIN_NUM_LCD_RGB_PCLK, .vsync_gpio_num = EXAMPLE_PIN_NUM_LCD_RGB_VSYNC, .hsync_gpio_num = EXAMPLE_PIN_NUM_LCD_RGB_HSYNC, .disp_gpio_num = EXAMPLE_PIN_NUM_LCD_RGB_DISP, .data_gpio_nums = { EXAMPLE_PIN_NUM_LCD_RGB_DATA0, EXAMPLE_PIN_NUM_LCD_RGB_DATA1, EXAMPLE_PIN_NUM_LCD_RGB_DATA2, EXAMPLE_PIN_NUM_LCD_RGB_DATA3, EXAMPLE_PIN_NUM_LCD_RGB_DATA4, EXAMPLE_PIN_NUM_LCD_RGB_DATA5, EXAMPLE_PIN_NUM_LCD_RGB_DATA6, EXAMPLE_PIN_NUM_LCD_RGB_DATA7, }, .timings = ST77903_RGB_320_480_PANEL_48HZ_RGB_TIMING(), .flags.fb_in_psram = 1, }; st77903_vendor_config_t vendor_config = { .rgb_config = &rgb_config, // .init_cmds = lcd_init_cmds, // Uncomment these line if use custom initialization commands // .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(st77903_lcd_init_cmd_t), .flags = { .use_rgb_interface = 1, .mirror_by_cmd = 0, // Only work when `auto_del_panel_io` is set to 0 .auto_del_panel_io = 1, /** * Send initialization commands and delete the panel IO instance during creation if set to 1. * This flag is only used when `use_rgb_interface` is set to 1. * If the panel IO pins are sharing other pins of the RGB interface to save GPIOs, * Please set it to 1 to release the panel IO and its pins (except CS signal). */ }, }; const esp_lcd_panel_dev_config_t panel_config = { .reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST, .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h` .bits_per_pixel = EXAMPLE_LCD_BIT_PER_PIXEL, // Implemented by LCD command `3Ah` (16/18/24) .vendor_config = &vendor_config, }; ESP_ERROR_CHECK(esp_lcd_new_panel_st77903(io_handle, &panel_config, &panel_handle)); /** * Only create RGB when `auto_del_panel_io` is set to 0, * or initialize ST77903 meanwhile */ ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle)); // Only reset RGB when `auto_del_panel_io` is set to 1, or reset ST77903 meanwhile ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle)); // Only initialize RGB when `auto_del_panel_io` is set to 1, or initialize ST77903 meanwhile ```
# ChangeLog ## v0.0.1 - 2023-1-30 ### Enhancements: * Implement the driver for the ST77903 LCD controller * Support RGB interface
| Supported Targets | ESP32-S3 | | ----------------- | -------- | | Supported LCD Controllers | ST77903 | | ------------------------- | ------- | # RGB LCD 8BIT Example [esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) provides several panel drivers out-of box, e.g. ST7789, SSD1306, NT35510. However, there're a lot of other panels on the market, it's beyond `esp_lcd` component's responsibility to include them all. `esp_lcd` allows user to add their own panel drivers in the project scope (i.e. panel driver can live outside of esp-idf), so that the upper layer code like LVGL porting code can be reused without any modifications, as long as user-implemented panel driver follows the interface defined in the `esp_lcd` component. This example demonstrates how to drive an RGB interface LCD screen with an 8-bit RGB requirement in an esp-idf project. The example will use the LVGL library to draw a stylish music player. This example uses the [esp_timer](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/esp_timer.html) to generate the ticks needed by LVGL and uses a dedicated task to run the `lv_timer_handler()`. Since the LVGL APIs are not thread-safe, this example uses a mutex which be invoked before the call of `lv_timer_handler()` and released after it. The same mutex needs to be used in other tasks and threads around every LVGL (lv_...) related function call and code. For more porting guides, please refer to [LVGL porting doc](https://docs.lvgl.io/master/porting/index.html). ## How to use the example ## ESP-IDF Required ### Hardware Required * An ESP32-S3R8 development board * A ST77903 LCD panel, with RGB interface * An USB cable for power supply and programming ### Hardware Connection The connection between ESP Board and the LCD is as follows: ``` ESP Board RGB Panel +-----------------------+ +-------------------+ | GND +--------------+GND | | | | | | 3V3 +--------------+VCC | | | | | | PCLK+--------------+PCLK | | | | | | DATA[7:0]+--------------+DATA[7:0] | | | | | | HSYNC+--------------+HSYNC | | | | | | VSYNC+--------------+VSYNC | | | | | | DE+--------------+DE | | | | | | BK_LIGHT+--------------+BLK | +-----------------------+ | | 3V3-----+DISP_EN | | | +-------------------+ ``` * The LCD parameters and GPIO number used by this example can be changed in [lv_port.h](main/lv_port.h). * Especially, please pay attention to the **vendor specific initialization**, it can be different between manufacturers and should consult the LCD supplier for initialization sequence code. * Furthermore, pay attention to the voltage level used when turning on the LCD backlight. Some LCD modules require a low voltage level to turn on, while others require a high voltage level. You can modify the macro definition `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL` to change the backlight voltage level in [lv_port.h](main/lv_port.h). * If the RGB LCD panel exclusively supports the DE mode, you can even bypass the HSYNC and VSYNC signals by assigning `EXAMPLE_PIN_NUM_HSYNC` and `EXAMPLE_PIN_NUM_VSYNC` with -1. ### Build and Flash Run `idf.py set-target esp32s3` to select the target chip. Run `idf.py -p PORT build flash monitor` to build, flash and monitor the project. A fancy animation will show up on the LCD as expected. The first time you run `idf.py` for the example will cost extra time as the build system needs to address the component dependencies and downloads the missing components from registry into `managed_components` folder. (To exit the serial monitor, type ``Ctrl-]``.) See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects. ### Example Output ```bash ... I (846) main_task: Calling app_main() I (850) lvgl_port: Install 3-wire SPI panel IO I (855) gpio: GPIO[40]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (865) gpio: GPIO[42]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (874) gpio: GPIO[45]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (883) lcd_panel.io.3wire_spi: Panel IO create success, version: 1.0.1 I (891) lvgl_port: Install st77903 panel driver I (896) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 W (1292) lcd_panel.io.3wire_spi: Delete but keep CS line inactive I (1292) gpio: GPIO[40]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (1297) gpio: GPIO[42]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (1318) lvgl_port: Starting LVGL task I (2335) example: Display LVGL demos I (2483) main_task: Returned from app_main() ... ``` ## Troubleshooting For any technical queries, please open an [issue] (https://github.com/espressif/esp-iot-solution/issues) on GitHub. We will get back to you soon.
idf.py add-dependency "espressif/esp_lcd_st77903_rgb^0.0.1"
To create a project from this example, run:
idf.py create-project-from-example "espressif/esp_lcd_st77903_rgb^0.0.1:rgb_lcd_8bit"