Skip to content

Commit 0690e53

Browse files
committed
Merge branch 'refactor/rgb_lcd_gpio_assign' into 'master'
feat(lcd): add Kconfig to assign default GPIO for RGB LCD example See merge request espressif/esp-idf!33734
2 parents 68e6939 + 63ccbd0 commit 0690e53

File tree

12 files changed

+359
-127
lines changed

12 files changed

+359
-127
lines changed

examples/peripherals/camera/camera_dsi/components/dsi_init/include/example_dsi_init_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
#endif
1414

1515
#if CONFIG_EXAMPLE_LCD_PATTERN_ILI9881C
16-
// FPS = 80000000/(40+140+40+800)/(4+16+16+1280) = 60Hz
16+
// Refresh Rate = 80000000/(40+140+40+800)/(4+16+16+1280) = 60Hz
1717
#define EXAMPLE_MIPI_DSI_DPI_CLK_MHZ 80
1818
#define EXAMPLE_MIPI_DSI_IMAGE_HSYNC 40
1919
#define EXAMPLE_MIPI_DSI_IMAGE_HBP 140
@@ -22,7 +22,7 @@ extern "C" {
2222
#define EXAMPLE_MIPI_DSI_IMAGE_VBP 16
2323
#define EXAMPLE_MIPI_DSI_IMAGE_VFP 16
2424
#elif CONFIG_EXAMPLE_LCD_PATTERN_EK79007
25-
// FPS = 48000000/(10+120+120+1024)/(1+20+10+600) = 60Hz
25+
// Refresh Rate = 48000000/(10+120+120+1024)/(1+20+10+600) = 60Hz
2626
#define EXAMPLE_MIPI_DSI_DPI_CLK_MHZ 48
2727
#define EXAMPLE_MIPI_DSI_IMAGE_HSYNC 10
2828
#define EXAMPLE_MIPI_DSI_IMAGE_HBP 120

examples/peripherals/lcd/mipi_dsi/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Run `idf.py menuconfig` and go to `Example Configuration`:
5151

5252
* Choose the LCD model in `Select MIPI LCD model` according to your board.
5353
* Choose whether to `Use DMA2D to copy draw buffer to frame buffer` asynchronously. If you choose `No`, the draw buffer will be copied to the frame buffer synchronously by CPU.
54-
* Choose if you want to `Monitor FPS by GPIO`. If you choose `Yes`, then you can attach an oscilloscope or logic analyzer to the GPIO pin to monitor the FPS of the display.
55-
Please note, the actual FPS should be **double** the square wave frequency.
54+
* Choose if you want to `Monitor Refresh Rate by GPIO`. If you choose `Yes`, then you can attach an oscilloscope or logic analyzer to the GPIO pin to monitor the Refresh Rate of the display.
55+
Please note, the actual Refresh Rate should be **double** the square wave frequency.
5656

5757
### Build and Flash
5858

examples/peripherals/lcd/mipi_dsi/main/Kconfig.projbuild

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ menu "Example Configuration"
66
Enable this option, DMA2D will be used to copy the LVGL draw buffer to the target frame buffer.
77
This can save some CPU time and improve the performance.
88

9-
config EXAMPLE_MONITOR_FPS_BY_GPIO
10-
bool "Monitor FPS by GPIO"
9+
config EXAMPLE_MONITOR_REFRESH_BY_GPIO
10+
bool "Monitor Refresh Rate by GPIO"
1111
default y
1212
help
13-
Enable this option, you can visualize the FPS by attaching a logic analyzer to a specific GPIO.
14-
The GPIO will output a square wave with the frequency of FPS/2.
13+
Enable this option, you can visualize the refresh rate by attaching a logic analyzer to a specific GPIO.
14+
The GPIO will output a square wave with the frequency equals to half of the refresh rate.
1515

1616
choice
1717
prompt "Select MIPI LCD model"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dependencies:
2-
lvgl/lvgl: "^9.0.0"
2+
lvgl/lvgl: "~9.2.0"
33
esp_lcd_ili9881c: "^1.0.0"
44
esp_lcd_ek79007: "^1.0.0"

examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static const char *TAG = "example";
2929
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3030

3131
#if CONFIG_EXAMPLE_LCD_USE_ILI9881C
32-
// FPS = 80000000/(40+140+40+800)/(4+16+16+1280) = 60Hz
32+
// Refresh Rate = 80000000/(40+140+40+800)/(4+16+16+1280) = 60Hz
3333
#define EXAMPLE_MIPI_DSI_DPI_CLK_MHZ 80
3434
#define EXAMPLE_MIPI_DSI_LCD_H_RES 800
3535
#define EXAMPLE_MIPI_DSI_LCD_V_RES 1280
@@ -40,7 +40,7 @@ static const char *TAG = "example";
4040
#define EXAMPLE_MIPI_DSI_LCD_VBP 16
4141
#define EXAMPLE_MIPI_DSI_LCD_VFP 16
4242
#elif CONFIG_EXAMPLE_LCD_USE_EK79007
43-
// FPS = 48000000/(10+120+120+1024)/(1+20+10+600) = 60Hz
43+
// Refresh Rate = 48000000/(10+120+120+1024)/(1+20+10+600) = 60Hz
4444
#define EXAMPLE_MIPI_DSI_DPI_CLK_MHZ 48
4545
#define EXAMPLE_MIPI_DSI_LCD_H_RES 1024
4646
#define EXAMPLE_MIPI_DSI_LCD_V_RES 600
@@ -67,8 +67,8 @@ static const char *TAG = "example";
6767
#define EXAMPLE_PIN_NUM_BK_LIGHT -1
6868
#define EXAMPLE_PIN_NUM_LCD_RST -1
6969

70-
#if CONFIG_EXAMPLE_MONITOR_FPS_BY_GPIO
71-
#define EXAMPLE_PIN_NUM_FPS_MONITOR 20 // Monitor the FPS by toggling the GPIO
70+
#if CONFIG_EXAMPLE_MONITOR_REFRESH_BY_GPIO
71+
#define EXAMPLE_PIN_NUM_REFRESH_MONITOR 20 // Monitor the Refresh Rate by toggling the GPIO
7272
#endif
7373

7474
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -110,6 +110,11 @@ static void example_lvgl_port_task(void *arg)
110110
_lock_acquire(&lvgl_api_lock);
111111
time_till_next_ms = lv_timer_handler();
112112
_lock_release(&lvgl_api_lock);
113+
114+
// in case of task watch dog timeout, set the minimal delay to 10ms
115+
if (time_till_next_ms < 10) {
116+
time_till_next_ms = 10;
117+
}
113118
usleep(1000 * time_till_next_ms);
114119
}
115120
}
@@ -121,12 +126,12 @@ static bool example_notify_lvgl_flush_ready(esp_lcd_panel_handle_t panel, esp_lc
121126
return false;
122127
}
123128

