Skip to content

Commit

Permalink
Merge pull request espressif#322 from espressif/feature/lvgl_port_rgb
Browse files Browse the repository at this point in the history
feat(LVGL port): Support for RGB screen
  • Loading branch information
espzav authored May 22, 2024
2 parents 0f4476a + b88a0a4 commit b5f68c3
Show file tree
Hide file tree
Showing 25 changed files with 1,034 additions and 226 deletions.
5 changes: 5 additions & 0 deletions .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ components/lcd/esp_lcd_ssd1681:
disable:
- if: IDF_VERSION_MAJOR < 5
reason: Component is supported only for IDF >= 5.0

components/esp_lvgl_port/examples/rgb_lcd:
disable:
- if: IDF_VERSION_MAJOR < 5
reason: Example for RGB LCD is supported only for IDF >= 5.0
14 changes: 0 additions & 14 deletions bsp/esp32_p4_function_ev_board/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,3 @@ ESP32-P4 Function EV Board is internal Espressif board for testing features on E
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
| IMU | :x: | | |
<!-- Autogenerated end: Dependencies -->
<!-- Autogenerated start: Dependencies -->
### Capabilities and dependencies
| Capability | Available | Component |Version|
|-------------|------------------|----------------------------------------------------------------------------------------------------------|-------|
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9881c](https://components.espressif.com/components/espressif/esp_lcd_ili9881c) |>=0.2.0|
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911)| ^1 |
| BUTTONS | :x: | | |
| AUDIO | :x: | | |
|AUDIO_SPEAKER| :x: | | |
| AUDIO_MIC | :x: | | |
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
| IMU | :x: | | |
<!-- Autogenerated end: Dependencies -->
3 changes: 1 addition & 2 deletions bsp/esp32_p4_function_ev_board/esp32_p4_function_ev_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
.hres = BSP_LCD_V_RES,
.vres = BSP_LCD_H_RES,
.monochrome = false,
.mipi_dsi = true,
/* Rotation values must be same as used in esp_lcd for initial settings of the screen */
.rotation = {
.swap_xy = false,
Expand All @@ -365,7 +364,7 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
}
};

return lvgl_port_add_disp(&disp_cfg);
return lvgl_port_add_disp_dsi(&disp_cfg, NULL);
}

static lv_indev_t *bsp_display_indev_init(lv_display_t *disp)
Expand Down
2 changes: 1 addition & 1 deletion bsp/esp32_p4_function_ev_board/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.1.1"
version: "1.2.0"
description: Board Support Package (BSP) for ESP32-P4 Function EV Board (preview)
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_p4_function_ev_board

Expand Down
9 changes: 9 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 2.2.0

### Features
- Added RGB display support
- Added support for direct mode and full refresh mode

### Breaking changes
- Removed MIPI-DSI from display configuration structure - use `lvgl_port_add_disp_dsi` instead

## 2.1.0

### Features
Expand Down
7 changes: 6 additions & 1 deletion components/esp_lvgl_port/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ endif()

set(PORT_PATH "src/${PORT_FOLDER}")

idf_component_register(SRCS "${PORT_PATH}/esp_lvgl_port.c" "${PORT_PATH}/esp_lvgl_port_disp.c" INCLUDE_DIRS "include" REQUIRES "esp_lcd" PRIV_REQUIRES "esp_timer")
idf_component_register(
SRCS "${PORT_PATH}/esp_lvgl_port.c" "${PORT_PATH}/esp_lvgl_port_disp.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES "esp_lcd"
PRIV_REQUIRES "esp_timer")