124-
#if CONFIG_EXAMPLE_MONITOR_FPS_BY_GPIO
125-
static bool example_monitor_fps(esp_lcd_panel_handle_t panel, esp_lcd_dpi_panel_event_data_t *edata, void *user_ctx)
129+
#if CONFIG_EXAMPLE_MONITOR_REFRESH_BY_GPIO
130+
static bool example_monitor_refresh_rate(esp_lcd_panel_handle_t panel, esp_lcd_dpi_panel_event_data_t *edata, void *user_ctx)
126131
{
127132
static int io_level = 0;
128-
// please note, the real FPS should be 2*frequency of this GPIO toggling
129-
gpio_set_level(EXAMPLE_PIN_NUM_FPS_MONITOR, io_level);
133+
// please note, the real refresh rate should be 2*frequency of this GPIO toggling
134+
gpio_set_level(EXAMPLE_PIN_NUM_REFRESH_MONITOR, io_level);
130135
io_level = !io_level;
131136
return false;
132137
}
@@ -164,21 +169,21 @@ static void example_bsp_set_lcd_backlight(uint32_t level)
164169
#endif
165170
}
166171

167-
#if CONFIG_EXAMPLE_MONITOR_FPS_BY_GPIO
168-
static void example_bsp_init_fps_monitor_io(void)
172+
#if CONFIG_EXAMPLE_MONITOR_REFRESH_BY_GPIO
173+
static void example_bsp_init_refresh_monitor_io(void)
169174
{
170175
gpio_config_t monitor_io_conf = {
171176
.mode = GPIO_MODE_OUTPUT,
172-
.pin_bit_mask = 1ULL << EXAMPLE_PIN_NUM_FPS_MONITOR,
177+
.pin_bit_mask = 1ULL << EXAMPLE_PIN_NUM_REFRESH_MONITOR,
173178
};
174179
ESP_ERROR_CHECK(gpio_config(&monitor_io_conf));
175180
}
176181
#endif
177182