set(ADD_SRCS "")
set(ADD_LIBS "")
Expand Down
53 changes: 32 additions & 21 deletions components/esp_lvgl_port/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Component Registry](https://components.espressif.com/components/espressif/esp_lvgl_port/badge.svg)](https://components.espressif.com/components/espressif/esp_lvgl_port)

This component helps with using LVGL with Espressif's LCD and touch drivers. It can be used with any project with LCD display.
This component helps with using LVGL with Espressif's LCD and touch drivers. It can be used with any project with LCD display.

## Features
* Initialization of the LVGL
Expand Down Expand Up @@ -42,16 +42,16 @@ This component is fully compatible with LVGL version 9. All types and functions

### Add screen

Add an LCD screen to the LVGL. It can be called multiple times for adding multiple LCD screens.
Add an LCD screen to the LVGL. It can be called multiple times for adding multiple LCD screens.

``` c
static lv_disp_t * disp_handle;

/* LCD IO */
esp_lcd_panel_io_handle_t io_handle = NULL;
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t) 1, &io_config, &io_handle));

/* LCD driver initialization */
/* LCD driver initialization */
esp_lcd_panel_handle_t lcd_panel_handle;
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &lcd_panel_handle));

Expand All @@ -77,18 +77,20 @@ Add an LCD screen to the LVGL. It can be called multiple times for adding multip
}
};
disp_handle = lvgl_port_add_disp(&disp_cfg);

/* ... the rest of the initialization ... */

/* If deinitializing LVGL port, remember to delete all displays: */
lvgl_port_remove_disp(disp_handle);
```
**Note:** DMA buffer can be used only When you use color format LV_COLOR_FORMAT_RGB565.
> [!NOTE]
> 1. For adding RGB or MIPI-DSI screen, use functions `lvgl_port_add_disp_rgb` or `lvgl_port_add_disp_dsi`.
> 2. DMA buffer can be used only when you use color format `LV_COLOR_FORMAT_RGB565`.
### Add touch input
Add touch input to the LVGL. It can be called more times for adding more touch inputs.
Add touch input to the LVGL. It can be called more times for adding more touch inputs.
``` c
/* Touch driver initialization */
...
Expand All @@ -101,7 +103,7 @@ Add touch input to the LVGL. It can be called more times for adding more touch i
.handle = tp,
};
lv_indev_t* touch_handle = lvgl_port_add_touch(&touch_cfg);
/* ... the rest of the initialization ... */
/* If deinitializing LVGL port, remember to delete all touches: */
Expand Down Expand Up @@ -146,14 +148,14 @@ Add buttons input to the LVGL. It can be called more times for adding more butto

/* Add buttons input (for selected screen) */
lv_indev_t* buttons_handle = lvgl_port_add_navigation_buttons(&btns);

/* ... the rest of the initialization ... */

/* If deinitializing LVGL port, remember to delete all buttons: */
lvgl_port_remove_navigation_buttons(buttons_handle);
```
**Note:** When you use navigation buttons for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
> [!NOTE]
> When you use navigation buttons for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
### Add encoder input
Expand Down Expand Up @@ -181,14 +183,14 @@ Add encoder input to the LVGL. It can be called more times for adding more encod
/* Add encoder input (for selected screen) */
lv_indev_t* encoder_handle = lvgl_port_add_encoder(&encoder);
/* ... the rest of the initialization ... */
/* If deinitializing LVGL port, remember to delete all encoders: */
lvgl_port_remove_encoder(encoder_handle);
```

**Note:** When you use encoder for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
> [!NOTE]
> When you use encoder for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
### Add USB HID keyboard and mouse input

Expand Down Expand Up @@ -225,7 +227,8 @@ Keyboard special behavior (when objects are in group):
- **ARROWS** or **HOME** or **END**: Move in text area
- **DEL** or **Backspace**: Remove character in textarea
**Note:** When you use keyboard for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
> [!NOTE]
> When you use keyboard for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
### LVGL API usage
Expand Down Expand Up @@ -262,7 +265,11 @@ Display rotation can be changed at runtime.
lv_disp_set_rotation(disp_handle, LV_DISP_ROT_90);
```

**Note:** During the hardware rotating, the component call [`esp_lcd`](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) API. When using software rotation, you cannot use neither `direct_mode` nor `full_refresh` in the driver. See [LVGL documentation](https://docs.lvgl.io/8.3/porting/display.html?highlight=sw_rotate) for more info.
> [!WARNING]
> Software rotation is available only in LVGL 8.
> [!NOTE]
> During the hardware rotating, the component call [`esp_lcd`](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) API. When using software rotation, you cannot use neither `direct_mode` nor `full_refresh` in the driver. See [LVGL documentation](https://docs.lvgl.io/8.3/porting/display.html?highlight=sw_rotate) for more info.
### Using PSRAM canvas

Expand All @@ -285,15 +292,15 @@ If the SRAM is insufficient, you can use the PSRAM as a canvas and use a small t
Images can be generated during build by adding these lines to end of the main CMakeLists.txt:
```
# Generate C array for each image
lvgl_port_create_c_image("images/logo.png" "images/" "ARGB8888" "NONE")
lvgl_port_create_c_image("images/logo.png" "images/" "ARGB8888" "NONE")
lvgl_port_create_c_image("images/image.png" "images/" "ARGB8888" "NONE")
# Add generated images to build
lvgl_port_add_images(${COMPONENT_LIB} "images/")
```
Usage of create C image function:
```
lvgl_port_create_c_image(input_image output_folder color_format compression)
lvgl_port_create_c_image(input_image output_folder color_format compression)
```
Available color formats:
Expand All @@ -302,7 +309,8 @@ L8,I1,I2,I4,I8,A1,A2,A4,A8,ARGB8888,XRGB8888,RGB565,RGB565A8,RGB888,TRUECOLOR,TR
Available compression:
NONE,RLE,LZ4
**Note:** Parameters `color_format` and `compression` are used only in LVGL 9.
> [!NOTE]
> Parameters `color_format` and `compression` are used only in LVGL 9.
## Power Saving
Expand All @@ -322,8 +330,11 @@ The LVGL task can sleep till these situations:
* Timeout (`task_max_sleep_ms` in configuration structure)
* User wake (by function `lvgl_port_task_wake`)
**Warning:** This feature is available from LVGL 9.
**Note:** Don't forget to set the interrupt pin in LCD touch when you set a big time for sleep in `task_max_sleep_ms`.
> [!WARNING]
> This feature is available from LVGL 9.
> [!NOTE]
> Don't forget to set the interrupt pin in LCD touch when you set a big time for sleep in `task_max_sleep_ms`.
### Stopping the timer
Expand Down
9 changes: 9 additions & 0 deletions components/esp_lvgl_port/examples/rgb_lcd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

# "Trim" the build. Include the minimal set of components, main and anything it depends on.
set(COMPONENTS main)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(rgb_lcd)
19 changes: 19 additions & 0 deletions components/esp_lvgl_port/examples/rgb_lcd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ESP LVGL RGB Screen Example

Very simple example for demonstration of initialization and usage of the `esp_lvgl_port` component with RGB LCD. This example contains four main parts:

## 1. LCD HW initialization - `app_lcd_init()`

Standard HW initialization of the LCD using [`esp_lcd`](https://github.com/espressif/esp-idf/tree/master/components/esp_lcd) component. Settings of this example are fully compatible with [ESP32-S3-LCD-EV-Board-2](https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_lcd_ev_board) board.

## 2. Touch HW initialization - `app_touch_init()`

Standard HW initialization of the LCD touch using [`esp_lcd_touch`](https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch) component. Settings of this example are fully compatible with [ESP32-S3-LCD-EV-Board-2](https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_lcd_ev_board) board.

## 3. LVGL port initialization - `app_lvgl_init()`

Initialization of the LVGL port.

## 4. LVGL objects example usage - `app_main_display()`

Very simple demonstration code of using LVGL objects after LVGL port initialization.
10 changes: 10 additions & 0 deletions components/esp_lvgl_port/examples/rgb_lcd/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "." ${LV_DEMO_DIR})

lvgl_port_create_c_image("images/esp_logo.png" "images/" "ARGB8888" "NONE")
lvgl_port_add_images(${COMPONENT_LIB} "images/")

set_source_files_properties(
PROPERTIES COMPILE_OPTIONS
"-DLV_LVGL_H_INCLUDE_SIMPLE;-Wno-format;"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencies:
idf: ">=5.0"
esp_lcd_touch_gt1151:
version: "^1"
override_path: "../../../../lcd_touch/esp_lcd_touch_gt1151/"
esp_lvgl_port:
version: "*"
override_path: "../../../"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.c
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b5f68c3

Please sign in to comment.