178183
void app_main(void)
179184
{
180-
#if CONFIG_EXAMPLE_MONITOR_FPS_BY_GPIO
181-
example_bsp_init_fps_monitor_io();
185+
#if CONFIG_EXAMPLE_MONITOR_REFRESH_BY_GPIO
186+
example_bsp_init_refresh_monitor_io();
182187
#endif
183188

184189
example_bsp_enable_dsi_phy_power();
@@ -291,8 +296,8 @@ void app_main(void)
291296
ESP_LOGI(TAG, "Register DPI panel event callback for LVGL flush ready notification");
292297
esp_lcd_dpi_panel_event_callbacks_t cbs = {
293298
.on_color_trans_done = example_notify_lvgl_flush_ready,
294-
#if CONFIG_EXAMPLE_MONITOR_FPS_BY_GPIO
295-
.on_refresh_done = example_monitor_fps,
299+
#if CONFIG_EXAMPLE_MONITOR_REFRESH_BY_GPIO
300+
.on_refresh_done = example_monitor_refresh_rate,
296301
#endif
297302
};
298303
ESP_ERROR_CHECK(esp_lcd_dpi_panel_register_event_callbacks(mipi_dpi_panel, &cbs, display));

examples/peripherals/lcd/rgb_panel/README.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This example uses 3 kinds of **buffering mode**:
2727

2828
The connection between ESP Board and the LCD is as follows:
2929

30-
```
30+
```text
3131
ESP Board RGB Panel
3232
+-----------------------+ +-------------------+
3333
| GND +--------------+GND |
@@ -51,19 +51,15 @@ The connection between ESP Board and the LCD is as follows:
5151
+-------------------+
5252
```
5353

54-
The GPIO number used by this example can be changed in [lvgl_example_main.c](main/rgb_lcd_example_main.c).
55-
56-
Especially, please pay attention to the level used to turn on the LCD backlight, some LCD module needs a low level to turn it on, while others take a high level. You can change the backlight level macro `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL` in [lvgl_example_main.c](main/rgb_lcd_example_main.c).
57-
58-
If the RGB LCD panel only supports DE mode, you can even bypass the `HSYNC` and `VSYNC` signals, by assigning `EXAMPLE_PIN_NUM_HSYNC` and `EXAMPLE_PIN_NUM_VSYNC` with `-1`.
59-
6054
### Configure
6155

6256
Run `idf.py menuconfig` and go to `Example Configuration`:
6357

6458
1. Choose whether to `Use double Frame Buffer`
6559
2. Choose whether to `Avoid tearing effect` (available only when step `1` was chosen to false)
6660
3. Choose whether to `Use bounce buffer` (available only when step `1` was chosen to false)
61+
4. Choose the number of LCD data lines in `RGB LCD Data Lines`
62+
5. Set the GPIOs used by RGB LCD peripheral in `GPIO assignment`, e.g. the synchronization signals (HSYNC, VSYNC, DE) and the data lines
6763

6864
### Build and Flash
6965

@@ -79,29 +75,28 @@ See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/l
7975

8076
```bash
8177
...
82-
I (0) cpu_start: Starting scheduler on APP CPU.
83-
I (856) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
84-
I (856) example: Create semaphores
85-
I (866) example: Turn off LCD backlight
86-
I (866) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
87-
I (876) example: Install RGB LCD panel driver
88-
I (906) example: Register event callbacks
89-
I (906) example: Initialize RGB LCD panel
90-
I (906) example: Turn on LCD backlight
91-
I (906) example: Initialize LVGL library
92-
I (916) example: Allocate separate LVGL draw buffers from PSRAM
93-
I (916) example: Register display driver to LVGL
94-
I (926) example: Install LVGL tick timer
95-
I (926) example: Create LVGL task
96-
I (926) example: Starting LVGL task
97-
I (926) example: Display LVGL Scatter Chart
78+
I (872) main_task: Started on CPU0
79+
I (882) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
80+
I (882) main_task: Calling app_main()
81+
I (892) example: Turn off LCD backlight
82+
I (892) example: Install RGB LCD panel driver
83+
I (922) example: Initialize RGB LCD panel
84+
I (922) example: Turn on LCD backlight
85+
I (922) example: Initialize LVGL library
86+
I (932) example: Allocate LVGL draw buffers
87+
I (932) example: Register event callbacks
88+
I (932) example: Install LVGL tick timer
89+
I (942) example: Create LVGL task
90+
I (942) example: Starting LVGL task
91+
I (992) example: Display LVGL UI
92+
I (1102) main_task: Returned from app_main()
9893
...
9994
```
10095

10196
## Troubleshooting
10297

10398
* Why the LCD doesn't light up?
104-
* Check the backlight's turn-on level, and update it in `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL`
99+
* Please pay attention to the level used to turn on the LCD backlight, some LCD module needs a low level to turn it on, while others take a high level. You can change the backlight level macro `EXAMPLE_LCD_BK_LIGHT_ON_LEVEL` in [lvgl_example_main.c](main/rgb_lcd_example_main.c).
105100
* No memory for frame buffer
106101
* The frame buffer of RGB panel is located in ESP side (unlike other controller based LCDs, where the frame buffer is located in external chip). As the frame buffer usually consumes much RAM (depends on the LCD resolution and color depth), we recommend to put the frame buffer into PSRAM (like what we do in this example). However, putting frame buffer in PSRAM will limit the maximum PCLK due to the bandwidth of **SPI0**.
107102
* LCD screen drift

examples/peripherals/lcd/rgb_panel/main/Kconfig.projbuild

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,101 @@ menu "Example Configuration"
1818
help
1919
Enable this option, the example will use a pair of semaphores to avoid the tearing effect.
2020
Note, if the Double Frame Buffer is used, then we can also avoid the tearing effect without the lock.
21+
22+
choice EXAMPLE_LCD_DATA_LINES
23+
prompt "RGB LCD Data Lines"
24+
default EXAMPLE_LCD_DATA_LINES_16
25+
help
26+
Select the number of data lines of the RGB LCD.
27+
28+
config EXAMPLE_LCD_DATA_LINES_16
29+
bool "16 data lines"
30+
endchoice
31+
32+
config EXAMPLE_LCD_DATA_LINES
33+
int
34+
default 16 if EXAMPLE_LCD_DATA_LINES_16
35+
36+
menu "GPIO assignment"
37+
config EXAMPLE_LCD_VSYNC_GPIO
38+
int "VSYNC GPIO"
39+
help
40+
GPIO pin number for VSYNC signal.
41+
config EXAMPLE_LCD_HSYNC_GPIO
42+
int "HSYNC GPIO"
43+
help
44+
GPIO pin number for HSYNC signal.
45+
config EXAMPLE_LCD_DE_GPIO
46+
int "DE GPIO"
47+
help
48+
GPIO pin number for DE signal.
49+
config EXAMPLE_LCD_PCLK_GPIO
50+
int "PCLK GPIO"
51+
help
52+
GPIO pin number for PCLK signal.
53+
config EXAMPLE_LCD_DATA0_GPIO
54+
int "DATA0 GPIO"
55+
help
56+
GPIO pin number for data bus[0].
57+
config EXAMPLE_LCD_DATA1_GPIO
58+
int "DATA1 GPIO"
59+
help
60+
GPIO pin number for data bus[1].
61+
config EXAMPLE_LCD_DATA2_GPIO
62+
int "DATA2 GPIO"
63+
help
64+
GPIO pin number for data bus[2].
65+
config EXAMPLE_LCD_DATA3_GPIO
66+
int "DATA3 GPIO"
67+
help
68+
GPIO pin number for data bus[3].
69+
config EXAMPLE_LCD_DATA4_GPIO
70+
int "DATA4 GPIO"
71+
help
72+
GPIO pin number for data bus[4].
73+
config EXAMPLE_LCD_DATA5_GPIO
74+
int "DATA5 GPIO"
75+
help
76+
GPIO pin number for data bus[5].
77+
config EXAMPLE_LCD_DATA6_GPIO
78+
int "DATA6 GPIO"
79+
help
80+
GPIO pin number for data bus[6].
81+
config EXAMPLE_LCD_DATA7_GPIO
82+
int "DATA7 GPIO"
83+
help
84+
GPIO pin number for data bus[7].
85+
config EXAMPLE_LCD_DATA8_GPIO
86+
int "DATA8 GPIO"
87+
help
88+
GPIO pin number for data bus[8].
89+
config EXAMPLE_LCD_DATA9_GPIO
90+
int "DATA9 GPIO"
91+
help
92+
GPIO pin number for data bus[9].
93+
config EXAMPLE_LCD_DATA10_GPIO
94+
int "DATA10 GPIO"
95+
help
96+
GPIO pin number for data bus[10].
97+
config EXAMPLE_LCD_DATA11_GPIO
98+
int "DATA11 GPIO"
99+
help
100+
GPIO pin number for data bus[11].
101+
config EXAMPLE_LCD_DATA12_GPIO
102+
int "DATA12 GPIO"
103+
help
104+
GPIO pin number for data bus[12].
105+
config EXAMPLE_LCD_DATA13_GPIO
106+
int "DATA13 GPIO"
107+
help
108+
GPIO pin number for data bus[13].
109+
config EXAMPLE_LCD_DATA14_GPIO
110+
int "DATA14 GPIO"
111+
help
112+
GPIO pin number for data bus[14].
113+
config EXAMPLE_LCD_DATA15_GPIO
114+
int "DATA15 GPIO"
115+
help
116+
GPIO pin number for data bus[15].
117+
endmenu
21118
endmenu
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
dependencies:
2-
lvgl/lvgl: "^9.0.0"
2+
lvgl/lvgl: "~9.2.0"

0 commit comments

Comments
 (0)